Ejemplo n.º 1
0
    def setup(self):
        uimanager = self.main_window.uimanager

        # Create an ActionGroup
        actiongroup = Gtk.ActionGroup('FormatActionGroup')

        def apply_format(action):
            format_ = action.get_name().lower()
            iter_ = self.main_window.categories_tree_view.get_selected_node()
            if iter_:
                markup = self.FORMAT_TO_MARKUP[format_]
                text = self.main_window.categories_tree_view.get_iter_value(iter_)
                text = '%s%s%s' % (markup, text, markup)
                self.main_window.categories_tree_view.set_iter_value(iter_, text)
            else:
                self.main_window.day_text_field.apply_format(format_)

        def shortcut(char):
            # Translators: The Control (Ctrl) key
            return ''  # return ' (%s+%s)' % (_('Ctrl'), char)

        # Create actions
        actions = [
            ('Bold', Gtk.STOCK_BOLD, _('Bold') + shortcut('B'),
             '<Control>B', None, apply_format),
            ('Italic', Gtk.STOCK_ITALIC, _('Italic') + shortcut('I'),
             '<Control>I', None, apply_format),
            ('Monospace', None, _('Monospace') + shortcut('M'),
             '<Control>M', None, apply_format),
            ('Underline', Gtk.STOCK_UNDERLINE, _('Underline') + shortcut('U'),
             '<Control>U', None, apply_format),
            ('Strikethrough', Gtk.STOCK_STRIKETHROUGH, _('Strikethrough') + shortcut('K'),
             '<Control>K', None, apply_format),
            ('Clear', Gtk.STOCK_CLEAR, _('Clear format') + shortcut('R'),
             '<Control>R', None, self.on_clear_format),
            # Translators: Noun
            ('FormatMenuBar', None, _('_Format')),
        ]

        actiongroup.add_actions(actions)

        # Add the actiongroup to the uimanager
        uimanager.insert_action_group(actiongroup, 0)

        # Add a UI description
        uimanager.add_ui_from_string(TOOLBAR_XML)

        # Create a Menu
        menu = uimanager.get_widget('/FormatMenu')

        self.main_window.format_button = customwidgets.ToolbarMenuButton(Gtk.STOCK_BOLD, menu)
        # Translators: Noun
        self.main_window.format_button.set_label(_('Format'))
        tip = _('Format the selected text or tag')
        self.main_window.format_button.set_tooltip_text(tip)
        self.main_window.builder.get_object('edit_toolbar').insert(self.main_window.format_button, -1)
        self.main_window.format_actiongroup = actiongroup
Ejemplo n.º 2
0
    def setup_template_menu(self):
        def update_menu(button):
            self.template_button.set_menu(self.template_manager.get_menu())

        self.template_button = customwidgets.ToolbarMenuButton(
            Gtk.STOCK_PASTE, self.template_manager.get_menu())
        self.template_button.set_label(_('Template'))
        self.template_button.connect('clicked', update_menu)
        self.template_button.set_tooltip_text(
            _("Insert this weekday's template. "
              "Click the arrow on the right for more options"))
        self.builder.get_object('edit_toolbar').insert(self.template_button, 2)
Ejemplo n.º 3
0
    def setup(self):
        uimanager = self.main_window.uimanager

        # Create an ActionGroup
        actiongroup = Gtk.ActionGroup("FormatActionGroup")

        def apply_format(action):
            format_ = action.get_name().lower()
            iter_ = self.main_window.categories_tree_view.get_selected_node()
            if iter_:
                markup = self.FORMAT_TO_MARKUP[format_]
                text = self.main_window.categories_tree_view.get_iter_value(
                    iter_)
                text = "{}{}{}".format(markup, text, markup)
                self.main_window.categories_tree_view.set_iter_value(
                    iter_, text)
            else:
                self.main_window.day_text_field.apply_format(format_)

        def shortcut(char):
            # Translators: The Control (Ctrl) key
            return ""  # return ' (%s+%s)' % (_('Ctrl'), char)

        # Create actions
        actions = [
            (
                "Bold",
                Gtk.STOCK_BOLD,
                _("Bold") + shortcut("B"),
                "<Control>B",
                None,
                apply_format,
            ),
            (
                "Italic",
                Gtk.STOCK_ITALIC,
                _("Italic") + shortcut("I"),
                "<Control>I",
                None,
                apply_format,
            ),
            (
                "Monospace",
                None,
                _("Monospace") + shortcut("M"),
                "<Control>M",
                None,
                apply_format,
            ),
            (
                "Underline",
                Gtk.STOCK_UNDERLINE,
                _("Underline") + shortcut("U"),
                "<Control>U",
                None,
                apply_format,
            ),
            (
                "Strikethrough",
                Gtk.STOCK_STRIKETHROUGH,
                _("Strikethrough") + shortcut("K"),
                "<Control>K",
                None,
                apply_format,
            ),
            (
                "Clear",
                Gtk.STOCK_CLEAR,
                _("Clear format") + shortcut("R"),
                "<Control>R",
                None,
                self.on_clear_format,
            ),
            # Translators: Noun
            ("FormatMenuBar", None, _("_Format")),
        ]

        actiongroup.add_actions(actions)

        # Add the actiongroup to the uimanager
        uimanager.insert_action_group(actiongroup, 0)

        # Add a UI description
        uimanager.add_ui_from_string(TOOLBAR_XML)

        # Create a Menu
        menu = uimanager.get_widget("/FormatMenu")

        self.main_window.format_button = customwidgets.ToolbarMenuButton(
            Gtk.STOCK_BOLD, menu)
        # Translators: Noun
        self.main_window.format_button.set_label(_("Format"))
        tip = _("Format the selected text or tag")
        self.main_window.format_button.set_tooltip_text(tip)
        self.main_window.builder.get_object("edit_toolbar").insert(
            self.main_window.format_button, -1)
        self.main_window.format_actiongroup = actiongroup
Ejemplo n.º 4
0
    def setup(self):
        '''
        See http://www.pyGtk.org/pygtk2tutorial/sec-UIManager.html for help
        A popup menu cannot show accelerators (HIG).
        '''
        uimanager = self.main_window.uimanager

        # Add the accelerator group to the toplevel window
        accelgroup = uimanager.get_accel_group()
        self.main_window.main_frame.add_accel_group(accelgroup)

        # Create an ActionGroup
        self.main_window.insert_actiongroup = Gtk.ActionGroup(
            'InsertActionGroup')

        line = '\n====================\n'

        # table = ('\n|| Whitespace Left | Whitespace Right | Resulting Alignment |\n'
        #            '| 1               | more than 1     | Align left   |\n'
        #            '|     more than 1 |               1 |   Align right |\n'
        #            '|   more than 1   |   more than 1   |   Center   |\n'
        #            '|| Title rows | are always | centered |\n'
        #            '|  Use two vertical  |  lines on the left  |  for title rows  |\n'
        #            '|  Always use  |  at least  |  one whitespace  |\n')

        def tmpl(_letter):
            return ''  # return ' (Ctrl+%s)' % letter

        # Create actions
        self.main_window.insert_actiongroup.add_actions([
            ('Picture', Gtk.STOCK_ORIENTATION_PORTRAIT, _('Picture'), None,
             _('Insert an image from the harddisk'),
             self.get_insert_handler(self.on_insert_pic)),
            ('File', Gtk.STOCK_FILE, _('File'), None,
             _('Insert a link to a file'),
             self.get_insert_handler(self.on_insert_file)),
            # Translators: Noun
            ('Link', Gtk.STOCK_JUMP_TO, _('_Link') + tmpl('L'), '<Control>L',
             _('Insert a link to a website'),
             self.get_insert_handler(self.on_insert_link)),
            ('BulletList', None, _('Bullet List'), None, None,
             self.get_insert_handler(self.on_insert_bullet_list)),
            # ('NumberedList', None, _('Numbered List'), None, None,
            #     self.get_insert_handler(self.on_insert_numbered_list)),
            ('Title', None, _('Title'), None, None, self.on_insert_title),
            ('Line', None, _('Line'), None, _('Insert a separator line'),
             self.get_insert_handler(lambda sel_text: line)),
            # ('Table', None, _('Table'), None, None,
            #     self.get_insert_handler(lambda sel_text: table)),
            # ('Formula', None, _('Latex Formula'), None, None,
            #     self.get_insert_handler(self.on_insert_formula)),
            ('Date', None, _('Date/Time') + tmpl('D'), '<Ctrl>D',
             _('Insert the current date and time (edit format in preferences)'
               ), self.get_insert_handler(self.on_insert_date_time)),
            ('LineBreak', None, _('Line Break'), '<Ctrl>Return',
             _('Insert a manual line break'),
             self.get_insert_handler(lambda sel_text: '\\\\\n')),
            ('InsertMenuBar', None, _('_Insert')),
        ])

        # Add the actiongroup to the uimanager
        uimanager.insert_action_group(self.main_window.insert_actiongroup, 0)

        # Add a UI description
        uimanager.add_ui_from_string(TOOLBAR_XML)

        # Create a Menu
        menu = uimanager.get_widget('/InsertMenu')

        image_items = 'Picture Link BulletList Title Line Date LineBreak Table'.split(
        )

        for item in image_items:
            menu_item = uimanager.get_widget('/InsertMenu/' + item)
            filename = item.lower()
            # We may have disabled menu items
            if menu_item:
                menu_item.set_image(get_image(filename + '.png'))

        self.main_window.insert_button = customwidgets.ToolbarMenuButton(
            Gtk.STOCK_ADD, menu)
        self.main_window.insert_button.set_label(_('Insert'))
        self.main_window.insert_button.set_tooltip_text(
            _('Insert images, files, links and other content'))
        self.main_window.builder.get_object('edit_toolbar').insert(
            self.main_window.insert_button, -1)
Ejemplo n.º 5
0
    def setup(self):
        '''
        See http://www.pygtk.org/pygtk2tutorial/sec-UIManager.html for help
        A popup menu cannot show accelerators (HIG).
        '''

        uimanager = self.main_window.uimanager

        # Create an ActionGroup
        actiongroup = gtk.ActionGroup('FormatActionGroup')

        def tmpl(word):
            return word + ' (Ctrl+%s)' % word[0]

        def apply_format(action, format='bold'):
            if type(action) == gtk.Action:
                format = action.get_name().lower()

            markup = self.FORMAT_TO_MARKUP[format]

            focus = self.main_window.main_frame.get_focus()
            iter = self.main_window.categories_tree_view.get_selected_node()

            if isinstance(focus, gtk.Entry):
                entry = focus
                pos = entry.get_position()
                # bounds can be an empty tuple
                bounds = entry.get_selection_bounds() or (pos, pos)
                selected_text = entry.get_chars(*bounds).decode('utf-8')
                entry.delete_text(*bounds)
                entry.insert_text('%s%s%s' % (markup, selected_text, markup),
                                  bounds[0])
                # Set cursor after the end of the formatted text
                entry.set_position(bounds[0] + len(markup) +
                                   len(selected_text))
            elif focus == self.main_window.categories_tree_view.tree_view and iter:
                text = self.main_window.categories_tree_view.get_iter_value(
                    iter)
                text = '%s%s%s' % (markup, text, markup)
                self.main_window.categories_tree_view.set_iter_value(
                    iter, text)
            elif focus == self.main_window.day_text_field.day_text_view:
                self.main_window.day_text_field.apply_format(format)
            else:
                self.main_window.journal.show_message(
                    _('No text or tag has been selected.'), error=True)

        def shortcut(char):
            # Translators: The Control (Ctrl) key
            return ''  # return ' (%s+%s)' % (_('Ctrl'), char)

        # Create actions
        actions = [
            ('Bold', gtk.STOCK_BOLD, _('Bold') + shortcut('B'), '<Control>B',
             None, apply_format),
            ('Italic', gtk.STOCK_ITALIC, _('Italic') + shortcut('I'),
             '<Control>I', None, apply_format),
            ('Monospace', None, _('Monospace') + shortcut('M'), '<Control>M',
             None, apply_format),
            ('Underline', gtk.STOCK_UNDERLINE, _('Underline') + shortcut('U'),
             '<Control>U', None, apply_format),
            ('Strikethrough', gtk.STOCK_STRIKETHROUGH,
             _('Strikethrough') + shortcut('K'), '<Control>K', None,
             apply_format),
            ('Clear', gtk.STOCK_CLEAR, _('Clear format') + shortcut('R'),
             '<Control>R', None, self.on_clear_format),
            # Translators: Noun
            ('FormatMenuBar', None, _('_Format')),
        ]

        actiongroup.add_actions(actions)

        # Add the actiongroup to the uimanager
        uimanager.insert_action_group(actiongroup, 0)

        # Add a UI description
        uimanager.add_ui_from_string(TOOLBAR_XML)

        # Create a Menu
        menu = uimanager.get_widget('/FormatMenu')

        self.main_window.format_button = customwidgets.ToolbarMenuButton(
            gtk.STOCK_BOLD, menu)
        # Translators: Noun
        self.main_window.format_button.set_label(_('Format'))
        tip = _('Format the selected text or tag')
        self.main_window.format_button.set_tooltip_text(tip)
        self.main_window.builder.get_object('edit_toolbar').insert(
            self.main_window.format_button, -1)
        self.main_window.format_actiongroup = actiongroup
Ejemplo n.º 6
0
    def setup(self):
        """
        See http://www.pyGtk.org/pygtk2tutorial/sec-UIManager.html for help
        A popup menu cannot show accelerators (HIG).
        """
        uimanager = self.main_window.uimanager

        # Add the accelerator group to the toplevel window
        accelgroup = uimanager.get_accel_group()
        self.main_window.main_frame.add_accel_group(accelgroup)

        # Create an ActionGroup
        self.main_window.insert_actiongroup = Gtk.ActionGroup(
            "InsertActionGroup")

        # Create actions
        actions = [
            (
                "Picture",
                Gtk.STOCK_ORIENTATION_PORTRAIT,
                _("Picture"),
                None,
                _("Insert an image from the harddisk"),
                self.on_insert_pic,
            ),
            (
                "File",
                Gtk.STOCK_FILE,
                _("File"),
                None,
                _("Insert a link to a file"),
                self.on_insert_file,
            ),
            # Translators: Noun
            (
                "Link",
                Gtk.STOCK_JUMP_TO,
                _("_Link"),
                "<Control>L",
                _("Insert a link to a website"),
                self.on_insert_link,
            ),
            (
                "BulletList",
                None,
                _("Bullet List"),
                None,
                None,
                self.on_insert_bullet_list,
            ),
            ("TitleMenu", None, _("Title")),
            (
                "Line",
                None,
                _("Line"),
                None,
                _("Insert a separator line"),
                self.on_insert_line,
            ),
            (
                "Date",
                None,
                _("Date/Time"),
                "<Ctrl>D",
                _("Insert the current date and time (edit format in preferences)"
                  ),
                self.on_insert_date_time,
            ),
            (
                "LineBreak",
                None,
                _("Line Break"),
                "<Ctrl>Return",
                _("Insert a manual line break"),
                self.on_insert_line_break,
            ),
            ("InsertMenuBar", None, _("_Insert")),
        ]

        # Create title submenu actions
        for level in range(1, 6):
            action_label = "{} {}".format(_("Level"), level)
            actions.append((
                "Title{}".format(level),
                None,
                action_label,
                "<Control>{}".format(level),
                None,
                functools.partial(self.on_insert_title, level=level),
            ))

        self.main_window.insert_actiongroup.add_actions(actions)

        # Add the actiongroup to the uimanager
        uimanager.insert_action_group(self.main_window.insert_actiongroup, 0)

        # Add a UI description
        uimanager.add_ui_from_string(TOOLBAR_XML)

        # Create a Menu
        menu = uimanager.get_widget("/InsertMenu")

        image_items = "Picture Link BulletList Title Line Date LineBreak Table".split(
        )

        for item in image_items:
            menu_item = uimanager.get_widget("/InsertMenu/" + item)
            filename = item.lower()
            # We may have disabled menu items
            if menu_item:
                menu_item.set_image(get_image(filename + ".png"))

        self.main_window.insert_button = customwidgets.ToolbarMenuButton(
            Gtk.STOCK_ADD, menu)
        self.main_window.insert_button.set_label(_("Insert"))
        self.main_window.insert_button.set_tooltip_text(
            _("Insert images, files, links and other content"))
        self.main_window.builder.get_object("edit_toolbar").insert(
            self.main_window.insert_button, -1)
Ejemplo n.º 7
0
    def setup(self):
        '''
        See http://www.pyGtk.org/pygtk2tutorial/sec-UIManager.html for help
        A popup menu cannot show accelerators (HIG).
        '''
        uimanager = self.main_window.uimanager

        # Add the accelerator group to the toplevel window
        accelgroup = uimanager.get_accel_group()
        self.main_window.main_frame.add_accel_group(accelgroup)

        # Create an ActionGroup
        self.main_window.insert_actiongroup = Gtk.ActionGroup(
            'InsertActionGroup')

        # Create actions
        actions = [
            ('Picture', Gtk.STOCK_ORIENTATION_PORTRAIT, _('Picture'), None,
             _('Insert an image from the harddisk'), self.on_insert_pic),
            ('File', Gtk.STOCK_FILE, _('File'), None,
             _('Insert a link to a file'), self.on_insert_file),
            # Translators: Noun
            ('Link', Gtk.STOCK_JUMP_TO, _('_Link'), '<Control>L',
             _('Insert a link to a website'), self.on_insert_link),
            ('BulletList', None, _('Bullet List'), None, None,
             self.on_insert_bullet_list),
            ('TitleMenu', None, _('Title')),
            ('Line', None, _('Line'), None, _('Insert a separator line'),
             self.on_insert_line),
            ('Date', None, _('Date/Time'), '<Ctrl>D',
             _('Insert the current date and time (edit format in preferences)'
               ), self.on_insert_date_time),
            ('LineBreak', None, _('Line Break'), '<Ctrl>Return',
             _('Insert a manual line break'), self.on_insert_line_break),
            ('InsertMenuBar', None, _('_Insert')),
        ]

        # Create title submenu actions
        for level in range(1, 6):
            action_label = '{} {}'.format(_('Level'), level)
            actions.append(('Title{}'.format(level), None, action_label,
                            '<Control>{}'.format(level), None,
                            functools.partial(self.on_insert_title,
                                              level=level)))

        self.main_window.insert_actiongroup.add_actions(actions)

        # Add the actiongroup to the uimanager
        uimanager.insert_action_group(self.main_window.insert_actiongroup, 0)

        # Add a UI description
        uimanager.add_ui_from_string(TOOLBAR_XML)

        # Create a Menu
        menu = uimanager.get_widget('/InsertMenu')

        image_items = 'Picture Link BulletList Title Line Date LineBreak Table'.split(
        )

        for item in image_items:
            menu_item = uimanager.get_widget('/InsertMenu/' + item)
            filename = item.lower()
            # We may have disabled menu items
            if menu_item:
                menu_item.set_image(get_image(filename + '.png'))

        self.main_window.insert_button = customwidgets.ToolbarMenuButton(
            Gtk.STOCK_ADD, menu)
        self.main_window.insert_button.set_label(_('Insert'))
        self.main_window.insert_button.set_tooltip_text(
            _('Insert images, files, links and other content'))
        self.main_window.builder.get_object('edit_toolbar').insert(
            self.main_window.insert_button, -1)