Пример #1
0
    def __init__(self, item):
        super(NoteEntry, self).__init__(height_request=150,
                                        width_request=150,
                                        valign=Gtk.Align.START,
                                        halign=Gtk.Align.CENTER,
                                        margin=10)

        self.item = item

        self.set_has_window(False)

        self.buffer = NoteBuffer()
        self.text = Gtk.TextView(wrap_mode=Gtk.WrapMode.WORD_CHAR,
                                 populate_all=True,
                                 buffer=self.buffer,
                                 visible=True,
                                 sensitive=False)

        self.buffer.set_view(self.text)
        self.buffer.set_from_internal_markup(item.text)

        self.text.set_parent(self)

        self.initialized = True

        self.show_all()
Пример #2
0
    def __init__(self, app, info={}):
        self.app = app

        self.showing = False
        self.is_pinned = False

        self.x = info.get('x', 0)
        self.y = info.get('y', 0)
        self.height = info.get('height', self.app.settings.get_uint('default-height'))
        self.width = info.get('width', self.app.settings.get_uint('default-width'))
        title = info.get('title', '')
        text = info.get('text', '')
        self.color = info.get('color', self.app.settings.get_string('default-color'))

        super(Note, self).__init__(
            skip_taskbar_hint=True,
            # skip_pager_hint=False,
            type_hint=Gdk.WindowTypeHint.UTILITY,
            default_height=self.height,
            default_width=self.width,
            resizable=True,
            deletable=False,
            name='sticky-note'
        )

        if self.color == 'random':
            self.color = random.choice(list(COLORS.keys()))

        context = self.get_style_context()
        context.add_class(self.color)

        if self.app.settings.get_boolean('desktop-window-state'):
            self.stick()

        # title bar
        self.title_bar = Gtk.Box(height_request=30, name='title-box')
        self.connect('button-press-event', self.on_title_click)

        # formatting items are shown here
        more_menu_icon = Gtk.Image.new_from_icon_name('view-more', Gtk.IconSize.BUTTON)
        more_menu_button = Gtk.Button(image=more_menu_icon, relief=Gtk.ReliefStyle.NONE, name='window-button', valign=Gtk.Align.CENTER)
        more_menu_button.connect('clicked', self.show_more_menu)
        more_menu_button.connect('button-press-event', self.on_title_click)
        more_menu_button.set_tooltip_text(_("Format"))
        self.title_bar.pack_start(more_menu_button, False, False, 0)

        # used to show the edit title icon when the title is hovered
        self.title_hover = Gtk.EventBox()
        self.title_bar.pack_start(self.title_hover, True, True, 4)
        self.title_hover.connect('enter-notify-event', self.set_edit_button_visibility)
        self.title_hover.connect('leave-notify-event', self.set_edit_button_visibility)

        self.title_box = Gtk.Box()
        self.title_hover.add(self.title_box)
        self.title = Gtk.Label(label=title, margin_top=4)
        self.title_box.pack_start(self.title, False, False, 0)

        edit_title_icon = Gtk.Image.new_from_icon_name('edit', Gtk.IconSize.BUTTON)
        self.edit_title_button = Gtk.Button(image=edit_title_icon, relief=Gtk.ReliefStyle.NONE, name='window-button', valign=Gtk.Align.CENTER, no_show_all=True)
        self.edit_title_button.connect('clicked', self.set_title)
        self.edit_title_button.connect('button-press-event', self.on_title_click)
        self.edit_title_button.set_tooltip_text(_("Format"))
        self.title_box.pack_start(self.edit_title_button, False, False, 0)

        close_icon = Gtk.Image.new_from_icon_name('window-close', Gtk.IconSize.BUTTON)
        close_button = Gtk.Button(image=close_icon, relief=Gtk.ReliefStyle.NONE, name='window-button', valign=Gtk.Align.CENTER)
        close_button.connect('clicked', self.remove)
        close_button.connect('button-press-event', self.on_title_click)
        close_button.set_tooltip_text(_("Delete Note"))
        self.title_bar.pack_end(close_button, False, False, 0)

        add_icon = Gtk.Image.new_from_icon_name('add', Gtk.IconSize.BUTTON)
        add_button = Gtk.Button(image=add_icon, relief=Gtk.ReliefStyle.NONE, name='window-button', valign=Gtk.Align.CENTER)
        add_button.connect('clicked', self.app.new_note)
        add_button.connect('button-press-event', self.on_title_click)
        add_button.set_tooltip_text(_("New Note"))
        self.title_bar.pack_end(add_button, False, False, 0)

        # test_icon = Gtk.Image.new_from_icon_name('system-run-symbolic', Gtk.IconSize.BUTTON)
        # test_button = Gtk.Button(image=test_icon, relief=Gtk.ReliefStyle.NONE, name='window-button', valign=Gtk.Align.CENTER)
        # test_button.connect('clicked', self.test)
        # test_button.connect('button-press-event', self.on_title_click)
        # self.title_bar.pack_end(test_button, False, False, 0)

        self.set_titlebar(self.title_bar)

        # buffer
        self.buffer = NoteBuffer()

        # text view
        self.view = Gtk.TextView(wrap_mode=Gtk.WrapMode.WORD_CHAR, populate_all=True, buffer=self.buffer)
        self.buffer.set_view(self.view)
        spell_checker = Gspell.TextView.get_from_gtk_text_view(self.view)
        spell_checker.basic_setup()
        self.app.settings.bind('inline-spell-check', spell_checker, 'inline-spell-checking', Gio.SettingsBindFlags.GET)
        self.view.set_left_margin(10)
        self.view.set_right_margin(10)
        self.view.set_top_margin(10)
        self.view.set_bottom_margin(10)
        self.view.connect('populate-popup', lambda w, p: self.add_context_menu_items(p))
        self.view.connect('key-press-event', self.on_key_press)

        scroll = Gtk.ScrolledWindow()
        self.add(scroll)
        scroll.add(self.view)

        self.buffer.set_from_internal_markup(text)
        self.changed_id = self.buffer.connect('content-changed', self.changed)

        self.connect('configure-event', self.handle_update)
        self.connect('show', self.on_show)
        self.connect('window-state-event', self.update_window_state)

        self.move(self.x, self.y)

        self.show_all()
Пример #3
0
    def __init__(self, app, info={}):
        self.app = app

        self.showing = False

        self.x = info.get('x', 0)
        self.y = info.get('y', 0)
        self.height = info.get('height',
                               self.app.settings.get_uint('default-height'))
        self.width = info.get('width',
                              self.app.settings.get_uint('default-width'))
        title = info.get('title', '')
        text = info.get('text', '')
        self.color = info.get('color',
                              self.app.settings.get_string('default-color'))

        super(Note, self).__init__(
            skip_taskbar_hint=True,
            # skip_pager_hint=False,
            type_hint=Gdk.WindowTypeHint.UTILITY,
            default_height=self.height,
            default_width=self.width,
            resizable=True,
            deletable=False,
            name='sticky-note')

        if self.color == 'random':
            self.color = random.choice(COLORS)

        context = self.get_style_context()
        context.add_class(self.color)

        self.stick()

        # title bar
        self.title_box = Gtk.Box(height_request=30, name='title-box')
        self.connect('button-press-event', self.on_title_click)

        self.title = Gtk.Label(label=title)
        self.title_box.pack_start(self.title, False, False, 0)

        close_icon = Gtk.Image.new_from_icon_name('window-close',
                                                  Gtk.IconSize.BUTTON)
        close_button = Gtk.Button(image=close_icon,
                                  relief=Gtk.ReliefStyle.NONE,
                                  name='window-button',
                                  valign=Gtk.Align.CENTER)
        close_button.connect('clicked', self.remove)
        close_button.connect('button-press-event', self.on_title_click)
        self.title_box.pack_end(close_button, False, False, 0)

        add_icon = Gtk.Image.new_from_icon_name('add', Gtk.IconSize.BUTTON)
        add_button = Gtk.Button(image=add_icon,
                                relief=Gtk.ReliefStyle.NONE,
                                name='window-button',
                                valign=Gtk.Align.CENTER)
        add_button.connect('clicked', self.app.new_note)
        add_button.connect('button-press-event', self.on_title_click)
        self.title_box.pack_end(add_button, False, False, 0)

        test_icon = Gtk.Image.new_from_icon_name('system-run-symbolic',
                                                 Gtk.IconSize.BUTTON)
        test_button = Gtk.Button(image=test_icon,
                                 relief=Gtk.ReliefStyle.NONE,
                                 name='window-button',
                                 valign=Gtk.Align.CENTER)
        test_button.connect('clicked', self.test)
        test_button.connect('button-press-event', self.on_title_click)
        self.title_box.pack_end(test_button, False, False, 0)

        self.set_titlebar(self.title_box)

        # buffer
        self.buffer = NoteBuffer()

        tag = self.buffer.create_tag('red', foreground='red')

        # text view
        self.view = Gtk.TextView(wrap_mode=Gtk.WrapMode.WORD_CHAR,
                                 populate_all=True,
                                 buffer=self.buffer)
        self.buffer.view = self.view  #fixme: this is an ugly hack so that we can add checkboxes and bullet points from the buffer
        self.view.set_left_margin(10)
        self.view.set_right_margin(10)
        self.view.set_top_margin(10)
        self.view.set_bottom_margin(10)
        self.view.connect('populate-popup',
                          lambda w, p: self.add_context_menu_items(p))
        self.view.connect('key-press-event', self.on_key_press)

        scroll = Gtk.ScrolledWindow()
        self.add(scroll)
        scroll.add(self.view)

        # self.buffer.begin_not_undoable_action()
        self.buffer.set_from_internal_markup(text)
        # self.buffer.end_not_undoable_action()
        self.changed_id = self.buffer.connect('changed', self.changed)

        self.connect('configure-event', self.handle_update)
        self.connect('show', self.on_show)

        self.move(self.x, self.y)

        self.show_all()