This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathACExplorer.py
651 lines (569 loc) · 22.7 KB
/
ACExplorer.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
"""
This is an explorer for the forge file format used in a number of Ubisoft games mainly consisting
of the Assassin's Creed franchise. This is just a UI wrapper for pyUbiForge where the heavy lifting is done.
"""
import pyUbiForge.misc
from plugins import right_click_plugins
from typing import Union, Dict, List, Tuple
from PySide2 import QtCore, QtGui, QtWidgets
import time
import os
import json
import sys
import subprocess
import re
import logging
log_file = logging.FileHandler('ACExplorer.log', 'w')
log_file.setFormatter(
logging.Formatter('[%(levelname)s]:[%(module)s]:[%(message)s]')
)
console = logging.StreamHandler()
console.setFormatter(
logging.Formatter('%(message)s')
)
logging.basicConfig(
level=logging.INFO,
handlers=[
log_file,
console
]
)
class App(QtWidgets.QApplication):
"""This is the main application that contains the file tree."""
def __init__(self):
QtWidgets.QApplication.__init__(self)
# logging.info('Building GUI Window')
# load the style
self.icons = {}
# set up main window
self.main_window = QtWidgets.QMainWindow()
self.main_window.setObjectName("MainWindow")
self.main_window.setWindowIcon(QtGui.QIcon('icon.ico'))
self.main_window.resize(809, 698)
self.central_widget = QtWidgets.QWidget(self.main_window)
self.central_widget.setObjectName("centralwidget")
self.main_window.setCentralWidget(self.central_widget)
self.vertical_layout = QtWidgets.QVBoxLayout(self.central_widget)
self.vertical_layout.setObjectName("verticalLayout")
self.horizontal_layout = QtWidgets.QHBoxLayout()
self.horizontal_layout.setObjectName("horizontal_layout")
self.vertical_layout.addLayout(self.horizontal_layout)
# drop down box to select the game
self.game_select = QtWidgets.QComboBox()
self.game_select.setObjectName("game_select")
self.game_select.addItems(pyUbiForge.game_identifiers())
self.horizontal_layout.addWidget(self.game_select)
# search box
self.search_box = QtWidgets.QLineEdit(placeholderText='Enter a search term.')
self.search_box.setClearButtonEnabled(True)
self.search_box.setObjectName("search_box")
self.search_box.textChanged.connect(self.search)
self.horizontal_layout.addWidget(self.search_box)
self.match_case = QtWidgets.QCheckBox('Match Case')
self.match_case.stateChanged.connect(self.search)
self.horizontal_layout.addWidget(self.match_case)
self.regex = QtWidgets.QCheckBox('Regex')
self.regex.stateChanged.connect(self.regex_changed)
self.horizontal_layout.addWidget(self.regex)
self.search_time = time.time() + 2**30
self.search_update = QtCore.QTimer()
self.search_update.setInterval(150)
self.search_update.timeout.connect(self.search_)
self.search_update.start()
# file tree view
self.file_view = TreeView(self.central_widget, self.icons)
self.file_view.setObjectName("file_view")
self.file_view.setHeaderHidden(True)
self.vertical_layout.addWidget(self.file_view)
default_options = {
"style": 'QDarkStyle'
}
try:
with open('config.json') as config:
self._options = json.load(config)
for key, val in default_options:
if key not in self._options:
self._options[key] = val
except:
self._options = default_options
# menu options
self.menubar = QtWidgets.QMenuBar()
self.menubar.setGeometry(QtCore.QRect(0, 0, 809, 26))
self.menubar.setObjectName("menubar")
self.main_window.setMenuBar(self.menubar)
self.menubar.addAction(
'Games',
lambda: self._show_games()
)
self.menubar.addAction(
'Options',
lambda: self._show_options()
)
self.menubar.addAction(
'Donate',
lambda: self._donate()
)
# statusbar
self.statusbar = QtWidgets.QStatusBar()
self.statusbar.setObjectName("statusbar")
self.main_window.setStatusBar(self.statusbar)
status_bar_handler = logging.StreamHandler(
StatusBar(self, self.statusbar)
)
status_bar_handler.setFormatter(
logging.Formatter('%(message)s')
)
logging.getLogger('').addHandler(
status_bar_handler
)
self.load_style(self._options['style'])
self.translate_()
# QtCore.QMetaObject.connectSlotsByName(self.main_window)
self.main_window.show()
self.load_game(self.game_select.currentText())
self.exec_()
def translate_(self):
self.main_window.setWindowTitle(QtWidgets.QApplication.translate("MainWindow", "ACExplorer"))
def load_game(self, game_identifier: str):
"""Tell pyUbiForge to load the new game and populate the file tree with the data it gives."""
self.processEvents()
for _ in pyUbiForge.load_game(game_identifier):
self.processEvents()
self.file_view.load_game(game_identifier)
for forge_file_name, forge_file in pyUbiForge.forge_files.items():
self.file_view.insert(forge_file_name, forge_file_name, icon=self.icons.get('unknown_file', None))
for forge_file_name, forge_file in pyUbiForge.forge_files.items():
logging.info(f'Populating File Tree For {forge_file_name}')
for datafile_id, datafile in sorted(forge_file.datafiles.items(), key=lambda v: v[1].file_name.lower()):
self.file_view.insert(datafile.file_name, forge_file_name, datafile_id, icon=self.icons.get(datafile.file_type, None))
self.processEvents()
self.search()
logging.info('Finished Populating File Tree')
def save(self):
pyUbiForge.save()
with open('config.json', 'w') as config:
json.dump(self._options, config)
def search(self):
self.search_time = time.time() + 0.15
def search_(self):
if self.search_time < time.time():
self.search_time = time.time() + 2**30
self.file_view.search(self.search_box.text(), self.match_case.isChecked(), self.regex.isChecked())
def regex_changed(self):
if self.regex.isChecked():
self.match_case.setEnabled(False)
else:
self.match_case.setEnabled(True)
self.search()
def load_style(self, style_name: str):
with open(f'./resources/themes/{style_name}/style.qss') as style:
self.setStyleSheet(style.read())
for icon in os.listdir('resources/icons'):
self.icons[os.path.splitext(icon)[0]] = QtGui.QIcon(f'resources/icons/{icon}')
if os.path.isdir(f'resources/themes/{style_name}/icons'):
for icon in os.listdir(f'resources/themes/{style_name}/icons'):
self.icons[os.path.splitext(icon)[0]] = QtGui.QIcon(f'resources/themes/{style_name}/icons/{icon}')
self._options['style'] = style_name
def _show_games(self):
current_game_path = pyUbiForge.CONFIG.game_folder(self.game_select.currentText())
screen = PluginOptionsScreen(
'Game Paths',
{
game_identifier: {
'type': 'dir_select',
'default': game_path
} for game_identifier, game_path in pyUbiForge.CONFIG.get('gameFolders', {}).items()
}
)
if not screen.escape:
pyUbiForge.CONFIG['gameFolders'] = screen.options
if pyUbiForge.CONFIG.game_folder(self.game_select.currentText()) != current_game_path:
self.load_game(self.game_select.currentText())
def _show_options(self):
screen = PluginOptionsScreen(
'Options',
{
'Missing Texture Path': {
'type': 'file_select',
'default': pyUbiForge.CONFIG.get('missingNo', 'resources/missingNo.png')
},
'Default Output Folder': {
'type': 'dir_select',
'default': pyUbiForge.CONFIG.get('dumpFolder', 'output')
},
'Log File': {
'type': 'file_select',
'default': pyUbiForge.CONFIG.get('logFile', 'ACExplorer.log')
},
'Temporary Files Memory Buffer (MB)': {
'type': 'int_entry',
'default': pyUbiForge.CONFIG.get('tempFilesMaxMemoryMB', 2048),
"min": 50
},
'Style': {
'type': "select",
"options": [
theme for theme in os.listdir('./resources/themes') if os.path.isdir(f'./resources/themes/{theme}') and os.path.isfile(f'./resources/themes/{theme}/style.qss')
]
}
}
)
options = screen.options
if not screen.escape:
pyUbiForge.CONFIG['missingNo'] = options['Missing Texture Path']
pyUbiForge.CONFIG['dumpFolder'] = options['Default Output Folder']
pyUbiForge.CONFIG['logFile'] = options['Log File']
pyUbiForge.CONFIG['tempFilesMaxMemoryMB'] = options['Temporary Files Memory Buffer (MB)']
if self._options['style'] != options['Style']:
self._options['style'] = options['Style']
self.load_style(self._options['style'])
@staticmethod
def _donate():
if sys.platform == 'win32':
os.startfile('https://www.paypal.me/gentlegiantJGC')
elif sys.platform == 'darwin':
subprocess.Popen(['open', 'https://www.paypal.me/gentlegiantJGC'])
else:
try:
subprocess.Popen(['xdg-open', 'https://www.paypal.me/gentlegiantJGC'])
except OSError:
pass
class StatusBar:
def __init__(self, parent, statusbar):
self.parent = parent
self.statusbar = statusbar
def write(self, msg):
if msg != '\n':
self.statusbar.showMessage(msg)
class TreeView(QtWidgets.QTreeWidget):
"""This is the file tree used in the main application.
Wraps QTreeWidget and adds search functionality and a context menu
"""
def __init__(self, parent: QtWidgets.QWidget, icons: Dict[str, QtGui.QIcon]):
QtWidgets.QTreeWidget.__init__(self, parent)
self.icons = icons
self._entries: Dict[Tuple[Union[None, str], Union[None, int], Union[None, int]], TreeViewEntry] = {}
self._search: Dict[str, List[TreeViewEntry]] = {}
self._game_identifier = None
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.open_context_menu)
def load_game(self, game_identifier: str):
self._entries.clear()
self._search.clear()
self.clear()
self._game_identifier = game_identifier
self.insert(game_identifier, icon=self.icons['directory'])
def search(self, search_string: str, match_case: bool, regex: bool) -> None:
if search_string == '':
for entry in self._entries.values():
entry.setHidden(False)
entry.children_shown = True
else:
for entry in self._entries.values():
entry.setHidden(True)
entry.children_shown = False
if regex:
regex_search = re.compile(search_string)
for entry_name in self._search.keys():
if (regex and regex_search.search(entry_name))\
or (
not regex and (
(match_case and search_string in entry_name)
or
(not match_case and search_string.lower() in entry_name.lower())
)
):
for entry in self._search[entry_name]:
entry.recursively_unhide_children()
entry.recursively_unhide_parents()
def insert(self, entry_name: str, forge_file_name: str = None, datafile_id: int = None, file_id: int = None, icon: QtGui.QIcon = None) -> None:
if forge_file_name is not None:
if datafile_id is not None:
if file_id is not None: # the fact that the ends of these align makes me very happy
parent = self._entries[(forge_file_name, datafile_id, None)]
else:
parent = self._entries[(forge_file_name, None, None)]
else:
parent = self._entries[(None, None, None)]
entry = TreeViewEntry(parent, entry_name, forge_file_name, datafile_id, file_id, icon=icon)
parent.addChild(entry)
else:
entry = TreeViewEntry(self, entry_name, icon=icon)
self._entries[(forge_file_name, datafile_id, file_id)] = entry
if entry_name not in self._search:
self._search[entry_name] = []
self._search[entry_name].append(entry)
def populate_tree(self):
"""A helper function to populate files in the file view."""
for forge_file_name, forge_file in pyUbiForge.forge_files.items():
for datafile_id in forge_file.new_datafiles:
for file_id, file_name in sorted(forge_file.datafiles[datafile_id].files.items(), key=lambda v: v[1].lower()):
self.insert(
file_name,
forge_file_name,
datafile_id,
file_id,
icon=self.icons.get(
pyUbiForge.temp_files(file_id, forge_file_name, datafile_id).file_type,
None
)
)
forge_file.new_datafiles.clear()
def mousePressEvent(self, event: QtGui.QMouseEvent):
entry: TreeViewEntry = self.itemAt(event.pos())
if entry is not None and entry.depth == 3 and entry.childCount() == 0:
forge_file_name, datafile_id = entry.forge_file_name, entry.datafile_id
pyUbiForge.forge_files[forge_file_name].decompress_datafile(datafile_id)
self.populate_tree()
QtWidgets.QTreeWidget.mousePressEvent(self, event)
def open_context_menu(self, position: QtCore.QPoint):
entry: TreeViewEntry = self.itemAt(position)
if entry is not None:
unique_identifier = (None, entry.forge_file_name, entry.datafile_id, entry.file_id)[entry.depth-1]
plugin_names, file_id = right_click_plugins.query(entry.depth, unique_identifier, entry.forge_file_name, entry.datafile_id)
if len(plugin_names) > 0:
menu = ContextMenu(self.icons, plugin_names, file_id, entry.forge_file_name, entry.datafile_id)
menu.exec_(self.viewport().mapToGlobal(position))
self.populate_tree()
class TreeViewEntry(QtWidgets.QTreeWidgetItem):
"""Individual entries in the file tree.
Wraps QTreeWidgetItem and saves more data related to each entry
"""
def __init__(self, tree_view: Union[TreeView, 'TreeViewEntry'], entry_name: str, forge_file_name: str = None, datafile_id: int = None, file_id: int = None, icon: QtGui.QIcon = None):
QtWidgets.QTreeWidgetItem.__init__(self, tree_view, [entry_name])
if icon is not None:
self.setIcon(0, icon)
self._entry_name = entry_name
self._forge_file_name = forge_file_name
self._datafile_id = datafile_id
self._file_id = file_id
self._dev_search = None
self._depth = None
self.children_shown = True
@property
def entry_name(self) -> str:
return self._entry_name
@property
def forge_file_name(self) -> Union[str, None]:
return self._forge_file_name
@property
def datafile_id(self) -> Union[int, None]:
return self._datafile_id
@property
def file_id(self) -> Union[int, None]:
return self._file_id
@property
def dev_search(self) -> List[str]:
if self._dev_search is None:
self._dev_search = [f'{attr:016X}' for attr in [self.datafile_id, self.file_id] if attr is not None]
self._dev_search += [''.join(attr[n:n + 2] for n in reversed(range(0, 16, 2))) for attr in self._dev_search]
return self._dev_search
@property
def depth(self) -> int:
if self._depth is None:
if self.forge_file_name is not None:
if self.datafile_id is not None:
if self.file_id is not None:
self._depth = 4
else:
self._depth = 3
else:
self._depth = 2
else:
self._depth = 1
return self._depth
def search(self, search_string: str) -> bool:
if search_string == '' or any(search_string in attr for attr in [self._entry_name, self._forge_file_name] if attr is not None):
# if the string is empty or matches one of the parameters unhide self and children.
self.recursively_unhide_children()
return True
elif pyUbiForge.CONFIG.get('dev', False) and any(search_string.upper() in attr for attr in self.dev_search):
# if in dev mode and matches one of the file ids unhide self and children
self.recursively_unhide_children()
return True
else:
shown = any([self.child(index).search(search_string) for index in range(self.childCount())])
self.setHidden(not shown)
return shown
def recursively_unhide_children(self):
if not self.children_shown:
self.children_shown = True
self.setHidden(False)
for index in range(self.childCount()):
self.child(index).recursively_unhide_children()
def recursively_unhide_parents(self):
parent = self.parent()
if parent is not None:
parent.setHidden(False)
parent.recursively_unhide_parents()
class ContextMenu(QtWidgets.QMenu):
"""Context menu for use upon right click of an item in the file tree to access the plugin system."""
def __init__(self: pyUbiForge, icons: Dict[str, QtGui.QIcon], plugin_names: List[str], file_id: Union[str, int], forge_file_name: Union[None, str], datafile_id: Union[None, int]):
QtWidgets.QMenu.__init__(self)
self.icons = icons
for plugin_name in sorted(plugin_names):
self.add_command(plugin_name, file_id, forge_file_name, datafile_id)
def add_command(self, plugin_name: str, file_id: Union[str, int], forge_file_name: Union[None, str] = None, datafile_id: Union[None, int] = None):
"""Workaround for plugin in post method getting overwritten which lead to all options calling the last plugin."""
if right_click_plugins.get_screen_options(plugin_name, []) is None:
self.addAction(
plugin_name,
lambda: self.run_plugin(plugin_name, file_id, forge_file_name, datafile_id)
)
else:
self.addAction(
self.icons.get('context_right_click_icon', None),
plugin_name,
lambda: self.run_plugin(plugin_name, file_id, forge_file_name, datafile_id)
)
def run_plugin(self, plugin_name: str, file_id: Union[str, int], forge_file_name: Union[None, str] = None, datafile_id: Union[None, int] = None) -> None:
"""Method to run and handle plugin options."""
right_click_plugins.run(plugin_name, file_id, forge_file_name, datafile_id)
def mousePressEvent(self, event: QtGui.QMouseEvent):
if event.button() == QtCore.Qt.RightButton:
entry = self.actionAt(event.pos())
if entry is not None:
plugin_name = entry.text()
options = []
escape = False
new_screen = right_click_plugins.get_screen_options(plugin_name, options)
while new_screen is not None and not escape:
# show screen
screen = PluginOptionsScreen(plugin_name, new_screen)
escape = screen.escape
if not escape:
# pull options from screen
options.append(screen.options)
new_screen = right_click_plugins.get_screen_options(plugin_name, options)
if not escape:
entry.trigger()
else:
QtWidgets.QMenu.mousePressEvent(self, event)
elif event.button() == QtCore.Qt.LeftButton:
QtWidgets.QMenu.mousePressEvent(self, event)
class PluginOptionsScreen(QtWidgets.QDialog):
def __init__(self: pyUbiForge, plugin_name: str, screen: Dict[str, dict]):
QtWidgets.QDialog.__init__(self)
self.setModal(True)
self._screen = screen
self._options = {}
self._labels = []
self._escape = False
self.setWindowTitle(plugin_name)
self.setWindowIcon(QtGui.QIcon('icon.ico'))
self._vertical_layout = QtWidgets.QVBoxLayout()
self._vertical_layout.setObjectName("verticalLayout")
self.setLayout(self._vertical_layout)
self._horizontal_layouts = []
for option_name, option in screen.items():
option_type = option.get('type', None)
self._horizontal_layouts.append(QtWidgets.QHBoxLayout())
self._vertical_layout.addLayout(self._horizontal_layouts[-1])
self._labels.append(QtWidgets.QLabel())
self._labels[-1].setText(option_name)
self._horizontal_layouts[-1].addWidget(self._labels[-1])
if option_type == 'select':
selection = [str(op) for op in option.get('options', [])]
self._options[option_name] = QtWidgets.QComboBox()
self._options[option_name].addItems(selection)
self._horizontal_layouts[-1].addWidget(self._options[option_name])
elif option_type == 'str_entry':
self._options[option_name] = QtWidgets.QLineEdit()
self._options[option_name].setText(option.get('default', ''))
self._horizontal_layouts[-1].addWidget(self._options[option_name])
elif option_type == 'int_entry':
self._options[option_name] = QtWidgets.QSpinBox()
val = option.get('default', 0)
if not isinstance(val, int):
val = 0
if isinstance(option.get('min', None), int):
self._options[option_name].setMinimum(option.get('min'))
else:
self._options[option_name].setMinimum(-999999999)
if isinstance(option.get('max', None), int):
self._options[option_name].setMaximum(option.get('max'))
else:
self._options[option_name].setMaximum(999999999)
self._options[option_name].setValue(val)
self._horizontal_layouts[-1].addWidget(self._options[option_name])
elif option_type == 'float_entry':
self._options[option_name] = QtWidgets.QDoubleSpinBox()
self._options[option_name].setDecimals(10)
val = option.get('default', 0.0)
if isinstance(val, int):
val = float(val)
elif not isinstance(val, float):
val = 0.0
if isinstance(option.get('min', None), (int, float)):
self._options[option_name].setMinimum(float(option.get('min')))
else:
self._options[option_name].setMinimum(float('-Inf'))
if isinstance(option.get('max', None), (int, float)):
self._options[option_name].setMaximum(float(option.get('max')))
else:
self._options[option_name].setMaximum(float('Inf'))
self._options[option_name].setValue(val)
self._horizontal_layouts[-1].addWidget(self._options[option_name])
elif option_name == 'check_box':
self._options[option_name] = QtWidgets.QCheckBox()
self._options[option_name].setChecked(option.get('default', True))
self._horizontal_layouts[-1].addWidget(self._options[option_name])
elif option_type == 'dir_select':
self.create_dialog_button(option_name, option, 'dir')
elif option_type == 'file_select':
self.create_dialog_button(option_name, option, 'file')
self._horizontal_layouts.append(QtWidgets.QHBoxLayout())
self._vertical_layout.addLayout(self._horizontal_layouts[-1])
self._okay_button = QtWidgets.QPushButton('OK')
self._okay_button.clicked.connect(lambda: self.done(1))
self._cancel_button = QtWidgets.QPushButton('Cancel')
self._cancel_button.clicked.connect(self.reject)
self._horizontal_layouts[-1].addWidget(self._okay_button)
self._horizontal_layouts[-1].addWidget(self._cancel_button)
self.show()
self.exec_()
def reject(self):
self._escape = True
QtWidgets.QDialog.reject(self)
@property
def options(self) -> Dict[str, Union[str, int, float]]:
options = {}
for option_name, var in self._options.items():
if isinstance(var, QtWidgets.QComboBox):
options[option_name] = self._screen[option_name]['options'][var.currentIndex()]
elif isinstance(var, QtWidgets.QLineEdit):
options[option_name] = var.text()
elif isinstance(var, QtWidgets.QSpinBox):
options[option_name] = var.value()
elif isinstance(var, QtWidgets.QDoubleSpinBox):
options[option_name] = var.value()
elif isinstance(var, QtWidgets.QCheckBox):
options[option_name] = var.isChecked()
elif isinstance(var, QtWidgets.QPushButton):
options[option_name] = var.text()
return options
@property
def escape(self) -> bool:
return self._escape
def create_dialog_button(self, option_name: str, option: dict, mode: str):
self._options[option_name] = QtWidgets.QPushButton()
if "default" in option and isinstance(option["default"], str):
path = option["default"]
else:
path = self._pyUbiForge.CONFIG.get("dumpFolder")
self._options[option_name].setText(path)
self._options[option_name].clicked.connect(lambda: self.open_dialog(option_name, mode, path))
self._horizontal_layouts[-1].addWidget(self._options[option_name])
def open_dialog(self, option_name: str, mode: str, path: str):
text = None
if mode == 'dir':
text = QtWidgets.QFileDialog.getExistingDirectory(self, "Open Directory", path)
elif mode == 'file':
text = QtWidgets.QFileDialog.getOpenFileName(self, "Open File", path)
if text != '':
text = text[0]
if text != '':
self._options[option_name].setText(text)
if __name__ == "__main__":
app = App()
app.save()