def _ExportToPNGs(self): export_object = self._GetExportObject() if export_object is None: return if not isinstance(export_object, HydrusSerialisable.SerialisableList): self._ExportToPNG() return from hydrus.client.gui import ClientGUITopLevelWindowsPanels from hydrus.client.gui import ClientGUISerialisable with ClientGUITopLevelWindowsPanels.DialogNullipotent( self, 'export to pngs') as dlg: panel = ClientGUISerialisable.PNGsExportPanel(dlg, export_object) dlg.SetPanel(panel) dlg.exec()
def GetDeleteFilesJobs(win, media, default_reason, suggested_file_service_key=None): title = 'Delete files?' with ClientGUITopLevelWindowsPanels.DialogEdit( win, title, frame_key='regular_center_dialog') as dlg: panel = ClientGUIScrolledPanelsEdit.EditDeleteFilesPanel( dlg, media, default_reason, suggested_file_service_key=suggested_file_service_key) dlg.SetPanel(panel) if panel.QuestionIsAlreadyResolved(): (involves_physical_delete, jobs) = panel.GetValue() return (involves_physical_delete, jobs) if dlg.exec() == QW.QDialog.Accepted: (involves_physical_delete, jobs) = panel.GetValue() return (involves_physical_delete, jobs) else: raise HydrusExceptions.CancelledException('Dialog cancelled.')
def SelectFromList(win, title, choice_tuples, value_to_select=None, sort_tuples=True): with ClientGUITopLevelWindowsPanels.DialogEdit(win, title) as dlg: panel = ClientGUIScrolledPanelsEdit.EditSelectFromListPanel( dlg, choice_tuples, value_to_select=value_to_select, sort_tuples=sort_tuples) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: result = panel.GetValue() return result else: raise HydrusExceptions.CancelledException('Dialog cancelled.')
def EventButton(self): with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit time delta') as dlg: panel = ClientGUIScrolledPanels.EditSingleCtrlPanel(dlg) control = TimeDeltaCtrl(panel, min=self._min, days=self._show_days, hours=self._show_hours, minutes=self._show_minutes, seconds=self._show_seconds, monthly_allowed=self._monthly_allowed) control.SetValue(self._value) panel.SetControl(control) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: value = panel.GetValue() self.SetValue(value) self.timeDeltaChanged.emit()
def _Add( self ): with ClientGUIDialogs.DialogTextEntry( self, 'enter the ' + self._key_name, allow_blank = False ) as dlg: if dlg.exec() == QW.QDialog.Accepted: key = dlg.GetValue() if key in self._GetExistingKeys(): QW.QMessageBox.warning( self, 'Warning', 'That {} already exists!'.format( self._key_name ) ) return with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit match' ) as dlg: string_match = ClientParsing.StringMatch() panel = ClientGUIStringPanels.EditStringMatchPanel( dlg, string_match ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: string_match = panel.GetValue() data = ( key, string_match ) self._listctrl.AddDatas( ( data, ) )
def _Add( self, service_type ): service_key = HydrusData.GenerateKey() port = self._GetNextPort() name = 'new service' dictionary = HydrusNetwork.GenerateDefaultServiceDictionary( service_type ) service = HydrusNetwork.GenerateService( service_key, service_type, name, port, dictionary ) with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit serverside service' ) as dlg_edit: panel = EditServersideService( dlg_edit, service ) dlg_edit.SetPanel( panel ) if dlg_edit.exec() == QW.QDialog.Accepted: new_service = panel.GetValue() self._services_listctrl.SetNonDupeName( new_service ) self._SetNonDupePort( new_service ) self._services_listctrl.AddDatas( ( new_service, ) )
def _AddSomeDefaults(self, defaults_callable, add_callable): defaults = defaults_callable() selected = False choice_tuples = [(default.GetName(), default, selected) for default in defaults] from hydrus.client.gui import ClientGUITopLevelWindowsPanels from hydrus.client.gui import ClientGUIScrolledPanelsEdit with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'select the defaults to add') as dlg: panel = ClientGUIScrolledPanelsEdit.EditChooseMultiple( dlg, choice_tuples) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: defaults_to_add = panel.GetValue() for default in defaults_to_add: add_callable(default) self._listctrl.Sort()
def GetYesNo( win, message, title = 'Are you sure?', yes_label = 'yes', no_label = 'no', auto_yes_time = None, auto_no_time = None, check_for_cancelled = False ): with ClientGUITopLevelWindowsPanels.DialogCustomButtonQuestion( win, title ) as dlg: panel = ClientGUIScrolledPanelsButtonQuestions.QuestionYesNoPanel( dlg, message, yes_label = yes_label, no_label = no_label ) dlg.SetPanel( panel ) if auto_yes_time is None and auto_no_time is None: return dlg.exec() if not check_for_cancelled else ( dlg.exec(), dlg.WasCancelled() ) else: if auto_yes_time is not None: job = HG.client_controller.CallLaterQtSafe( dlg, auto_yes_time, 'dialog auto-yes', dlg.done, QW.QDialog.Accepted ) elif auto_no_time is not None: job = HG.client_controller.CallLaterQtSafe( dlg, auto_no_time, 'dialog auto-no', dlg.done, QW.QDialog.Rejected ) try: return dlg.exec() if not check_for_cancelled else ( dlg.exec(), dlg.WasCancelled() ) finally: job.Cancel()
def _SetTxtServices(self): services_manager = HG.client_controller.services_manager tag_services = services_manager.GetServices(HC.REAL_TAG_SERVICES) choice_tuples = [(service.GetName(), service.GetServiceKey(), service.GetServiceKey() in self._neighbouring_txt_tag_service_keys) for service in tag_services] with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'select tag services') as dlg: panel = ClientGUIScrolledPanelsEdit.EditChooseMultiple( dlg, choice_tuples) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: self._neighbouring_txt_tag_service_keys = panel.GetValue() HG.client_controller.new_options.SetKeyList( 'default_neighbouring_txt_tag_service_keys', self._neighbouring_txt_tag_service_keys) if len(self._neighbouring_txt_tag_service_keys) == 0: self._export_tag_txts.setChecked(False) self._UpdateTxtButton()
def _Edit( self ): selected_rules = self._listctrl.GetData( only_selected = True ) for rule in selected_rules: with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit rule' ) as dlg: panel = self._EditPanel( dlg, rule ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: edited_rule = panel.GetValue() self._listctrl.DeleteDatas( ( rule, ) ) self._listctrl.AddDatas( ( edited_rule, ) ) else: break self._listctrl.Sort()
def SelectFromListButtons(win, title, choice_tuples, message=''): if len(choice_tuples) == 1: ((text, data, tooltip), ) = choice_tuples return data with ClientGUITopLevelWindowsPanels.DialogEdit(win, title, hide_buttons=True) as dlg: panel = ClientGUIScrolledPanelsEdit.EditSelectFromListButtonsPanel( dlg, choice_tuples, message=message) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: result = panel.GetValue() return result else: raise HydrusExceptions.CancelledException('Dialog cancelled.')
def ManageShortcuts(win: QW.QWidget): shortcuts_manager = ClientGUIShortcuts.shortcuts_manager() all_shortcuts = shortcuts_manager.GetShortcutSets() with ClientGUITopLevelWindowsPanels.DialogEdit(win, 'manage shortcuts') as dlg: panel = EditShortcutsPanel(dlg, all_shortcuts) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: shortcut_sets = panel.GetValue() dupe_shortcut_sets = [ shortcut_set.Duplicate() for shortcut_set in shortcut_sets ] HG.client_controller.Write( 'serialisables_overwrite', [HydrusSerialisable.SERIALISABLE_TYPE_SHORTCUT_SET], dupe_shortcut_sets) shortcuts_manager.SetShortcutSets(shortcut_sets)
def EditShortcuts(self): name = self._name.text() for data in self._shortcuts.GetData(only_selected=True): (shortcut, command) = data with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit shortcut command') as dlg: panel = EditShortcutAndCommandPanel(dlg, shortcut, command, name) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: (new_shortcut, new_command) = panel.GetValue() new_data = (new_shortcut, new_command) self._shortcuts.ReplaceData(data, new_data) else: break
def _Edit(self): datas = self._account_types_listctrl.GetData(only_selected=True) if True in (at.IsNullAccount() for at in datas): QW.QMessageBox.critical(self, 'Error', 'You cannot edit the null account type!') return for account_type in datas: with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit account type') as dlg_edit: panel = EditAccountTypePanel(dlg_edit, self._service_type, account_type) dlg_edit.SetPanel(panel) if dlg_edit.exec() == QW.QDialog.Accepted: edited_account_type = panel.GetValue() self._account_types_listctrl.ReplaceData( account_type, edited_account_type) else: return
def _Edit( self ): for service in self._services_listctrl.GetData( only_selected = True ): original_name = service.GetName() with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit serverside service' ) as dlg_edit: panel = EditServersideService( dlg_edit, service ) dlg_edit.SetPanel( panel ) result = dlg_edit.exec() if result == QW.QDialog.Accepted: edited_service = panel.GetValue() if edited_service.GetName() != original_name: self._services_listctrl.SetNonDupeName( edited_service ) self._SetNonDupePort( edited_service ) self._services_listctrl.ReplaceData( service, edited_service ) elif dlg_edit.WasCancelled(): break
def _Edit(self): export_folders = self._export_folders.GetData(only_selected=True) for export_folder in export_folders: with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit export folder') as dlg: panel = EditExportFolderPanel(dlg, export_folder) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: edited_export_folder = panel.GetValue() self._export_folders.DeleteDatas((export_folder, )) edited_export_folder.SetNonDupeName( self._GetExistingNames()) self._export_folders.AddDatas((edited_export_folder, )) else: return
def _AddFolder( self ): new_options = HG.client_controller.new_options phrase = new_options.GetString( 'export_phrase' ) name = 'export folder' path = '' export_type = HC.EXPORT_FOLDER_TYPE_REGULAR delete_from_client_after_export = False file_search_context = ClientSearch.FileSearchContext( file_service_key = CC.LOCAL_FILE_SERVICE_KEY ) period = 15 * 60 export_folder = ClientExporting.ExportFolder( name, path, export_type = export_type, delete_from_client_after_export = delete_from_client_after_export, file_search_context = file_search_context, period = period, phrase = phrase ) with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit export folder' ) as dlg: panel = EditExportFolderPanel( dlg, export_folder ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: export_folder = panel.GetValue() export_folder.SetNonDupeName( self._GetExistingNames() ) self._export_folders.AddDatas( ( export_folder, ) )
def _ShowGallerySeedLogFrame( self ): gallery_seed_log = self._gallery_seed_log_get_callable() tlw = self.window() title = '{} log'.format( self._gallery_type_string ) if isinstance( tlw, QP.Dialog ): if self._gallery_seed_log_set_callable is None: # throw up a dialog that edits the gallery_seed log in place with ClientGUITopLevelWindowsPanels.DialogNullipotent( self, title ) as dlg: panel = EditGallerySeedLogPanel( dlg, self._controller, self._read_only, self._can_generate_more_pages, gallery_seed_log ) dlg.SetPanel( panel ) dlg.exec() else: # throw up a dialog that edits the gallery_seed log but can be cancelled dupe_gallery_seed_log = gallery_seed_log.Duplicate() with ClientGUITopLevelWindowsPanels.DialogEdit( self, title ) as dlg: panel = EditGallerySeedLogPanel( dlg, self._controller, self._read_only, self._can_generate_more_pages, dupe_gallery_seed_log ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: self._gallery_seed_log_set_callable( dupe_gallery_seed_log ) else: # throw up a frame that edits the gallery_seed log in place frame_key = 'gallery_import_log' frame = ClientGUITopLevelWindowsPanels.FrameThatTakesScrollablePanel( self, title, frame_key ) panel = EditGallerySeedLogPanel( frame, self._controller, self._read_only, self._can_generate_more_pages, gallery_seed_log ) frame.SetPanel( panel )
def _Edit(self): edited_datas = [] for data in self._listctrl.GetData(only_selected=True): (key, string_match) = data with ClientGUIDialogs.DialogTextEntry(self, 'edit the ' + self._key_name, default=key, allow_blank=False) as dlg: if dlg.exec() == QW.QDialog.Accepted: edited_key = dlg.GetValue() if edited_key != key and edited_key in self._GetExistingKeys( ): QW.QMessageBox.warning( self, 'Warning', 'That {} already exists!'.format(self._key_name)) break else: break with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit match') as dlg: string_match = ClientStrings.StringMatch() panel = ClientGUIStringPanels.EditStringMatchPanel( dlg, string_match) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: edited_string_match = panel.GetValue() else: break self._listctrl.DeleteDatas((data, )) edited_data = (edited_key, edited_string_match) self._listctrl.AddDatas((edited_data, )) edited_datas.append(edited_data) self._listctrl.SelectDatas(edited_datas) self._listctrl.Sort()
def _ShowFileSeedCacheFrame( self ): file_seed_cache = self._file_seed_cache_get_callable() tlw = self.window() if isinstance( tlw, QP.Dialog ): if self._file_seed_cache_set_callable is None: # throw up a dialog that edits the file_seed cache in place with ClientGUITopLevelWindowsPanels.DialogNullipotent( self, 'file import status' ) as dlg: panel = EditFileSeedCachePanel( dlg, self._controller, file_seed_cache ) dlg.SetPanel( panel ) dlg.exec() else: # throw up a dialog that edits the file_seed cache but can be cancelled dupe_file_seed_cache = file_seed_cache.Duplicate() with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'file import status' ) as dlg: panel = EditFileSeedCachePanel( dlg, self._controller, dupe_file_seed_cache ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: self._file_seed_cache_set_callable( dupe_file_seed_cache ) else: # throw up a frame that edits the file_seed cache in place title = 'file import status' frame_key = 'file_import_status' frame = ClientGUITopLevelWindowsPanels.FrameThatTakesScrollablePanel( self, title, frame_key ) panel = EditFileSeedCachePanel( frame, self._controller, file_seed_cache ) frame.SetPanel( panel )
def _Edit( self ): for data in self._listctrl.GetData( only_selected = True ): ( key_string_match, value_string_match ) = data with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit ' + self._key_name ) as dlg: panel = ClientGUIStringPanels.EditStringMatchPanel( dlg, key_string_match ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: key_string_match = panel.GetValue() else: break with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit match' ) as dlg: panel = ClientGUIStringPanels.EditStringMatchPanel( dlg, value_string_match ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: value_string_match = panel.GetValue() else: break self._listctrl.DeleteDatas( ( data, ) ) edited_data = ( key_string_match, value_string_match ) self._listctrl.AddDatas( ( edited_data, ) ) self._listctrl.Sort()
def _AddNewFavouriteSearch(self, search_row=None): existing_folders_to_names = self._GetExistingFoldersToNames() existing_names = { name for name in itertools.chain.from_iterable( existing_folders_to_names.values()) } if search_row is None: foldername = None name = 'new favourite search' default_local_file_service_key = HG.client_controller.services_manager.GetDefaultLocalFileServiceKey( ) location_search_context = ClientSearch.LocationSearchContext( current_service_keys=[default_local_file_service_key]) file_search_context = ClientSearch.FileSearchContext( location_search_context=location_search_context) synchronised = True media_sort = None media_collect = None else: (foldername, name, file_search_context, synchronised, media_sort, media_collect) = search_row name = HydrusData.GetNonDupeName(name, existing_names) with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit favourite search') as dlg: panel = EditFavouriteSearchPanel(dlg, existing_folders_to_names, foldername, name, file_search_context, synchronised, media_sort, media_collect) dlg.SetPanel(panel) if dlg.exec() == QW.QDialog.Accepted: row = panel.GetValue() self._DeleteRow(row[0], row[1]) self._favourite_searches.AddDatas((row, )) self._favourite_searches.Sort()
def _ExportToPng( self ): payload = self._GetExportableURLsString() with ClientGUITopLevelWindowsPanels.DialogNullipotent( self, 'export to png' ) as dlg: panel = ClientGUISerialisable.PngExportPanel( dlg, payload ) dlg.SetPanel( panel ) dlg.exec()
def GetFinishFilteringAnswer( win, label ): with ClientGUITopLevelWindowsPanels.DialogCustomButtonQuestion( win, label ) as dlg: panel = ClientGUIScrolledPanelsButtonQuestions.QuestionFinishFilteringPanel( dlg, label ) dlg.SetPanel( panel ) result = ( dlg.exec(), dlg.WasCancelled() ) return result
def GetInterstitialFilteringAnswer( win, label ): with ClientGUITopLevelWindowsPanels.DialogCustomButtonQuestion( win, label ) as dlg: panel = ClientGUIScrolledPanelsButtonQuestions.QuestionCommitInterstitialFilteringPanel( dlg, label ) dlg.SetPanel( panel ) result = dlg.exec() return result
def _ModifyAccounts( self ): accounts = self._account_list.GetData( only_selected = True ) if len( accounts ) > 0: subject_account_identifiers = [ HydrusNetwork.AccountIdentifier( account_key = account.GetAccountKey() ) for account in accounts ] frame = ClientGUITopLevelWindowsPanels.FrameThatTakesScrollablePanel( self.window().parentWidget(), 'manage accounts' ) panel = ModifyAccountsPanel( frame, self._service_key, subject_account_identifiers ) frame.SetPanel( panel )
def _Edit( self ): with ClientGUITopLevelWindowsPanels.DialogEdit( self, 'edit string match', frame_key = 'deeply_nested_dialog' ) as dlg: panel = ClientGUIStringPanels.EditStringMatchPanel( dlg, self._string_match ) dlg.SetPanel( panel ) if dlg.exec() == QW.QDialog.Accepted: self._string_match = panel.GetValue() self._UpdateLabel()
def ExportToPNG(win: QW.QWidget, file_seed_cache: ClientImportFileSeeds.FileSeedCache): payload = GetExportableSourcesString(file_seed_cache) with ClientGUITopLevelWindowsPanels.DialogNullipotent( win, 'export to png') as dlg: panel = ClientGUISerialisable.PNGExportPanel(dlg, payload) dlg.SetPanel(panel) dlg.exec()
def ExportToPNG(win: QW.QWidget, gallery_seed_log: ClientImportGallerySeeds.GallerySeedLog): payload = GetExportableURLsString(gallery_seed_log) with ClientGUITopLevelWindowsPanels.DialogNullipotent( win, 'export to png') as dlg: panel = ClientGUISerialisable.PNGExportPanel(dlg, payload) dlg.SetPanel(panel) dlg.exec()
def GetFinishArchiveDeleteFilteringAnswer( win, kept_label, deletion_options ): with ClientGUITopLevelWindowsPanels.DialogCustomButtonQuestion( win, 'filtering done?' ) as dlg: panel = ClientGUIScrolledPanelsButtonQuestions.QuestionArchiveDeleteFinishFilteringPanel( dlg, kept_label, deletion_options ) dlg.SetPanel( panel ) result = dlg.exec() location_context = panel.GetLocationContext() was_cancelled = dlg.WasCancelled() return ( result, location_context, was_cancelled )