From 39a3b4bf006ae6d6f52506d5dfc9656344b3e7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 13 Feb 2019 10:44:04 +0100 Subject: [PATCH] Use ShortcutsWindow issue8072 review58511002 --- CHANGELOG | 1 + tryton/gui/main.py | 108 ++++++++++++++++++++++++++++- tryton/gui/window/shortcuts.py | 123 --------------------------------- 3 files changed, 107 insertions(+), 125 deletions(-) delete mode 100644 tryton/gui/window/shortcuts.py diff --git a/CHANGELOG b/CHANGELOG index 94d1fe6cbc..391d3ca9d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 --git a/tryton/gui/main.py b/tryton/gui/main.py index c122f96ba4..6a9c5ccc70 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -106,9 +106,11 @@ class Main(Gtk.Application): 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('F1', 'app.shortcuts') action = Gio.SimpleAction.new('about', None) action.connect('activate', lambda *a: self.about()) @@ -583,8 +585,110 @@ class Main(Gtk.Application): 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"), [ + ('x', _("Cut selected text")), + ('c', _("Copy selected text")), + ('v', _("Paste copied text")), + ('Tab', _("Next entry")), + ('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"), [ + ('a slash', _("Select all")), + ('a slash', + _("Unselect all")), + ('BackSpace', _("Select parent")), + ('space', _("Select/Activate current row")), + ('space Return', + _("Select/Activate current row")), + ('space', _("Toggle selection")), + ]), + (_("Expand/Collapse"), [ + ('plus', _("Expand row")), + ('minus', _("Collapse row")), + ('space', _("Toggle row")), + ('Left', _("Collapse all rows")), + ('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 --git a/tryton/gui/window/shortcuts.py b/tryton/gui/window/shortcuts.py deleted file mode 100644 index 6891eac4fa..0000000000 --- a/tryton/gui/window/shortcuts.py +++ /dev/null @@ -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'),), - (' + X', _('Cut selected text')), - (' + C', _('Copy selected text')), - (' + V', _('Paste copied text')), - ('', _('Next widget')), - (' + ', _('Previous widget')), - (_('Relation Entries Shortcuts'),), - ('', _('Create new relation')), - ('', _('Open/Search relation')), - (_('List Entries Shortcuts'),), - ('', _('Create new line')), - ('', _('Open relation')), - ('', _('Mark line for deletion')), - ('', _('Unmark line for deletion')), - ] - notebook.append_page(self._fill_table(shortcuts), - gtk.Label(_('Edition Widgets'))) - - shortcuts = [ - (_('Move Cursor'),), - ('', _('Move to right')), - ('', _('Move to left')), - ('', _('Move up')), - ('', _('Move down')), - ('', _('Move up of one page')), - ('', _('Move down of one page')), - ('', _('Move to top')), - ('', _('Move to bottom')), - ('', _('Move to parent')), - (_('Selection'),), - (' + a', _('Select all')), - (' + /', _('Select all')), - (' + + a', _('Unselect all')), - (' + + /', _('Unselect all')), - ('', _('Select parent')), - ('', _('Select/Activate current row')), - (' + ', _('Select/Activate current row')), - ('', _('Select/Activate current row')), - ('', _('Select/Activate current row')), - (' + ', _('Toggle selection')), - (_('Expand/Collapse'),), - ('+', _('Expand row')), - ('-', _('Collapse row')), - ('', _('Toggle row')), - (' + ', _('Collapse all rows')), - (' + ', _('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('' + shortcut[0] + '') - 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()