def __init__(self, api, language=None, **kwargs): resource_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'resources') resource_add_path(resource_path) resource_add_path(os.path.join(resource_path, 'objects')) resource_add_path(os.path.join(resource_path, 'shaders')) resource_add_path(os.path.join(resource_path, 'images')) self.last_print = LastPrint() self.api = api self.setting_translation = SettingsMapper(self.api) if language: lang = language else: lang = locale.getdefaultlocale()[0] Logger.info("Specifed Language Locale: %s" % lang) if lang not in self.supported_languages: lang = 'en_GB' Window.size = (1000, 700) Window.minimum_width = 1000 Window.minimum_height = 700 super(PeachyPrinter, self).__init__(**kwargs) self.lang = lang Config.set("input", "mouse", "mouse,disable_multitouch") Config.set("kivy", "exit_on_escape", 0) Config.adddefaultsection('internal') self.switch_lang(self.lang) self.manager = None
def __init__(self, api, language=None, **kwargs): resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources') resource_add_path(resource_path) resource_add_path(os.path.join(resource_path, 'objects')) resource_add_path(os.path.join(resource_path, 'shaders')) self.last_print = LastPrint() self.api = api self.setting_translation = SettingsMapper(self.api) if language: lang = language else: lang = locale.getdefaultlocale()[0] Logger.info("Specifed Language Locale: %s" % lang) if lang not in self.supported_languages: lang = 'en_GB' Window.size = (1000, 700) Window.minimum_width = 1000 Window.minimum_height = 700 super(PeachyPrinter, self).__init__(**kwargs) self.lang = lang Config.set("input", "mouse", "mouse,disable_multitouch") Config.set("kivy", "exit_on_escape", 0) Config.adddefaultsection('internal') self.switch_lang(self.lang) self.manager = None
class PeachyPrinter(App): large_button_height = NumericProperty(dp(52)) button_height = NumericProperty(dp(40)) label_height = NumericProperty(dp(30)) input_height = NumericProperty(dp(30)) refresh_rate = NumericProperty(1.0 / 30.0) use_kivy_settings = False lang = StringProperty('en_GB') translator = ObjectProperty(None, allownone=True) supported_languages = ['en_GB', 'en_US', 'tlh'] def __init__(self, api, language=None, **kwargs): resource_path = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'resources') resource_add_path(resource_path) resource_add_path(os.path.join(resource_path, 'objects')) resource_add_path(os.path.join(resource_path, 'shaders')) resource_add_path(os.path.join(resource_path, 'images')) self.last_print = LastPrint() self.api = api self.setting_translation = SettingsMapper(self.api) if language: lang = language else: lang = locale.getdefaultlocale()[0] Logger.info("Specifed Language Locale: %s" % lang) if lang not in self.supported_languages: lang = 'en_GB' Window.size = (1000, 700) Window.minimum_width = 1000 Window.minimum_height = 700 super(PeachyPrinter, self).__init__(**kwargs) self.lang = lang Config.set("input", "mouse", "mouse,disable_multitouch") Config.set("kivy", "exit_on_escape", 0) Config.adddefaultsection('internal') self.switch_lang(self.lang) self.manager = None def translation(self, text): if text: translated = self.translator(text) else: translated = "" Logger.debug("Translating '%s' -> '%s'" % (text, translated)) return translated def on_lang(self, instance, lang): self.switch_lang(lang) def open_settings(self): self.destroy_settings() super(PeachyPrinter, self).open_settings() def switch_lang(self, lang): Logger.info("Using Language Locale: %s" % self.lang) locale_dir = join(dirname(__file__), 'resources', 'il8n', 'locales') locales = gettext.translation('peachyprinter', locale_dir, languages=[self.lang]) self.translator = locales.ugettext if hasattr(self, 'settings'): self.settings.interface.menu.close_button.text = self.translation( _("Close")) def exit_app(self, *args): self.stop() def build(self): self.icon = os.path.join(os.path.dirname(__file__), 'resources', 'peachy.png') self.settings_cls = SettingsWithSidebar self.manager = MyScreenManager(self.api, self.setting_translation) return self.manager def connect_to_printer(self): try: self.setting_translation.load_config(self.config) self.config.add_callback(self.setting_translation.update_setting) self.api.get_configuration_api().get_current_config() return True except MissingPrinterException: return False except Exception as ex: fail_box = BoxLayout(orientation="vertical") pop_message = I18NLabel( text_source=_("An Error has Occured"), size_hint_y=None, height=self.label_height, ) pop_error = I18NLabel(text_source=str(ex)) pop_exit = I18NButton(text_source=_("Exit"), size_hint_y=None, height=self.button_height, on_release=self.exit_app) fail_box.add_widget(pop_message) fail_box.add_widget(pop_error) fail_box.add_widget(pop_exit) return fail_box def build_config(self, config): self.setting_translation.set_defaults(config) def build_settings(self, settings): self.setting_translation.refresh_settings(settings, self.config) settings.interface.menu.close_button.text = self.translation( _("Close")) def on_stop(self): if self.manager: self.manager.current = 'exit_ui'
class PeachyPrinter(App): large_button_height = NumericProperty(dp(52)) button_height = NumericProperty(dp(40)) label_height = NumericProperty(dp(30)) input_height = NumericProperty(dp(30)) refresh_rate = NumericProperty(1.0 / 30.0) use_kivy_settings = False lang = StringProperty('en_GB') translator = ObjectProperty(None, allownone=True) supported_languages = ['en_GB', 'en_US', 'tlh'] def __init__(self, api, language=None, **kwargs): resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'resources') resource_add_path(resource_path) resource_add_path(os.path.join(resource_path, 'objects')) resource_add_path(os.path.join(resource_path, 'shaders')) self.last_print = LastPrint() self.api = api self.setting_translation = SettingsMapper(self.api) if language: lang = language else: lang = locale.getdefaultlocale()[0] Logger.info("Specifed Language Locale: %s" % lang) if lang not in self.supported_languages: lang = 'en_GB' Window.size = (1000, 700) Window.minimum_width = 1000 Window.minimum_height = 700 super(PeachyPrinter, self).__init__(**kwargs) self.lang = lang Config.set("input", "mouse", "mouse,disable_multitouch") Config.set("kivy", "exit_on_escape", 0) Config.adddefaultsection('internal') self.switch_lang(self.lang) self.manager = None def translation(self, text): if text: translated = self.translator(text) else: translated = "" Logger.debug("Translating '%s' -> '%s'" % (text, translated)) return translated def on_lang(self, instance, lang): self.switch_lang(lang) def open_settings(self): self.destroy_settings() super(PeachyPrinter, self).open_settings() def switch_lang(self, lang): Logger.info("Using Language Locale: %s" % self.lang) locale_dir = join(dirname(__file__), 'resources', 'il8n', 'locales') locales = gettext.translation('peachyprinter', locale_dir, languages=[self.lang]) self.translator = locales.ugettext if hasattr(self, 'settings'): self.settings.interface.menu.close_button.text = self.translation(_("Close")) def exit_app(self, *args): self.stop() def build(self): self.icon = os.path.join(os.path.dirname(__file__), 'resources', 'peachy.png') self.settings_cls = SettingsWithSidebar try: self.setting_translation.load_config(self.config) self.config.add_callback(self.setting_translation.update_setting) except MissingPrinterException: fail_box = BoxLayout(orientation="vertical") pop_message = I18NLabel(text_source=_("Please connect your peachy printer before starting the software")) pop_exit = I18NButton(text_source=_("Exit"), size_hint_y=None, height=30, on_release=self.exit_app) fail_box.add_widget(pop_message) fail_box.add_widget(pop_exit) return fail_box except Exception as ex: fail_box = BoxLayout(orientation="vertical") pop_message = I18NLabel(text_source=_("An Error has Occured"), size_hint_y=None, height=self.label_height,) pop_error = I18NLabel(text_source=str(ex)) pop_exit = I18NButton(text_source=_("Exit"), size_hint_y=None, height=self.button_height, on_release=self.exit_app) fail_box.add_widget(pop_message) fail_box.add_widget(pop_error) fail_box.add_widget(pop_exit) return fail_box self.manager = MyScreenManager(self.api, self.setting_translation) return self.manager def build_config(self, config): self.setting_translation.set_defaults(config) def build_settings(self, settings): self.setting_translation.refresh_settings(settings, self.config) settings.interface.menu.close_button.text = self.translation(_("Close")) def on_stop(self): if self.manager: self.manager.current = 'mainui'