changeset 4f13475b5cb8 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset;node=4f13475b5cb8
description:
        Use ShortcutsWindow

        issue8072
        review58511002
diffstat:

 CHANGELOG                      |    1 +
 tryton/gui/main.py             |  108 +++++++++++++++++++++++++++++++++++-
 tryton/gui/window/shortcuts.py |  123 -----------------------------------------
 3 files changed, 107 insertions(+), 125 deletions(-)

diffs (263 lines):

diff -r 319c61b65e85 -r 4f13475b5cb8 CHANGELOG
--- a/CHANGELOG Wed Feb 13 10:13:35 2019 +0100
+++ b/CHANGELOG Wed Feb 13 10:44:04 2019 +0100
@@ -1,3 +1,4 @@
+* Use ShortcutsWindow
 * Improve default size of widgets and dialog
 * Use record and field properties of widget instead of method arguments
 * Reduce offset when no search result
diff -r 319c61b65e85 -r 4f13475b5cb8 tryton/gui/main.py
--- a/tryton/gui/main.py        Wed Feb 13 10:13:35 2019 +0100
+++ b/tryton/gui/main.py        Wed Feb 13 10:44:04 2019 +0100
@@ -106,9 +106,11 @@
         action.connect('activate', lambda *a: self.edit_email())
         self.add_action(action)
 
+        self._shortcuts = None
         action = Gio.SimpleAction.new('shortcuts', None)
         action.connect('activate', lambda *a: self.shortcuts())
         self.add_action(action)
+        self.add_accelerator('<Primary>F1', 'app.shortcuts')
 
         action = Gio.SimpleAction.new('about', None)
         action.connect('activate', lambda *a: self.about())
@@ -583,8 +585,110 @@
         About()
 
     def shortcuts(self):
-        from tryton.gui.window.shortcuts import Shortcuts
-        Shortcuts().run()
+        if self._shortcuts:
+            self._shortcuts.destroy()
+        self._shortcuts = window = Gtk.ShortcutsWindow()
+        window.set_transient_for(common.get_toplevel_window())
+        window.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
+        window.set_destroy_with_parent(True)
+        self.add_window(window)
+
+        section = Gtk.ShortcutsSection()
+        section.props.section_name = 'app'
+        section.props.title = _("Application Shortcuts")
+        section.props.visible = True
+
+        group = Gtk.ShortcutsGroup()
+        group.props.title = _("Global")
+        section.add(group)
+
+        for action, title in [
+                ('app.menu-search', _("Search menu")),
+                ('app.menu-toggle', _("Toggle menu")),
+                ('app.tab-previous', _("Previous tab"), ),
+                ('app.tab-next', _("Next tab")),
+                ('app.shortcuts', _("Shortcuts")),
+                ('app.quit', _("Quit")),
+                ]:
+            shortcut = Gtk.ShortcutsShortcut()
+            shortcut.props.title = title
+            accels = self.get_accels_for_action(action)
+            if accels:
+                shortcut.props.accelerator = ' '.join(accels)
+                group.add(shortcut)
+
+        window.add(section)
+
+        for name, title, groups in [
+                ('entry', _("Edition Shortcuts"), [
+                        (_("Text Entries"), [
+                                ('<Primary>x', _("Cut selected text")),
+                                ('<Primary>c', _("Copy selected text")),
+                                ('<Primary>v', _("Paste copied text")),
+                                ('Tab', _("Next entry")),
+                                ('<Shift>Tab', _("Previous entry")),
+                                ]),
+                        (_("Relation Entries"), [
+                                ('F3', _("Create new relation")),
+                                ('F2', _("Open/Search relation")),
+                                ]),
+                        (_("List Entries"), [
+                                ('F3', _("Create new line")),
+                                ('F2', _("Open relation")),
+                                ('Delete', _("Mark line for deletion")),
+                                ('Insert', _("Unmark line for deletion")),
+                                ]),
+                        ]),
+                ('tree', _("List/Tree Shortcuts"), [
+                        (_("Move Cursor"), [
+                                ('Right', _("Move right")),
+                                ('Left', _("Move left")),
+                                ('Up', _("Move up")),
+                                ('Down', _("Move down")),
+                                ('Page_Up', _("Move up of one page")),
+                                ('Page_Down', _("Move down of one page")),
+                                ('Home', _("Move to top")),
+                                ('End', _("Move to bottom")),
+                                ('BackSpace', _("Move to parent")),
+                                ]),
+                        (_("Selection"), [
+                                ('<Ctrl>a <Ctrl>slash', _("Select all")),
+                                ('<Shift><Ctrl>a <Shift><Ctrl>slash',
+                                    _("Unselect all")),
+                                ('BackSpace', _("Select parent")),
+                                ('space', _("Select/Activate current row")),
+                                ('<Shift>space Return',
+                                    _("Select/Activate current row")),
+                                ('<Ctrl>space', _("Toggle selection")),
+                                ]),
+                        (_("Expand/Collapse"), [
+                                ('plus', _("Expand row")),
+                                ('minus', _("Collapse row")),
+                                ('space', _("Toggle row")),
+                                ('<Shift>Left', _("Collapse all rows")),
+                                ('<Shift>Right', _("Expand all rows")),
+                                ]),
+                        ]),
+                ]:
+            section = Gtk.ShortcutsSection()
+            section.props.section_name = name
+            section.props.title = title
+            section.props.visible = True
+
+            for title, shortcuts in groups:
+                group = Gtk.ShortcutsGroup()
+                group.props.title = title
+                section.add(group)
+
+                for accelerator, title in shortcuts:
+                    shortcut = Gtk.ShortcutsShortcut()
+                    shortcut.props.title = title
+                    shortcut.props.accelerator = accelerator
+                    group.add(shortcut)
+
+            window.add(section)
+
+        window.show_all()
 
     def menu_toggle(self, *args):
         if self.menu.get_visible():
diff -r 319c61b65e85 -r 4f13475b5cb8 tryton/gui/window/shortcuts.py
--- a/tryton/gui/window/shortcuts.py    Wed Feb 13 10:13:35 2019 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-# This file is part of Tryton.  The COPYRIGHT file at the top level of
-# this repository contains the full copyright notices and license terms.
-
-import gtk
-import gettext
-
-from tryton.common import get_toplevel_window, IconFactory
-from tryton.common.underline import set_underline
-from tryton.config import TRYTON_ICON
-from tryton.gui import Main
-
-_ = gettext.gettext
-
-
-class Shortcuts(object):
-    'Shortcuts window'
-
-    def __init__(self):
-        self.parent = get_toplevel_window()
-        self.dialog = gtk.Dialog(_('Keyboard Shortcuts'), self.parent,
-            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
-            | gtk.WIN_POS_CENTER_ON_PARENT | gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
-        Main().add_window(self.dialog)
-        ok_button = self.dialog.add_button(
-            set_underline(_("OK")), gtk.RESPONSE_OK)
-        ok_button.set_image(IconFactory.get_image(
-                'tryton-ok', gtk.ICON_SIZE_BUTTON))
-        ok_button.set_always_show_image(True)
-        self.dialog.set_icon(TRYTON_ICON)
-        self.dialog.set_default_response(gtk.RESPONSE_OK)
-        notebook = gtk.Notebook()
-        self.dialog.vbox.pack_start(notebook)
-
-        shortcuts = [
-            (_('Text Entries Shortcuts'),),
-            ('<Ctrl> + X', _('Cut selected text')),
-            ('<Ctrl> + C', _('Copy selected text')),
-            ('<Ctrl> + V', _('Paste copied text')),
-            ('<Tab>', _('Next widget')),
-            ('<Shift> + <Tab>', _('Previous widget')),
-            (_('Relation Entries Shortcuts'),),
-            ('<F3>', _('Create new relation')),
-            ('<F2>', _('Open/Search relation')),
-            (_('List Entries Shortcuts'),),
-            ('<F3>', _('Create new line')),
-            ('<F2>', _('Open relation')),
-            ('<Del>', _('Mark line for deletion')),
-            ('<Ins>', _('Unmark line for deletion')),
-            ]
-        notebook.append_page(self._fill_table(shortcuts),
-                gtk.Label(_('Edition Widgets')))
-
-        shortcuts = [
-            (_('Move Cursor'),),
-            ('<Right>', _('Move to right')),
-            ('<Left>', _('Move to left')),
-            ('<Up>', _('Move up')),
-            ('<Down>', _('Move down')),
-            ('<Page Up>', _('Move up of one page')),
-            ('<Page Down>', _('Move down of one page')),
-            ('<Home>', _('Move to top')),
-            ('<End>', _('Move to bottom')),
-            ('<Backspace>', _('Move to parent')),
-            (_('Selection'),),
-            ('<Ctrl> + a', _('Select all')),
-            ('<Ctrl> + /', _('Select all')),
-            ('<Shift> + <Ctrl> + a', _('Unselect all')),
-            ('<Shift> + <Ctrl> + /', _('Unselect all')),
-            ('<Backspace>', _('Select parent')),
-            ('<Space>', _('Select/Activate current row')),
-            ('<Shift> + <Space>', _('Select/Activate current row')),
-            ('<Return>', _('Select/Activate current row')),
-            ('<Enter>', _('Select/Activate current row')),
-            ('<Ctrl> + <Space>', _('Toggle selection')),
-            (_('Expand/Collapse'),),
-            ('+', _('Expand row')),
-            ('-', _('Collapse row')),
-            ('<Space>', _('Toggle row')),
-            ('<Shift> + <Left>', _('Collapse all rows')),
-            ('<Shift> + <Right>', _('Expand all rows')),
-            ]
-        notebook.append_page(self._fill_table(shortcuts),
-                gtk.Label(_('Tree view')))
-
-        self.dialog.show_all()
-
-    def _fill_table(self, shortcuts):
-        table = gtk.Table(len(shortcuts), 2)
-        table.set_col_spacings(15)
-        table.set_row_spacings(3)
-        table.set_border_width(8)
-
-        i = 0
-        for shortcut in shortcuts:
-            if len(shortcut) == 1:
-                label = gtk.Label()
-                if '\n' not in shortcut[0]:
-                    label.set_markup('<b>' + shortcut[0] + '</b>')
-                else:
-                    label.set_text(shortcut[0])
-                    label.set_alignment(0, 0.5)
-                label.set_padding(2, 0)
-                table.attach(label, 0, 2, i, i + 1,
-                        yoptions=False, xoptions=gtk.FILL)
-            elif len(shortcut) == 2:
-                label = gtk.Label()
-                label.set_text(shortcut[0])
-                label.set_alignment(0, 0.5)
-                table.attach(label, 0, 1, i, i + 1,
-                        yoptions=False, xoptions=gtk.FILL)
-                label = gtk.Label()
-                label.set_text(shortcut[1])
-                label.set_alignment(0, 0.5)
-                table.attach(label, 1, 2, i, i + 1,
-                        yoptions=False, xoptions=gtk.FILL)
-            i += 1
-        return table
-
-    def run(self):
-        'Run the window'
-        self.dialog.run()
-        self.parent.present()
-        self.dialog.destroy()

Reply via email to