-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprojectbrowser.py
More file actions
69 lines (56 loc) · 2.1 KB
/
projectbrowser.py
File metadata and controls
69 lines (56 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
import os
from qtpy.QtCore import QObject, Property, Signal, QUrl, QDir, Slot
class ProjectBrowser(QObject):
projectPathChanged = Signal(QUrl)
qmlFilesChanged = Signal()
extensionsChanged = Signal()
def __init__(self, parent=None):
super(ProjectBrowser, self).__init__(parent)
path = os.path.dirname(os.path.abspath(__file__))
self._project_path = QUrl.fromLocalFile(
os.path.realpath(os.path.join(path, '..'))
)
self._qml_files = []
self._extensions = []
self.projectPathChanged.connect(self._update_files)
self.extensionsChanged.connect(self._update_files)
@Property(QUrl, notify=projectPathChanged)
def projectPath(self):
return self._project_path
@projectPath.setter
def projectPath(self, value):
if self._project_path == value:
return
self._project_path = value
self.projectPathChanged.emit(value)
@Property('QStringList', notify=qmlFilesChanged)
def qmlFiles(self):
return self._qml_files
@Property('QStringList', notify=extensionsChanged)
def extensions(self):
return self._extensions
@extensions.setter
def extensions(self, value):
if self._extensions == value:
return
self._extensions = value
self.extensionsChanged.emit()
@Slot()
def update(self):
self._update_files()
def _update_files(self):
file_list = []
root = QDir.toNativeSeparators(self._project_path.toLocalFile())
for subdir, dirs, files in os.walk(root):
for f in files:
path = os.path.join(root, subdir, f)
_, ext = os.path.splitext(path)
if ext[1:].lower() in self._extensions:
# convert file separators to consistent style
url = QUrl.fromLocalFile(path).toLocalFile()
if not url.startswith('/'):
url = '/' + url
file_list.append(url)
self._qml_files = file_list
self.qmlFilesChanged.emit()