Skip to content

Commit

Permalink
Added separate button for folders
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrumpis committed Nov 15, 2023
1 parent 9599a2a commit 409cd4a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
32 changes: 23 additions & 9 deletions main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,36 @@
<item>
<layout class="QHBoxLayout" name="itemButtonLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="toolTip">
<string>Add packed lens files (.lns) files or unpacked lens folders</string>
</property>
<property name="text">
<string>Add Lens Files/Folder</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="addFilesButton">
<property name="toolTip">
<string>Add packed lens files (.lns) files</string>
</property>
<property name="text">
<string>Add Files</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addFolderButton">
<property name="toolTip">
<string>Add unpacked lens folder</string>
</property>
<property name="text">
<string>Add Folder</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="toolTip">
<string>Remove the selected files and folders</string>
</property>
<property name="text">
<string>Remove Selected Items</string>
<string>Remove Selected</string>
</property>
</widget>
</item>
Expand Down
14 changes: 11 additions & 3 deletions src/qt/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def __init__(self, parent=None):

uic.loadUi('main.ui', self)

self.addButton.clicked.connect(self.onAddButtonClicked)
self.addFilesButton.clicked.connect(self.onAddFilesButtonClicked)
self.addFolderButton.clicked.connect(self.onAddFolderButtonClicked)
self.removeButton.clicked.connect(self.onRemoveButtonClicked)
self.clearButton.clicked.connect(self.onClearButtonClicked)
self.unpackButton.clicked.connect(self.onUnpackButtonClicked)
Expand All @@ -29,16 +30,23 @@ def __init__(self, parent=None):

self.toggleButtons()

def onAddButtonClicked(self):
def onAddFilesButtonClicked(self):
options = QFileDialog.Options()
options |= QFileDialog.ReadOnly | QFileDialog.ExistingFile
files, _ = QFileDialog.getOpenFileNames(self, "Select lens files and folder", "",
files, _ = QFileDialog.getOpenFileNames(self, "Select lens files", "",
"Lens files (*.lns);;All Files (*)", options=options)
if not files:
return

self.treeWidget.addFiles(files)

def onAddFolderButtonClicked(self):
folder = QFileDialog.getExistingDirectory(self, "Select folder", "")
if not folder:
return

self.treeWidget.addFolders(folder)

def onRemoveButtonClicked(self):
selectedFiles = self.treeWidget.selectedFiles()
self.treeWidget.removeFiles(selectedFiles)
Expand Down
12 changes: 12 additions & 0 deletions src/qt/my_tree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def selectedFiles(self):
return [os.path.normpath(item.text(0)) for item in self.selectedItems()]

def addFiles(self, files):
if not isinstance(files, list):
files = [files]

for file in files:
file = os.path.normpath(file)

Expand All @@ -54,7 +57,13 @@ def addFiles(self, files):

self.filesChanged.emit()

def addFolders(self, folders):
return self.addFiles(folders)

def removeFiles(self, files):
if not isinstance(files, list):
files = [files]

for file in files:
file = os.path.normpath(file)
item = self._files.get(file) or self._folders.get(file)
Expand All @@ -67,3 +76,6 @@ def removeFiles(self, files):
self._folders.pop(file, None)

self.filesChanged.emit()

def removeFolders(self, folders):
return self.removeFiles(folders)

0 comments on commit 409cd4a

Please sign in to comment.