Exemple #1
0
    def reload_global(self, settings, key, user_data):
        value = settings.get_string(key)
        if value == 'disabled':
            return

        try:
            self.guake.hotkeys.unbind(self.globalhotkeys[key])
        except Exception as e:
            pass

        self.globalhotkeys[key] = value
        if key == "show-hide":
            log.debug("reload_global: %r", value)
            if not self.guake.hotkeys.bind(value, self.guake.show_hide):
                keyval, mask = Gtk.accelerator_parse(value)
                label = Gtk.accelerator_get_label(keyval, mask)
                filename = pixmapfile('guake-notification.png')
                notifier.showMessage(
                    _('Guake Terminal'),
                    _('A problem happened when binding <b>%s</b> key.\n'
                      'Please use Guake Preferences dialog to choose another '
                      'key') % label, filename)
        elif key == "show-focus":
            if not self.guake.hotkeys.bind(value, self.guake.show_focus):
                log.warn("can't bind show-focus key")
                return
Exemple #2
0
    def reload_global(self, settings, key, user_data):
        value = settings.get_string(key)
        if value == 'disabled':
            return

        try:
            self.guake.hotkeys.unbind(self.globalhotkeys[key])
        except Exception as e:
            pass

        self.globalhotkeys[key] = value
        if key == "show-hide":
            log.debug("reload_global: %r", value)
            if not self.guake.hotkeys.bind(value, self.guake.show_hide):
                keyval, mask = Gtk.accelerator_parse(value)
                label = Gtk.accelerator_get_label(keyval, mask)
                filename = pixmapfile('guake-notification.png')
                notifier.showMessage(
                    _('Guake Terminal'),
                    _(
                        'A problem happened when binding <b>%s</b> key.\n'
                        'Please use Guake Preferences dialog to choose another '
                        'key'
                    ) % label, filename
                )
        elif key == "show-focus":
            if not self.guake.hotkeys.bind(value, self.guake.show_focus):
                log.warn("can't bind show-focus key")
                return
Exemple #3
0
    def reload_global(self, settings, key, user_data):
        value = settings.get_string(key)
        if value == 'disabled':
            return

        try:
            self.guake.hotkeys.unbind(self.globalhotkeys[key])
        except Exception as e:
            pass

        self.globalhotkeys[key] = value
        if not self.guake.hotkeys.bind(value, self.guake.show_hide):
            print("shit")
            # TODO port this
            return
            keyval, mask = Gtk.accelerator_parse(value)
            label = Gtk.accelerator_get_label(keyval, mask)
            filename = pixmapfile('guake-notification.png')
            notifier.showMessage(
                _('Guake Terminal'),
                _('A problem happened when binding <b>%s</b> key.\n'
                  'Please use Guake Preferences dialog to choose another '
                  'key') % xml_escape(label), filename)
Exemple #4
0
    def __init__(self):
        def load_schema():
            return Gio.SettingsSchemaSource.new_from_directory(
                SCHEMA_DIR, Gio.SettingsSchemaSource.get_default(), False)

        try:
            schema_source = load_schema()
        except GLib.Error:  # pylint: disable=catching-non-exception
            log.exception("Unable to load the GLib schema, try to compile it")
            try_to_compile_glib_schemas()
            schema_source = load_schema()
        self.settings = Settings(schema_source)

        super(Guake, self).__init__(gladefile('guake.glade'))

        select_gtk_theme(self.settings)
        patch_gtk_theme(
            self.get_widget("window-root").get_style_context(), self.settings)
        self.add_callbacks(self)

        self.debug_mode = self.settings.general.get_boolean('debug-mode')
        setupLogging(self.debug_mode)
        log.info('Guake Terminal %s', guake_version())
        log.info('VTE %s', vte_version())
        log.info('Gtk %s', gtk_version())

        self.hidden = True
        self.forceHide = False

        # trayicon! Using SVG handles better different OS trays
        # img = pixmapfile('guake-tray.svg')
        # trayicon!
        img = pixmapfile('guake-tray.png')
        try:
            import appindicator
        except ImportError:
            self.tray_icon = Gtk.StatusIcon()
            self.tray_icon.set_from_file(img)
            self.tray_icon.set_tooltip_text(_("Guake Terminal"))
            self.tray_icon.connect('popup-menu', self.show_menu)
            self.tray_icon.connect('activate', self.show_hide)
        else:
            # TODO PORT test this on a system with app indicator
            self.tray_icon = appindicator.Indicator(
                _("guake-indicator"), _("guake-tray"),
                appindicator.CATEGORY_OTHER)
            self.tray_icon.set_icon(img)
            self.tray_icon.set_status(appindicator.STATUS_ACTIVE)
            menu = self.get_widget('tray-menu')
            show = Gtk.MenuItem(_('Show'))
            show.set_sensitive(True)
            show.connect('activate', self.show_hide)
            show.show()
            menu.prepend(show)
            self.tray_icon.set_menu(menu)

        # important widgets
        self.window = self.get_widget('window-root')
        self.window.set_keep_above(True)
        self.mainframe = self.get_widget('mainframe')
        self.mainframe.remove(self.get_widget('notebook-teminals'))
        self.notebook = TerminalNotebook(self)
        self.notebook.connect('terminal-spawned', self.terminal_spawned)
        self.notebook.connect('page-deleted', self.page_deleted)

        self.mainframe.add(self.notebook)
        self.set_tab_position()

        # check and set ARGB for real transparency
        color = self.window.get_style_context().get_background_color(
            Gtk.StateFlags.NORMAL)
        self.window.set_app_paintable(True)

        def draw_callback(widget, cr):
            if widget.transparency:
                cr.set_source_rgba(color.red, color.green, color.blue, 1)
            else:
                cr.set_source_rgb(0, 0, 0)
            cr.set_operator(cairo.OPERATOR_SOURCE)
            cr.paint()
            cr.set_operator(cairo.OPERATOR_OVER)

        screen = self.window.get_screen()
        visual = screen.get_rgba_visual()

        if visual and screen.is_composited():
            self.window.set_visual(visual)
            self.window.transparency = True
        else:
            log.warn('System doesn\'t support transparency')
            self.window.transparency = False
            self.window.set_visual(screen.get_system_visual())

        self.window.connect('draw', draw_callback)

        # holds the timestamp of the losefocus event
        self.losefocus_time = 0

        # holds the timestamp of the previous show/hide action
        self.prev_showhide_time = 0

        # Controls the transparency state needed for function accel_toggle_transparency
        self.transparency_toggled = False

        # store the default window title to reset it when update is not wanted
        self.default_window_title = self.window.get_title()

        self.abbreviate = False

        self.window.connect('focus-out-event', self.on_window_losefocus)

        # Handling the delete-event of the main window to avoid
        # problems when closing it.
        def destroy(*args):
            self.hide()
            return True

        def window_event(*args):
            return self.window_event(*args)

        self.window.connect('delete-event', destroy)
        self.window.connect('window-state-event', window_event)

        # this line is important to resize the main window and make it
        # smaller.
        # TODO PORT do we still need this?
        # self.window.set_geometry_hints(min_width=1, min_height=1)

        # special trick to avoid the "lost guake on Ubuntu 'Show Desktop'" problem.
        # DOCK makes the window foundable after having being "lost" after "Show
        # Desktop"
        self.window.set_type_hint(Gdk.WindowTypeHint.DOCK)
        # Restore back to normal behavior
        self.window.set_type_hint(Gdk.WindowTypeHint.NORMAL)

        # loading and setting up configuration stuff
        GSettingHandler(self)
        Keybinder.init()
        self.hotkeys = Keybinder
        Keybindings(self)
        self.load_config()

        # adding the first tab on guake
        self.add_tab()

        if self.settings.general.get_boolean('start-fullscreen'):
            self.fullscreen()

        refresh_user_start(self.settings)

        # Pop-up that shows that guake is working properly (if not
        # unset in the preferences windows)
        if self.settings.general.get_boolean('use-popup'):
            key = self.settings.keybindingsGlobal.get_string('show-hide')
            keyval, mask = Gtk.accelerator_parse(key)
            label = Gtk.accelerator_get_label(keyval, mask)
            filename = pixmapfile('guake-notification.png')
            notifier.showMessage(
                _("Guake Terminal"),
                _("Guake is now running,\n"
                  "press <b>{!s}</b> to use it.").format(xml_escape(label)),
                filename)

        log.info("Guake initialized")
Exemple #5
0
    def restore_tabs(self, filename='session.json', suppress_notify=False):
        path = self.get_xdg_config_directory() / filename
        if not path.exists():
            log.info('Cannot found tabs session.json file')
            return
        with open(path) as f:
            try:
                config = json.load(f)
            except Exception:
                log.warning('session.json is broken')
                shutil.copy(
                    path,
                    self.get_xdg_config_directory() / f'{filename}.bak')
                img_filename = pixmapfile('guake-notification.png')
                notifier.showMessage(
                    _('Guake Terminal'),
                    _(f'Your session.json file is broken, backup to {filename}.bak'
                      ), img_filename)
                return

        # Disable auto save tabs
        v = self.settings.general.get_boolean('save-tabs-when-changed')
        self.settings.general.set_boolean('save-tabs-when-changed', False)

        # Restore all tabs for all workspaces
        try:
            for key, frames in config['workspace'].items():
                nb = self.notebook_manager.get_notebook(int(key))
                current_pages = nb.get_n_pages()

                # Restore each frames' tabs from config
                # NOTE: If frame implement in future, we will need to update this code
                for tabs in frames:
                    for index, tab in enumerate(tabs):
                        nb.new_page_with_focus(tab['directory'], tab['label'],
                                               tab['custom_label_set'])

                    # Remove original pages in notebook
                    for i in range(current_pages):
                        nb.delete_page(0)
        except KeyError:
            log.warning('session.json schema is broken')
            shutil.copy(path,
                        self.get_xdg_config_directory() / f'{filename}.bak')
            with open(self.get_xdg_config_directory() / f'{filename}.log.err',
                      'w') as f:
                traceback.print_exc(file=f)
            img_filename = pixmapfile('guake-notification.png')
            notifier.showMessage(
                _('Guake Terminal'),
                _(f'Your session.json schema is broken, backup to {filename}.bak,'
                  f'and error message has been saved to {filename}.log.err'),
                img_filename)

        # Reset auto save tabs
        self.settings.general.set_boolean('save-tabs-when-changed', v)

        # Notify the user
        if (self.settings.general.get_boolean('restore-tabs-notify')
                and not suppress_notify):
            filename = pixmapfile('guake-notification.png')
            notifier.showMessage(_("Guake Terminal"),
                                 _("Your tabs has been restored!"), filename)

        log.info('Guake tabs restored')
Exemple #6
0
    def restore_tabs(self, filename='session.json', suppress_notify=False):
        session_file = self.get_xdg_config_directory() / filename
        if not session_file.exists():
            log.info('Cannot found tabs session.json file')
            return
        with session_file.open() as f:
            try:
                config = json.load(f)
            except Exception:
                log.warning('%s is broken', session_filen)
                shutil.copy(
                    session_file,
                    self.get_xdg_config_directory() / '{0}.bak'.format(filename)
                )
                img_filename = pixmapfile('guake-notification.png')
                notifier.showMessage(
                    _('Guake Terminal'),
                    _('Your {session_filename} file is broken, backup to {session_filename}.bak'
                      ).format(session_filename=filename), img_filename
                )
                return

        # Disable auto save tabs
        v = self.settings.general.get_boolean('save-tabs-when-changed')
        self.settings.general.set_boolean('save-tabs-when-changed', False)

        # Restore all tabs for all workspaces
        try:
            for key, frames in config['workspace'].items():
                nb = self.notebook_manager.get_notebook(int(key))
                current_pages = nb.get_n_pages()

                # Restore each frames' tabs from config
                # NOTE: If frame implement in future, we will need to update this code
                for tabs in frames:
                    for index, tab in enumerate(tabs):
                        nb.new_page_with_focus(
                            tab['directory'], tab['label'], tab['custom_label_set']
                        )

                    # Remove original pages in notebook
                    for i in range(current_pages):
                        nb.delete_page(0)
        except KeyError:
            log.warning('%s schema is broken', session_file)
            shutil.copy(path, self.get_xdg_config_directory() / '{}.bak'.format(filename))
            with open(self.get_xdg_config_directory() / '{}.log.err'.format(filename), 'w') as f:
                traceback.print_exc(file=f)
            img_filename = pixmapfile('guake-notification.png')
            notifier.showMessage(
                _('Guake Terminal'),
                _(
                    'Your {session_filename} schema is broken, backup to {session_filename}.bak, '
                    'and error message has been saved to {session_filename}.log.err.'.format(
                        session_filename=filename
                    )
                ), img_filename
            )

        # Reset auto save tabs
        self.settings.general.set_boolean('save-tabs-when-changed', v)

        # Notify the user
        if (self.settings.general.get_boolean('restore-tabs-notify') and not suppress_notify):
            filename = pixmapfile('guake-notification.png')
            notifier.showMessage(_("Guake Terminal"), _("Your tabs has been restored!"), filename)

        log.info('Guake tabs restored from %s', session_file)
Exemple #7
0
    def __init__(self):

        def load_schema():
            return Gio.SettingsSchemaSource.new_from_directory(
                SCHEMA_DIR, Gio.SettingsSchemaSource.get_default(), False
            )

        try:
            schema_source = load_schema()
        except GLib.Error:  # pylint: disable=catching-non-exception
            log.exception("Unable to load the GLib schema, try to compile it")
            try_to_compile_glib_schemas()
            schema_source = load_schema()
        self.settings = Settings(schema_source)

        super(Guake, self).__init__(gladefile('guake.glade'))

        select_gtk_theme(self.settings)
        patch_gtk_theme(self.get_widget("window-root").get_style_context(), self.settings)
        self.add_callbacks(self)

        log.info('Guake Terminal %s', guake_version())
        log.info('VTE %s', vte_version())
        log.info('Gtk %s', gtk_version())

        self.hidden = True
        self.forceHide = False

        # trayicon! Using SVG handles better different OS trays
        # img = pixmapfile('guake-tray.svg')
        # trayicon!
        img = pixmapfile('guake-tray.png')
        try:
            import appindicator
        except ImportError:
            self.tray_icon = Gtk.StatusIcon()
            self.tray_icon.set_from_file(img)
            self.tray_icon.set_tooltip_text(_("Guake Terminal"))
            self.tray_icon.connect('popup-menu', self.show_menu)
            self.tray_icon.connect('activate', self.show_hide)
        else:
            # TODO PORT test this on a system with app indicator
            self.tray_icon = appindicator.Indicator(
                _("guake-indicator"), _("guake-tray"), appindicator.CATEGORY_OTHER
            )
            self.tray_icon.set_icon(img)
            self.tray_icon.set_status(appindicator.STATUS_ACTIVE)
            menu = self.get_widget('tray-menu')
            show = Gtk.MenuItem(_('Show'))
            show.set_sensitive(True)
            show.connect('activate', self.show_hide)
            show.show()
            menu.prepend(show)
            self.tray_icon.set_menu(menu)

        # important widgets
        self.window = self.get_widget('window-root')
        self.window.set_keep_above(True)
        self.mainframe = self.get_widget('mainframe')
        self.mainframe.remove(self.get_widget('notebook-teminals'))

        # Workspace tracking
        self.notebook_manager = NotebookManager(
            self.window, self.mainframe,
            self.settings.general.get_boolean('workspace-specific-tab-sets'), self.terminal_spawned,
            self.page_deleted
        )
        self.notebook_manager.connect('notebook-created', self.notebook_created)
        self.notebook_manager.set_workspace(0)
        self.set_tab_position()

        # check and set ARGB for real transparency
        color = self.window.get_style_context().get_background_color(Gtk.StateFlags.NORMAL)
        self.window.set_app_paintable(True)

        def draw_callback(widget, cr):
            if widget.transparency:
                cr.set_source_rgba(color.red, color.green, color.blue, 1)
            else:
                cr.set_source_rgb(0, 0, 0)
            cr.set_operator(cairo.OPERATOR_SOURCE)
            cr.paint()
            cr.set_operator(cairo.OPERATOR_OVER)

        screen = self.window.get_screen()
        visual = screen.get_rgba_visual()

        if visual and screen.is_composited():
            self.window.set_visual(visual)
            self.window.transparency = True
        else:
            log.warn('System doesn\'t support transparency')
            self.window.transparency = False
            self.window.set_visual(screen.get_system_visual())

        self.window.connect('draw', draw_callback)

        # Debounce accel_search_terminal
        self.prev_accel_search_terminal_time = 0.0

        # holds the timestamp of the losefocus event
        self.losefocus_time = 0

        # holds the timestamp of the previous show/hide action
        self.prev_showhide_time = 0

        # Controls the transparency state needed for function accel_toggle_transparency
        self.transparency_toggled = False

        # store the default window title to reset it when update is not wanted
        self.default_window_title = self.window.get_title()

        self.abbreviate = False

        self.window.connect('focus-out-event', self.on_window_losefocus)

        # Handling the delete-event of the main window to avoid
        # problems when closing it.
        def destroy(*args):
            self.hide()
            return True

        def window_event(*args):
            return self.window_event(*args)

        self.window.connect('delete-event', destroy)
        self.window.connect('window-state-event', window_event)

        # this line is important to resize the main window and make it
        # smaller.
        # TODO PORT do we still need this?
        # self.window.set_geometry_hints(min_width=1, min_height=1)

        # special trick to avoid the "lost guake on Ubuntu 'Show Desktop'" problem.
        # DOCK makes the window foundable after having being "lost" after "Show
        # Desktop"
        self.window.set_type_hint(Gdk.WindowTypeHint.DOCK)
        # Restore back to normal behavior
        self.window.set_type_hint(Gdk.WindowTypeHint.NORMAL)

        # loading and setting up configuration stuff
        GSettingHandler(self)
        Keybinder.init()
        self.hotkeys = Keybinder
        Keybindings(self)
        self.load_config()

        if self.settings.general.get_boolean('start-fullscreen'):
            self.fullscreen()

        refresh_user_start(self.settings)

        # Restore tabs when startup
        if self.settings.general.get_boolean('restore-tabs-startup'):
            self.restore_tabs(suppress_notify=True)

        # Pop-up that shows that guake is working properly (if not
        # unset in the preferences windows)
        if self.settings.general.get_boolean('use-popup'):
            key = self.settings.keybindingsGlobal.get_string('show-hide')
            keyval, mask = Gtk.accelerator_parse(key)
            label = Gtk.accelerator_get_label(keyval, mask)
            filename = pixmapfile('guake-notification.png')
            notifier.showMessage(
                _("Guake Terminal"),
                _("Guake is now running,\n"
                  "press <b>{!s}</b> to use it.").format(xml_escape(label)), filename
            )

        log.info("Guake initialized")