Skip to content

Commit 91fb2ca

Browse files
committed
Merge pull request #179 from aoblet/dialogs_clean
Dialogs clean
2 parents 8a5241a + 340556b commit 91fb2ca

18 files changed

+813
-347
lines changed

blackMosquito.png

55 KB
Loading

buttleofx/MainWindow.qml

Lines changed: 119 additions & 169 deletions
Large diffs are not rendered by default.

buttleofx/data/buttleData.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,8 @@ def loadData(self, url='buttleofx/backup/data.bofx'):
524524
"""
525525
Loads all data from a Json file (the default Json file if no url is given)
526526
"""
527-
528-
filepath = QtCore.QUrl(url).toLocalFile()
529-
527+
Qurl = QtCore.QUrl(url)
528+
filepath = (Qurl.isLocalFile() and Qurl.toLocalFile()) or url
530529
self.newData()
531530

532531
with open(filepath, 'r') as f:
@@ -647,14 +646,21 @@ def saveData(self, url):
647646
"""
648647
Saves all data in a json file
649648
"""
649+
# If called from Python, it could be a str or a QUrl
650650
if isinstance(url, str):
651-
# If called from Python, it could be a str or a QUrl.
652-
filepath = QtCore.QUrl.fromLocalFile(url).toLocalFile()
651+
filepath = url
653652
else:
654-
filepath = QtCore.QUrl(url).toLocalFile()
653+
filepath = url.toLocalFile() if url.isLocalFile() else url.toString()
654+
655+
if filepath.endswith('buttleSave_now.bofx'):
656+
filepath = os.path.dirname(filepath)
655657

656-
if not filepath.lower().endswith(".bofx"):
657-
filepath = filepath + ".bofx"
658+
# if destination path is a folder, we create a file name containing date and time of now
659+
if os.path.isdir(filepath):
660+
filepath = os.path.join(filepath, 'buttleSave%s' % datetime.today().strftime('%m_%d_%y_%I_%M'))
661+
662+
if not filepath.lower().endswith('.bofx'):
663+
filepath += '.bofx'
658664

659665
with io.open(filepath, 'w', encoding='utf-8') as f:
660666
dictJson = {
@@ -675,8 +681,8 @@ def saveData(self, url):
675681
# Graph
676682
dictJson["graph"] = self.getGraph().object_to_dict()
677683

678-
# Graph : currentSeletedNodes
679-
for node in self.getGraph().getNodes():
684+
# Graph : currentSelectedNodes
685+
for node in self._graph.getNodes():
680686
if node.getName() in self.getCurrentSelectedNodeNames():
681687
dictJson["graph"]["currentSelectedNodes"].append(node.getName())
682688

@@ -736,6 +742,9 @@ def zoom(self, width, height, nodeWidth, zoomCoeff, graphPreviousWidth, graphPre
736742
def getButtlePath(self):
737743
return self._buttlePath
738744

745+
def getHomeDir(self):
746+
return os.path.expanduser("~")
747+
739748
def getCurrentConnectionWrapper(self):
740749
"""
741750
Returns the current currentConnectionWrapper.
@@ -1036,6 +1045,7 @@ def graphCanBeSaved(self):
10361045

10371046
# filePath
10381047
buttlePath = QtCore.pyqtProperty(str, getButtlePath, constant=True)
1048+
homeDir = QtCore.pyqtProperty(str, getHomeDir, constant=True)
10391049

10401050
# Current param, view, and selected node
10411051
currentParamNodeChanged = QtCore.pyqtSignal()
@@ -1092,12 +1102,12 @@ def graphCanBeSaved(self):
10921102
globalButtleData = ButtleData()
10931103

10941104

1095-
def _decode_dict(dict_):
1105+
def _decode_dict(_dict):
10961106
"""
10971107
This function will recursively pass in nested dicts, and will convert
10981108
all str elements into string (essential for some Tuttle functions).
10991109
"""
1100-
for key in dict_:
1101-
if isinstance(dict_[key], str):
1102-
dict_[key] = str(dict_[key])
1103-
return dict_
1110+
for key in _dict:
1111+
if isinstance(_dict[key], str):
1112+
_dict[key] = str(_dict[key])
1113+
return _dict

buttleofx/gui/browser_v2/actions/browserAction.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
from buttleofx.gui.browser_v2.actions.actionManager import globalActionManager
99
from buttleofx.gui.browser_v2.actions.actionWrapper import ActionWrapper
10-
from buttleofx.gui.browser_v2.browserModel import globalBrowserModel
1110
from buttleofx.gui.browser_v2.browserItem import BrowserItem
1211
from buttleofx.gui.browser_v2.actions.concreteActions.copy import Copy
1312
from buttleofx.gui.browser_v2.actions.concreteActions.move import Move
1413
from buttleofx.gui.browser_v2.actions.concreteActions.create import Create
1514
from buttleofx.gui.browser_v2.actions.concreteActions.delete import Delete
15+
from buttleofx.gui.browser_v2.browserModel import globalBrowserDialog, globalBrowser
1616

1717

1818
class BrowserAction(QtCore.QObject):
@@ -21,11 +21,11 @@ class BrowserAction(QtCore.QObject):
2121
"""
2222
cacheChanged = QtCore.pyqtSignal()
2323

24-
def __init__(self):
24+
def __init__(self, bModel):
2525
logging.debug('BrowserAction begin constructor')
2626
QtCore.QObject.__init__(self)
2727
self._cacheActions = None # for copy, move actions
28-
self._browserModel = globalBrowserModel
28+
self._browserModel = bModel
2929
logging.debug('BrowserAction end constructor')
3030

3131
def pushCache(self, listActions):
@@ -99,4 +99,5 @@ def handleNew(self, typeItem):
9999
isCache = QtCore.pyqtProperty(bool, isEmptyCache, notify=cacheChanged)
100100

101101

102-
globalBrowserAction = BrowserAction()
102+
globalBrowserAction = BrowserAction(globalBrowser)
103+
globalBrowserActionDialog = BrowserAction(globalBrowserDialog)

buttleofx/gui/browser_v2/browserModel.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self, path=op.expanduser("~/"), sync=False, showSeq=True, hideDotFi
4242
"""
4343
QtCore.QObject.__init__(self, parent)
4444
self._currentPath = path
45+
self._bufferBrowserItems = [] # used when recursive process: fix async signal connection when add object
4546
self._browserItems = [] # used only in python side
4647
self._browserItemsModel = QObjectListModel(self) # used for UI
4748
self._filter = filterFiles
@@ -98,6 +99,7 @@ def updateItems(self, recursivePattern):
9899
return
99100

100101
self.clearItemsSync.emit()
102+
self._bufferBrowserItems.clear()
101103
detectOption = sequenceParser.eDetectionDefaultWithDotFile
102104
if self._hideDotFiles:
103105
detectOption = sequenceParser.eDetectionDefault
@@ -146,6 +148,7 @@ def pushBrowserItems(self, allItems, toModel=True):
146148
if not self._isSync:
147149
itemToAdd.moveToThread(self.thread())
148150
self.addItemSync.emit(itemToAdd, toModel)
151+
self._bufferBrowserItems.append(itemToAdd)
149152

150153
@QtCore.pyqtSlot(object, bool)
151154
def onAddItemSync(self, bItem, toModel=True):
@@ -168,30 +171,37 @@ def onClearItemsSync(self):
168171
@QtCore.pyqtSlot(str, object)
169172
def searchRecursively(self, pattern, modelRequester):
170173
"""
171-
Process a recursive search. Disable thumbnail build for sub BrowserModel
174+
Process a recursive search. Disable thumbnail build for sub BrowserModel.
175+
176+
:param pattern: user input search pattern
177+
:param modelRequester: main model which starts the recursive search
172178
"""
173179
logging.debug("Start recursive search: %s", self._currentPath)
174180
if modelRequester.getParallelThread().isStopped():
175181
return
176182

177-
listToBrowse = self._browserItems
183+
listToBrowse = self._bufferBrowserItems
184+
# Clear on the first level
178185
if self == modelRequester:
179-
listToBrowse = self._browserItems.copy() # copy: _browserItems deleted line after
180186
modelRequester.clearItemsSync.emit()
181187

182188
for bItem in listToBrowse: # 1st pass, all files in current dir
183189
logging.debug("processing %s" % bItem.getPath())
184190
if pattern.lower() in bItem.getName().lower():
185191
bItem.moveToThread(modelRequester.thread())
192+
# Build thumbnails manually only on matching files
186193
bItem.startBuildThumbnail()
187194
modelRequester.addItemSync.emit(bItem, True)
188195

189196
for bItem in listToBrowse: # 2nd pass, recurse
190197
if not modelRequester._isSync and modelRequester.getParallelThread().isStopped():
191198
return
192199
if bItem.isFolder():
200+
# Do not compute thumbnails on all elements, but only manually on matching files.
193201
recursiveModel = BrowserModel(bItem.getPath(), True, self._showSeq, self._hideDotFiles, self._filter, buildThumbnail=False)
202+
# Browse items for this folder and fill model
194203
recursiveModel.loadData()
204+
# Launch a search on all sub directories
195205
recursiveModel.searchRecursively(pattern.lower(), modelRequester)
196206

197207
def getFilter(self):
@@ -250,7 +260,7 @@ def onSortBrowserItems(self):
250260
self._browserItems.sort(key=lambda it: (it.getType(), it.getWeight()), reverse=rev)
251261

252262
# sort by folder, file
253-
self._browserItems.sort(key=lambda it: (it.getType()))
263+
self._browserItems.sort(key=lambda it: (it.getType())) # TODO: check needed
254264

255265
def searchIndexItem(self, bItem):
256266
"""
@@ -417,4 +427,5 @@ def selectItemTo(self, index):
417427
loading = QtCore.pyqtProperty(bool, isLoading, notify=loadingChanged)
418428

419429

420-
globalBrowserModel = BrowserModel()
430+
globalBrowser = BrowserModel()
431+
globalBrowserDialog = BrowserModel()

buttleofx/gui/browser_v2/qml/Browser.qml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ Rectangle {
99
height: 600
1010
color: "#353535"
1111

12+
property alias fileWindow: fileWindow
13+
property alias navBar: navBar
14+
property bool showTab: true
15+
property variant bModel: _browser
16+
property variant bAction: _browserAction
1217
property int visitedFolderListIndex: 0
18+
1319
signal buttonCloseClicked(bool clicked)
1420
signal buttonFullscreenClicked(bool clicked)
1521

@@ -22,6 +28,13 @@ Rectangle {
2228
++ visitedFolderListIndex
2329
}
2430

31+
function popVisitedFolder(){
32+
if (visitedFolderList.count > 0 && visitedFolderListIndex > 0) {
33+
-- visitedFolderListIndex
34+
bModel.currentPath = visitedFolderList.get(visitedFolderListIndex).url
35+
}
36+
}
37+
2538
// Recently visited folder stack
2639
ListModel {
2740
id: visitedFolderList
@@ -32,9 +45,10 @@ Rectangle {
3245
spacing: 0
3346

3447
Tab {
35-
Layout.fillWidth: true
3648
id: tabBar
49+
Layout.fillWidth: true
3750
name: "Browser"
51+
visible: root.showTab
3852
onCloseClicked: root.buttonCloseClicked(true)
3953
onFullscreenClicked: root.buttonFullscreenClicked(true)
4054
}
@@ -44,20 +58,19 @@ Rectangle {
4458
Layout.fillWidth: true
4559
Layout.preferredHeight: childrenRect.height
4660

47-
property var model: _browser
61+
property var model: root.bModel
4862
property alias visitedFolderList: visitedFolderList
4963
property alias visitedFolderListIndex: root.visitedFolderListIndex
64+
5065
onPushVisitedFolder: {
5166
root.pushVisitedFolder(path)
5267
}
5368
}
5469

5570
Rectangle {
5671
id: separator
57-
5872
Layout.fillWidth: true
5973
Layout.preferredHeight: 1
60-
6174
color: "#00b2a1"
6275
}
6376

@@ -67,7 +80,8 @@ Rectangle {
6780
Layout.fillWidth: true
6881
Layout.fillHeight: true
6982

70-
property var model: _browser
83+
property var model: root.bModel
84+
property var bAction: root.bAction
7185
property alias visitedFolderList: visitedFolderList
7286
property alias visitedFolderListIndex: root.visitedFolderListIndex
7387

@@ -76,4 +90,14 @@ Rectangle {
7690
}
7791
}
7892
}
93+
94+
Keys.onPressed: {
95+
if ((event.modifiers & Qt.ControlModifier) && (event.key == Qt.Key_L)){
96+
navBar.toggleUrlEdit()
97+
}
98+
99+
if (event.key == Qt.Key_Backspace){
100+
popVisitedFolder()
101+
}
102+
}
79103
}

0 commit comments

Comments
 (0)