コード例 #1
0
ファイル: editor.py プロジェクト: richiware/draobpilc
    def __init__(self):
        super().__init__(_('Edit'),
                         priority=ItemsProcessorPriority.NORMAL,
                         default=True)

        self._text_window = TextWindow()
        self._text_window.connect('changed', self._edit_item)
        self._text_window.textview.set_name('EditorTextView')

        self.grid.set_name('EditorGrid')
        self.grid.attach(self._text_window, 0, 0, 1, 1)
コード例 #2
0
ファイル: previewer.py プロジェクト: richiware/draobpilc
    def __init__(self):
        super().__init__(_('Preview'), ItemsProcessorPriority.HIGH)

        self._thumb_max_width = Previewer.THUMB_MAX_WIDTH
        self._thumb_max_height = Previewer.THUMB_MAX_HEIGHT

        self._thumb = ItemThumb()
        self._thumb.set_vexpand(True)
        self._thumb.set_hexpand(True)
        self._thumb.set_valign(Gtk.Align.CENTER)
        self._thumb.set_halign(Gtk.Align.CENTER)
        self._thumb.props.margin = ItemsProcessorBase.MARGIN
        self._thumb.show()

        self._thumb_eventbox = Gtk.EventBox()
        self._thumb_eventbox.set_no_show_all(True)
        self._thumb_eventbox.add(self._thumb)
        self._thumb_eventbox.connect('realize', self._change_cursor)
        self._thumb_eventbox.connect('button-release-event',
                                     self._on_thumb_button_release)
        self._thumb_eventbox.set_tooltip_text(
            _('Click to locate the file on disk'))
        self._thumb_eventbox.hide()

        self._path_entry = Gtk.Entry()
        self._path_entry.set_editable(False)
        self._path_entry.set_hexpand(True)
        self._path_entry.set_icon_from_icon_name(
            Gtk.EntryIconPosition.PRIMARY, 'system-file-manager-symbolic')
        self._path_entry.props.margin = ItemsProcessorBase.MARGIN

        self._text_window = TextWindow()
        self._text_window.set_no_show_all(True)
        self._text_window.textview.set_name('EditorTextView')
        self._text_window.textview.set_editable(False)
        self._text_window.hide()

        self.grid.set_name('PreviwerGrid')
        self.grid.attach(self._path_entry, 0, 0, 2, 1)
        self.grid.attach(self._thumb_eventbox, 0, 1, 2, 1)
        self.grid.attach(self._text_window, 0, 1, 2, 1)
コード例 #3
0
ファイル: editor.py プロジェクト: awamper/draobpilc
    def __init__(self):
        super().__init__(
            _('Edit'),
            priority=ItemsProcessorPriority.NORMAL,
            default=True
        )

        self._text_window = TextWindow()
        self._text_window.connect('changed', self._edit_item)
        self._text_window.textview.set_name('EditorTextView')

        self.grid.set_name('EditorGrid')
        self.grid.attach(self._text_window, 0, 0, 1, 1)
コード例 #4
0
ファイル: previewer.py プロジェクト: awamper/draobpilc
    def __init__(self):
        super().__init__(_('Preview'), ItemsProcessorPriority.HIGH)

        self._thumb_max_width = Previewer.THUMB_MAX_WIDTH
        self._thumb_max_height = Previewer.THUMB_MAX_HEIGHT

        self._thumb = ItemThumb()
        self._thumb.set_vexpand(True)
        self._thumb.set_hexpand(True)
        self._thumb.set_valign(Gtk.Align.CENTER)
        self._thumb.set_halign(Gtk.Align.CENTER)
        self._thumb.props.margin = ItemsProcessorBase.MARGIN
        self._thumb.show()

        self._thumb_eventbox = Gtk.EventBox()
        self._thumb_eventbox.set_no_show_all(True)
        self._thumb_eventbox.add(self._thumb)
        self._thumb_eventbox.connect(
            'realize',
            self._change_cursor
        )
        self._thumb_eventbox.connect(
            'button-release-event',
            self._on_thumb_button_release
        )
        self._thumb_eventbox.set_tooltip_text(
            _('Click to locate the file on disk')
        )
        self._thumb_eventbox.hide()

        self._path_entry = Gtk.Entry()
        self._path_entry.set_editable(False)
        self._path_entry.set_hexpand(True)
        self._path_entry.set_icon_from_icon_name(
            Gtk.EntryIconPosition.PRIMARY,
            'system-file-manager-symbolic'
        )
        self._path_entry.props.margin = ItemsProcessorBase.MARGIN

        self._text_window = TextWindow()
        self._text_window.set_no_show_all(True)
        self._text_window.textview.set_name('EditorTextView')
        self._text_window.textview.set_editable(False)
        self._text_window.hide()

        self.grid.set_name('PreviwerGrid')
        self.grid.attach(self._path_entry, 0, 0, 2, 1)
        self.grid.attach(self._thumb_eventbox, 0, 1, 2, 1)
        self.grid.attach(self._text_window, 0, 1, 2, 1)
コード例 #5
0
ファイル: editor.py プロジェクト: awamper/draobpilc
class Editor(ItemsProcessorBase):

    def __init__(self):
        super().__init__(
            _('Edit'),
            priority=ItemsProcessorPriority.NORMAL,
            default=True
        )

        self._text_window = TextWindow()
        self._text_window.connect('changed', self._edit_item)
        self._text_window.textview.set_name('EditorTextView')

        self.grid.set_name('EditorGrid')
        self.grid.attach(self._text_window, 0, 0, 1, 1)

    def _edit_item(self, text_window, buffer):
        if not self.item: return

        contents = self._text_window.buffer.props.text

        if contents and contents != self.item.raw:
            gpaste_client.replace(self.item.index, contents)

    def clear(self):
        super().clear()

        self._text_window.buffer.set_text('')
        self._text_window.set_sensitive(False)

    def set_items(self, items):
        self.items = items
        self._text_window.set_sensitive(True)
        self._text_window.buffer.set_text(self.item.raw)
        self._text_window.set_filename(None)

    def can_process(self, items):
        if (
            len(items) == 1 and (
                items[0].kind == HistoryItemKind.TEXT or
                items[0].kind == HistoryItemKind.LINK
            )
        ):
            return True
        else:
            return False
コード例 #6
0
ファイル: editor.py プロジェクト: richiware/draobpilc
class Editor(ItemsProcessorBase):
    def __init__(self):
        super().__init__(_('Edit'),
                         priority=ItemsProcessorPriority.NORMAL,
                         default=True)

        self._text_window = TextWindow()
        self._text_window.connect('changed', self._edit_item)
        self._text_window.textview.set_name('EditorTextView')

        self.grid.set_name('EditorGrid')
        self.grid.attach(self._text_window, 0, 0, 1, 1)

    def _edit_item(self, text_window, buffer):
        if not self.item: return

        contents = self._text_window.buffer.props.text

        if contents and contents != self.item.raw:
            gpaste_client.replace(self.item.uuid, contents)

    def clear(self):
        super().clear()

        self._text_window.buffer.set_text('')
        self._text_window.set_sensitive(False)

    def set_items(self, items):
        self.items = items
        self._text_window.set_sensitive(True)
        self._text_window.buffer.set_text(self.item.raw)
        self._text_window.set_filename(None)

    def can_process(self, items):
        if (len(items) == 1 and (items[0].kind == HistoryItemKind.TEXT
                                 or items[0].kind == HistoryItemKind.LINK)):
            return True
        else:
            return False
コード例 #7
0
ファイル: previewer.py プロジェクト: awamper/draobpilc
class Previewer(ItemsProcessorBase):

    THUMB_MAX_WIDTH = 200
    THUMB_MAX_HEIGHT = 200

    def __init__(self):
        super().__init__(_('Preview'), ItemsProcessorPriority.HIGH)

        self._thumb_max_width = Previewer.THUMB_MAX_WIDTH
        self._thumb_max_height = Previewer.THUMB_MAX_HEIGHT

        self._thumb = ItemThumb()
        self._thumb.set_vexpand(True)
        self._thumb.set_hexpand(True)
        self._thumb.set_valign(Gtk.Align.CENTER)
        self._thumb.set_halign(Gtk.Align.CENTER)
        self._thumb.props.margin = ItemsProcessorBase.MARGIN
        self._thumb.show()

        self._thumb_eventbox = Gtk.EventBox()
        self._thumb_eventbox.set_no_show_all(True)
        self._thumb_eventbox.add(self._thumb)
        self._thumb_eventbox.connect(
            'realize',
            self._change_cursor
        )
        self._thumb_eventbox.connect(
            'button-release-event',
            self._on_thumb_button_release
        )
        self._thumb_eventbox.set_tooltip_text(
            _('Click to locate the file on disk')
        )
        self._thumb_eventbox.hide()

        self._path_entry = Gtk.Entry()
        self._path_entry.set_editable(False)
        self._path_entry.set_hexpand(True)
        self._path_entry.set_icon_from_icon_name(
            Gtk.EntryIconPosition.PRIMARY,
            'system-file-manager-symbolic'
        )
        self._path_entry.props.margin = ItemsProcessorBase.MARGIN

        self._text_window = TextWindow()
        self._text_window.set_no_show_all(True)
        self._text_window.textview.set_name('EditorTextView')
        self._text_window.textview.set_editable(False)
        self._text_window.hide()

        self.grid.set_name('PreviwerGrid')
        self.grid.attach(self._path_entry, 0, 0, 2, 1)
        self.grid.attach(self._thumb_eventbox, 0, 1, 2, 1)
        self.grid.attach(self._text_window, 0, 1, 2, 1)

    def _change_cursor(self, sender):
        window = sender.get_window()
        if not window: return

        display = Gdk.Display.get_default()
        cursor = Gdk.Cursor.new_for_display(display, Gdk.CursorType.HAND1)
        window.set_cursor(cursor)

    def _on_thumb_button_release(self, event_box, event):
        app_info = Gio.AppInfo.get_default_for_type('inode/directory', True)
        if not app_info: return
        app_info.launch_uris(['file://%s' % self._path_entry.get_text()], None)
        common.APPLICATION.hide()

    def _is_previewable_type(self, content_type):
        if not content_type: return False

        if content_type.startswith('text') or 'bash' in content_type:
            return True
        else:
            return False

    def _preview_supported(self, item):
        if (
            item.kind == HistoryItemKind.FILE or
            item.kind == HistoryItemKind.IMAGE
        ):
            return True
        elif (
            not item or
            not os.path.exists(item.raw) or
            not common.SETTINGS[common.PREVIEW_TEXT_FILES] or
            not self._is_previewable_type(item.content_type)
        ):
            return False

        return True

    def clear(self):
        super().clear()

        self._path_entry.set_text('')
        self._text_window.buffer.set_text('')
        self._thumb.clear()

    def set_max_size(self, width, height):
        self._thumb_max_width = width or Previewer.THUMB_MAX_WIDTH
        self._thumb_max_height = height or Previewer.THUMB_MAX_HEIGHT

    def set_items(self, items):
        self.items = items
        self._path_entry.set_text(self.item.raw)
        exists = os.path.exists(self.item.raw)

        if (
            exists and
            self._preview_supported(self.item) and
            self._is_previewable_type(self.item.content_type)
        ):
            self._thumb_eventbox.hide()
            self._text_window.show()
            self._path_entry.show()

            with open(self.item.raw, 'r') as fp:
                contents = fp.read()
                self._text_window.set_filename(self.item.raw)
                self._text_window.buffer.set_text(contents)
        elif self.item.thumb_path:
            self._thumb.set_filename(
                self.item.thumb_path,
                self._thumb_max_width * 0.8,
                self._thumb_max_height * 0.8
            )
            self._text_window.hide()
            self._thumb_eventbox.show()
            self._path_entry.show()
        else:
            self._path_entry.hide()
            self._thumb_eventbox.hide()

            self._text_window.show()
            self._text_window.buffer.set_text(self.item.raw)
            self._text_window.set_filename(None)

    def can_process(self, items):
        if (
            len(items) == 1 and (
                self._preview_supported(items[0]) or
                items[0].thumb_path
            )
        ):
            return True
        else:
            return False
コード例 #8
0
    def __init__(self):
        super().__init__(_('Merge'), ItemsProcessorPriority.HIGHEST)

        self._counter_label = Gtk.Label()
        self._counter_label.set_markup(COUNTER_LABEL_TPL % 0)
        self._counter_label.set_hexpand(True)
        self._counter_label.set_vexpand(False)
        self._counter_label.set_valign(Gtk.Align.CENTER)
        self._counter_label.set_halign(Gtk.Align.CENTER)

        self._decorator_label = Gtk.Label()
        self._decorator_label.props.margin = ItemsProcessorBase.MARGIN
        self._decorator_label.set_label(_('Decorator'))

        self._decorator_combo = Gtk.ComboBoxText.new_with_entry()
        self._decorator_combo.connect('changed', lambda c: self.update())
        self._decorator_combo.props.margin = ItemsProcessorBase.MARGIN

        self._separator_label = Gtk.Label()
        self._separator_label.props.margin = ItemsProcessorBase.MARGIN
        self._separator_label.set_label(_('Separator'))

        self._separator_combo = Gtk.ComboBoxText.new_with_entry()
        self._separator_combo.connect('changed', lambda c: self.update())
        self._separator_combo.props.margin = ItemsProcessorBase.MARGIN

        self._text_window = TextWindow()
        self._text_window.textview.set_name('MergerTextView')

        self._merge_btn = Gtk.Button()
        self._merge_btn.set_label(_('Merge'))
        self._merge_btn.connect(
            'clicked',
            lambda b: self.emit('merge', self.items, False)
        )

        self._merge_del_btn = Gtk.Button()
        self._merge_del_btn.set_label(_('Merge & Delete'))
        self._merge_del_btn.set_tooltip_text(
            _('Merge and delete merged items')
        )
        self._merge_del_btn.connect(
            'clicked',
            lambda b: self.emit('merge', self.items, True)
        )

        self._reverse_order_btn = Gtk.CheckButton(_('Reverse order'))
        self._reverse_order_btn.props.margin = ItemsProcessorBase.MARGIN
        self._reverse_order_btn.set_active(False)
        self._reverse_order_btn.connect('toggled', lambda b: self.update())

        buttons_box = Gtk.ButtonBox()
        buttons_box.set_layout(Gtk.ButtonBoxStyle.EXPAND)
        buttons_box.props.margin = ItemsProcessorBase.MARGIN
        buttons_box.add(self._merge_del_btn)
        buttons_box.add(self._merge_btn)

        self.grid.set_name('MergerBox')
        self.grid.attach(self._counter_label, 0, 1, 2, 1)
        self.grid.attach(self._decorator_label, 0, 2, 1, 1)
        self.grid.attach(self._decorator_combo, 0, 3, 1, 1)
        self.grid.attach(self._separator_label, 1, 2, 1, 1)
        self.grid.attach(self._separator_combo, 1, 3, 1, 1)
        self.grid.attach(self._text_window, 0, 4, 2, 1)
        self.grid.attach(self._reverse_order_btn, 0, 5, 2, 1)
        self.grid.attach(buttons_box, 0, 6, 2, 1)

        common.SETTINGS.connect(
            'changed::' + common.MERGE_DEFAULT_DECORATOR,
            self._on_settings_changed
        )
        common.SETTINGS.connect(
            'changed::' + common.MERGE_DEFAULT_SEPARATOR,
            self._on_settings_changed
        )
        common.SETTINGS.connect(
            'changed::' + common.MERGE_DECORATORS,
            lambda s, k: self._update_merge_data()
        )
        common.SETTINGS.connect(
            'changed::' + common.MERGE_SEPARATORS,
            lambda s, k: self._update_merge_data()
        )

        self._update_merge_data()
コード例 #9
0
ファイル: previewer.py プロジェクト: richiware/draobpilc
class Previewer(ItemsProcessorBase):

    THUMB_MAX_WIDTH = 200
    THUMB_MAX_HEIGHT = 200

    def __init__(self):
        super().__init__(_('Preview'), ItemsProcessorPriority.HIGH)

        self._thumb_max_width = Previewer.THUMB_MAX_WIDTH
        self._thumb_max_height = Previewer.THUMB_MAX_HEIGHT

        self._thumb = ItemThumb()
        self._thumb.set_vexpand(True)
        self._thumb.set_hexpand(True)
        self._thumb.set_valign(Gtk.Align.CENTER)
        self._thumb.set_halign(Gtk.Align.CENTER)
        self._thumb.props.margin = ItemsProcessorBase.MARGIN
        self._thumb.show()

        self._thumb_eventbox = Gtk.EventBox()
        self._thumb_eventbox.set_no_show_all(True)
        self._thumb_eventbox.add(self._thumb)
        self._thumb_eventbox.connect('realize', self._change_cursor)
        self._thumb_eventbox.connect('button-release-event',
                                     self._on_thumb_button_release)
        self._thumb_eventbox.set_tooltip_text(
            _('Click to locate the file on disk'))
        self._thumb_eventbox.hide()

        self._path_entry = Gtk.Entry()
        self._path_entry.set_editable(False)
        self._path_entry.set_hexpand(True)
        self._path_entry.set_icon_from_icon_name(
            Gtk.EntryIconPosition.PRIMARY, 'system-file-manager-symbolic')
        self._path_entry.props.margin = ItemsProcessorBase.MARGIN

        self._text_window = TextWindow()
        self._text_window.set_no_show_all(True)
        self._text_window.textview.set_name('EditorTextView')
        self._text_window.textview.set_editable(False)
        self._text_window.hide()

        self.grid.set_name('PreviwerGrid')
        self.grid.attach(self._path_entry, 0, 0, 2, 1)
        self.grid.attach(self._thumb_eventbox, 0, 1, 2, 1)
        self.grid.attach(self._text_window, 0, 1, 2, 1)

    def _change_cursor(self, sender):
        window = sender.get_window()
        if not window: return

        display = Gdk.Display.get_default()
        cursor = Gdk.Cursor.new_for_display(display, Gdk.CursorType.HAND1)
        window.set_cursor(cursor)

    def _on_thumb_button_release(self, event_box, event):
        app_info = Gio.AppInfo.get_default_for_type('inode/directory', True)
        if not app_info: return
        app_info.launch_uris(['file://%s' % self._path_entry.get_text()], None)
        common.APPLICATION.hide()

    def _is_previewable_type(self, content_type):
        if not content_type: return False

        if content_type.startswith('text') or 'bash' in content_type:
            return True
        else:
            return False

    def _preview_supported(self, item):
        if (item.kind == HistoryItemKind.FILE
                or item.kind == HistoryItemKind.IMAGE):
            return True
        elif (not item or not os.path.exists(item.raw)
              or not common.SETTINGS[common.PREVIEW_TEXT_FILES]
              or not self._is_previewable_type(item.content_type)):
            return False

        return True

    def clear(self):
        super().clear()

        self._path_entry.set_text('')
        self._text_window.buffer.set_text('')
        self._thumb.clear()

    def set_max_size(self, width, height):
        self._thumb_max_width = width or Previewer.THUMB_MAX_WIDTH
        self._thumb_max_height = height or Previewer.THUMB_MAX_HEIGHT

    def set_items(self, items):
        self.items = items
        self._path_entry.set_text(self.item.raw)
        exists = os.path.exists(self.item.raw)

        if (exists and self._preview_supported(self.item)
                and self._is_previewable_type(self.item.content_type)):
            self._thumb_eventbox.hide()
            self._text_window.show()
            self._path_entry.show()

            with open(self.item.raw, 'r') as fp:
                contents = fp.read()
                self._text_window.set_filename(self.item.raw)
                self._text_window.buffer.set_text(contents)
        elif self.item.thumb_path:
            self._thumb.set_filename(self.item.thumb_path,
                                     self._thumb_max_width * 0.8,
                                     self._thumb_max_height * 0.8)
            self._text_window.hide()
            self._thumb_eventbox.show()
            self._path_entry.show()
        else:
            self._path_entry.hide()
            self._thumb_eventbox.hide()

            self._text_window.show()
            self._text_window.buffer.set_text(self.item.raw)
            self._text_window.set_filename(None)

    def can_process(self, items):
        if (len(items) == 1 and
            (self._preview_supported(items[0]) or items[0].thumb_path)):
            return True
        else:
            return False