Ejemplo n.º 1
0
 def create_bitmap(self, artid, client, size):
     artid = wal.untr(artid)
     if artid in self.match_keys:
         filename = self.iconmatch[artid] + self.file_ext
         size_dir = '%sx%s' % (size[0], size[0])
         if size == wal.DEF_SIZE:
             size_dir = 'fixed'
         path = os.path.join(self.theme_path, size_dir, filename)
         if fsutils.isfile(path):
             return self.get_bitmap(path)
     elif artid in self.iconset:
         path = os.path.join(self.iconset_path, artid + self.file_ext)
         sized_name = artid + '-' + str(size[0]) + self.file_ext
         sized_path = os.path.join(self.iconset_path, sized_name)
         if fsutils.isfile(sized_path):
             return self.get_bitmap(sized_path)
         elif fsutils.isfile(path):
             return self.get_bitmap(path)
     else:
         filename = artid + self.file_ext
         size_dir = '%dx%d' % (size[0], size[0])
         if size == wal.DEF_SIZE:
             size_dir = 'fixed'
         path = os.path.join(self.theme_path, size_dir, filename)
         if fsutils.isfile(path):
             return self.get_bitmap(path)
     if fsutils.isfile(artid):
         return self.get_bitmap(artid)
     return self.get_bitmap()
Ejemplo n.º 2
0
 def remove_palette(self, palette_name):
     filepath = os.path.join(self.app.appdata.app_palette_dir,
                             config.palette_files[palette_name])
     if fsutils.isfile(filepath):
         fsutils.remove(filepath)
     del self.palettes[palette_name]
     del config.palette_files[palette_name]
Ejemplo n.º 3
0
    def open(self, doc_file='', silent=False):
        doc_file = doc_file or \
                   dialogs.get_open_file_name(self.mw, config.open_dir)
        if doc_file and fsutils.lexists(doc_file) and fsutils.isfile(doc_file):
            try:
                doc = SK1Presenter(self, doc_file, silent)

            except RuntimeError:
                msg = _('Cannot open file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file contains newer SK2 format.\n')
                msg += _('Try updating sK1 application from '
                         'http://www.sk1project.net')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.error('Cannot open file <%s>: newer SK2 format.', doc_file)
                return
            except Exception as e:
                msg = _('Cannot open file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format.')
                msg += '\n'
                msg += _('Details see in application logs.')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.error('Cannot open file <%s> %s', doc_file, e)
                return
            self.docs.append(doc)
            config.open_dir = str(os.path.dirname(doc_file))
            self.history.add_entry(doc_file)
            self.set_current_doc(doc)
            events.emit(events.APP_STATUS, _('Document opened'))
Ejemplo n.º 4
0
    def import_palette(self, parent=None):
        parent = parent or self.mw
        file_types = uc2const.PALETTE_LOADERS
        doc_file = dialogs.get_open_file_name(parent,
                                              config.import_dir,
                                              _('Select palette to import'),
                                              file_types=file_types)
        if fsutils.lexists(doc_file) and fsutils.isfile(doc_file):

            pd = dialogs.ProgressDialog(_('Opening file...'), parent)
            try:
                loader = get_loader(doc_file)
                if not loader:
                    raise IOError(_('Loader is not found for <%s>') % doc_file)
                palette = pd.run(loader,
                                 [self.appdata, doc_file, None, False, True])
                if not palette:
                    raise IOError(_('Error while opening'), doc_file)
                self.palettes.add_palette(palette)
                config.import_dir = str(os.path.dirname(doc_file))
                msg = _('Palette is successfully imported')
                events.emit(events.APP_STATUS, msg)
                return palette.model.name
            except Exception as e:
                msg = _('Cannot import file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format.')
                msg += '\n'
                msg += _('Details see in application logs.')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.error('Cannot import file <%s> %s', doc_file, e)
            finally:
                pd.destroy()
Ejemplo n.º 5
0
    def import_file(self, doc_file=None, point=None):
        msg = _('Select file to import')
        if not doc_file:
            doc_file = dialogs.get_open_file_name(self.mw,
                                                  config.import_dir, msg)
        if doc_file and fsutils.isfile(doc_file):
            try:
                ret = self.current_doc.import_file(doc_file)
                if not ret:
                    msg = _('Cannot import graphics from file:')
                    msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                    msg += _('It seems the document is empty or '
                             'contains unsupported objects.')
                    dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                    LOG.warn('Cannot import graphics from file <%s>', doc_file)
                elif point and self.current_doc.selection.bbox:
                    x0, y0 = self.current_doc.canvas.win_to_doc(point)
                    x1 = self.current_doc.selection.bbox[0]
                    y1 = self.current_doc.selection.bbox[-1]
                    dx = x0 - x1
                    dy = y0 - y1
                    self.current_doc.api.move_selected(dx, dy)

                config.import_dir = str(os.path.dirname(doc_file))
            except Exception as e:
                msg = _('Cannot import file:')
                msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                msg += _('The file may be corrupted or not supported format')
                msg += '\n'
                msg += _('Details see in application logs.')
                dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                LOG.warn('Cannot import file <%s>', doc_file, e)
Ejemplo n.º 6
0
 def profile_info(self):
     index = self.viewer.get_active()
     name = self.pf_list[index]
     filename = self.profiles[name]
     dst_dir = self.app.appdata.app_color_profile_dir
     dst = os.path.join(dst_dir, filename)
     if fsutils.isfile(dst):
         ProfileInfoViewer(self, dst).show()
Ejemplo n.º 7
0
 def on_ok(self, *args):
     path = self.lc.get_selected()[2]
     if fsutils.isfile(path):
         self.ret = path
         self.end_modal(wal.BUTTON_OK)
     else:
         txt = "%s '%s' %s" % (_('File'), path, _('is not found.'))
         wal.error_dialog(self, _('File not found'), txt)
Ejemplo n.º 8
0
def get_loader(path, experimental=False, return_id=False):
    if not fsutils.exists(path):
        return None
    if not fsutils.isfile(path):
        return None

    ret_id = None

    ext = get_file_extension(path)
    loader = None
    ld_formats = [] + uc2const.LOADER_FORMATS

    msg = 'Start to search for loader by file extension %s' % (ext.__str__())
    events.emit(events.MESSAGES, msgconst.INFO, msg)

    if experimental:
        ld_formats += uc2const.EXPERIMENTAL_LOADERS
    for item in ld_formats:
        if ext in uc2const.FORMAT_EXTENSION[item]:
            checker = _get_checker(item)
            if checker and checker(path):
                loader = _get_loader(item)
                ret_id = item
                break

    if loader is None:
        msg = 'Loader is not found or not suitable for %s' % path
        events.emit(events.MESSAGES, msgconst.WARNING, msg)
        msg = 'Start to search loader by file content'
        events.emit(events.MESSAGES, msgconst.INFO, msg)

        for item in ld_formats:
            checker = _get_checker(item)
            if checker is not None:
                if checker(path):
                    loader = _get_loader(item)
                    ret_id = item
                    break

    if loader is None:
        msg = 'By file content loader is not found for %s' % path
        events.emit(events.MESSAGES, msgconst.WARNING, msg)
        msg = 'Try using fallback loader'
        events.emit(events.MESSAGES, msgconst.INFO, msg)
        if fallback_check(path):
            loader = im_loader

    if loader is None:
        msg = 'Loader is not found for %s' % path
        events.emit(events.MESSAGES, msgconst.ERROR, msg)
    else:
        loader_name = loader.__str__().split(' ')[1]
        msg = 'Loader "%s" is found for %s' % (loader_name, path)
        events.emit(events.MESSAGES, msgconst.OK, msg)

    if return_id:
        return loader, ret_id
    return loader
Ejemplo n.º 9
0
 def remove_profile(self):
     index = self.viewer.get_active()
     name = self.pf_list[index]
     filename = self.profiles[name]
     dst_dir = self.app.appdata.app_color_profile_dir
     dst = os.path.join(dst_dir, filename)
     if fsutils.isfile(dst):
         os.remove(fsutils.get_sys_path(dst))
     self.profiles.pop(name)
     self.apply_changes()
     self.viewer.set_active(index - 1)
Ejemplo n.º 10
0
 def load_palettes(self):
     paldir = self.app.appdata.app_palette_dir
     loader = get_loader_by_id(uc2const.SKP)
     for item in config.palette_files.keys():
         filepath = os.path.join(paldir, config.palette_files[item])
         try:
             self.palettes[item] = loader(self.app.appdata, filepath, False,
                                          False, True)
         except Exception:
             if fsutils.isfile(filepath):
                 fsutils.remove(filepath)
             del config.palette_files[item]
Ejemplo n.º 11
0
def read_locale(cfg_file):
    lang = 'system'
    if fsutils.isfile(cfg_file):
        try:
            with fsutils.uopen(cfg_file) as fp:
                while True:
                    line = fp.readline()
                    if not line:
                        break
                    if line.startswith('language'):
                        lang = line.split('=')[1].strip().replace('\'', '')
                        break
        except Exception:
            lang = 'system'
    return lang
Ejemplo n.º 12
0
 def new_from_template(self):
     msg = _('Select Template')
     doc_file = dialogs.get_open_file_name(self.mw, config.template_dir, msg)
     if fsutils.isfile(doc_file):
         try:
             doc = SK1Presenter(self, doc_file, template=True)
         except Exception as e:
             msg = _('Cannot parse file:')
             msg = "%s\n'%s'" % (msg, doc_file) + '\n'
             msg += _('The file may be corrupted or not supported format')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             LOG.error('Cannot parse file <%s> %s', doc_file, e)
             return
         self.docs.append(doc)
         config.template_dir = str(os.path.dirname(doc_file))
         self.set_current_doc(doc)
         events.emit(events.APP_STATUS, _('New document from template'))
Ejemplo n.º 13
0
 def read_history(self):
     if fsutils.isfile(self.history_file):
         fp = fsutils.get_fileptr(self.history_file)
         lines = [line.strip(' \n\r') for line in fp.readlines()]
         for line in lines:
             items = line.split('\t')
             if len(items) == 3:
                 status = int(items[0])
                 path = items[1]
                 try:
                     path = path.decode('utf-8')
                 except Exception:
                     path = path.decode(sys.getfilesystemencoding())
                 finally:
                     path = path.encode('utf-8')
                 timestamp = int(items[2])
                 self.history.append([status, path, timestamp])
         fp.close()
Ejemplo n.º 14
0
 def import_file(self):
     doc_file = dialogs.get_open_file_name(self.mw, config.import_dir,
                                           _('Select file to import'))
     if fsutils.lexists(doc_file) and fsutils.isfile(doc_file):
         try:
             ret = self.current_doc.import_file(doc_file)
             if not ret:
                 msg = _('Cannot import graphics from file:')
                 msg = "%s\n'%s'" % (msg, doc_file) + '\n'
                 msg += _('It seems the document is empty or '
                          'contains unsupported objects.')
                 dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
                 LOG.warn('Cannot import graphics from file <%s>', doc_file)
             config.import_dir = str(os.path.dirname(doc_file))
         except Exception as e:
             msg = _('Cannot import file:')
             msg = "%s\n'%s'" % (msg, doc_file) + '\n'
             msg += _('The file may be corrupted or not supported format.')
             msg += '\n'
             msg += _('Details see in application logs.')
             dialogs.error_dialog(self.mw, self.appdata.app_name, msg)
             LOG.warn('Cannot import file <%s>', doc_file, e)
Ejemplo n.º 15
0
 def import_pattern(self, parent=None):
     parent = parent or self.mw
     file_types = uc2const.PATTERN_FORMATS
     img_file = dialogs.get_open_file_name(parent, config.import_dir,
                                           _('Select pattern to load'),
                                           file_types=file_types)
     if fsutils.isfile(img_file):
         first = _('Cannot load pattern for:')
         msg = "%s\n'%s'." % (first, self.current_doc.doc_name) + '\n'
         msg += _('The file may be corrupted or not supported format')
         msg += '\n'
         msg += _('Details see in application logs.')
         try:
             if libimg.check_image(img_file):
                 config.import_dir = str(os.path.dirname(img_file))
                 return img_file
             else:
                 dialogs.error_dialog(parent, self.appdata.app_name, msg)
                 LOG.error('Cannot load pattern <%s>', img_file)
         except Exception as e:
             dialogs.error_dialog(parent, self.appdata.app_name, msg)
             LOG.error('Cannot load pattern <%s> %s', img_file, e)