| 76 | return [f for f in os.listdir(bundle_dir) if os.path.isfile(os.path.join(bundle_dir, f))] |
| 77 | |
| 78 | class BundleComboBox(QComboBox): |
| 79 | def __init__(self, parent=None): |
| 80 | super().__init__(parent) |
| 81 | self.setView(QListView()) |
| 82 | self.setItemDelegate(QStyledItemDelegate()) |
| 83 | self.refresh() |
| 84 | |
| 85 | def refresh(self): |
| 86 | self.clear() |
| 87 | bundle_files = list_bundle_files() |
| 88 | bundle_icon = QIcon(os.path.join('gui', 'icons', 'bundle.ico')) if os.path.exists(os.path.join('gui', 'icons', 'bundle.ico')) else QIcon() |
| 89 | for f in bundle_files: |
| 90 | file_path = os.path.abspath(os.path.join('bundle', f)) |
| 91 | self.addItem(bundle_icon, f, file_path) |
| 92 | if self.count() > 0 and self.currentIndex() == -1: |
| 93 | self.setCurrentIndex(0) |
| 94 | |
| 95 | def choose_file(self, parent=None): |
| 96 | path, _ = QFileDialog.getOpenFileName(parent, 'Select File to Bundle', '.', 'All Files (*)') |
| 97 | if path: |
| 98 | # Ensure absolute path |
| 99 | path = os.path.abspath(path) |
| 100 | display_name = os.path.basename(path) |
| 101 | bundle_icon = QIcon(os.path.join('gui', 'icons', 'bundle.ico')) if os.path.exists(os.path.join('gui', 'icons', 'bundle.ico')) else QIcon() |
| 102 | for i in range(self.count()): |
| 103 | if self.itemData(i) == path: |
| 104 | self.setCurrentIndex(i) |
| 105 | return |
| 106 | self.addItem(bundle_icon, display_name, path) |
| 107 | self.setCurrentIndex(self.count() - 1) |