Exemplo n.º 1
0
 def _setup_action(self, name, cb):
     action = Gio.SimpleAction(name=name)
     action.connect("activate", cb)
     self._actions.append(action)
     self.window.add_action(action)
     return action
Exemplo n.º 2
0
 def do_activate(self):
     action = Gio.SimpleAction(name="colorpicker")
     action.connect('activate',
                    lambda a, p: self.on_color_picker_activate())
     self.window.add_action(action)
     self._update()
Exemplo n.º 3
0
 def add_action_boolean(self, action_name, default, callback):
     action = Gio.SimpleAction().new_stateful(action_name, None, \
                                           GLib.Variant.new_boolean(default))
     action.connect('change-state', callback)
     self.add_action(action)
 def add_format_action(self, action_name, method_name):
     action = Gio.SimpleAction(name=action_name)
     action.connect('activate', lambda i, j: self.view_method(method_name))
     self.window.add_action(action)
Exemplo n.º 5
0
    def init_actions(self) -> None:
        """Initialize app-wide actions.

        """
        action_items = {
            'document': [
                {
                    'name': 'create',
                    'action': self.on_document_create_activated,
                    'accels': ('<Control>n',)
                },
                {
                    'name': 'save',
                    'action': self.on_document_save_activated,
                    'accels': ('<Control>s',)
                },
                {
                    'name': 'close',
                    'action': self.on_document_close_activated,
                    'accels': ('<Control>w',)
                },
                {
                    'name': 'rename',
                    'action': self.on_document_rename,
                    'accels': ('F2',)
                },
                {
                    'name': 'archive',
                    'action': self.on_document_archive_activated,
                    'accels': (None,)
                },
                {
                    'name': 'unarchive',
                    'action': self.on_document_unarchive_activated,
                    'accels': (None,)
                },
                {
                    'name': 'delete',
                    'action': self.on_document_delete_activated,
                    'accels': ('<Shift>Delete',)
                },
                {
                    'name': 'import',
                    'action': self.on_document_import_activated,
                    'accels': ('<Control>o',)
                },
                {
                    'name': 'export',
                    'action': self.on_export_plaintext,
                    'accels': (None,)
                },
                {
                    'name': 'export-markdown',
                    'action': self.on_export_markdown,
                    'accels': ('<Control><Shift>s',)
                },
                {
                    'name': 'export-html',
                    'action': self.on_export_html,
                    'accels': (None,)
                },
                {
                    'name': 'export-medium',
                    'action': self.on_export_medium,
                    'accels': (None,)
                },
                {
                    'name': 'export-writeas',
                    'action': self.on_export_writeas,
                    'accels': (None,)
                },
                {
                    'name': 'preview',
                    'action': self.on_preview,
                    'accels': ('<Control><Shift>p',)
                },
                # {
                #     'name': 'print',
                #     'action': self.on_print,
                #     'accels': ('<Control>p',)
                # },
                # {
                #     'name': 'search',
                #     'action': self.search_activated,
                #     'accels': ('<Control>k',)
                # },
                {
                    'name': 'zoom_in',
                    'action': self.on_zoom_in,
                    'accels': ('<Control>equal', '<Control>plus')
                },
                {
                    'name': 'zoom_out',
                    'action': self.on_zoom_out,
                    'accels': ('<Control>minus',)
                },
                {
                    'name': 'zoom_default',
                    'action': self.on_zoom_default,
                    'accels': ('<Control>0',)
                },
                {
                    'name': 'search_text',
                    'action': self.search_activated,
                    'accels': ('<Control>f',)
                },
                {
                    'name': 'search_text_next',
                    'action': self.on_text_search_forward,
                    'accels': ('<Control>g',)
                },
                {
                    'name': 'search_text_prev',
                    'action': self.on_text_search_backward,
                    'accels': ('<Control><Shift>g',)
                },
                {
                    'name': 'toggle_archived',
                    'action': self.on_toggle_archive,
                    'accels': (None,)
                },
            ]
        }

        for action_group_key, actions in action_items.items():
            action_group = Gio.SimpleActionGroup()

            for item in actions:
                action = Gio.SimpleAction(name=item['name'])
                action.connect('activate', item['action'])
                self.get_application().set_accels_for_action(f'{action_group_key}.{item["name"]}', item["accels"])
                action_group.add_action(action)

            self.insert_action_group(action_group_key, action_group)
Exemplo n.º 6
0
 def _connect_menu(self):
     action = Gio.SimpleAction(name="adorn")
     action.connect("activate", self.action_cb)
     self.window.add_action(action)
Exemplo n.º 7
0
 def do_activate(self):
     action = Gio.SimpleAction(name="indented-paste")
     action.connect('activate', lambda a, p: self.indented_paste())
     self.window.add_action(action)
Exemplo n.º 8
0
    def init_actions(self) -> None:
        """Initialize app-wide actions.

        """
        action_items = {
            'document': [
                {
                    'name': 'create',
                    'action': self.on_document_create_activated,
                    'accels': ('<Control>n', )
                },
                {
                    'name': 'save',
                    'action': self.on_document_save_activated,
                    'accels': ('<Control>s', )
                },
                {
                    'name': 'close',
                    'action': self.on_document_close_activated,
                    'accels': ('<Control>w', )
                },
                {
                    'name': 'rename',
                    'action': self.on_document_rename_activated,
                    'accels': ('F2', )
                },
                {
                    'name': 'archive',
                    'action': self.on_document_archive_activated,
                    'accels': ('Delete', )
                },
                {
                    'name': 'delete',
                    'action': self.on_document_delete_activated,
                    'accels': ('<Shift>Delete', )
                },
                {
                    'name': 'export',
                    'action': self.on_document_export_activated,
                    'accels': ('<Control><Shift>s', )
                },
                {
                    'name': 'search',
                    'action': self.on_document_search_activated,
                    'accels': ('<Control>k', )
                },
                {
                    'name': 'zoom_in',
                    'action': self.on_zoom_in,
                    'accels': ('<Control>equal', '<Control>plus')
                },
                {
                    'name': 'zoom_out',
                    'action': self.on_zoom_out,
                    'accels': ('<Control>minus', )
                },
                {
                    'name': 'zoom_default',
                    'action': self.on_zoom_default,
                    'accels': ('<Control>0', )
                },
            ]
        }

        for action_group_key, actions in action_items.items():
            action_group = Gio.SimpleActionGroup()

            for item in actions:
                action = Gio.SimpleAction(name=item['name'])
                action.connect('activate', item['action'])
                self.get_application().set_accels_for_action(
                    f'{action_group_key}.{item["name"]}', item["accels"])
                action_group.add_action(action)

            self.insert_action_group(action_group_key, action_group)
Exemplo n.º 9
0
 def do_activate( self ):
     self.do_update_state()
     for action_name, key, menu_name in actions:
         action = Gio.SimpleAction(name=action_name)
         action.connect('activate', getattr(self, action_name))
         self.window.add_action(action)
    def do_activate(self):
        AddiksDBGPApp.get().register_window(self)

        action = Gio.SimpleAction(name="switch_listener")
        action.connect('activate', AddiksDBGPApp.get().switch_listening)
        self.window.add_action(action)

        # plugin_path = os.path.dirname(__file__)
        actions = [
            ['DebugAction', "Debugging", "", None],
            [
                'StartListeningAction', "Start listening for debug-sessions",
                "",
                AddiksDBGPApp.get().start_listening
            ],
            [
                'StopListeningAction', "Stop listening for debug-sessions", "",
                AddiksDBGPApp.get().stop_listening
            ],
            [
                'ManageProfilesAction', "Manage profiles", "",
                AddiksDBGPApp.get().show_profile_manager
            ],
            [
                'SessionStopAction', "Stop session", "",
                AddiksDBGPApp.get().session_stop
            ],
            [
                'SessionStepIntoAction', "Step into", "",
                AddiksDBGPApp.get().session_step_into
            ],
            [
                'SessionStepOverAction', "Step over", "",
                AddiksDBGPApp.get().session_step_over
            ],
            [
                'SessionStepOutAction', "Step out", "",
                AddiksDBGPApp.get().session_step_out
            ],
            ['SessionRunAction', "Run", "",
             AddiksDBGPApp.get().session_run],
            [
                'SessionRunToEndAction', "Run to end (ignore breakpoints)", "",
                AddiksDBGPApp.get().session_run_to_end
            ],
        ]

        self._actions = Gtk.ActionGroup("AddiksDBGPMenuActions")
        for actionName, title, shortcut, callback in actions:
            self._actions.add_actions([
                (actionName, Gtk.STOCK_INFO, title, shortcut, "", callback),
            ])

        for profileName in AddiksDBGPApp.get().get_profile_manager(
        ).get_profiles():

            menuItem = Gtk.MenuItem()
            menuItem._addiks_profile_name = profileName
            menuItem.set_label("Send start-debugging request to: " +
                               profileName)
            menuItem.connect("activate", self.on_run_session_per_menu)
            menuItem.show()

        for profileName in AddiksDBGPApp.get().get_profile_manager(
        ).get_profiles():

            menuItem = Gtk.MenuItem()
            menuItem._addiks_profile_name = profileName
            menuItem.set_label("Send stop-debugging request to: " +
                               profileName)
            menuItem.connect("activate", self.on_stop_session_per_menu)
            menuItem.show()

        if AddiksDBGPApp.get().does_listen():
            self.set_listen_menu_set_started()
        else:
            self.set_listen_menu_set_stopped()
Exemplo n.º 11
0
 def _connect_menu(self):
     action = Gio.SimpleAction(name='clear_document')
     action.connect('activate', self.action_cb)
     self.window.add_action(action)
Exemplo n.º 12
0
 def do_load(self, view):
     self.view = view
     action = Gio.SimpleAction(name='send-to-fpaste')
     action.connect('activate', self.send_to_faste)
     self.view.get_action_group('view').add_action(action)
Exemplo n.º 13
0
 def do_activate(self):
     action = Gio.SimpleAction(name="yredo")
     action.connect('activate', self._yredo_activate)
     self.window.add_action(action)
Exemplo n.º 14
0
 def __on_context_menu(self, webview, context_menu, event, hit):
     """
         Add custom items to menu
         @param webview as WebView
         @param context_menu as WebKit2.ContextMenu
         @param event as Gdk.Event
         @param hit as WebKit2.HitTestResult
     """
     # https://bugs.webkit.org/show_bug.cgi?id=181126
     webview.get_inspector()
     if hit.context_is_editable():
         return
     # HACK, don't know how to add web inspector
     inspector_item = None
     if App().settings.get_value("developer-extras"):
         count = context_menu.get_n_items()
         if count > 0:
             inspector_item = context_menu.get_item_at_position(count - 1)
     context_menu.remove_all()
     parsed = urlparse(webview.uri)
     if parsed.scheme == "populars":
         if hit.context_is_link():
             action = Gio.SimpleAction(name="reload_preview")
             App().add_action(action)
             action.connect("activate",
                            self.__on_reload_preview_activate,
                            hit.get_link_uri())
             item = WebKit2.ContextMenuItem.new_from_gaction(
                 action,
                 _("Reload preview"),
                 None)
             context_menu.append(item)
             return
     # Get current selection
     selection = ""
     user_data = context_menu.get_user_data()
     if user_data is not None and user_data.get_string():
         selection = user_data.get_string()
     if hit.context_is_link():
         action = Gio.SimpleAction(name="open_new_page")
         App().add_action(action)
         action.connect("activate",
                        self.__on_open_new_page_activate,
                        hit.get_link_uri(), False)
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Open link in a new page"),
             None)
         context_menu.append(item)
         action = Gio.SimpleAction(name="open_new_private_page")
         App().add_action(action)
         action.connect("activate",
                        self.__on_open_new_page_activate,
                        hit.get_link_uri(), True)
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Open link in a new private page"),
             None)
         context_menu.append(item)
         action = Gio.SimpleAction(name="open_new_window")
         App().add_action(action)
         action.connect("activate",
                        self.__on_open_new_window_activate,
                        hit.get_link_uri())
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Open link in a new window"),
             None)
         context_menu.append(item)
         item = WebKit2.ContextMenuItem.new_separator()
         context_menu.append(item)
     if selection:
         action = Gio.SimpleAction(name="copy_text")
         App().add_action(action)
         action.connect("activate",
                        self.__on_copy_text_activate,
                        selection)
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Copy"),
             None)
         context_menu.append(item)
     if hit.context_is_link() or\
             hit.context_is_image() or\
             hit.context_is_media():
         action = Gio.SimpleAction(name="copy_link_uri")
         App().add_action(action)
         action.connect("activate",
                        self.__on_copy_link_uri_activate,
                        hit.get_link_uri() or
                        hit.get_image_uri() or
                        hit.get_media_uri())
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Copy link address"),
             None)
         context_menu.append(item)
     if selection and hit.context_is_selection():
         action = Gio.SimpleAction(name="search_words")
         App().add_action(action)
         action.connect("activate",
                        self.__on_search_words_activate,
                        selection)
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Search on the Web"),
             None)
         context_menu.append(item)
     if hit.context_is_link() or\
             hit.context_is_image() or\
             hit.context_is_media():
         # Download link if uri looks like a file
         uri = hit.get_link_uri()
         if not uri or not uri.split(".")[-1].isalnum():
             if hit.get_image_uri():
                 msg = _("Download this image")
                 uri = hit.get_image_uri()
             else:
                 msg = _("Download this video")
                 uri = hit.get_media_uri()
         else:
             msg = _("Download this file")
         if uri:
             action = Gio.SimpleAction(name="download")
             App().add_action(action)
             action.connect("activate",
                            self.__on_download_activate,
                            uri)
             item = WebKit2.ContextMenuItem.new_from_gaction(
                 action,
                 msg,
                 None)
             context_menu.append(item)
     elif parsed.scheme in ["http", "https"]:
         item = WebKit2.ContextMenuItem.new_separator()
         context_menu.append(item)
         # Save all images
         action = Gio.SimpleAction(name="save_imgs")
         App().add_action(action)
         action.connect("activate",
                        self.__on_save_images_activate)
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Save images"),
             None)
         context_menu.append(item)
         # Save all videos
         action = Gio.SimpleAction(name="save_videos")
         App().add_action(action)
         action.connect("activate",
                        self.__on_save_videos_activate)
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Save videos"),
             None)
         context_menu.append(item)
         # Save page as image
         action = Gio.SimpleAction(name="save_as_image")
         App().add_action(action)
         action.connect("activate",
                        self.__on_save_as_image_activate)
         item = WebKit2.ContextMenuItem.new_from_gaction(
             action,
             _("Save page as image"),
             None)
         context_menu.append(item)
     # Dev tools
     if inspector_item is not None:
         item = WebKit2.ContextMenuItem.new_separator()
         context_menu.append(item)
         context_menu.append(inspector_item)
Exemplo n.º 15
0
 def __init__(self):
     super().__init__()
     self.action_new = Gio.SimpleAction(name=self.ACTION_NEW_NAME)
     self.action_move = Gio.SimpleAction(name=self.ACTION_MOVE_NAME)
     self.action_new.connect("activate", self._new_activated_cb)
     self.action_move.connect("activate", self._move_activated_cb)
Exemplo n.º 16
0
    def _init_tool_actions(self):
        """
         - Load defined Tools
         - create and init ToolActions from them
         - hook them in the window UI
         - create a map from extensions to lists of ToolActions
        """
        items_ui = ""
        self._action_handlers = {}

        # this is used for enable/disable actions by name (None = every extension)
        self._tool_action_extensions = {None: []}
        self._tool_action_group = Gtk.ActionGroup("LaTeXPluginToolActions")

        i = 1  # counting tool actions
        accel_counter = 1  # counting tool actions without custom accel
        for tool in self._tool_preferences.tools:
            # hopefully unique action name
            name = "Tool%sAction" % i

            # update extension-tool mapping
            for extension in tool.extensions:
                try:
                    self._tool_action_extensions[extension].append(name)
                except KeyError:
                    # extension not yet mapped
                    self._tool_action_extensions[extension] = [name]

            # create action
            action = ToolAction(tool)
            gtk_action = Gtk.Action(name, action.label, action.tooltip,
                                    action.stock_id)
            self._action_handlers[gtk_action] = gtk_action.connect(
                "activate", lambda gtk_action, action: action.activate(
                    self._window_context), action)

            # create simple actions to be used by menu (created in appactivatable.py)
            simpleaction = Gio.SimpleAction(name=name)
            simpleaction.connect(
                "activate",
                lambda _a, _b, action: action.activate(self._window_context),
                action)
            self.window.add_action(simpleaction)

            accelerator = None
            if tool.accelerator and len(tool.accelerator) > 0:
                key, mods = Gtk.accelerator_parse(tool.accelerator)
                if Gtk.accelerator_valid(key, mods):
                    accelerator = tool.accelerator
            if not accelerator:
                accelerator = "<Ctrl><Alt>%s" % accel_counter
                accel_counter += 1
            self._tool_action_group.add_action_with_accel(
                gtk_action, accelerator)

            # add UI definition
            items_ui += """<menuitem action="%s" />""" % name
            i += 1
        items_ui += """<separator/>"""

        tool_ui = self._tool_ui_template.substitute({
            "items":
            items_ui,
            "toolbar_name":
            self._toolbar_name
        })

        self._ui_manager.insert_action_group(self._tool_action_group, -1)
        self._tool_ui_id = self._ui_manager.add_ui_from_string(tool_ui)
Exemplo n.º 17
0
 def do_activate(self):
     action = Gio.SimpleAction(name='quicklangsel',
                               parameter_type=GLib.VariantType('s'))
     action.connect('activate',
                    lambda a, p: self.select_language(p.get_string()))
     self.window.add_action(action)
Exemplo n.º 18
0
 def simplehook(self, window, window_context):
     self._simple_internal_action = Gio.SimpleAction(
         name=self.__class__.__name__)
     self._simplehandler = self._simple_internal_action.connect(
         "activate", lambda action, param: self.activate(window_context))
     window.add_action(self._simple_internal_action)
Exemplo n.º 19
0
 def do_activate(self):
     action = Gio.SimpleAction(name="headerswitch")
     action.connect('activate', self.on_switch)
     self.window.add_action(action)
    def do_activate(self):
        action = Gio.SimpleAction(name="striptrailingwhitespace")
        action.connect('activate', lambda a, p: self.strip_trailing_ws())
        self.window.add_action(action)

        self.statusbar = Statusbar(self.window.get_statusbar(), 'strip_ws')
    def connect_actions(self):
        action_export = Gio.SimpleAction(name='md-prev-export-doc')
        action_print = Gio.SimpleAction(name='md-prev-print-doc')
        action_export.connect('activate', self.export_doc)
        action_print.connect('activate', self.print_doc)

        self.window.add_action(action_export)
        self.window.add_action(action_print)

        action_zoom_in = Gio.SimpleAction(name='md-prev-zoom-in')
        action_zoom_original = Gio.SimpleAction(name='md-prev-zoom-original')
        action_zoom_out = Gio.SimpleAction(name='md-prev-zoom-out')
        action_zoom_in.connect('activate', self.preview.on_zoom_in)
        action_zoom_original.connect('activate', self.preview.on_zoom_original)
        action_zoom_out.connect('activate', self.preview.on_zoom_out)

        self.window.add_action(action_zoom_in)
        self.window.add_action(action_zoom_original)
        self.window.add_action(action_zoom_out)

        action_view_mode = Gio.SimpleAction().new_stateful('md-set-view-mode', \
         GLib.VariantType.new('s'), GLib.Variant.new_string('whole'))
        action_view_mode.connect('change-state', self.on_change_view_mode)

        action_next = Gio.SimpleAction(name='md-prev-next')
        action_next.connect('activate', self.preview.on_next_page)

        action_previous = Gio.SimpleAction(name='md-prev-previous')
        action_previous.connect('activate', self.preview.on_previous_page)

        autoreload = self._settings.get_boolean('auto-reload')
        self.preview.auto_reload = autoreload
        action_autoreload = Gio.SimpleAction().new_stateful('md-prev-set-autoreload', \
         None, GLib.Variant.new_boolean(autoreload))
        action_autoreload.connect('change-state', self.preview.on_set_reload)

        self.action_reload_preview = Gio.SimpleAction(name='md-prev-reload')
        self.action_reload_preview.connect('activate', self.preview.on_reload)

        self.action_open_link_with = Gio.SimpleAction(
            name='md-prev-open-link-with')
        self.action_open_link_with.connect('activate',
                                           self.preview.on_open_link_with)

        self.action_open_image_with = Gio.SimpleAction(
            name='md-prev-open-image-with')
        self.action_open_image_with.connect('activate',
                                            self.preview.on_open_image_with)

        action_panel = Gio.SimpleAction().new_stateful('md-prev-panel', GLib.VariantType.new('s'), \
         GLib.Variant.new_string(self._settings.get_string('position')))
        action_panel.connect('change-state', self.on_change_panel_from_popover)

        self.window.add_action(action_view_mode)
        self.window.add_action(action_next)
        self.window.add_action(action_previous)
        self.window.add_action(action_panel)
        self.window.add_action(action_autoreload)
        self.window.add_action(self.action_reload_preview)
        self.window.add_action(self.action_open_link_with)
        self.window.add_action(self.action_open_image_with)

        #-------------------------

        action_remove = Gio.SimpleAction(name='md-prev-remove-all')
        action_remove.connect('activate',
                              lambda i, j: self.view_method('remove_all'))

        self.add_format_action('md-prev-format-title-1', 'format_title_1')
        self.add_format_action('md-prev-format-title-2', 'format_title_2')
        self.add_format_action('md-prev-format-title-3', 'format_title_3')
        self.add_format_action('md-prev-format-title-4', 'format_title_4')
        self.add_format_action('md-prev-format-title-5', 'format_title_5')
        self.add_format_action('md-prev-format-title-6', 'format_title_6')

        self.add_format_action('md-prev-format-title-upper',
                               'format_title_upper')
        self.add_format_action('md-prev-format-title-lower',
                               'format_title_lower')

        self.add_format_action('md-prev-format-bold', 'format_bold')
        self.add_format_action('md-prev-format-italic', 'format_italic')
        #		self.add_format_action('md-prev-format-underline', 'format_underline')
        #		self.add_format_action('md-prev-format-stroke', 'format_stroke')
        self.add_format_action('md-prev-format-monospace', 'format_monospace')
        self.add_format_action('md-prev-format-quote', 'format_quote')

        self.add_format_action('md-prev-list-unordered', 'list_unordered')
        self.add_format_action('md-prev-list-ordered', 'list_ordered')
        self.add_format_action('md-prev-insert-picture', 'insert_picture')
        self.add_format_action('md-prev-insert-link', 'insert_link')
        self.add_format_action('md-prev-insert-table', 'insert_table')
Exemplo n.º 22
0
 def do_activate(self):
     action = Gio.SimpleAction(name=actions[0])
     action.connect('activate', getattr(self, actions[0]))#  %
     self.window.add_action(action)
Exemplo n.º 23
0
 def do_activate(self):
     action = Gio.SimpleAction(name="reflow")
     action.connect('activate', self.on_reflow_text_activate)
     self.window.add_action(action)
Exemplo n.º 24
0
 def do_activate(self):
     action = Gio.SimpleAction(name="devhelp")
     action.connect(
         'activate',
         lambda a, p: self.do_devhelp(self.window.get_active_document()))
     self.window.add_action(action)
Exemplo n.º 25
0
    def __init__(self, application, giofile=None):
        Gtk.ApplicationWindow.__init__(self,
                                       application=application,
                                       default_width=640,
                                       default_height=480,
                                       title="Python Bloatpad")
        # create window ui

        toolbar = Gtk.Toolbar()

        button = Gtk.ToggleToolButton.new_from_stock(Gtk.STOCK_JUSTIFY_LEFT)
        button.set_detailed_action_name("win.justify::left")
        toolbar.add(button)

        button = Gtk.ToggleToolButton.new_from_stock(Gtk.STOCK_JUSTIFY_CENTER)
        button.set_detailed_action_name("win.justify::center")
        toolbar.add(button)

        button = Gtk.ToggleToolButton.new_from_stock(Gtk.STOCK_JUSTIFY_RIGHT)
        button.set_detailed_action_name("win.justify::right")
        toolbar.add(button)

        button = Gtk.SeparatorToolItem(draw=False, hexpand=True)
        button.set_expand(True)
        toolbar.add(button)

        switch = Gtk.Switch()
        switch.set_action_name("win.fullscreen")
        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
        box.add(Gtk.Label("Fullscreen:"))
        box.add(switch)
        button = Gtk.ToolItem()
        button.add(box)
        toolbar.add(button)

        scrolled = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
        textview = Gtk.TextView()
        scrolled.add(textview)

        grid = Gtk.Grid()
        grid.attach(toolbar, 0, 0, 1, 1)
        grid.attach(scrolled, 0, 1, 1, 1)

        self.add(grid)
        self.show_all()

        # Cannot use add_action_entries()
        # see https://bugzilla.gnome.org/show_bug.cgi?id=678655

        # setup actions
        action = Gio.SimpleAction(name="copy")
        action.connect("activate", self.copy, textview)
        self.add_action(action)

        # is the UI XML "parse" intentional?
        action = Gio.SimpleAction(name="paste")
        action.connect("activate", self.paste, textview)
        self.add_action(action)

        action = Gio.SimpleAction.new_stateful("fullscreen", None,
                                               GLib.Variant('b', False))
        action.connect("activate", self.activate_toggle)
        action.connect("change-state", self.change_fullscreen_state)
        self.add_action(action)

        variant = GLib.Variant('s', "left")
        action = Gio.SimpleAction.new_stateful("justify", variant.get_type(),
                                               variant)
        action.connect("activate", self.activate_radio)
        action.connect("change-state", self.change_justify_state, textview)
        self.add_action(action)

        # open file
        if giofile:
            contents = giofile.load_contents(giofile, None)
            textview.get_buffer().set_text(contents)
Exemplo n.º 26
0
    def __init__(self, webview, window):
        """
            Init menu
            @param webview as WebView
            @param window as Window
        """
        self.__window = window
        Gtk.Grid.__init__(self)
        self.set_margin_start(5)
        self.set_margin_end(5)
        self.set_margin_top(5)
        self.set_margin_bottom(5)
        self.set_orientation(Gtk.Orientation.VERTICAL)

        # Back button
        item = Gtk.ModelButton.new()
        item.set_hexpand(True)
        item.set_property("centered", True)
        item.set_property("text", _("Profiles"))
        item.set_property("inverted", True)
        item.set_property("menu-name", "main")
        item.show()
        self.add(item)

        # Profile buttons
        action = Gio.SimpleAction.new_stateful("switch_profile",
                                               GLib.VariantType.new("s"),
                                               GLib.Variant("s", "none"))
        action.connect("activate", self.__on_profiles_activate, webview)
        self.__window.add_action(action)
        # Get first view URI
        uri = webview.uri
        profile = El().websettings.get_profile(uri)
        # Load user profiles
        try:
            f = Gio.File.new_for_path(EOLIE_DATA_PATH + "/profiles.json")
            if f.query_exists():
                (status, contents, tag) = f.load_contents(None)
                profiles = json.loads(contents.decode("utf-8"))

            for key in profiles.keys():
                item = Gtk.ModelButton.new()
                item.set_property("text", profiles[key])
                item.set_action_name("win.switch_profile")
                item.set_action_target_value(GLib.Variant("s", key))
                item.show()
                self.add(item)
                if profile == key:
                    action.change_state(GLib.Variant("s", profile))
        except Exception as e:
            print("ProfilesMenu::__init__():", e)

        # Edit button
        item = Gtk.Separator.new(Gtk.Orientation.HORIZONTAL)
        item.show()
        self.add(item)
        action = Gio.SimpleAction(name="edit_profiles")
        action.connect('activate', self.__on_edit_profiles_activate)
        self.__window.add_action(action)
        item = Gtk.ModelButton.new()
        item.set_property("text", _("Edit profiles"))
        item.set_action_name("win.edit_profiles")
        item.show()
        self.add(item)
Exemplo n.º 27
0
 def _menu_connect(action_name, func):
     action = Gio.SimpleAction(name=action_name)
     action.connect('activate', func)
     action.set_enabled(True)
     self.shell.props.window.add_action(action)
Exemplo n.º 28
0
    def __init__(self, app, paths={}, group=None):
        '''Load alternative database and fetch objects from the builder.'''
        self.paths = paths
        self.group = alternative.Group(group, create=True) if group else None
        self.use_polkit = app.use_polkit if app else \
            os.getuid() and bool(spawn.find_executable('pkexec'))

        # glade XML
        self.builder = Gtk.Builder.new_from_file(
            get_data_path('glade/galternatives.glade'))
        for widget_id in {
                # main window
                'main_window',
                'pending_box',
                'groups_tv',
                'alternative_label',
                'link_label',
                'description_label',
                'status_switch',
                'options_tv',
                'options_column_package',
                'options_menu',
                # dialogs and messages
                'preferences_dialog',
                'edit_warning',
                'edit_warning_show_check',
                'confirm_closing',
                'commit_failed',
                'results_tv'
        }:
            setattr(self, widget_id, self.builder.get_object(widget_id))
        self.main_window.set_application(app)
        self.main_window.set_icon_from_file(LOGO_PATH)
        self.main_window.main_instance = self

        # save placeholder text strings
        self.empty_group = \
            alternative.Group(self.alternative_label.get_text(), create=True)
        self.empty_group[self.empty_group.name] = self.link_label.get_text()
        self.empty_group.description = self.description_label.get_text()
        self.empty_group._current = False

        # signals
        self.builder.connect_signals(self)
        # actions
        self.options_menu.insert_action_group('win', self.main_window)
        self.actions = {}
        for name, activate in {
            ('preferences', lambda *args: self.preferences_dialog.show()),
            ('quit', self.on_quit),
            ('group.add', self.add_group),
            ('group.edit', self.edit_group),
            ('group.remove', self.remove_group),
            ('option.add', self.add_option),
            ('option.edit', self.edit_option),
            ('option.remove', self.remove_option),
            ('change.save', self.on_save),
            ('change.reload', self.load_db),
        }:
            action = Gio.SimpleAction(name=name)
            action.connect('activate', activate)
            self.main_window.add_action(action)
            self.actions[name] = action
        for name in {'delay_mode', 'query_package', 'use_polkit'}:
            action = Gio.SimpleAction.new_stateful(
                name, None, GLib.Variant('b', getattr(self, name)))

            def on_action_toggle_func(name):
                def on_action_toggle(action, value):
                    action.set_state(value)
                    setattr(self, name, value.get_boolean())

                return on_action_toggle

            action.connect('change-state', on_action_toggle_func(name))
            self.main_window.add_action(action)

        self.load_db()
Exemplo n.º 29
0
 def do_activate(self):
     action = Gio.SimpleAction(name="findent")
     action.connect('activate', lambda a, p: self.do_findent())
     self.window.add_action(action)
     self._insert_bottom_panel()
Exemplo n.º 30
0
 def add_action_simple(self, action_name, callback):
     new_action = Gio.SimpleAction(name=action_name)
     new_action.connect('activate', callback)
     self.window.add_action(new_action)