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 clock_thread(self): while True: if GLO.stop.is_set(): # stop thread so that the program can quit return # get some basic settings config = ConfigParser.get_configparser('app') maxw = max(10, int(config.get('settings', 'labw'))) maxh = max(10, int(config.get('settings', 'labh'))) # create blank canvas canvas_img = pilImage.new('RGB', (maxw, maxh), color=(255, 255, 255)) # draw text on the canvas if GLO.font_pool: self.canvas_drawtext(canvas_img, maxw, maxh, self.textbox.text) # clean up spaces from text input #self.textbox.text = re.sub(r'\s\s+', ' ', self.textbox.text.lstrip()) # save png to disk #canvas_img.save('image_main.png') # live memory texture data = BytesIO() canvas_img.save(data, format='jpeg') data.seek(0) # yes, this is also important! self.imbytes = data.read() im = CoreImage(BytesIO(self.imbytes), ext='jpeg') self.update_elements( im ) # instead of self.beeld.texture = im.texture, cannot update root widget from thread sleep(1)
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 execute_print(self): self.textbox.select_all() lpname = ConfigParser.get_configparser('app').get('settings', 'lpname') if not lpname or lpname == 'default': p = Popen(['lp'], stdin=PIPE) else: p = Popen(['lp', '-d', lpname], stdin=PIPE) p.stdin.write(self.imbytes) p.stdin.close()
def btn_IMG(self, btn): # spam control: wait for cycle to get drawn if GLO.processed_immode != GLO.immode: return # cycle image GLO.immode += 1 config = ConfigParser.get_configparser('app') multimod = int(config.get('settings', 'multimod')) if GLO.immode >= 4: GLO.immode = 0 if multimod == 0 and GLO.immode >= 2: GLO.immode = 0
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)
def canvas_drawtext(self, canvas_img, maxw, maxh, txt): # read config settings # alternative: config = App.get_running_app().config config = ConfigParser.get_configparser('app') font = config.get('settings', 'font') if font in GLO.font_pool: font_path = GLO.font_pool[font] # get a nice absolute font path else: font_path = def_defaultcfg[ 'font'] # fallback in case of broken config settings (shouldn't happen) minfos = max(4, int(config.get('settings', 'minfos'))) splitsep = max(0, int(config.get('settings', 'splitsep'))) focorr = max(0, float(config.get('settings', 'focorr'))) # write actual text sepdist = int(splitsep / 2) # halve the distance if GLO.immode == 3: # facing: double, toward center func_makebox(canvas_img, (0, maxh, int(maxw / 2 - sepdist), 0), minfos, focorr, font_path, txt) overflow = func_makebox(canvas_img, (maxw, 0, int(maxw / 2 + sepdist), maxh), minfos, focorr, font_path, txt) elif GLO.immode == 2: # facing: double, plain func_makebox(canvas_img, (0, 0, int(maxw / 2 - sepdist), maxh), minfos, focorr, font_path, txt) overflow = func_makebox(canvas_img, (int(maxw / 2 + sepdist), 0, maxw, maxh), minfos, focorr, font_path, txt) elif GLO.immode == 1: # facing: double, away from center func_makebox(canvas_img, (int(maxw / 2 - sepdist), 0, 0, maxh), minfos, focorr, font_path, txt) overflow = func_makebox(canvas_img, (int(maxw / 2 + sepdist), maxh, maxw, 0), minfos, focorr, font_path, txt) else: # facing: single, plain overflow = func_makebox(canvas_img, (0, 0, maxw, maxh), minfos, focorr, font_path, txt) if overflow: # check text overflow GLO.bad_status = 'Warning: your text does not fit the label!'
def __init__(self, **kwargs): super(Profiler, self).__init__(**kwargs) self.profile_config = ConfigParser(name='profiler')
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)