def _save_spec(self, *args): '''Try to save the spec file. If there is a error, show the label. If not, save the file and dispatch on_change ''' f = tempfile.NamedTemporaryFile() f.write(self.text_input.text) try: cfg = ConfigParser() cfg.read(f.name) except Exception: self.lbl_error.color = [1, 0, 0, 1] else: spec = open(self.spec_path, 'w') spec.write(self.text_input.text) spec.close() self.dispatch('on_change') f.close()
def _save_spec(self, *args): '''Try to save the spec file. If there is a error, show the label. If not, save the file and dispatch on_change ''' designer = App.get_running_app().root designer.project_watcher.stop() f = tempfile.NamedTemporaryFile() f.write(self.text_input.text) try: cfg = ConfigParser() cfg.read(f.name) except Exception: self.lbl_error.color = [1, 0, 0, 1] else: spec = open(self.spec_path, 'w') spec.write(self.text_input.text) spec.close() self.dispatch('on_change') f.close() designer.project_watcher.start_watching( designer.project_loader.proj_dir)
class Profiler(EventDispatcher): profile_path = StringProperty('') ''' Profile settings path :class:`~kivy.properties.StringProperty` and defaults to ''. ''' project_path = StringProperty('') ''' Project path :class:`~kivy.properties.StringProperty` and defaults to ''. ''' designer = ObjectProperty(None) '''Reference of :class:`~designer.app.Designer`. :data:`designer` is a :class:`~kivy.properties.ObjectProperty` ''' profile_config = ObjectProperty(None) '''Reference to a ConfigParser with the profile settings :class:`~kivy.properties.ObjectProperty` and defaults to None. ''' pro_name = ConfigParserProperty('', 'profile', 'name', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile name :class:`~kivy.properties.ConfigParserProperty` ''' pro_builder = ConfigParserProperty('', 'profile', 'builder', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile builder :class:`~kivy.properties.ConfigParserProperty` ''' pro_target = ConfigParserProperty('', 'profile', 'target', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile target :class:`~kivy.properties.ConfigParserProperty` ''' pro_mode = ConfigParserProperty('', 'profile', 'mode', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile builder :class:`~kivy.properties.ConfigParserProperty` ''' pro_install = ConfigParserProperty('', 'profile', 'install', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile install_on_device :class:`~kivy.properties.ConfigParserProperty` ''' pro_debug = ConfigParserProperty('', 'profile', 'debug', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile debug mode :class:`~kivy.properties.ConfigParserProperty` ''' pro_verbose = ConfigParserProperty('', 'profile', 'verbose', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile verbose mode :class:`~kivy.properties.ConfigParserProperty` ''' builder = ObjectProperty(None) '''Reference to the builder class. Can be Hanga, Buildozer or Desktop :class:`~kivy.properties.ObjectProperty` ''' __events__ = ('on_run', 'on_stop', 'on_error', 'on_message', 'on_build', 'on_deploy', 'on_clean') def __init__(self, **kwargs): super(Profiler, self).__init__(**kwargs) self.profile_config = ConfigParser(name='profiler') def run(self, *args, **kwargs): '''Run project ''' self.builder.run(*args, **kwargs) def stop(self): '''Stop project ''' self.builder.stop() def clean(self): '''Clean project ''' self.builder.clean() def build(self): '''Build project ''' self.builder.build() def rebuild(self): '''Rebuild project ''' self.builder.rebuild() def load_profile(self, prof_path, proj_path): '''Read the settings ''' self.profile_path = prof_path self.project_path = proj_path self.profile_config.read(self.profile_path) if self.pro_target == 'Desktop': self.builder = Desktop(self) else: if self.pro_builder == 'Buildozer': self.builder = Buildozer(self) elif self.pro_builder == 'Hanga': # TODO implement hanga self.builder = Desktop(self) self.dispatch( 'on_error', 'Hanga Builder not yet implemented!\n' 'Using Desktop') else: self.builder = Desktop(self) def on_error(self, *args): '''on_error event handler ''' pass def on_message(self, *args): '''on_message event handler ''' pass def on_run(self, *args): '''on_run event handler ''' pass def on_stop(self, *args): '''on_stop event handler ''' pass def on_build(self, *args): '''on_build event handler ''' pass def on_deploy(self, *args): '''on_deploy event handler ''' pass def on_clean(self, *args): '''on_clean event handler ''' pass
class BuildozerSpecEditor(Settings): '''Subclass of :class:`kivy.uix.settings.Settings` responsible for the UI editor of buildozer spec ''' config_parser = ObjectProperty(None) '''Config Parser for this class. Instance of :class:`kivy.config.ConfigParser` ''' def __init__(self, **kwargs): super(BuildozerSpecEditor, self).__init__(**kwargs) self.register_type('dict', SettingDict) self.register_type('list', SettingList) self.SPEC_PATH = '' self.proj_dir = '' self.config_parser = ConfigParser.get_configparser("buildozer_spec") if self.config_parser is None: self.config_parser = ConfigParser(name="buildozer_spec") def load_settings(self, proj_dir): '''This function loads project settings :param proj_dir: project directory with buildozer.spec ''' self.interface.menu.buttons_layout.clear_widgets() self.proj_dir = proj_dir self.SPEC_PATH = os.path.join(proj_dir, 'buildozer.spec') _dir = os.path.dirname(designer.__file__) _dir = os.path.split(_dir)[0] self.config_parser.read(self.SPEC_PATH) self.add_json_panel('Application', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_app.json')) self.add_json_panel('Android', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_android.json')) self.add_json_panel('iOS', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_ios.json')) self.add_json_panel('Buildozer', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_buildozer.json')) raw_spec = SpecCodeInput(spec_path=self.SPEC_PATH) raw_spec.bind(on_change=self.on_spec_changed) self.interface.add_panel(raw_spec, "buildozer.spec", raw_spec.uid) menu = self.interface.menu menu.selected_uid = menu.buttons_layout.children[-1].uid def on_spec_changed(self, *args): self.load_settings(self.proj_dir) # force to show the last panel menu = self.interface.menu menu.selected_uid = menu.buttons_layout.children[0].uid def create_json_panel(self, title, config, filename=None, data=None): '''Override the original method to use the custom SpecSettingsPanel ''' if filename is None and data is None: raise Exception('You must specify either the filename or data') if filename is not None: with open(filename, 'r') as fd: data = json.loads(fd.read()) else: data = json.loads(data) if type(data) != list: raise ValueError('The first element must be a list') panel = SpecSettingsPanel(title=title, settings=self, config=config) for setting in data: # determine the type and the class to use if not 'type' in setting: raise ValueError('One setting are missing the "type" element') ttype = setting['type'] cls = self._types.get(ttype) if cls is None: raise ValueError( 'No class registered to handle the <%s> type' % setting['type']) # create a instance of the class, without the type attribute del setting['type'] str_settings = {} for key, item in setting.items(): str_settings[str(key)] = item instance = cls(panel=panel, **str_settings) # instance created, add to the panel panel.add_widget(instance) return panel @ignore_proj_watcher def on_config_change(self, *args): super(BuildozerSpecEditor, self).on_config_change(*args)
class Profiler(EventDispatcher): profile_path = StringProperty('') ''' Profile settings path :class:`~kivy.properties.StringProperty` and defaults to ''. ''' project_path = StringProperty('') ''' Project path :class:`~kivy.properties.StringProperty` and defaults to ''. ''' designer = ObjectProperty(None) '''Reference of :class:`~designer.app.Designer`. :data:`designer` is a :class:`~kivy.properties.ObjectProperty` ''' profile_config = ObjectProperty(None) '''Reference to a ConfigParser with the profile settings :class:`~kivy.properties.ObjectProperty` and defaults to None. ''' pro_name = ConfigParserProperty('', 'profile', 'name', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile name :class:`~kivy.properties.ConfigParserProperty` ''' pro_builder = ConfigParserProperty('', 'profile', 'builder', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile builder :class:`~kivy.properties.ConfigParserProperty` ''' pro_target = ConfigParserProperty('', 'profile', 'target', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile target :class:`~kivy.properties.ConfigParserProperty` ''' pro_mode = ConfigParserProperty('', 'profile', 'mode', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile builder :class:`~kivy.properties.ConfigParserProperty` ''' pro_install = ConfigParserProperty('', 'profile', 'install', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile install_on_device :class:`~kivy.properties.ConfigParserProperty` ''' pro_debug = ConfigParserProperty('', 'profile', 'debug', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile debug mode :class:`~kivy.properties.ConfigParserProperty` ''' pro_verbose = ConfigParserProperty('', 'profile', 'verbose', 'profiler') '''Reference to a ConfigParser with the profile settings Get the profile verbose mode :class:`~kivy.properties.ConfigParserProperty` ''' builder = ObjectProperty(None) '''Reference to the builder class. Can be Hanga, Buildozer or Desktop :class:`~kivy.properties.ObjectProperty` ''' __events__ = ('on_run', 'on_stop', 'on_error', 'on_message', 'on_build', 'on_deploy', 'on_clean') def __init__(self, **kwargs): super(Profiler, self).__init__(**kwargs) self.profile_config = ConfigParser(name='profiler') def run(self, *args, **kwargs): '''Run project ''' self.builder.run(*args, **kwargs) def stop(self): '''Stop project ''' self.builder.stop() def clean(self): '''Clean project ''' self.builder.clean() def build(self): '''Build project ''' self.builder.build() def rebuild(self): '''Rebuild project ''' self.builder.rebuild() def load_profile(self, prof_path, proj_path): '''Read the settings ''' self.profile_path = prof_path self.project_path = proj_path self.profile_config.read(self.profile_path) if self.pro_target == 'Desktop': self.builder = Desktop(self) else: if self.pro_builder == 'Buildozer': self.builder = Buildozer(self) elif self.pro_builder == 'Hanga': # TODO implement hanga self.builder = Desktop(self) self.dispatch('on_error', 'Hanga Builder not yet implemented!\n' 'Using Desktop') else: self.builder = Desktop(self) def on_error(self, *args): '''on_error event handler ''' pass def on_message(self, *args): '''on_message event handler ''' pass def on_run(self, *args): '''on_run event handler ''' pass def on_stop(self, *args): '''on_stop event handler ''' pass def on_build(self, *args): '''on_build event handler ''' pass def on_deploy(self, *args): '''on_deploy event handler ''' pass def on_clean(self, *args): '''on_clean event handler ''' pass
class BuildozerSpecEditor(Settings): '''Subclass of :class:`kivy.uix.settings.Settings` responsible for the UI editor of buildozer spec ''' config_parser = ObjectProperty(None) '''Config Parser for this class. Instance of :class:`kivy.config.ConfigParser` ''' def __init__(self, **kwargs): super(BuildozerSpecEditor, self).__init__(**kwargs) self.register_type('dict', SettingDict) self.register_type('list', SettingList) self.SPEC_PATH = '' self.proj_dir = '' self.config_parser = ConfigParser.get_configparser("buildozer_spec") if self.config_parser is None: self.config_parser = ConfigParser(name="buildozer_spec") def load_settings(self, proj_dir): '''This function loads project settings ''' self.interface.menu.buttons_layout.clear_widgets() self.proj_dir = proj_dir self.SPEC_PATH = os.path.join(proj_dir, 'buildozer.spec') _dir = os.path.dirname(designer.__file__) _dir = os.path.split(_dir)[0] self.config_parser.read(self.SPEC_PATH) self.add_json_panel( 'Application', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_app.json')) self.add_json_panel( 'Android', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_android.json')) self.add_json_panel( 'iOS', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_ios.json')) self.add_json_panel( 'Buildozer', self.config_parser, os.path.join(_dir, 'designer', 'settings', 'buildozer_spec_buildozer.json')) raw_spec = SpecCodeInput(spec_path=self.SPEC_PATH) raw_spec.bind(on_change=self.on_spec_changed) self.interface.add_panel(raw_spec, "buildozer.spec", raw_spec.uid) menu = self.interface.menu menu.selected_uid = menu.buttons_layout.children[-1].uid def on_spec_changed(self, *args): self.load_settings(self.proj_dir) # force to show the last panel menu = self.interface.menu menu.selected_uid = menu.buttons_layout.children[0].uid def create_json_panel(self, title, config, filename=None, data=None): '''Override the original method to use the custom SpecSettingsPanel ''' if filename is None and data is None: raise Exception('You must specify either the filename or data') if filename is not None: with open(filename, 'r') as fd: data = json.loads(fd.read()) else: data = json.loads(data) if type(data) != list: raise ValueError('The first element must be a list') panel = SpecSettingsPanel(title=title, settings=self, config=config) for setting in data: # determine the type and the class to use if not 'type' in setting: raise ValueError('One setting are missing the "type" element') ttype = setting['type'] cls = self._types.get(ttype) if cls is None: raise ValueError( 'No class registered to handle the <%s> type' % setting['type']) # create a instance of the class, without the type attribute del setting['type'] str_settings = {} for key, item in setting.items(): str_settings[str(key)] = item instance = cls(panel=panel, **str_settings) # instance created, add to the panel panel.add_widget(instance) return panel def on_config_change(self, *args): designer = App.get_running_app().root designer.project_watcher.stop() self.config_parser.write() super(BuildozerSpecEditor, self).on_config_change(*args) designer.project_watcher.start_watching( designer.project_loader.proj_dir)