def install_mac_additions(self): #GLib.unix_signal_add( # GLib.PRIORITY_HIGH, 2, lambda *args: invalidate_state()) # header_bar = Gtk.Template.Child() self.maximize_button = Gtk.Template.Child() # Manually handle GAction additions actions = ( ("close-window", self.action_close_window), ("minimize-window", self.action_minimize_window), ("maximize-window", self.action_maximize_window), ) for name, callback in actions: action = Gio.SimpleAction.new(name, None) action.connect('activate', callback) self.add_action(action) # Menu actions actions = ( ("FileMenu", None, _("_File")), ("New", Gtk.STOCK_NEW, _("_New Comparison…"), "<Primary>N", _("Start a new comparison"), self.on_menu_file_new_activate), ("Save", Gtk.STOCK_SAVE, None, None, _("Save the current file"), self.on_menu_save_activate), ("SaveAs", Gtk.STOCK_SAVE_AS, _("Save As…"), "<Primary><shift>S", _("Save the current file with a different name"), self.on_menu_save_as_activate), ("Close", Gtk.STOCK_CLOSE, None, None, _("Close the current file"), self.on_menu_close_activate), ("EditMenu", None, _("_Edit")), ("Undo", Gtk.STOCK_UNDO, None, "<Primary>Z", _("Undo the last action"), self.on_menu_undo_activate), ("Redo", Gtk.STOCK_REDO, None, "<Primary><shift>Z", _("Redo the last undone action"), self.on_menu_redo_activate), ("Cut", Gtk.STOCK_CUT, None, None, _("Cut the selection"), self.on_menu_cut_activate), ("Copy", Gtk.STOCK_COPY, None, None, _("Copy the selection"), self.on_menu_copy_activate), ("Paste", Gtk.STOCK_PASTE, None, None, _("Paste the clipboard"), self.on_menu_paste_activate), ("Find", Gtk.STOCK_FIND, _("Find…"), None, _("Search for text"), self.on_menu_find_activate), ("FindNext", None, _("Find Ne_xt"), "<Primary>G", _("Search forwards for the same text"), self.on_menu_find_next_activate), ("FindPrevious", None, _("Find _Previous"), "<Primary><shift>G", _("Search backwards for the same text"), self.on_menu_find_previous_activate), ("Replace", Gtk.STOCK_FIND_AND_REPLACE, _("_Replace…"), "<Primary>H", _("Find and replace text"), self.on_menu_replace_activate), ("GoToLine", None, _("Go to _Line"), "<Primary>I", _("Go to a specific line"), self.on_menu_go_to_line_activate), ("ChangesMenu", None, _("_Changes")), ("NextChange", Gtk.STOCK_GO_DOWN, _("Next Change"), "<Alt>Down", _("Go to the next change"), self.on_menu_edit_down_activate), ("PrevChange", Gtk.STOCK_GO_UP, _("Previous Change"), "<Alt>Up", _("Go to the previous change"), self.on_menu_edit_up_activate), ("OpenExternal", None, _("Open Externally"), None, _("Open selected file or directory in the default external " "application"), self.on_open_external), ("ViewMenu", None, _("_View")), ("FileStatus", None, _("File Status")), ("VcStatus", None, _("Version Status")), ("FileFilters", None, _("File Filters")), ("Stop", Gtk.STOCK_STOP, None, "Escape", _("Stop the current action"), self.on_toolbar_stop_clicked), ("Refresh", Gtk.STOCK_REFRESH, None, "<Primary>R", _("Refresh the view"), self.on_menu_refresh_activate), ) self.actiongroup = Gtk.ActionGroup(name='MainActions') self.actiongroup.set_translation_domain("meld") self.actiongroup.add_actions(actions) recent_action = Gtk.RecentAction( name="Recent", label=_("Open Recent"), tooltip=_("Open recent files"), stock_id=None) recent_action.set_show_private(True) recent_action.set_filter(recent_comparisons.recent_filter) recent_action.set_sort_type(Gtk.RecentSortType.MRU) recent_action.connect("item-activated", self.on_action_recent) self.actiongroup.add_action(recent_action) self.ui = Gtk.UIManager() self.ui.insert_action_group(self.actiongroup, 0) self.ui.add_ui_from_file(ui_file("meldapp-ui.xml")) for menuitem in ("Save", "Undo"): self.actiongroup.get_action(menuitem).props.is_important = True self.add_accel_group(self.ui.get_accel_group()) self.menubar = self.ui.get_widget('/Menubar') self.menubar.hide() self.menu_created = False self.app_ready = False # Alternate keybindings for a few commands. extra_accels = ( ("<Primary>D", self.on_menu_edit_down_activate), ("<Primary>E", self.on_menu_edit_up_activate), ("<Alt>KP_Down", self.on_menu_edit_down_activate), ("<Alt>KP_Up", self.on_menu_edit_up_activate), ("F5", self.on_menu_refresh_activate), ) accel_group = self.ui.get_accel_group() for accel, callback in extra_accels: keyval, mask = Gtk.accelerator_parse(accel) accel_group.connect(keyval, mask, 0, callback) self.connect('window-state-event', self.on_window_state_event)
def add_template(cls): template_path = ui_file(template_file) template = open(template_path, 'rb').read() template_bytes = GLib.Bytes.new(template) cls.set_template(template_bytes) return cls
def __init__(self): super().__init__() self.init_template() actions = ( ("FileMenu", None, _("_File")), ("New", Gtk.STOCK_NEW, _("_New Comparison…"), "<Primary>N", _("Start a new comparison"), self.on_menu_file_new_activate), ("Save", Gtk.STOCK_SAVE, None, None, _("Save the current file"), self.on_menu_save_activate), ("SaveAs", Gtk.STOCK_SAVE_AS, _("Save As…"), "<Primary><shift>S", _("Save the current file with a different name"), self.on_menu_save_as_activate), ("Close", Gtk.STOCK_CLOSE, None, None, _("Close the current file"), self.on_menu_close_activate), ("EditMenu", None, _("_Edit")), ("Undo", Gtk.STOCK_UNDO, None, "<Primary>Z", _("Undo the last action"), self.on_menu_undo_activate), ("Redo", Gtk.STOCK_REDO, None, "<Primary><shift>Z", _("Redo the last undone action"), self.on_menu_redo_activate), ("Cut", Gtk.STOCK_CUT, None, None, _("Cut the selection"), self.on_menu_cut_activate), ("Copy", Gtk.STOCK_COPY, None, None, _("Copy the selection"), self.on_menu_copy_activate), ("Paste", Gtk.STOCK_PASTE, None, None, _("Paste the clipboard"), self.on_menu_paste_activate), ("Find", Gtk.STOCK_FIND, _("Find…"), None, _("Search for text"), self.on_menu_find_activate), ("FindNext", None, _("Find Ne_xt"), "<Primary>G", _("Search forwards for the same text"), self.on_menu_find_next_activate), ("FindPrevious", None, _("Find _Previous"), "<Primary><shift>G", _("Search backwards for the same text"), self.on_menu_find_previous_activate), ("Replace", Gtk.STOCK_FIND_AND_REPLACE, _("_Replace…"), "<Primary>H", _("Find and replace text"), self.on_menu_replace_activate), ("GoToLine", None, _("Go to _Line"), "<Primary>I", _("Go to a specific line"), self.on_menu_go_to_line_activate), ("ChangesMenu", None, _("_Changes")), ("NextChange", Gtk.STOCK_GO_DOWN, _("Next Change"), "<Alt>Down", _("Go to the next change"), self.on_menu_edit_down_activate), ("PrevChange", Gtk.STOCK_GO_UP, _("Previous Change"), "<Alt>Up", _("Go to the previous change"), self.on_menu_edit_up_activate), ("OpenExternal", None, _("Open Externally"), None, _("Open selected file or directory in the default external " "application"), self.on_open_external), ("ViewMenu", None, _("_View")), ("FileStatus", None, _("File Status")), ("VcStatus", None, _("Version Status")), ("FileFilters", None, _("File Filters")), ("Stop", Gtk.STOCK_STOP, None, "Escape", _("Stop the current action"), self.on_toolbar_stop_clicked), ("Refresh", Gtk.STOCK_REFRESH, None, "<Primary>R", _("Refresh the view"), self.on_menu_refresh_activate), ) toggleactions = (("Fullscreen", None, _("Fullscreen"), "F11", _("View the comparison in fullscreen"), self.on_action_fullscreen_toggled, False), ) self.actiongroup = Gtk.ActionGroup(name='MainActions') self.actiongroup.set_translation_domain("meld") self.actiongroup.add_actions(actions) self.actiongroup.add_toggle_actions(toggleactions) recent_action = Gtk.RecentAction(name="Recent", label=_("Open Recent"), tooltip=_("Open recent files"), stock_id=None) recent_action.set_show_private(True) recent_action.set_filter(recent_comparisons.recent_filter) recent_action.set_sort_type(Gtk.RecentSortType.MRU) recent_action.connect("item-activated", self.on_action_recent) self.actiongroup.add_action(recent_action) self.ui = Gtk.UIManager() self.ui.insert_action_group(self.actiongroup, 0) self.ui.add_ui_from_file(ui_file("meldapp-ui.xml")) for menuitem in ("Save", "Undo"): self.actiongroup.get_action(menuitem).props.is_important = True self.add_accel_group(self.ui.get_accel_group()) self.menubar = self.ui.get_widget('/Menubar') self.toolbar = self.ui.get_widget('/Toolbar') self.toolbar.get_style_context().add_class( Gtk.STYLE_CLASS_PRIMARY_TOOLBAR) # Alternate keybindings for a few commands. extra_accels = ( ("<Primary>D", self.on_menu_edit_down_activate), ("<Primary>E", self.on_menu_edit_up_activate), ("<Alt>KP_Down", self.on_menu_edit_down_activate), ("<Alt>KP_Up", self.on_menu_edit_up_activate), ("F5", self.on_menu_refresh_activate), ) accel_group = self.ui.get_accel_group() for accel, callback in extra_accels: keyval, mask = Gtk.accelerator_parse(accel) accel_group.connect(keyval, mask, 0, callback) # Initialise sensitivity for important actions self.actiongroup.get_action("Stop").set_sensitive(False) self._update_page_action_sensitivity() self.appvbox.pack_start(self.menubar, False, True, 0) self.toolbar_holder.pack_start(self.toolbar, True, True, 0) # This double toolbar works around integrating non-UIManager widgets # into the toolbar. It's no longer used, but kept as a possible # GAction porting helper. self.secondary_toolbar = Gtk.Toolbar() self.secondary_toolbar.get_style_context().add_class( Gtk.STYLE_CLASS_PRIMARY_TOOLBAR) self.toolbar_holder.pack_end(self.secondary_toolbar, False, True, 0) self.secondary_toolbar.show_all() # Manually handle GAction additions actions = (("close", self.on_menu_close_activate, None), ) for (name, callback, accel) in actions: action = Gio.SimpleAction.new(name, None) action.connect('activate', callback) self.add_action(action) # Fake out the spinner on Windows. See Gitlab issue #133. if os.name == 'nt': for attr in ('stop', 'hide', 'show', 'start'): setattr(self.spinner, attr, lambda *args: True) self.drag_dest_set( Gtk.DestDefaults.MOTION | Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP, None, Gdk.DragAction.COPY) self.drag_dest_add_uri_targets() self.connect("drag_data_received", self.on_widget_drag_data_received) self.window_state = SavedWindowState() self.window_state.bind(self) self.should_close = False self.idle_hooked = 0 self.scheduler = LifoScheduler() self.scheduler.connect("runnable", self.on_scheduler_runnable) self.ui.ensure_update() self.diff_handler = None self.undo_handlers = tuple() # Set tooltip on map because the recentmenu is lazily created rmenu = self.ui.get_widget('/Menubar/FileMenu/Recent').get_submenu() rmenu.connect("map", self._on_recentmenu_map)
def __init__(self): super().__init__() # FIXME: # This unimaginable hack exists because GObject (or GTK+?) # doesn't actually correctly chain init calls, even if they're # not to GObjects. As a workaround, we *should* just be able to # put our class first, but because of Gtk.Template we can't do # that if it's a GObject, because GObject doesn't support # multiple inheritance and we need to inherit from our Widget # parent to make Template work. MeldDoc.__init__(self) self.init_template() bind_settings(self) self.ui_file = ui_file("vcview-ui.xml") self.actiongroup = self.VcviewActions self.actiongroup.set_translation_domain("meld") self.model = VcTreeStore() self.connect("style-updated", self.model.on_style_updated) self.model.on_style_updated(self) self.treeview.set_model(self.model) self.treeview.get_selection().connect( "changed", self.on_treeview_selection_changed) self.treeview.set_search_equal_func(tree.treeview_search_cb, None) self.current_path, self.prev_path, self.next_path = None, None, None self.name_column.set_attributes( self.emblem_renderer, icon_name=tree.COL_ICON, icon_tint=tree.COL_TINT) self.name_column.set_attributes( self.name_renderer, text=tree.COL_TEXT, foreground_rgba=tree.COL_FG, style=tree.COL_STYLE, weight=tree.COL_WEIGHT, strikethrough=tree.COL_STRIKE) self.location_column.set_attributes( self.location_renderer, markup=COL_LOCATION) self.status_column.set_attributes( self.status_renderer, markup=COL_STATUS) self.extra_column.set_attributes( self.extra_renderer, markup=COL_OPTIONS) self.location_column.bind_property( 'visible', self.actiongroup.get_action("VcFlatten"), 'active') self.consolestream = ConsoleStream(self.consoleview) self.location = None self.vc = None settings.bind('vc-console-visible', self.actiongroup.get_action('VcConsoleVisible'), 'active', Gio.SettingsBindFlags.DEFAULT) settings.bind('vc-console-visible', self.console_vbox, 'visible', Gio.SettingsBindFlags.DEFAULT) settings.bind('vc-console-pane-position', self.vc_console_vpaned, 'position', Gio.SettingsBindFlags.DEFAULT) for s in self.props.status_filters: if s in self.state_actions: self.actiongroup.get_action( self.state_actions[s][0]).set_active(True)
def add_template(cls): template_path = ui_file(template_file) template = open(template_path, 'rb').read() template_bytes = GLib.Bytes.new(template) cls.set_template(template_bytes) return cls