class TestApp(App): def build_settings(self, settings): self.config = ConfigParser() self.settings = Settings() self.settings.add_json_panel('Preferences', self.config, data=SETTINGS) def build(self): return sm
def on_enter(self): root = App.get_running_app().root s = Settings(on_close=self.close) s.add_json_panel('Network', root.config, 'panels/network.json') s.add_json_panel('Stream', root.config, 'panels/stream.json') self.add_widget(s)
def ConfigDownLoadSettings(self, *, oSetting: KivySettings) -> KivySettings: """ Creates the settings tab for download """ self.oSetting = oSetting self.bForce = False uSettingsJSONResources: str = u'[{"type": "title","title": "$lvar(694)" },\n' iNumber: int = 0 uURL: str uSubRep: str RegisterSettingTypes(oSetting) for uURL in Globals.aRepositories: if not uURL == '': uSettingsJSONResources += u'{"type": "bool","title": "$lvar(695) %s","desc": "%s","section": "ORCA","key": "repository_state%s"},\n' % ( str(iNumber), uURL, str(iNumber)) iNumber += 1 uSettingsJSONResources += u'{"type": "buttons","title": "$lvar(696)","desc": "$lvar(697)","section": "ORCA","key": "button_load_resources","buttons":[{"title":"$lvar(5016)","id":"button_load_resources"}]}]\n' aSubList2: List = sorted(oRepository.aRepEntries, key=lambda entry: entry.uName) for uSubRep in self.aSubReps: aSubList = [ oEntry for oEntry in aSubList2 if oEntry.uRepType == uSubRep[1] ] if len(aSubList) > 0: uSettingsJSON = u'[' for oEntry in aSubList: uDescription: str = '' if len(oEntry.oDescriptions.dDescriptions) > 0: uDescription = oEntry.oDescriptions.dDescriptions.get( Globals.uLanguage) if uDescription is None: uDescription = oEntry.oDescriptions.dDescriptions.get( 'English') if uDescription is None: for uKey in oEntry.oDescriptions.dDescriptions: uDescription = oEntry.oDescriptions.dDescriptions[ uKey] break uSettingsJSON += u'{"type": "buttons","title": "%s ","desc": "%s %s:%s","section": "ORCA","key": "button_add_resource","buttons":[{"title":"$lvar(5016)","id":"button:%s:%s"}]},' % ( oEntry.uName, uDescription, '$lvar(673)', oEntry.uVersion, uSubRep[1], oEntry.uName) uSettingsJSON: str = uSettingsJSON[:-1] + u']' oSetting.add_json_panel(ReplaceVars(uSubRep[0]), None, data=ReplaceVars(uSettingsJSON)) oSetting.add_json_panel("Resources", Globals.oOrcaConfigParser, data=ReplaceVars(uSettingsJSONResources)) oSetting.bind(on_close=self.On_SettingsClose) oSetting.bind(on_config_change=self.On_ConfigChange) return oSetting
def __init__(self, **kwargs): super(ListParam, self).__init__(**kwargs) from kivy.uix.settings import Settings, SettingsWithSpinner, SettingsPanel from kivy.config import ConfigParser print("parammmmmmmm") #json param #graphics conf_graphics = [ #{"type": "title", "title": "Windows"}, { "type": "bool", "title": "Fullscreen", "desc": "Set the window in windowed or fullscreen", "section": "graphics", "key": "fullscreen" } ] #theme conf_theme = [{ "type": "options", "title": "Style", "desc": "Style des fenêtres", "section": "theme", "key": "Style", 'options': ['Light', 'Dark'] }, { "type": "options", "title": "Palette", "desc": "Couleurs des fenêtres", "section": "theme", "key": "Palette", 'options': [ "Red", "Pink", "Purple", "DeepPurple", "Indigo", "Blue", "LightBlue", "Cyan", "Teal", "Green", "LightGreen", "Lime", "Yellow", "Amber", "Orange", "DeepOrange", "Brown", "Gray", "BlueGray" ] }] config = ConfigParser() config.read('config.ini') s = Settings() #s.add_json_panel('My custom panel', config, 'settings_custom.json') #s.add_json_panel('Another panel', config, 'settings_test2.json') s.add_json_panel('Graphics', config, data=json.dumps(conf_graphics)) s.add_json_panel('Theme', config, data=json.dumps(conf_theme)) self.ids.grid_id.add_widget(s)
def generate_settings(self): config = ConfigParser() if not config.has_section("root"): self.build_config(config) settings_panel = Settings() #create instance of Settings settings_panel.add_json_panel('QFlash Settings', config, 'settings.json') return settings_panel # show the settings interface
def ConfigureKivySettingsForDiscoverParameter( self, oKivySetting: KivySettings, uConfigName: str) -> Union[KivyConfigParser, None]: """ Create the JSON string for all discover scripts and applies it to a kivy settings object :param setting oKivySetting: :param string uConfigName: :return: The KivySetting object """ uSettingsJSON: str uKey: str uDictKey: str SetVar(uVarName=u'ObjectConfigSection', oVarValue=uConfigName) self.uConfigName = uConfigName RegisterSettingTypes(oKivySetting) oSetting: cBaseInterFaceSettings = self.oInterFace.GetSettingObjectForConfigName( uConfigName=uConfigName) dSettingsJSON: Dict[str, Dict] = self.CreateSettingJsonCombined( oSetting=oSetting) if len(dSettingsJSON) == 0: return None # return self.On_SettingsClose(None) # add the jSon to the Kivy Setting dTarget: Dict[str, Dict] = {} for uKey in dSettingsJSON: uDictKey = dSettingsJSON[uKey]['scriptsection'] if dTarget.get(uDictKey) is None: dTarget[uDictKey] = {} dTarget[uDictKey][uKey] = dSettingsJSON[uKey] for uKey in dTarget: if not uKey.startswith('discover'): uSettingsJSON = SettingDictToString2(dTarget[uKey]) uSettingsJSON = ReplaceVars(uSettingsJSON) if uSettingsJSON != u'[]': oKivySetting.add_json_panel(ReplaceVars(uKey), self.oConfigParser, data=uSettingsJSON) for uKey in dTarget: if uKey.startswith('discover'): if uKey in GetVar("DISCOVERSCRIPTLIST"): uSettingsJSON = SettingDictToString2(dTarget[uKey]) uSettingsJSON = ReplaceVars(uSettingsJSON) if uSettingsJSON != u'[]': oKivySetting.add_json_panel(uKey[9:].upper(), self.oConfigParser, data=uSettingsJSON) # Adds the action handler oKivySetting.bind(on_config_change=self.On_ConfigChange) return oKivySetting
def settings_func(self, p): s = Settings() config = ConfigParser() try: config.setdefaults('EVM', {'school': self.school, 'names': self.temp, 'post': self.post, 'p_col': self.color, 'im_path': self.im_path, "code1": self.code1, "code2": self.code2, 'number':self.number}) except: config.setdefaults('EVM', {'school': 'Unknown', 'names': self.temp, 'post': "Unknown", 'p_col': 'FFFFFF', 'im_path': self.im_path, "code1": "voting", "code2": "results", 'number':self.number}) s.add_json_panel('EVM', config, data = self.json) s.bind(on_config_change = self.settings_change) setting = Popup(title = "Settings", content = s) s.bind(on_close = lambda *func: self.save_settings(s)) setting.open()
def build_settings(self, settings: Settings) -> None: """Builds and adds custom setting pannels to original settings, called when the user open settings for the first time. [requires]: isinstance(self.config, kivy.config.Config) [see [ensures] of build_config] """ if not asserts(isinstance(self.config, ConfigParser), "self.config is not initialized."): return settings.add_json_panel("Sira", self.config, filename="res/sira.json") settings.add_json_panel("Jira", self.config, filename="res/jira.json")
class Popup_parametres(Popup): def __init__(self, *args, **kwargs): self.callback = kwargs.pop("callback", None) self.pages = kwargs.pop("pages", ["general", "synchronisation", "kivy"]) self.title = "Paramètres" self.size_hint = (0.9, 0.9) config = ConfigParser() config.read(os.path.join(UTILS_Divers.GetRepData(), "config.cfg")) self.settings = Settings() self.settings.register_type('password', SettingPassword) self.settings.register_type('chaine', SettingChaine) if "general" in self.pages: self.settings.add_json_panel("Généralités", config, data=json.dumps(JSON_GENERAL)) if "synchronisation" in self.pages: self.settings.add_json_panel("Synchronisation", config, data=json.dumps(JSON_SYNCHRONISATION)) if "kivy" in self.pages: self.settings.add_kivy_panel() self.settings.interface.menu.close_button.text = "Fermer" self.content = self.settings self.settings.bind(on_close=self.OnBoutonFermer) self.bind(on_dismiss=self.on_dismiss) super(Popup, self).__init__(*args, **kwargs) def AfficherPage(self, nom="Synchronisation"): for button in self.settings.interface.menu.buttons_layout.children: if button.text == nom: button.selected = True self.settings.interface.menu.selected_uid = button.uid #settings.interface.menu.on_selected_uid() def OnBoutonFermer(self, *args): self.dismiss() def on_dismiss(self, *arg): if self.callback != None: self.callback()
def _setup_panel(settings: Settings, section_name: str, panel_options: List[Dict[str, Any]]): processed_options = [] for option in panel_options: processed_options.append( {k: option[k] for k in _ORIGINAL_KEYS_KEYS if k in option}) if "section" not in option or "key" not in option: continue assert option["section"] == section_name _OPTION_BY_KEY[(section_name, option["key"])] = option settings.add_json_panel("Light Controls", Config, data=json.dumps(processed_options))
def build(self): self.frame = MainFrame() self._trash_can = self.frame.ids.sm.screens[ 0].ids.rightborder.ids.trash_can parser = ConfigParser() parser.read("jointbtn.ini") # parser. self._cfg = parser s = Settings() s.add_json_panel('config', parser, data=config_json) s.on_close = partial(self.on_screen_n, 'script', 0) self.frame.ids.sm.screens[1].add_widget(s) self.coord = 'Both' return self.frame
class Popup_parametres(Popup): def __init__(self, *args, **kwargs): self.callback = kwargs.pop("callback", None) self.pages = kwargs.pop("pages", ["general", "synchronisation", "kivy"]) self.title = "Paramètres" self.size_hint = (0.9, 0.9) config = ConfigParser() config.read(UTILS_Divers.GetRepData() + "config.cfg") self.settings = Settings() self.settings.register_type('password', SettingPassword) self.settings.register_type('chaine', SettingChaine) if "general" in self.pages : self.settings.add_json_panel("Généralités", config, data=json.dumps(JSON_GENERAL, encoding="utf-8")) if "synchronisation" in self.pages : self.settings.add_json_panel("Synchronisation", config, data=json.dumps(JSON_SYNCHRONISATION, encoding="utf-8")) if "kivy" in self.pages : self.settings.add_kivy_panel() self.settings.interface.menu.close_button.text = "Fermer" self.content = self.settings self.settings.bind(on_close=self.OnBoutonFermer) self.bind(on_dismiss=self.on_dismiss) super(Popup, self).__init__(*args, **kwargs) def AfficherPage(self, nom="Synchronisation"): for button in self.settings.interface.menu.buttons_layout.children: if button.text == nom : button.selected = True self.settings.interface.menu.selected_uid = button.uid #settings.interface.menu.on_selected_uid() def OnBoutonFermer(self, *args): self.dismiss() def on_dismiss(self, *arg): if self.callback != None : self.callback()
def build(self): s = Settings() s.add_json_panel('Test Panel', self.config, data=data) return s
def build_settings(self, settings: Settings): settings.add_json_panel("Kivy Creator", self.config, "settings.json")
class PlaceSettingScreen(Screen): placeid = NumericProperty(0) def __init__(self, placeid, **kwargs): super(PlaceSettingScreen,self).__init__(**kwargs) self.data = None self.placeid = placeid self.draw() def update(self): self.clear_widgets() #define structure of fields (like an INI file) config = ConfigParser() config.add_section('general') config.add_section('location') config.add_section('icon_file') #--- set values (needs to come from database) todo #config.set('general','place_name','Name of the place: ' + str(self.placeid)) if self.data == None: config.set('location','lat','Enter lat here') config.set('location','lon','This is a dummy lon.') config.set('general','place_name','This is a dummy which should never be seen') config.set('general','category_name','This is a dummy which should never be seen') config.set('general','ranking','This is a dummy which should never be seen') config.set('general','visited','This is a dummy which should never be seen') config.set('icon_file','icon_file','This is a dummy which should never be seen') else: place = self.data config.set('location','lat',place.lat) config.set('location','lon',place.lon) config.set('general','place_name',place.name) config.set('general','category_name',place.cat_name ) config.set('general','ranking', self._ranking2str(place.stars)) config.set('general','visited',place.status) config.set('icon_file','icon_file','Testpath') #todo:how to deal with image data ??? return config def _ranking2str(self,n): """ convert the ranking from DB into a string """ s = '' if n <= 0: s = 'unspecified' else: for i in range(n): s += '*' return s def _str2ranking(self,s): return len(s) def _get_category_widget(self): #return widget which contains category information panel=self._get_panel() for c in panel.children: print c if isinstance(c,SettingOptions): if c.key == 'category_name': return c return None def _get_catname_list(self): """ get a name of categories as a list """ cl = db.get_categories() res = [] for id in cl.keys(): res.append(cl[id]['name']) res.sort() return res def draw(self): config = self.update() #--- specify settings screen from file self.settings = Settings() self.settings.add_json_panel('Settings', config, filename='setting_place.json') #todo: do not read this from file, but from string cat_widget = self._get_category_widget() cat_widget.options = self._get_catname_list() #get list of category names from DB #--- add widget --- self.add_widget(self.settings) btn_close = self.settings.children[1].children[0] #todo this is not so good if it is hardwired like this! btn_close.bind(on_press=self.close) def close(self,touch): self._save() s = sm.get_screen('mainscreen') s.data = db.get_places() s.update() sm.current = 'mainscreen' def _get_panel(self): k = self.settings._panels.keys() if len(k) != 1: raise ValueError, 'Expecting a single entry here!' panel = self.settings._panels[k[0]][0] return panel def _save(self): """ save current setting to database """ panel = self._get_panel() lat = panel.get_value('location','lat') lon = panel.get_value('location','lon') name = panel.get_value('general','place_name') ranking = panel.get_value('general','ranking') stars = self._str2ranking(ranking) status = panel.get_value('general','visited') cat_name = panel.get_value('general','category_name') #--- save Location information --- if self.placeid < 1: placeid = None else: placeid = self.placeid L = Location(placeid,lat,lon,name,stars,status) db.save_location(L) if placeid is None: L.id = db._get_last_key('Location')[0] #id of location #--- save Category information db.save_place(L.id,self._categoryname2id(cat_name)) def _categoryname2id(self,name): c = db.get_categories() for k in c.keys(): if c[k]['name'] == name: return k return 0
class MarketSettingScreen(Screen): marketid = NumericProperty(0) data = ObjectProperty(None) def __init__(self, marketid, **kwargs): super(MarketSettingScreen,self).__init__(**kwargs) self.marketid = marketid x = self.data self.draw() def _str2ranking(self,s): return len(s) def update(self): """ add data to Category settings retrieves data from database for a particular 'catid' """ #/// add data /// self.clear_widgets() #define structure of fields (like an INI file) config = ConfigParser() config.add_section('market') config.add_section('location') #--- set values (needs to come from database) #config.set('category','category_name','TestnameID: ' + str(self.catid)) if self.data == None: config.set('market','day','Enter the market DAY here') config.set('location','lon','enter longitude here') config.set('location','lat','enter latitude here') config.set('location','place_name','enter place name here') config.set('location','ranking','Ranking here') config.set('location','visited',False) else: config.set('market','day',self.data['day']) return config def draw(self): config = self.update() #--- specify settings screen from file self.settings = Settings() self.settings.add_json_panel('Settings', config, filename='setting_market.json') #todo: do not read this from file, but from string #--- add widget --- self.add_widget(self.settings) btn_close = self.settings.children[1].children[0] #todo this is not so good if it is hardwired like this! btn_close.bind(on_press=self.close) def close(self,touch): #save results in database self._save() #update category list in main category screen s = sm.get_screen('marketscreen') s.data = db.get_markets() s.update() #set focus sm.current = 'marketscreen' def _get_panel(self): k = self.settings._panels.keys() if len(k) != 1: raise ValueError, 'Expecting a single entry here!' panel = self.settings._panels[k[0]][0] return panel def _save(self): """ save current setting to database """ panel = self._get_panel() lat = panel.get_value('location','lat') lon = panel.get_value('location','lon') name = panel.get_value('location','place_name') ranking = panel.get_value('location','ranking') stars = self._str2ranking(ranking) status = panel.get_value('location','visited') #todo this might cuase trouble if the same Location is used for markets and other things !!! #--- save Location information --- if self.marketid < 1: #new market placeid = None else: placeid = self.placeid L = Location(placeid,lat,lon,name,stars,status) db.save_location(L) if placeid is None: L.id = db._get_last_key('Location')[0] #id of location #--- save Category information db.save_place(L.id,0) #todo: might cause trouble when using same Location data for different categories !!! db.save_market(panel.get_value('market','day'),self.marketid, L.id)
class CategorySettingScreen(Screen): catid = NumericProperty(0) data = ObjectProperty(None) def __init__(self, catid, **kwargs): super(CategorySettingScreen,self).__init__(**kwargs) self.catid = catid x = self.data self.draw() def update(self): """ add data to Category settings retrieves data from database for a particular 'catid' """ #/// add data /// self.clear_widgets() #define structure of fields (like an INI file) config = ConfigParser() config.add_section('category') config.add_section('icon_file') #--- set values (needs to come from database) #config.set('category','category_name','TestnameID: ' + str(self.catid)) if self.data == None: config.set('category','category_name','Enter your category name here') else: config.set('category','category_name',self.data['name']) config.set('icon_file','icon_file','Testpath') #todo:how to deal with image data ??? return config def draw(self): config = self.update() #--- specify settings screen from file self.settings = Settings() self.settings.add_json_panel('Settings', config, filename='setting_category.json') #todo: do not read this from file, but from string #--- add widget --- self.add_widget(self.settings) btn_close = self.settings.children[1].children[0] #todo this is not so good if it is hardwired like this! btn_close.bind(on_press=self.close) def close(self,touch): #save results in database self._save() #update category list in main category screen s = sm.get_screen('catscreen') s.data = db.get_categories() s.update() #set focus sm.current = 'catscreen' def _get_panel(self): k = self.settings._panels.keys() if len(k) != 1: raise ValueError, 'Expecting a single entry here!' panel = self.settings._panels[k[0]][0] return panel def _save(self): """ save current setting to database """ panel = self._get_panel() db.save_category(panel.get_value('category','category_name'),self.catid)
class ControllerApp(App): title = 'Fetcher' directory = './gui' def build(self): # Can't import Window at the top or it will open early with default config. from kivy.core.window import Window Window.bind(on_key_down=self.on_key_down) access_token = self.config.get('put.io', 'access_token') if not access_token: Clock.schedule_once(lambda dt: self.show_settings(), 0) open_path('http://fetcher.codi.st/api/auth') Clock.schedule_once(lambda dt: self.apply_config(), 0) def on_key_down(self, src, key, scancode, char, mods): from kivy.base import stopTouchApp if is_quit_key(char, mods): stopTouchApp() elif char == ',' and 'meta' in mods: self.show_settings() def resize(self, width, height): from kivy.core.window import Window Window.size = (width, height) def autosize(self): if self.settings: return downloads = self.root.downloads.children if downloads: row_height = downloads[0].height new_height = 15 + (row_height + self.root.downloads.spacing)*len(downloads) self.resize(320, new_height) else: self.resize(320, 20) def build_config(self, config): self.settings = None config.setdefaults('put.io', { 'access_token': '', 'download_path': '~/Movies/TV Shows', }) with open('gui/settings.yml', 'r') as settings_yaml: settings_data = yaml.load(settings_yaml) self.settings_json = json.dumps(settings_data) def apply_config(self): fetcher.CFG.putio.access_token = self.config.get('put.io', 'access_token') fetcher.CFG.download.local = self.config.get('put.io', 'download_path') fetcher.load_api() fetcher.check_now.set() def show_settings(self): self.settings = Settings() self.settings.add_json_panel('put.io', self.config, data=self.settings_json) self.resize(640, 250) self.settings.remove_widget(self.settings.menu) self.root.add_widget(self.settings) def on_close(wgt): self.apply_config() self.root.remove_widget(self.settings) self.settings = None self.autosize() self.settings.bind(on_close=on_close)
def show_settings(self): settings = Settings() settings.add_json_panel( 'My custom panel', self.config, 'settings.json') settings.bind(on_close=self.remove_widget) self.add_widget(settings)
def Build_Settings(oSettings: KivySettings) -> None: """ will be called, when showing the settings dialog We add a further panel for the orca.ini settings If we had a successful init, lets build the default full settings view otherwise just build a very minimalistic settings dialog, where the user can just change the ini path """ RegisterSettingTypes(oSettings) if Globals.bInit: uOrcaSettingsJSON: str = BuildSettingsString() oSettings.add_json_panel(u'ORCA', Globals.oOrcaConfigParser, data=uOrcaSettingsJSON) uBuildSettingsStringDefinitionList: str = BuildSettingsStringDefinitionList( ) if uBuildSettingsStringDefinitionList != '': oSettings.add_json_panel(ReplaceVars('$lvar(580)'), Globals.oDefinitionConfigParser, data=uBuildSettingsStringDefinitionList) # Add the Info panel oSettings.add_json_panel(ReplaceVars('$lvar(585)'), Globals.oOrcaConfigParser, data=BuildSettingsStringInfo()) # add the tools settings # and pass to kivy oSettings.add_json_panel(ReplaceVars('$lvar(572)'), Globals.oOrcaConfigParser, data=BuildSettingsStringTools()) # add the Online settings # and pass to kivy oSettings.add_json_panel(ReplaceVars('$lvar(699)'), Globals.oOrcaConfigParser, data=BuildSettingsStringOnlineResources()) else: # just build the small settings oSettings.add_json_panel(u'ORCA', Globals.oOrcaConfigParser, data=BuildSmallSettingsString())
def ConfigureKivySettings(self, *, oKivySetting: KivySettings, uConfig: str = "") -> KivySettings: """ Create the JSON string for all sections and applies it to a kivy settings object Discover settings are excluded :param setting oKivySetting: :param str uConfig: If we want a specific section, this is the name to provide :return: The KivySetting object """ oSetting: cBaseSettings bFoundSetting: bool = False RegisterSettingTypes(oKivySetting) self.GetSectionList() SetVar(uVarName=u'SettingSectionList', oVarValue=self.CreateSectionsJSONString()) if self.uType == "interface": # The Codeset List could be applied as a orca var, so set it to the list SetVar(uVarName=u'InterfaceCodesetList', oVarValue=self.oObject.CreateCodesetListJSONString()) for uSection in self.aSections: if uConfig == "" or uConfig == uSection: # the Section list should be applied as an orca var SetVar(uVarName=u'ObjectConfigSection', oVarValue=uSection) # Let create a new temporary cSetting object to not harm the existing ones oSetting = self.oObject.GetNewSettingObject() # Read the ini file for this section oSetting.ReadConfigFromIniFile(uConfigName=uSection) # Create the setting string dSettingsJSON: Dict[str, Dict] = self.CreateSettingJsonCombined( oSetting=oSetting, bIncludeDiscoverSettings=False) uSettingsJSON = SettingDictToString(dSettingList=dSettingsJSON) uSettingsJSON = ReplaceVars(uSettingsJSON) if uSettingsJSON != u'[]': bFoundSetting = True # add the jSon to the Kivy Setting oKivySetting.add_json_panel(uSection, self.oConfigParser, data=uSettingsJSON) # if there is nothing to configure, then return if not bFoundSetting: if self.uType == "interface": Globals.oNotifications.SendNotification( uNotification='closesetting_interface') else: Globals.oNotifications.SendNotification( uNotification='closesetting_script') return oKivySetting # Adds the action handler oKivySetting.bind(on_config_change=self.On_ConfigChange) return oKivySetting
def build(self): from kivy.uix.settings import Settings s = Settings() s.add_json_panel('Test Panel', self.config, data=data) return s