def __init__(self, task=None, when=None, command=None): title = "Post command editor" if when == TaskCommand.WHEN_POST else "Pre command editor" BaseWidget.__init__(self, title, parent_win=task) self.command = command self.task = task self.when = when self.set_margin(5) self._type = ControlCombo('Type of command', changed_event=self.__type_changed_evt) self._cancelbtn = ControlButton('Cancel', default=self.__cancel_evt) self._okbtn = ControlButton('Ok', default=self.__ok_evt) self._command = ControlText('External command', visible=False) self._filesbrowser = ControlTreeView('Files browser') self._type.add_item('Execute a gui script', 'script') self._type.add_item('Execute a external command', 'external') self.formset = [ '_type', '_command', '_filesbrowser', (' ', '_cancelbtn', '_okbtn'), ' ' ] root_path = os.path.abspath(task.path if task else '/') self.syspath_model = QFileSystemModel(self) self.syspath_model.setRootPath(root_path) self.syspath_model.setNameFilters(['*.py']) self.syspath_model.setNameFilterDisables(False) self._filesbrowser.value = self.syspath_model root_index = self.syspath_model.index(root_path) self._filesbrowser.setRootIndex(root_index) for i in range(1, 4): self._filesbrowser.hideColumn(i)
def value(self, value): ControlBase.value.fset(self, value) model = QFileSystemModel(parent=None) self._form.setModel(model) model.setRootPath(QtCore.QDir.currentPath()) self._form.setRootIndex(model.setRootPath(value)) self._form.setIconSize(QtCore.QSize(32, 32))
def __init__(self, *args, **kwargs): global games_json super().__init__("NSScreenshotMaker") self._tmpinputfolder = tempfile.mkdtemp() self._settingsbutton = ControlButton("⚙️") self._settingsbutton.value = self.openSettings self._runbutton = ControlButton("Go!") self._runbutton.value = self.go self._combo = ControlCombo( helptext="The game the Switch will think the screenshot is from") self.gameslist = games_json for k in self.gameslist: self._combo.add_item(k, self.gameslist[k]) self._combo.add_item("Custom", "Custom") self._combolabel = ControlLabel( "Game ID", helptext="The game the Switch will think the screenshot is from") self._imagelist = ControlFilesTree() self._imagelist._form.setDragEnabled(True) self._imagelist._form.setAcceptDrops(True) self._imagelist._form.setDropIndicatorShown(True) self._imagelist._form.dropEvent = self.dropEvent model = QFileSystemModel(parent=None) model.setReadOnly(False) self._imagelist._form.setModel(model) model.setRootPath(QtCore.QDir.currentPath()) self._imagelist._form.setRootIndex( model.setRootPath(self._tmpinputfolder)) self._imagelist._form.setIconSize(QtCore.QSize(32, 32)) self.formset = [("_combolabel", "_combo", "_settingsbutton"), "_imagelist", "_runbutton"] self._firstrunpanel = ControlDockWidget() self._firstrunpanel.hide() self._firstrunwin = FirstRun() if not os.path.isfile( appdirs.AppDirs("NSScreenshotMaker", "").user_data_dir + "/settings.json"): self._firstrunwin.parent = self self._firstrunpanel.value = self._firstrunwin self._firstrunpanel.show() self._firstrunwin.show() self._settingspanel = ControlDockWidget() self._settingspanel.hide() self._settingswin = SettingsWindow()
def __init__(self, task): BaseWidget.__init__(self, task.name if task else '') self.set_margin(5) self.task = task self._taskselected = False self._fileselected = None root_path = os.path.abspath(task.path) syspath_model = QFileSystemModel(self) syspath_model.setRootPath(root_path) syspath_model.setNameFilters(['*.py']) syspath_model.setNameFilterDisables(False) self.syspath_model = syspath_model self._browser = ControlTreeView('Files browser', default=syspath_model) self._code = ControlCodeEditor( changed_event=self.__code_changed_evt, discard_event=self.__code_discard_evt ) self._browser.setSortingEnabled(True) self.formset = [vsplitter('_browser', '||', '_code')] for i in range(1, 4): self._browser.hideColumn(i) self._browser.item_selection_changed_event = self.__item_selection_changed_evt self.refresh_directory() self.select_file(task.filepath) self._browser.add_popup_menu_option('New module', self.__create_module_evt) self._browser.add_popup_menu_option('New module folder', self.__create_submodule_evt) self._browser.add_popup_menu_option('-') self._browser.add_popup_menu_option('Rename', self.__rename_evt) self._browser.add_popup_menu_option('Delete', self.__delete_evt)
class CommandEditor(BaseWidget): def __init__(self, task=None, when=None, command=None): title = "Post command editor" if when == TaskCommand.WHEN_POST else "Pre command editor" BaseWidget.__init__(self, title, parent_win=task) self.command = command self.task = task self.when = when self.set_margin(5) self._type = ControlCombo('Type of command', changed_event=self.__type_changed_evt) self._cancelbtn = ControlButton('Cancel', default=self.__cancel_evt) self._okbtn = ControlButton('Ok', default=self.__ok_evt) self._command = ControlText('External command', visible=False) self._filesbrowser = ControlTreeView('Files browser') self._type.add_item('Execute a gui script', 'script') self._type.add_item('Execute a external command', 'external') self.formset = [ '_type', '_command', '_filesbrowser', (' ', '_cancelbtn', '_okbtn'), ' ' ] root_path = os.path.abspath(task.path if task else '/') self.syspath_model = QFileSystemModel(self) self.syspath_model.setRootPath(root_path) self.syspath_model.setNameFilters(['*.py']) self.syspath_model.setNameFilterDisables(False) self._filesbrowser.value = self.syspath_model root_index = self.syspath_model.index(root_path) self._filesbrowser.setRootIndex(root_index) for i in range(1, 4): self._filesbrowser.hideColumn(i) def __type_changed_evt(self): if self._type.value == 'script': self._filesbrowser.show() self._command.hide() elif self._type.value == 'external': self._filesbrowser.hide() self._command.show() def __cancel_evt(self): self.close() self.task.cmdwin = None def __ok_evt(self): if self.command is not None: command = self.command else: command = self.task.create_scriptcmd( ) if self._type.value == 'script' else self.task.create_execcmd() command.when = self.when if self._type.value == 'script': for index in self._filesbrowser.selectedIndexes(): filepath = self.syspath_model.filePath(index) break if filepath is None: return file_path = Path(filepath) task_path = Path(self.task.path) relpath = file_path.relative_to(task_path) command.script = str(relpath) elif self._type.value == 'external': command.cmd = self._command.value self.task.update_commands() self.close() self.task.cmdwin = None