Пример #1
0
    def __init__(self, app):
        super(MainWindow, self).__init__(application=app, title='RunSQLRun')
        self.app = app
        self._internal_state = {}

        self.set_default_size(800, 600)
        self.set_icon(
            Pixbuf.new_from_resource('/org/runsqlrun/icons/runsqlrun.svg'))

        self.headerbar = HeaderBar(self)
        self.set_titlebar(self.headerbar)

        self.docview = DocViewer(self)
        self.statusbar = Gtk.Statusbar()
        self.statusbar.set_margin_top(0)
        self.statusbar.set_margin_bottom(0)
        self.statusbar.push(303, 'Ready when you are')
        GObject.timeout_add(3000, self.statusbar.pop, 303)
        self.statusbar.set_spacing(6)
        self.statusbar.pack_end(ConnectionIndicator(self), False, False, 0)

        vbox = Gtk.VBox()
        vbox.pack_start(self.docview, True, True, 0)
        vbox.pack_start(self.statusbar, False, False, 0)
        self.add(vbox)
        # TODO: Statusbar

        # track window settings
        self.connect('window-state-event', self.on_window_state_event)
        self.connect('configure-event', self.on_configure_event)

        # Actions
        self._setup_actions()

        self.show_all()
Пример #2
0
 def create_folder_model(self,
                         title: str,
                         path: str,
                         tooltip: str = None,
                         icon: Pixbuf = None):
     icon = icon or Pixbuf.new_from_resource(RESOURCE_PREFIX +
                                             '/icons/folder.svg')
     self.model.append([icon, title, path, -1, tooltip or title])
Пример #3
0
 def on_show_about(self, *args):
     dlg = Gtk.AboutDialog('RunSQLRun', self.win)
     logo = Pixbuf.new_from_resource(
         '/org/runsqlrun/icons/128x128/runsqlrun.png')
     dlg.set_logo(logo)
     dlg.set_program_name('RunSQLRun')
     dlg.set_version(__version__)
     dlg.set_copyright('2015 Andi Albrecht <*****@*****.**>')
     dlg.set_license_type(Gtk.License.MIT_X11)
     dlg.set_website('http://runsqlrun.org')
     dlg.set_authors(['Andi Albrecht'])
     dlg.run()
     dlg.destroy()
Пример #4
0
    def set_manga_cover_image(self, overlay, width, height, update=False):
        overlay.set_size_request(width, height)

        if overlay._pixbuf is None or update:
            manga = overlay.manga
            if manga.cover_fs_path is not None:
                overlay._pixbuf = Pixbuf.new_from_file(manga.cover_fs_path)
            else:
                overlay._pixbuf = Pixbuf.new_from_resource('/info/febvre/Komikku/images/missing_file.png')

        pixbuf = overlay._pixbuf.scale_simple(width, height, InterpType.BILINEAR)
        image = overlay.get_children()[0]
        image.set_from_pixbuf(pixbuf)
Пример #5
0
 def on_show_about(self, *args):
     dlg = Gtk.AboutDialog('RunSQLRun', self.win)
     logo = Pixbuf.new_from_resource(
         '/org/runsqlrun/icons/128x128/runsqlrun.png')
     dlg.set_logo(logo)
     dlg.set_program_name('RunSQLRun')
     dlg.set_version(__version__)
     dlg.set_copyright('2015 Andi Albrecht <*****@*****.**>')
     dlg.set_license_type(Gtk.License.MIT_X11)
     dlg.set_website('http://runsqlrun.org')
     dlg.set_authors(['Andi Albrecht'])
     dlg.run()
     dlg.destroy()
Пример #6
0
    def set_manga_cover_image(overlay, width, height, update=False):
        if overlay._pixbuf is None or update:
            manga = overlay.manga

            if manga.cover_fs_path is None:
                overlay._pixbuf = Pixbuf.new_from_resource('/info/febvre/Komikku/images/missing_file.png')
            else:
                if get_file_mime_type(manga.cover_fs_path) != 'image/gif':
                    overlay._pixbuf = Pixbuf.new_from_file_at_scale(manga.cover_fs_path, 200, -1, True)
                else:
                    overlay._pixbuf = scale_pixbuf_animation(PixbufAnimation.new_from_file(manga.cover_fs_path), 200, -1, True)

        overlay.set_size_request(width, height)
        image = overlay.get_children()[0]
        if isinstance(overlay._pixbuf, PixbufAnimation):
            image.set_from_animation(scale_pixbuf_animation(overlay._pixbuf, width, height, False, loop=True))
        else:
            image.set_from_pixbuf(overlay._pixbuf.scale_simple(width, height, InterpType.BILINEAR))
Пример #7
0
    def __init__(self, app):
        super(MainWindow, self).__init__(application=app, title='RunSQLRun')
        self.app = app

        self.set_default_size(800, 600)
        self.set_icon(Pixbuf.new_from_resource(
            '/org/runsqlrun/icons/runsqlrun.svg'))

        self.headerbar = HeaderBar(self)
        self.set_titlebar(self.headerbar)

        self.docview = DocViewer(self)
        self.statusbar = Gtk.Statusbar()
        self.statusbar.set_margin_top(0)
        self.statusbar.set_margin_bottom(0)
        self.statusbar.push(303, 'Ready when you are')
        GObject.timeout_add(3000, self.statusbar.pop, 303)
        self.statusbar.set_spacing(6)
        self.statusbar.pack_end(ConnectionIndicator(self), False, False, 0)

        vbox = Gtk.VBox()
        vbox.pack_start(self.docview, True, True, 0)
        vbox.pack_start(self.statusbar, False, False, 0)
        self.add(vbox)
        # TODO: Statusbar

        # save and restore window settings
        if self.app.config.get('window-maximized'):
            self.maximize()
        size_setting = self.app.config.get('window-size')
        if size_setting is not None:
            self.resize(size_setting[0], size_setting[1])
        position_setting = self.app.config.get('window-position')
        if position_setting is not None:
            self.move(position_setting[0], position_setting[1])
        self.connect('window-state-event', self.on_window_state_event)
        self.connect('configure-event', self.on_configure_event)

        # Actions
        self._setup_actions()

        self.show_all()
Пример #8
0
    def reload_items(self,
                     sender: Gtk.Widget = None,
                     path: str = None) -> None:
        order_desc = self.settings.get_boolean('sort-desc')
        self.model.clear()

        _old_path = self.current_path

        self.current_path = path or self.current_folder_path

        # For non-root path add virtual "upper" folder.
        if self.current_folder_path != '/':
            # /folder 1/folder 2 -> /folder 1
            folder_path = self.current_folder_path[:self.
                                                   current_folder_path[:-1].
                                                   rfind('/')] or '/'
            folder_open_icon = Pixbuf.new_from_resource(
                RESOURCE_PREFIX + '/icons/folder-open.svg')
            self.create_folder_model(title='..',
                                     path=folder_path,
                                     icon=folder_open_icon,
                                     tooltip=_('Go to the upper folder'))

        # Emit "path-changed" signal.
        self.emit('path-changed', _old_path, self.current_path)

        # Load folders first
        Logger.info(f"reload_items: {self.current_folder_path}")
        for folder in self.storage.get_folders(path=self.current_folder_path):
            self.create_folder_model(title=folder.title, path=folder.path)

        # Then load documents, not before foldes.
        for document in self.storage.all(path=self.current_folder_path,
                                         with_archived=self.show_archived,
                                         desc=order_desc):
            # icon = Gtk.IconTheme.get_default().load_icon('text-x-generic', 64, 0)
            opacity = 0.2 if document.archived else 1

            # generate icon. It needs to stay in cache
            icon = self.gen_preview(document.content[:200], opacity=opacity)

            # Generate tooltip
            tooltip = f"{document.title}"

            if document.created:
                created = datetime.strptime(document.created,
                                            "%Y-%m-%d %H:%M:%S.%f")
                tooltip += f"\n<span weight='600' size='smaller' alpha='75%'>" \
                           + _('Created') + f": {created.strftime('%x')}</span>"

            if document.modified:
                modified = datetime.strptime(document.modified,
                                             "%Y-%m-%d %H:%M:%S.%f")
                tooltip += f"\n<span weight='600' size='smaller' alpha='75%'>" \
                           + _('Modified') + f": {modified.strftime('%x')}</span>"

            self.model.append([
                icon, document.title, document.content, document.document_id,
                tooltip
            ])

        if self.selected_path:
            self.view.select_path(self.selected_path)
Пример #9
0
    def new_from_resource(cls, path):
        buffer = Pixbuf.new_from_resource(path)
        width = buffer.get_width()
        height = buffer.get_height()

        return cls(None, buffer, width, height)