def set_listener(self, start=True): if start: events.connect(events.MESSAGES, self.listener) self.connected = True else: events.disconnect(events.MESSAGES, self.listener) self.connected = False
def __init__(self, path, cfgdir): self.path = path wal.Application.__init__(self) UCApplication.__init__(self, path, cfgdir, False) if wal.IS_WINXP: msg = _('WindowsXP platform is obsolete and not supported!') dialogs.error_dialog(self.mw, 'sK1', msg) sys.exit() self.appdata = AppData(self, cfgdir) log_level = config.log_level self.log_filepath = os.path.join(self.appdata.app_config_dir, 'sk1.log') mixutils.config_logging(fsutils.get_sys_path(self.log_filepath), log_level) sys.stderr = StreamLogger() LOG.info('Logging started') wal.SPIN['overlay'] = config.spin_overlay wal.SPIN['sep'] = config.spin_sep plg_dir = os.path.join(self.path, 'share', 'pd_plugins') custom_plg_dir = self.appdata.plugin_dir config.plugin_dirs = [plg_dir, custom_plg_dir] sys.path.insert(1, fsutils.get_sys_path(self.appdata.app_config_dir)) sys.path.insert(1, fsutils.get_sys_path(os.path.join(self.path, 'share'))) config.app = self LOG.info('Config is updated') self.history = AppHistoryManager(self) self.artprovider = create_artprovider() self.cursors = modes.get_cursors() self.proxy = AppProxy(self) self.insp = AppInspector(self) self.plugins = app_plugins.scan_plugins(self) self.actions = app_actions.create_actions(self) self.default_cms = AppColorManager(self) self.palettes = AppPaletteManager(self) self.clipboard = AppClipboard(self) self.mw = AppMainWindow(self) self.mw.set_global_shortcuts(self.actions) self.proxy.update() self.insp.update() LOG.info('Application is initialized') uc2.events.connect(uc2.events.MESSAGES, self.uc2_event_logging) events.connect(events.APP_STATUS, self.sk1_event_logging) self.fsw = AppFileWatcher(self, self.mw) if wal.IS_WX2: events.emit(events.NO_DOCS)
def run(self, callback, args): events.connect(events.FILTER_INFO, self.listener) style = wx.PD_APP_MODAL | wx.PD_AUTO_HIDE self.dlg = wx.ProgressDialog(self.caption, ' ' * 100, parent=self.parent, style=style) return callback(*args)
def __init__(self, path, cfgdir='~'): self.path = path wal.Application.__init__(self) UCApplication.__init__(self, path, cfgdir) if wal.IS_WINXP: msg = _('WindowsXP platform is obsolete and not supported!') dialogs.error_dialog(self.mw, 'sK1', msg) sys.exit() self.appdata = AppData(self, cfgdir) config.load(self.appdata.app_config) config.resource_dir = os.path.join(path_unicode(self.path), 'share') log_level = config.log_level self.log_filepath = os.path.join(self.appdata.app_config_dir, 'sk1.log') config_logging(self.log_filepath, log_level) sys.stderr = StreamLogger() LOG.info('Logging started') self.update_wal() plg_dir = os.path.join(self.path, 'share', 'pd_plugins') custom_plg_dir = self.appdata.plugin_dir config.plugin_dirs = [plg_dir, custom_plg_dir] sys.path.insert(1, self.appdata.app_config) sys.path.insert(1, os.path.join(self.path, 'share')) config.app = self LOG.info('Config is updated') self.history = AppHistoryManager(self) self.artprovider = create_artprovider() self.cursors = modes.get_cursors() self.proxy = AppProxy(self) self.insp = AppInspector(self) self.plugins = app_plugins.scan_plugins(self) self.actions = app_actions.create_actions(self) self.default_cms = AppColorManager(self) self.palettes = AppPaletteManager(self) self.clipboard = AppClipboard(self) self.mw = AppMainWindow(self) self.mw.set_global_shortcuts(self.actions) self.proxy.update() self.insp.update() LOG.info('Application is initialized') uc2.events.connect(uc2.events.MESSAGES, self.uc2_event_logging) events.connect(events.APP_STATUS, self.sk1_event_logging) if wal.IS_WX2: events.emit(events.NO_DOCS) if config.make_font_cache_on_start: generate_fcache()
def run(self, executable, args): events.connect(events.FILTER_INFO, self.listener) self.progress_bar.set_text('0 %') self.progress_bar.set_fraction(0.0) while gtk.events_pending(): gtk.main_iteration() self.executable = executable self.args = args return gtk.Dialog.run(self)
def run(self, executable, args, save_result=True): events.connect(events.FILTER_INFO, self._listener) self.dlg = wx.ProgressDialog(self.caption, ' ' * 80, parent=self.parent, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE) try: if save_result: self.result = executable(*args) else: executable(*args) except: self.result = None self.error_info = sys.exc_info() return False return True
def run(self): if '--help' in sys.argv or '-help' in sys.argv or len(sys.argv) == 1: self.show_help() elif len(sys.argv) == 2: self.show_short_help(_('Not enough arguments!')) files = [] options_list = [] options = {} for item in sys.argv[1:]: if item.startswith('--'): options_list.append(item) elif item.startswith('-'): self.show_short_help(_('Unknown option "%s"') % item) else: files.append(item) if not files: self.show_short_help(_('File names are not provided!')) elif len(files) == 1: self.show_short_help(_('Destination file name is not provided!')) elif not os.path.lexists(files[0]): self.show_short_help( _('Source file "%s" is not found!') % files[0]) for item in options_list: result = item[2:].split('=') if not len(result) == 2: options[result[0]] = True else: key, value = result value = value.replace('"', '').replace("'", '') if value.lower() == 'yes': value = True if value.lower() == 'no': value = False options[key] = value self.do_verbose = options.get('verbose', False) events.connect(events.MESSAGES, self.verbose) log_level = options.get('log', self.config.log_level) self.log_filepath = os.path.join(self.appdata.app_config_dir, 'uc2.log') config_logging(self.log_filepath, log_level) self.default_cms = cms.ColorManager() self.palettes = PaletteManager(self) echo('') msg = _('Translation of "%s" into "%s"') % (files[0], files[1]) events.emit(events.MESSAGES, msgconst.JOB, msg) saver_ids = uc2const.PALETTE_SAVERS saver_ids += uc2const.MODEL_SAVERS + uc2const.BITMAP_SAVERS sid = options.get('format', '').lower() if sid and sid in saver_ids: saver_id = sid saver = get_saver_by_id(saver_id) else: saver, saver_id = get_saver(files[1], return_id=True) if saver is None: msg = _('Output file format of "%s" is unsupported.') % files[1] events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) loader, loader_id = get_loader(files[0], return_id=True) if loader is None: msg = _('Input file format of "%s" is unsupported.') % files[0] events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) doc = None try: if loader_id in uc2const.PALETTE_LOADERS and \ saver_id in uc2const.PALETTE_SAVERS: doc = loader(self.appdata, files[0], convert=True) else: doc = loader(self.appdata, files[0]) except Exception as e: msg = _('Error while loading "%s"') % files[0] msg += _( 'The file may be corrupted or contains unknown file format.') events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Loading is interrupted') LOG.error('%s %s', msg, e) events.emit(events.MESSAGES, msgconst.STOP, msg) if doc is not None: try: if loader_id in uc2const.PALETTE_LOADERS and \ saver_id in uc2const.PALETTE_SAVERS: saver(doc, files[1], translate=False, convert=True) else: saver(doc, files[1]) except Exception as e: msg = _('Error while translation and saving "%s"') % files[0] events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') LOG.error('%s %s', msg, e) events.emit(events.MESSAGES, msgconst.STOP, msg) else: msg = _('Error creating model for "%s"') % files[0] events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) doc.close() msg = _('Translation is successful') events.emit(events.MESSAGES, msgconst.OK, msg) echo('') sys.exit(0)
def run(self): if len(sys.argv) < 3 or '--help' in sys.argv: self.show_help() files = [] options_list = [] options = {} for item in sys.argv[1:]: if item[0] == '-': if item == '-verbose': events.connect(events.MESSAGES, self.verbose) else: options_list.append(item) else: files.append(item) if len(files) <> 2: self.show_help() if not os.path.lexists(files[0]):self.show_help() for item in options_list: result = item[1:].split('=') if not len(result) == 2: continue else: key, value = result if value == 'yes':value = True if value == 'no':value = False options[key] = value self.default_cms = cms.ColorManager() self.palettes = PaletteManager(self) print '' msg = _('Translation of') + ' "%s" ' % (files[0]) + _('into "%s"') % (files[1]) events.emit(events.MESSAGES, msgconst.JOB, msg) saver = get_saver(files[1]) if saver is None: msg = _("Output file format of '%s' is unsupported.") % (files[1]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) sys.exit(1) loader = get_loader(files[0]) if loader is None: msg = _("Input file format of '%s' is unsupported.") % (files[0]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) sys.exit(1) try: doc = loader(self.appdata, files[0]) except: msg = _("Error while loading '%s'") % (files[0]) msg += _("The file may be corrupted or contains unknown file format.") events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) print '\n', sys.exc_info()[1], sys.exc_info()[2] sys.exit(1) if doc is not None: try: saver(doc, files[1]) except: msg = _("Error while translation and saving '%s'") % (files[0]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) print '\n', sys.exc_info()[1], sys.exc_info()[2] sys.exit(1) else: msg = _("Error while model creating for '%s'") % (files[0]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) sys.exit(1) doc.close() events.emit(events.MESSAGES, msgconst.OK, _('Translation is successful')) print '' sys.exit(0)
def run(self, current_dir=None): if len(sys.argv) == 1: dt = self.appdata mark = '' if not dt.build else ' build %s' % dt.build msg = '%s %s%s%s\n' % (dt.app_name, dt.version, dt.revision, mark) cmds.show_short_help(msg) sys.exit(0) elif cmds.check_args(cmds.HELP_CMDS): cmds.show_help(self.appdata) sys.exit(0) elif cmds.check_args(cmds.PARTS_CMDS): cmds.show_parts(self.appdata) sys.exit(0) elif cmds.check_args(cmds.LOG_CMDS): log_filepath = os.path.join(self.appdata.app_config_dir, 'uc2.log') log_filepath = log_filepath.decode('utf-8') with open(log_filepath, 'rb') as fileptr: echo(fileptr.read()) sys.exit(0) elif cmds.check_args(cmds.DIR_CMDS): echo(os.path.dirname(os.path.dirname(__file__))) sys.exit(0) elif cmds.check_args(cmds.CFG_SHOW_CMDS): cmds.show_config() sys.exit(0) elif cmds.check_args(cmds.CONFIG_CMDS): options = cmds.parse_cmd_args(current_dir)[1] cmds.normalize_options(options) cmds.change_config(options) self.config.save() sys.exit(0) elif len(sys.argv) == 2: cmds.show_short_help('Not enough arguments!') sys.exit(1) self.do_verbose = cmds.check_args(cmds.VERBOSE_CMDS) current_dir = os.getcwdu() if current_dir is None else current_dir files, options = cmds.parse_cmd_args(current_dir) if not files: cmds.show_short_help('File names are not provided!') sys.exit(1) elif len(files) == 1: msg = 'Destination directory or file name is not provided!' cmds.show_short_help(msg) sys.exit(1) command = cmds.convert if any(['*' in files[0], '?' in files[0]]): command = cmds.wildcard_convert if os.path.exists(files[1]): if not os.path.isdir(files[1]): msg = 'Destination directory "%s" is not a directory!' cmds.show_short_help(msg % files[1]) sys.exit(1) else: os.makedirs(files[1]) elif len(files) > 2: command = cmds.multiple_convert if os.path.exists(files[-1]): if not os.path.isdir(files[-1]): msg = 'Destination directory "%s" is not a directory!' cmds.show_short_help(msg % files[-1]) sys.exit(1) else: os.makedirs(files[-1]) elif not fsutils.exists(files[0]): cmds.show_short_help('Source file "%s" is not found!' % files[0]) sys.exit(1) events.connect(events.MESSAGES, self.verbose) log_level = options.get('log', self.config.log_level) self.log_filepath = os.path.join(self.appdata.app_config_dir, 'uc2.log') config_logging(self.log_filepath, log_level) self.default_cms = app_cms.AppColorManager(self) self.palettes = PaletteManager(self) # EXECUTION ---------------------------- status = 0 # noinspection PyBroadException try: command(self.appdata, files, options) except Exception: status = 1 if self.do_verbose: echo() sys.exit(status)
def run(self): if len(sys.argv) < 3 or '--help' in sys.argv: self.show_help() files = [] options_list = [] options = {} for item in sys.argv[1:]: if item[0] == '-': if item == '-verbose': events.connect(events.MESSAGES, self.verbose) else: options_list.append(item) else: files.append(item) if len(files) <> 2: self.show_help() if not os.path.lexists(files[0]): self.show_help() for item in options_list: result = item[1:].split('=') if not len(result) == 2: continue else: key, value = result if value == 'yes': value = True if value == 'no': value = False options[key] = value self.default_cms = cms.ColorManager() self.palettes = PaletteManager(self) print '' msg = _('Translation of') + ' "%s" ' % (files[0]) + _('into "%s"') % ( files[1]) events.emit(events.MESSAGES, msgconst.JOB, msg) saver = get_saver(files[1]) if saver is None: msg = _("Output file format of '%s' is unsupported.") % (files[1]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) sys.exit(1) loader = get_loader(files[0]) if loader is None: msg = _("Input file format of '%s' is unsupported.") % (files[0]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) sys.exit(1) try: doc = loader(self.appdata, files[0]) except: msg = _("Error while loading '%s'") % (files[0]) msg += _( "The file may be corrupted or contains unknown file format.") events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) print '\n', sys.exc_info()[1], sys.exc_info()[2] sys.exit(1) if doc is not None: try: saver(doc, files[1]) except: msg = _("Error while translation and saving '%s'") % (files[0]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) print '\n', sys.exc_info()[1], sys.exc_info()[2] sys.exit(1) else: msg = _("Error while model creating for '%s'") % (files[0]) events.emit(events.MESSAGES, msgconst.ERROR, msg) msg = _('Translation is interrupted') events.emit(events.MESSAGES, msgconst.STOP, msg) sys.exit(1) doc.close() events.emit(events.MESSAGES, msgconst.OK, _('Translation is successful')) print '' sys.exit(0)
def run(self, callback, args): events.connect(events.FILTER_INFO, self.listener) result = wal.CustomProgressDialog.run(self, callback, args) events.disconnect(events.FILTER_INFO, self.listener) return result