Example #1
0
def get_version():
    display = Gdk.Display.get_default()

    print('Guake Version:\t\t{}'.format(guake_version()))
    print()
    print('Vte Version:\t\t{}'.format(vte_version()))
    print()
    print('Vte Runtime Version:\t{}'.format(vte_runtime_version()))
    print()
    horizonal_line()
    print('GTK+ Version:\t\t{}'.format(gtk_version()))
    print()
    print('GDK Backend:\t\t{}'.format(str(display).split(' ')[0][1:]))
    print()
    horizonal_line()
Example #2
0
def get_version():
    display = Gdk.Display.get_default()

    print('Guake Version:\t\t{}'.format(guake_version()))
    print()
    print('Vte Version:\t\t{}'.format(vte_version()))
    print()
    print('Vte Runtime Version:\t{}'.format(vte_runtime_version()))
    print()
    horizonal_line()
    print('GTK+ Version:\t\t{}'.format(gtk_version()))
    print()
    print('GDK Backend:\t\t{}'.format(str(display).split(' ')[0][1:]))
    print()
    horizonal_line()
Example #3
0
    def __init__(self):
        super(AboutDialog, self).__init__(gladefile('about.glade'), root='aboutdialog')
        dialog = self.get_widget('aboutdialog')

        # images
        # ipath = pixmapfile('guake-notification.png')
        # img = gtk.gdk.pixbuf_new_from_file(ipath)

        # img = pixmapfile('guake-notification.png')
        image = Gtk.Image()
        image.set_from_file(pixmapfile('guake-notification.png'))
        pixbuf = image.get_pixbuf()

        dialog.set_property('logo', pixbuf)

        dialog.set_name(_('Guake Terminal'))
        dialog.set_version(guake_version())
        dialog.connect("response", lambda x, y: dialog.destroy())
Example #4
0
    def __init__(self):
        super().__init__(gladefile("about.glade"), root="aboutdialog")
        dialog = self.get_widget("aboutdialog")

        # images
        # ipath = pixmapfile('guake-notification.png')
        # img = gtk.gdk.pixbuf_new_from_file(ipath)

        # img = pixmapfile('guake-notification.png')
        image = Gtk.Image()
        image.set_from_file(pixmapfile("guake-notification.png"))
        pixbuf = image.get_pixbuf()

        dialog.set_property("logo", pixbuf)

        dialog.set_name(_("Guake Terminal"))
        dialog.set_version(guake_version())
        dialog.connect("response", lambda x, y: dialog.destroy())
Example #5
0
def main():
    """Parses the command line parameters and decide if dbus methods
    should be called or not. If there is already a guake instance
    running it will be used and a True value will be returned,
    otherwise, false will be returned.
    """
    # Force to xterm-256 colors for compatibility with some old command line programs
    os.environ["TERM"] = "xterm-256color"

    # Force use X11 backend underwayland
    os.environ["GDK_BACKEND"] = "x11"

    # do not use version keywords here, pbr might be slow to find the version of Guake module
    parser = OptionParser()
    parser.add_option('-V',
                      '--version',
                      dest='version',
                      action='store_true',
                      default=False,
                      help=_('Show Guake version number and exit'))

    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help=_('Enable verbose logging'))

    parser.add_option('-f',
                      '--fullscreen',
                      dest='fullscreen',
                      action='store_true',
                      default=False,
                      help=_('Put Guake in fullscreen mode'))

    parser.add_option('--unfullscreen',
                      dest='unfullscreen',
                      action='store_true',
                      default=False,
                      help=_('Put Guake out from fullscreen mode'))

    parser.add_option('-t',
                      '--toggle-visibility',
                      dest='show_hide',
                      action='store_true',
                      default=False,
                      help=_('Toggles the visibility of the terminal window'))

    parser.add_option('--show',
                      dest="show",
                      action='store_true',
                      default=False,
                      help=_('Shows Guake main window'))

    parser.add_option('--hide',
                      dest='hide',
                      action='store_true',
                      default=False,
                      help=_('Hides Guake main window'))

    parser.add_option('-p',
                      '--preferences',
                      dest='show_preferences',
                      action='store_true',
                      default=False,
                      help=_('Shows Guake preference window'))

    parser.add_option('-a',
                      '--about',
                      dest='show_about',
                      action='store_true',
                      default=False,
                      help=_('Shows Guake\'s about info'))

    parser.add_option(
        '-n',
        '--new-tab',
        dest='new_tab',
        action='store',
        default='',
        help=_('Add a new tab (with current directory set to NEW_TAB)'))

    parser.add_option(
        '-s',
        '--select-tab',
        dest='select_tab',
        action='store',
        default='',
        help=_('Select a tab (SELECT_TAB is the index of the tab)'))

    parser.add_option('-g',
                      '--selected-tab',
                      dest='selected_tab',
                      action='store_true',
                      default=False,
                      help=_('Return the selected tab index.'))

    parser.add_option('-l',
                      '--selected-tablabel',
                      dest='selected_tablabel',
                      action='store_true',
                      default=False,
                      help=_('Return the selected tab label.'))

    parser.add_option('--split-vertical',
                      dest='split_vertical',
                      action='store_true',
                      default=False,
                      help=_('Split the selected tab vertically.'))

    parser.add_option('--split-horizontal',
                      dest='split_horizontal',
                      action='store_true',
                      default=False,
                      help=_('Split the selected tab horizontally.'))

    parser.add_option(
        '-e',
        '--execute-command',
        dest='command',
        action='store',
        default='',
        help=_('Execute an arbitrary command in the selected tab.'))

    parser.add_option(
        '-i',
        '--tab-index',
        dest='tab_index',
        action='store',
        default='0',
        help=
        _('Specify the tab to rename. Default is 0. Can be used to select tab by UUID.'
          ))

    parser.add_option('--bgcolor',
                      dest='bgcolor',
                      action='store',
                      default='',
                      help=_(
                          'Set the hexadecimal (#rrggbb) background color of '
                          'the selected tab.'))

    parser.add_option(
        '--fgcolor',
        dest='fgcolor',
        action='store',
        default='',
        help=_('Set the hexadecimal (#rrggbb) foreground color of the '
               'selected tab.'))

    parser.add_option('--bgcolor-focused',
                      dest='bgcolor_focused',
                      action='store',
                      default='',
                      help=_(
                          'Set the hexadecimal (#rrggbb) background color of '
                          'the focused terminal.'))

    parser.add_option(
        '--fgcolor-focused',
        dest='fgcolor_focused',
        action='store',
        default='',
        help=_('Set the hexadecimal (#rrggbb) foreground color of the '
               'focused terminal.'))

    parser.add_option('--change-palette',
                      dest='palette_name',
                      action='store',
                      default='',
                      help=_('Change Guake palette scheme'))

    parser.add_option('--reset-colors',
                      dest='reset_colors',
                      action='store_true',
                      default=False,
                      help=_('Set colors from settings.'))

    parser.add_option(
        '--reset-colors-focused',
        dest='reset_colors_focused',
        action='store_true',
        default=False,
        help=_('Set colors of the focused terminal from settings.'))

    parser.add_option(
        '--rename-tab',
        dest='rename_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_(
            'Rename the specified tab by --tab-index. Reset to default if TITLE is '
            'a single dash "-".'))

    parser.add_option(
        '-r',
        '--rename-current-tab',
        dest='rename_current_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_('Rename the current tab. Reset to default if TITLE is a '
               'single dash "-".'))

    parser.add_option('-q',
                      '--quit',
                      dest='quit',
                      action='store_true',
                      default=False,
                      help=_('Says to Guake go away =('))

    parser.add_option('-u',
                      '--no-startup-script',
                      dest='execute_startup_script',
                      action='store_false',
                      default=True,
                      help=_('Do not execute the start up script'))

    parser.add_option('--save-preferences',
                      dest='save_preferences',
                      action='store',
                      default=None,
                      help=_('Save Guake preferences to this filename'))

    parser.add_option('--restore-preferences',
                      dest='restore_preferences',
                      action='store',
                      default=None,
                      help=_('Restore Guake preferences from this file'))

    parser.add_option('--support',
                      dest='support',
                      action='store_true',
                      default=False,
                      help=_('Show support infomation'))

    # checking mandatory dependencies

    missing_deps = False
    try:
        import gi
        gi.require_version('Gtk', '3.0')
        gi.require_version('Gdk', '3.0')
    except ValueError:
        print("[ERROR] missing mandatory dependency: GtK 3.0")
        missing_deps = True

    try:
        gi.require_version('Vte', '2.91')  # vte-0.42
    except ValueError:
        print("[ERROR] missing mandatory dependency: Vte >= 0.42")
        missing_deps = True

    try:
        gi.require_version('Keybinder', '3.0')
    except ValueError:
        print("[ERROR] missing mandatory dependency: Keybinder 3")
        missing_deps = True

    try:
        import cairo
    except ImportError:
        print("[ERROR] missing mandatory dependency: cairo")
        missing_deps = True

    if missing_deps:
        print("[ERROR] missing at least one system dependencies. "
              "You need to install additional packages for Guake to run")
        print(
            "[ERROR] On Debian/Ubuntu you need to install the following libraries:\n"
            "    sudo apt-get install -y --no-install-recommends \\\n"
            "        gir1.2-keybinder-3.0 \\\n"
            "        gir1.2-notify-0.7 \\\n"
            "        gir1.2-vte-2.91 \\\n"
            "        gir1.2-wnck-3.0 \\\n"
            "        libkeybinder-3.0-0 \\\n"
            "        libutempter0 \\\n"
            "        python3 \\\n"
            "        python3-cairo \\\n"
            "        python3-dbus \\\n"
            "        python3-gi \\\n"
            "        python3-pbr \\\n"
            "        python3-pip")
        sys.exit(1)

    options = parser.parse_args()[0]
    if options.version:
        from guake import gtk_version
        from guake import guake_version
        from guake import vte_version
        from guake import vte_runtime_version
        print('Guake Terminal: {}'.format(guake_version()))
        print('VTE: {}'.format(vte_version()))
        print('VTE runtime: {}'.format(vte_runtime_version()))
        print('Gtk: {}'.format(gtk_version()))
        sys.exit(0)

    if options.save_preferences and options.restore_preferences:
        parser.error(
            'options --save-preferences and --restore-preferences are mutually exclusive'
        )
    if options.save_preferences:
        save_preferences(options.save_preferences)
        sys.exit(0)
    elif options.restore_preferences:
        restore_preferences(options.restore_preferences)
        sys.exit(0)

    if options.support:
        print_support()
        sys.exit(0)

    import dbus

    from guake.dbusiface import DBUS_NAME
    from guake.dbusiface import DBUS_PATH
    from guake.dbusiface import DbusManager
    from guake.guake_logging import setupLogging

    instance = None

    # Trying to get an already running instance of guake. If it is not
    # possible, lets create a new instance. This function will return
    # a boolean value depending on this decision.
    try:
        bus = dbus.SessionBus()
        remote_object = bus.get_object(DBUS_NAME, DBUS_PATH)
        already_running = True
    except dbus.DBusException:
        # can now configure the logging
        setupLogging(options.verbose)

        # COLORTERM is an environment variable set by some terminal emulators such as
        # gnome-terminal.
        # To avoid confusing applications running inside Guake, clean up COLORTERM at startup.
        if "COLORTERM" in os.environ:
            del os.environ['COLORTERM']

        log.info("Guake not running, starting it")
        # late loading of the Guake object, to speed up dbus comm
        from guake.guake_app import Guake
        instance = Guake()
        remote_object = DbusManager(instance)
        already_running = False

    only_show_hide = True

    if options.fullscreen:
        remote_object.fullscreen()

    if options.unfullscreen:
        remote_object.unfullscreen()

    if options.show:
        remote_object.show_from_remote()

    if options.hide:
        remote_object.hide_from_remote()

    if options.show_preferences:
        remote_object.show_prefs()
        only_show_hide = options.show

    if options.new_tab:
        remote_object.add_tab(options.new_tab)
        only_show_hide = options.show

    if options.select_tab:
        selected = int(options.select_tab)
        tab_count = int(remote_object.get_tab_count())
        if 0 <= selected < tab_count:
            remote_object.select_tab(selected)
        else:
            sys.stderr.write('invalid index: %d\n' % selected)
        only_show_hide = options.show

    if options.selected_tab:
        selected = remote_object.get_selected_tab()
        sys.stdout.write('%d\n' % selected)
        only_show_hide = options.show

    if options.selected_tablabel:
        selectedlabel = remote_object.get_selected_tablabel()
        sys.stdout.write('%s\n' % selectedlabel)
        only_show_hide = options.show

    if options.split_vertical:
        remote_object.v_split_current_terminal()
        only_show_hide = options.show

    if options.split_horizontal:
        remote_object.h_split_current_terminal()
        only_show_hide = options.show

    if options.command:
        remote_object.execute_command(options.command)
        only_show_hide = options.show

    if options.tab_index and options.rename_tab:
        try:
            remote_object.rename_tab_uuid(str(uuid.UUID(options.tab_index)),
                                          options.rename_tab)
        except ValueError:
            remote_object.rename_tab(int(options.tab_index),
                                     options.rename_tab)
        only_show_hide = options.show

    if options.bgcolor:
        remote_object.set_bgcolor(options.bgcolor)
        only_show_hide = options.show

    if options.fgcolor:
        remote_object.set_fgcolor(options.fgcolor)
        only_show_hide = options.show

    if options.bgcolor_focused:
        remote_object.set_bgcolor_focused_terminal(options.bgcolor_focused)
        only_show_hide = options.show

    if options.fgcolor_focused:
        remote_object.set_fgcolor_focused_terminal(options.fgcolor_focused)
        only_show_hide = options.show

    if options.palette_name:
        remote_object.change_palette_name(options.palette_name)
        only_show_hide = options.show

    if options.reset_colors:
        remote_object.reset_colors()
        only_show_hide = options.show

    if options.reset_colors_focused:
        remote_object.reset_colors_focused()
        only_show_hide = options.show

    if options.rename_current_tab:
        remote_object.rename_current_tab(options.rename_current_tab)
        only_show_hide = options.show

    if options.show_about:
        remote_object.show_about()
        only_show_hide = options.show

    if options.quit:
        try:
            remote_object.quit()
            return True
        except dbus.DBusException:
            return True

    if already_running and only_show_hide:
        # here we know that guake was called without any parameter and
        # it is already running, so, lets toggle its visibility.
        remote_object.show_hide()

    if options.execute_startup_script:
        if not already_running:
            startup_script = instance.settings.general.get_string(
                "startup-script")
            if startup_script:
                log.info("Calling startup script: %s", startup_script)
                pid = subprocess.Popen([startup_script],
                                       shell=True,
                                       stdin=None,
                                       stdout=None,
                                       stderr=None,
                                       close_fds=True)
                log.info("Startup script started with pid: %s", pid)
                # Please ensure this is the last line !!!!
    else:
        log.info(
            "--no-startup-script argument defined, so don't execute the startup script"
        )
    if already_running:
        log.info("Guake is already running")
    return already_running
Example #6
0
def main():
    """Parses the command line parameters and decide if dbus methods
    should be called or not. If there is already a guake instance
    running it will be used and a True value will be returned,
    otherwise, false will be returned.
    """
    # Force to xterm-256 colors for compatibility with some old command line programs
    os.environ["TERM"] = "xterm-256color"

    # Force use X11 backend underwayland
    os.environ["GDK_BACKEND"] = "x11"

    # do not use version keywords here, pbr might be slow to find the version of Guake module
    parser = OptionParser()
    parser.add_option('-V',
                      '--version',
                      dest='version',
                      action='store_true',
                      default=False,
                      help=_('Show Guake version number and exit'))

    parser.add_option('-v',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      default=False,
                      help=_('Enable verbose logging'))

    parser.add_option('-f',
                      '--fullscreen',
                      dest='fullscreen',
                      action='store_true',
                      default=False,
                      help=_('Put Guake in fullscreen mode'))

    parser.add_option('-t',
                      '--toggle-visibility',
                      dest='show_hide',
                      action='store_true',
                      default=False,
                      help=_('Toggles the visibility of the terminal window'))

    parser.add_option('--show',
                      dest="show",
                      action='store_true',
                      default=False,
                      help=_('Shows Guake main window'))

    parser.add_option('--hide',
                      dest='hide',
                      action='store_true',
                      default=False,
                      help=_('Hides Guake main window'))

    parser.add_option('-p',
                      '--preferences',
                      dest='show_preferences',
                      action='store_true',
                      default=False,
                      help=_('Shows Guake preference window'))

    parser.add_option('-a',
                      '--about',
                      dest='show_about',
                      action='store_true',
                      default=False,
                      help=_('Shows Guake\'s about info'))

    parser.add_option(
        '-n',
        '--new-tab',
        dest='new_tab',
        action='store',
        default='',
        help=_('Add a new tab (with current directory set to NEW_TAB)'))

    parser.add_option(
        '-s',
        '--select-tab',
        dest='select_tab',
        action='store',
        default='',
        help=_('Select a tab (SELECT_TAB is the index of the tab)'))

    parser.add_option('-g',
                      '--selected-tab',
                      dest='selected_tab',
                      action='store_true',
                      default=False,
                      help=_('Return the selected tab index.'))

    parser.add_option('-l',
                      '--selected-tablabel',
                      dest='selected_tablabel',
                      action='store_true',
                      default=False,
                      help=_('Return the selected tab label.'))

    parser.add_option(
        '-e',
        '--execute-command',
        dest='command',
        action='store',
        default='',
        help=_('Execute an arbitrary command in the selected tab.'))

    parser.add_option(
        '-i',
        '--tab-index',
        dest='tab_index',
        action='store',
        default='0',
        help=
        _('Specify the tab to rename. Default is 0. Can be used to select tab by UUID'
          ))

    parser.add_option('--bgcolor',
                      dest='bgcolor',
                      action='store',
                      default='',
                      help=_(
                          'Set the hexadecimal (#rrggbb) background color of '
                          'the selected tab.'))

    parser.add_option(
        '--fgcolor',
        dest='fgcolor',
        action='store',
        default='',
        help=_('Set the hexadecimal (#rrggbb) foreground color of the '
               'selected tab.'))

    parser.add_option(
        '--rename-tab',
        dest='rename_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_(
            'Rename the specified tab by --tab-index. Reset to default if TITLE is '
            'a single dash "-".'))

    parser.add_option(
        '-r',
        '--rename-current-tab',
        dest='rename_current_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_('Rename the current tab. Reset to default if TITLE is a '
               'single dash "-".'))

    parser.add_option('-q',
                      '--quit',
                      dest='quit',
                      action='store_true',
                      default=False,
                      help=_('Says to Guake go away =('))

    parser.add_option('-u',
                      '--no-startup-script',
                      dest='execute_startup_script',
                      action='store_false',
                      default=True,
                      help=_('Do not execute the start up script'))

    options = parser.parse_args()[0]
    if options.version:
        from guake import gtk_version
        from guake import guake_version
        from guake import vte_version
        from guake import vte_runtime_version
        print('Guake Terminal: {}'.format(guake_version()))
        print('VTE: {}'.format(vte_version()))
        print('VTE runtime: {}'.format(vte_runtime_version()))
        print('Gtk: {}'.format(gtk_version()))
        sys.exit(0)

    import dbus

    from guake.dbusiface import DBUS_NAME
    from guake.dbusiface import DBUS_PATH
    from guake.dbusiface import DbusManager
    from guake.guake_logging import setupLogging

    instance = None

    # Trying to get an already running instance of guake. If it is not
    # possible, lets create a new instance. This function will return
    # a boolean value depending on this decision.
    try:
        bus = dbus.SessionBus()
        remote_object = bus.get_object(DBUS_NAME, DBUS_PATH)
        already_running = True
    except dbus.DBusException:
        # can now configure the logging
        setupLogging(options.verbose)

        # COLORTERM is an environment variable set by some terminal emulators such as
        # gnome-terminal.
        # To avoid confusing applications running inside Guake, clean up COLORTERM at startup.
        if "COLORTERM" in os.environ:
            del os.environ['COLORTERM']

        log.info("Guake not running, starting it")
        # late loading of the Guake object, to speed up dbus comm
        from guake.guake_app import Guake
        instance = Guake()
        remote_object = DbusManager(instance)
        already_running = False

    only_show_hide = True

    if options.fullscreen:
        remote_object.fullscreen()

    if options.show:
        remote_object.show_from_remote()

    if options.hide:
        remote_object.hide_from_remote()

    if options.show_preferences:
        remote_object.show_prefs()
        only_show_hide = False

    if options.new_tab:
        remote_object.add_tab(options.new_tab)
        only_show_hide = False

    if options.select_tab:
        selected = int(options.select_tab)
        i = remote_object.select_tab(selected)
        if i is None:
            sys.stdout.write('invalid index: %d\n' % selected)
        only_show_hide = False

    if options.selected_tab:
        selected = remote_object.get_selected_tab()
        sys.stdout.write('%d\n' % selected)
        only_show_hide = False

    if options.selected_tablabel:
        selectedlabel = remote_object.get_selected_tablabel()
        sys.stdout.write('%s\n' % selectedlabel)
        only_show_hide = False

    if options.command:
        remote_object.execute_command(options.command)
        only_show_hide = False

    if options.tab_index and options.rename_tab:
        try:
            remote_object.rename_tab_uuid(str(uuid.UUID(options.tab_index)),
                                          options.rename_tab)
        except ValueError:
            remote_object.rename_tab(int(options.tab_index),
                                     options.rename_tab)
        only_show_hide = False

    if options.bgcolor:
        remote_object.set_bgcolor(options.bgcolor)
        only_show_hide = False

    if options.fgcolor:
        remote_object.set_fgcolor(options.fgcolor)
        only_show_hide = False

    if options.rename_current_tab:
        remote_object.rename_current_tab(options.rename_current_tab)
        only_show_hide = False

    if options.show_about:
        remote_object.show_about()
        only_show_hide = False

    if options.quit:
        try:
            remote_object.quit()
            return True
        except dbus.DBusException:
            return True

    if already_running and only_show_hide:
        # here we know that guake was called without any parameter and
        # it is already running, so, lets toggle its visibility.
        remote_object.show_hide()

    if options.execute_startup_script:
        if not already_running:
            startup_script = instance.settings.general.get_string(
                "startup-script")
            if startup_script:
                log.info("Calling startup script: %s", startup_script)
                pid = subprocess.Popen([startup_script],
                                       shell=True,
                                       stdin=None,
                                       stdout=None,
                                       stderr=None,
                                       close_fds=True)
                log.info("Startup script started with pid: %s", pid)
                # Please ensure this is the last line !!!!
    else:
        log.info(
            "--no-startup-script argument defined, so don't execute the startup script"
        )
    if already_running:
        log.info("Guake is already running")
    return already_running
Example #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)

        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")
Example #8
0
def test_version_test(dialog):
    assert dialog.get_widget("aboutdialog").get_version() == guake_version()
Example #9
0
def test_version_test(dialog):
    assert dialog.get_widget('aboutdialog').get_version() == guake_version()
Example #10
0
File: main.py Project: Guake/guake
def main():
    """Parses the command line parameters and decide if dbus methods
    should be called or not. If there is already a guake instance
    running it will be used and a True value will be returned,
    otherwise, false will be returned.
    """
    # Force to xterm-256 colors for compatibility with some old command line programs
    os.environ["TERM"] = "xterm-256color"

    # Force use X11 backend underwayland
    os.environ["GDK_BACKEND"] = "x11"

    # do not use version keywords here, pbr might be slow to find the version of Guake module
    parser = OptionParser()
    parser.add_option(
        '-V',
        '--version',
        dest='version',
        action='store_true',
        default=False,
        help=_('Show Guake version number and exit')
    )

    parser.add_option(
        '-v',
        '--verbose',
        dest='verbose',
        action='store_true',
        default=False,
        help=_('Enable verbose logging')
    )

    parser.add_option(
        '-f',
        '--fullscreen',
        dest='fullscreen',
        action='store_true',
        default=False,
        help=_('Put Guake in fullscreen mode')
    )

    parser.add_option(
        '-t',
        '--toggle-visibility',
        dest='show_hide',
        action='store_true',
        default=False,
        help=_('Toggles the visibility of the terminal window')
    )

    parser.add_option(
        '--show',
        dest="show",
        action='store_true',
        default=False,
        help=_('Shows Guake main window')
    )

    parser.add_option(
        '--hide',
        dest='hide',
        action='store_true',
        default=False,
        help=_('Hides Guake main window')
    )

    parser.add_option(
        '-p',
        '--preferences',
        dest='show_preferences',
        action='store_true',
        default=False,
        help=_('Shows Guake preference window')
    )

    parser.add_option(
        '-a',
        '--about',
        dest='show_about',
        action='store_true',
        default=False,
        help=_('Shows Guake\'s about info')
    )

    parser.add_option(
        '-n',
        '--new-tab',
        dest='new_tab',
        action='store',
        default='',
        help=_('Add a new tab (with current directory set to NEW_TAB)')
    )

    parser.add_option(
        '-s',
        '--select-tab',
        dest='select_tab',
        action='store',
        default='',
        help=_('Select a tab (SELECT_TAB is the index of the tab)')
    )

    parser.add_option(
        '-g',
        '--selected-tab',
        dest='selected_tab',
        action='store_true',
        default=False,
        help=_('Return the selected tab index.')
    )

    parser.add_option(
        '-l',
        '--selected-tablabel',
        dest='selected_tablabel',
        action='store_true',
        default=False,
        help=_('Return the selected tab label.')
    )

    parser.add_option(
        '--split-vertical',
        dest='split_vertical',
        action='store_true',
        default=False,
        help=_('Split the selected tab vertically.')
    )

    parser.add_option(
        '--split-horizontal',
        dest='split_horizontal',
        action='store_true',
        default=False,
        help=_('Split the selected tab horizontally.')
    )

    parser.add_option(
        '-e',
        '--execute-command',
        dest='command',
        action='store',
        default='',
        help=_('Execute an arbitrary command in the selected tab.')
    )

    parser.add_option(
        '-i',
        '--tab-index',
        dest='tab_index',
        action='store',
        default='0',
        help=_('Specify the tab to rename. Default is 0. Can be used to select tab by UUID.')
    )

    parser.add_option(
        '--bgcolor',
        dest='bgcolor',
        action='store',
        default='',
        help=_('Set the hexadecimal (#rrggbb) background color of '
               'the selected tab.')
    )

    parser.add_option(
        '--fgcolor',
        dest='fgcolor',
        action='store',
        default='',
        help=_('Set the hexadecimal (#rrggbb) foreground color of the '
               'selected tab.')
    )

    parser.add_option(
        '--change-palette',
        dest='palette_name',
        action='store',
        default='',
        help=_('Change Guake palette scheme')
    )

    parser.add_option(
        '--rename-tab',
        dest='rename_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_(
            'Rename the specified tab by --tab-index. Reset to default if TITLE is '
            'a single dash "-".'
        )
    )

    parser.add_option(
        '-r',
        '--rename-current-tab',
        dest='rename_current_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_('Rename the current tab. Reset to default if TITLE is a '
               'single dash "-".')
    )

    parser.add_option(
        '-q',
        '--quit',
        dest='quit',
        action='store_true',
        default=False,
        help=_('Says to Guake go away =(')
    )

    parser.add_option(
        '-u',
        '--no-startup-script',
        dest='execute_startup_script',
        action='store_false',
        default=True,
        help=_('Do not execute the start up script')
    )

    parser.add_option(
        '--save-preferences',
        dest='save_preferences',
        action='store',
        default=None,
        help=_('Save Guake preferences to this filename')
    )

    parser.add_option(
        '--restore-preferences',
        dest='restore_preferences',
        action='store',
        default=None,
        help=_('Restore Guake preferences from this file')
    )

    parser.add_option(
        '--support',
        dest='support',
        action='store_true',
        default=False,
        help=_('Show support infomations')
    )

    # checking mandatory dependencies
    import gi

    try:
        gi.require_version('Gtk', '3.0')
        gi.require_version('Gdk', '3.0')
    except ValueError:
        print("[ERROR] Unable to start Guake, missing mandatory dependency: GtK 3.0")
        sys.exit(1)

    try:
        gi.require_version('Vte', '2.91')  # vte-0.42
    except ValueError:
        print("[ERROR] Unable to start Guake, missing mandatory dependency: Vte >= 0.42")
        sys.exit(1)

    try:
        gi.require_version('Keybinder', '3.0')
    except ValueError:
        print("[ERROR] Unable to start Guake, missing mandatory dependency: Keybinder 3")
        sys.exit(1)

    options = parser.parse_args()[0]
    if options.version:
        from guake import gtk_version
        from guake import guake_version
        from guake import vte_version
        from guake import vte_runtime_version
        print('Guake Terminal: {}'.format(guake_version()))
        print('VTE: {}'.format(vte_version()))
        print('VTE runtime: {}'.format(vte_runtime_version()))
        print('Gtk: {}'.format(gtk_version()))
        sys.exit(0)

    if options.save_preferences and options.restore_preferences:
        parser.error('options --save-preferences and --restore-preferences are mutually exclusive')
    if options.save_preferences:
        save_preferences(options.save_preferences)
        sys.exit(0)
    elif options.restore_preferences:
        restore_preferences(options.restore_preferences)
        sys.exit(0)

    if options.support:
        print_support()
        sys.exit(0)

    import dbus

    from guake.dbusiface import DBUS_NAME
    from guake.dbusiface import DBUS_PATH
    from guake.dbusiface import DbusManager
    from guake.guake_logging import setupLogging

    instance = None

    # Trying to get an already running instance of guake. If it is not
    # possible, lets create a new instance. This function will return
    # a boolean value depending on this decision.
    try:
        bus = dbus.SessionBus()
        remote_object = bus.get_object(DBUS_NAME, DBUS_PATH)
        already_running = True
    except dbus.DBusException:
        # can now configure the logging
        setupLogging(options.verbose)

        # COLORTERM is an environment variable set by some terminal emulators such as
        # gnome-terminal.
        # To avoid confusing applications running inside Guake, clean up COLORTERM at startup.
        if "COLORTERM" in os.environ:
            del os.environ['COLORTERM']

        log.info("Guake not running, starting it")
        # late loading of the Guake object, to speed up dbus comm
        from guake.guake_app import Guake
        instance = Guake()
        remote_object = DbusManager(instance)
        already_running = False

    only_show_hide = True

    if options.fullscreen:
        remote_object.fullscreen()

    if options.show:
        remote_object.show_from_remote()

    if options.hide:
        remote_object.hide_from_remote()

    if options.show_preferences:
        remote_object.show_prefs()
        only_show_hide = options.show

    if options.new_tab:
        remote_object.add_tab(options.new_tab)
        only_show_hide = options.show

    if options.select_tab:
        selected = int(options.select_tab)
        tab_count = int(remote_object.get_tab_count())
        if 0 <= selected < tab_count:
            remote_object.select_tab(selected)
        else:
            sys.stderr.write('invalid index: %d\n' % selected)
        only_show_hide = options.show

    if options.selected_tab:
        selected = remote_object.get_selected_tab()
        sys.stdout.write('%d\n' % selected)
        only_show_hide = options.show

    if options.selected_tablabel:
        selectedlabel = remote_object.get_selected_tablabel()
        sys.stdout.write('%s\n' % selectedlabel)
        only_show_hide = options.show

    if options.split_vertical:
        remote_object.v_split_current_terminal()
        only_show_hide = options.show

    if options.split_horizontal:
        remote_object.h_split_current_terminal()
        only_show_hide = options.show

    if options.command:
        remote_object.execute_command(options.command)
        only_show_hide = options.show

    if options.tab_index and options.rename_tab:
        try:
            remote_object.rename_tab_uuid(str(uuid.UUID(options.tab_index)), options.rename_tab)
        except ValueError:
            remote_object.rename_tab(int(options.tab_index), options.rename_tab)
        only_show_hide = options.show

    if options.bgcolor:
        remote_object.set_bgcolor(options.bgcolor)
        only_show_hide = options.show

    if options.fgcolor:
        remote_object.set_fgcolor(options.fgcolor)
        only_show_hide = options.show

    if options.palette_name:
        remote_object.change_palette_name(options.palette_name)
        only_show_hide = options.show

    if options.rename_current_tab:
        remote_object.rename_current_tab(options.rename_current_tab)
        only_show_hide = options.show

    if options.show_about:
        remote_object.show_about()
        only_show_hide = options.show

    if options.quit:
        try:
            remote_object.quit()
            return True
        except dbus.DBusException:
            return True

    if already_running and only_show_hide:
        # here we know that guake was called without any parameter and
        # it is already running, so, lets toggle its visibility.
        remote_object.show_hide()

    if options.execute_startup_script:
        if not already_running:
            startup_script = instance.settings.general.get_string("startup-script")
            if startup_script:
                log.info("Calling startup script: %s", startup_script)
                pid = subprocess.Popen([startup_script],
                                       shell=True,
                                       stdin=None,
                                       stdout=None,
                                       stderr=None,
                                       close_fds=True)
                log.info("Startup script started with pid: %s", pid)
                # Please ensure this is the last line !!!!
    else:
        log.info("--no-startup-script argument defined, so don't execute the startup script")
    if already_running:
        log.info("Guake is already running")
    return already_running
Example #11
0
File: main.py Project: Arwez/guake
def main():
    """Parses the command line parameters and decide if dbus methods
    should be called or not. If there is already a guake instance
    running it will be used and a True value will be returned,
    otherwise, false will be returned.
    """
    # Force to xterm-256 colors for compatibility with some old command line programs
    os.environ["TERM"] = "xterm-256color"

    # Force use X11 backend underwayland
    os.environ["GDK_BACKEND"] = "x11"

    # do not use version keywords here, pbr might be slow to find the version of Guake module
    parser = OptionParser()
    parser.add_option(
        "-V",
        "--version",
        dest="version",
        action="store_true",
        default=False,
        help=_("Show Guake version number and exit"),
    )

    parser.add_option(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help=_("Enable verbose logging"),
    )

    parser.add_option(
        "-f",
        "--fullscreen",
        dest="fullscreen",
        action="store_true",
        default=False,
        help=_("Put Guake in fullscreen mode"),
    )

    parser.add_option(
        "--unfullscreen",
        dest="unfullscreen",
        action="store_true",
        default=False,
        help=_("Put Guake out from fullscreen mode"),
    )

    parser.add_option(
        "-t",
        "--toggle-visibility",
        dest="show_hide",
        action="store_true",
        default=False,
        help=_("Toggles the visibility of the terminal window"),
    )

    parser.add_option(
        "--show",
        dest="show",
        action="store_true",
        default=False,
        help=_("Shows Guake main window"),
    )

    parser.add_option(
        "--hide",
        dest="hide",
        action="store_true",
        default=False,
        help=_("Hides Guake main window"),
    )

    parser.add_option(
        "-p",
        "--preferences",
        dest="show_preferences",
        action="store_true",
        default=False,
        help=_("Shows Guake preference window"),
    )

    parser.add_option(
        "-a",
        "--about",
        dest="show_about",
        action="store_true",
        default=False,
        help=_("Shows Guake's about info"),
    )

    parser.add_option(
        "-n",
        "--new-tab",
        dest="new_tab",
        action="store",
        default="",
        help=_("Add a new tab (with current directory set to NEW_TAB)"),
    )

    parser.add_option(
        "-s",
        "--select-tab",
        dest="select_tab",
        action="store",
        default="",
        help=_("Select a tab (SELECT_TAB is the index of the tab)"),
    )

    parser.add_option(
        "-w",
        "--select-tab-label",
        dest="select_tab_label",
        action="store",
        default="",
        help=
        _("Select a tab (SELECT_TAB_LABEL is the case-sensitive label of the tab)"
          ),
    )

    parser.add_option(
        "-g",
        "--selected-tab",
        dest="selected_tab",
        action="store_true",
        default=False,
        help=_("Return the selected tab index."),
    )

    parser.add_option(
        "-l",
        "--selected-tablabel",
        dest="selected_tablabel",
        action="store_true",
        default=False,
        help=_("Return the selected tab label."),
    )

    parser.add_option(
        "-S",
        "--select-terminal",
        dest="select_terminal",
        metavar="TERMINAL_INDEX",
        action="store",
        default="",
        help=
        _("Select a specific terminal in a split tab. " +
          "Only useful with split terminals (TERMINAL_INDEX is the index of the tab)"
          ),
    )

    parser.add_option(
        "--selected-terminal",
        dest="selected_terminal",
        action="store_true",
        default=False,
        help=_("Return the selected terminal index."),
    )

    parser.add_option(
        "--split-vertical",
        dest="split_vertical",
        action="store_true",
        default=False,
        help=_("Split the selected tab vertically."),
    )

    parser.add_option(
        "--split-horizontal",
        dest="split_horizontal",
        action="store_true",
        default=False,
        help=_("Split the selected tab horizontally."),
    )

    parser.add_option(
        "-e",
        "--execute-command",
        dest="command",
        action="store",
        default="",
        help=_("Execute an arbitrary command in the selected tab."),
    )

    parser.add_option(
        "-i",
        "--tab-index",
        dest="tab_index",
        action="store",
        default="0",
        help=
        _("Specify the tab to rename. Default is 0. Can be used to select tab by UUID."
          ),
    )

    parser.add_option(
        "--bgcolor",
        dest="bgcolor",
        action="store",
        default="",
        help=_("Set the hexadecimal (#rrggbb) background color of "
               "the selected tab."),
    )

    parser.add_option(
        "--fgcolor",
        dest="fgcolor",
        action="store",
        default="",
        help=_("Set the hexadecimal (#rrggbb) foreground color of the "
               "selected tab."),
    )

    parser.add_option(
        "--bgcolor-current",
        dest="bgcolor_current",
        action="store",
        default="",
        help=_("Set the hexadecimal (#rrggbb) background color of "
               "the current terminal."),
    )

    parser.add_option(
        "--fgcolor-current",
        dest="fgcolor_current",
        action="store",
        default="",
        help=_("Set the hexadecimal (#rrggbb) foreground color of "
               "the current terminal."),
    )

    parser.add_option(
        "--change-palette",
        dest="palette_name",
        action="store",
        default="",
        help=_("Change Guake palette scheme"),
    )

    parser.add_option(
        "--reset-colors",
        dest="reset_colors",
        action="store_true",
        default=False,
        help=_("Set colors from settings."),
    )

    parser.add_option(
        "--reset-colors-current",
        dest="reset_colors_current",
        action="store_true",
        default=False,
        help=_("Set colors of the current terminal from settings."),
    )

    parser.add_option(
        "--rename-tab",
        dest="rename_tab",
        metavar="TITLE",
        action="store",
        default="",
        help=_(
            "Rename the specified tab by --tab-index. Reset to default if TITLE is "
            'a single dash "-".'),
    )

    parser.add_option(
        "-r",
        "--rename-current-tab",
        dest="rename_current_tab",
        metavar="TITLE",
        action="store",
        default="",
        help=_("Rename the current tab. Reset to default if TITLE is a "
               'single dash "-".'),
    )

    parser.add_option(
        "-q",
        "--quit",
        dest="quit",
        action="store_true",
        default=False,
        help=_("Says to Guake go away =("),
    )

    parser.add_option(
        "-u",
        "--no-startup-script",
        dest="execute_startup_script",
        action="store_false",
        default=True,
        help=_("Do not execute the start up script"),
    )

    parser.add_option(
        "--save-preferences",
        dest="save_preferences",
        action="store",
        default=None,
        help=_("Save Guake preferences to this filename"),
    )

    parser.add_option(
        "--restore-preferences",
        dest="restore_preferences",
        action="store",
        default=None,
        help=_("Restore Guake preferences from this file"),
    )

    parser.add_option(
        "--support",
        dest="support",
        action="store_true",
        default=False,
        help=_("Show support infomation"),
    )

    # checking mandatory dependencies

    missing_deps = False
    try:
        import gi

        gi.require_version("Gtk", "3.0")
        gi.require_version("Gdk", "3.0")
    except ValueError:
        print("[ERROR] missing mandatory dependency: GtK 3.0")
        missing_deps = True

    try:
        gi.require_version("Vte", "2.91")  # vte-0.42
    except ValueError:
        print("[ERROR] missing mandatory dependency: Vte >= 0.42")
        missing_deps = True

    try:
        gi.require_version("Keybinder", "3.0")
    except ValueError:
        print("[ERROR] missing mandatory dependency: Keybinder 3")
        missing_deps = True

    try:
        import cairo
    except ImportError:
        print("[ERROR] missing mandatory dependency: cairo")
        missing_deps = True

    if missing_deps:
        print("[ERROR] missing at least one system dependencies. "
              "You need to install additional packages for Guake to run")
        print(
            "[ERROR] On Debian/Ubuntu you need to install the following libraries:\n"
            "    sudo apt-get install -y --no-install-recommends \\\n"
            "        gir1.2-keybinder-3.0 \\\n"
            "        gir1.2-notify-0.7 \\\n"
            "        gir1.2-vte-2.91 \\\n"
            "        gir1.2-wnck-3.0 \\\n"
            "        libkeybinder-3.0-0 \\\n"
            "        libutempter0 \\\n"
            "        python3 \\\n"
            "        python3-cairo \\\n"
            "        python3-dbus \\\n"
            "        python3-gi \\\n"
            "        python3-pbr \\\n"
            "        python3-pip")
        sys.exit(1)

    options = parser.parse_args()[0]
    if options.version:
        from guake import gtk_version
        from guake import guake_version
        from guake import vte_version
        from guake import vte_runtime_version

        print("Guake Terminal: {}".format(guake_version()))
        print("VTE: {}".format(vte_version()))
        print("VTE runtime: {}".format(vte_runtime_version()))
        print("Gtk: {}".format(gtk_version()))
        sys.exit(0)

    if options.save_preferences and options.restore_preferences:
        parser.error(
            "options --save-preferences and --restore-preferences are mutually exclusive"
        )
    if options.save_preferences:
        save_preferences(options.save_preferences)
        sys.exit(0)
    elif options.restore_preferences:
        restore_preferences(options.restore_preferences)
        sys.exit(0)

    if options.support:
        print_support()
        sys.exit(0)

    import dbus

    from guake.dbusiface import DBUS_NAME
    from guake.dbusiface import DBUS_PATH
    from guake.dbusiface import DbusManager
    from guake.guake_logging import setupLogging

    instance = None

    # Trying to get an already running instance of guake. If it is not
    # possible, lets create a new instance. This function will return
    # a boolean value depending on this decision.
    try:
        bus = dbus.SessionBus()
        remote_object = bus.get_object(DBUS_NAME, DBUS_PATH)
        already_running = True
    except dbus.DBusException:
        # can now configure the logging
        setupLogging(options.verbose)

        # COLORTERM is an environment variable set by some terminal emulators such as
        # gnome-terminal.
        # To avoid confusing applications running inside Guake, clean up COLORTERM at startup.
        if "COLORTERM" in os.environ:
            del os.environ["COLORTERM"]

        log.info("Guake not running, starting it")
        # late loading of the Guake object, to speed up dbus comm
        from guake.guake_app import Guake

        instance = Guake()
        remote_object = DbusManager(instance)
        already_running = False

    only_show_hide = True

    if options.fullscreen:
        remote_object.fullscreen()

    if options.unfullscreen:
        remote_object.unfullscreen()

    if options.show:
        remote_object.show_from_remote()

    if options.hide:
        remote_object.hide_from_remote()

    if options.show_preferences:
        remote_object.show_prefs()
        only_show_hide = options.show

    if options.new_tab:
        remote_object.add_tab(options.new_tab)
        only_show_hide = options.show

    if options.select_tab:
        selected = int(options.select_tab)
        tab_count = int(remote_object.get_tab_count())
        if 0 <= selected < tab_count:
            remote_object.select_tab(selected)
        else:
            sys.stderr.write("invalid index: %d\n" % selected)
        only_show_hide = options.show

    if options.select_tab_label:
        tab_label = str(options.select_tab_label)
        if not tab_label:
            sys.stderr.write("no label was provided!\n")
        else:
            if not remote_object.select_tab_label(tab_label):
                sys.stderr.write("Could not find tab with label \"" +
                                 tab_label + "\"\n")
        only_show_hide = options.show

    if options.selected_tab:
        selected = remote_object.get_selected_tab()
        sys.stdout.write("%d\n" % selected)
        only_show_hide = options.show

    if options.selected_tablabel:
        selectedlabel = remote_object.get_selected_tablabel()
        sys.stdout.write("%s\n" % selectedlabel)
        only_show_hide = options.show

    if options.split_vertical:
        remote_object.v_split_current_terminal()
        only_show_hide = options.show

    if options.split_horizontal:
        remote_object.h_split_current_terminal()
        only_show_hide = options.show

    if options.selected_terminal:
        selected = remote_object.get_selected_terminal()
        sys.stdout.write("%d\n" % selected)
        only_show_hide = options.show

    if options.select_terminal:
        selected = int(options.select_terminal)
        term_count = int(remote_object.get_term_count())
        if 0 <= selected < term_count:
            remote_object.select_terminal(selected)
        else:
            sys.stderr.write("invalid index: %d\n" % selected)
        only_show_hide = options.show

    if options.command:
        remote_object.execute_command(options.command)
        only_show_hide = options.show

    if options.tab_index and options.rename_tab:
        try:
            remote_object.rename_tab_uuid(str(uuid.UUID(options.tab_index)),
                                          options.rename_tab)
        except ValueError:
            remote_object.rename_tab(int(options.tab_index),
                                     options.rename_tab)
        only_show_hide = options.show

    if options.bgcolor:
        remote_object.set_bgcolor(options.bgcolor)
        only_show_hide = options.show

    if options.fgcolor:
        remote_object.set_fgcolor(options.fgcolor)
        only_show_hide = options.show

    if options.bgcolor_current:
        remote_object.set_bgcolor_current_terminal(options.bgcolor_current)
        only_show_hide = options.show

    if options.fgcolor_current:
        remote_object.set_fgcolor_current_terminal(options.fgcolor_current)
        only_show_hide = options.show

    if options.palette_name:
        remote_object.change_palette_name(options.palette_name)
        only_show_hide = options.show

    if options.reset_colors:
        remote_object.reset_colors()
        only_show_hide = options.show

    if options.reset_colors_current:
        remote_object.reset_colors_current()
        only_show_hide = options.show

    if options.rename_current_tab:
        remote_object.rename_current_tab(options.rename_current_tab)
        only_show_hide = options.show

    if options.show_about:
        remote_object.show_about()
        only_show_hide = options.show

    if options.quit:
        try:
            remote_object.quit()
            return True
        except dbus.DBusException:
            return True

    if already_running and only_show_hide:
        # here we know that guake was called without any parameter and
        # it is already running, so, lets toggle its visibility.
        remote_object.show_hide()

    if options.execute_startup_script:
        if not already_running:
            startup_script = instance.settings.general.get_string(
                "startup-script")
            if startup_script:
                log.info("Calling startup script: %s", startup_script)
                pid = subprocess.Popen(
                    [startup_script],
                    shell=True,
                    stdin=None,
                    stdout=None,
                    stderr=None,
                    close_fds=True,
                )
                log.info("Startup script started with pid: %s", pid)
                # Please ensure this is the last line !!!!
    else:
        log.info(
            "--no-startup-script argument defined, so don't execute the startup script"
        )
    if already_running:
        log.info("Guake is already running")
    return already_running
Example #12
0
def main():
    """Parses the command line parameters and decide if dbus methods
    should be called or not. If there is already a guake instance
    running it will be used and a True value will be returned,
    otherwise, false will be returned.
    """
    # Force to xterm-256 colors for compatibility with some old command line programs
    os.environ["TERM"] = "xterm-256color"

    # do not use version keywords here, pbr might be slow to find the version of Guake module
    parser = OptionParser()
    parser.add_option(
        '-v',
        '--version',
        dest='version',
        action='store_true',
        default=False,
        help=_('Show Guake version number and exit')
    )
    parser.add_option(
        '-f',
        '--fullscreen',
        dest='fullscreen',
        action='store_true',
        default=False,
        help=_('Put Guake in fullscreen mode')
    )

    parser.add_option(
        '-t',
        '--toggle-visibility',
        dest='show_hide',
        action='store_true',
        default=False,
        help=_('Toggles the visibility of the terminal window')
    )

    parser.add_option(
        '--show',
        dest="show",
        action='store_true',
        default=False,
        help=_('Shows Guake main window')
    )

    parser.add_option(
        '--hide',
        dest='hide',
        action='store_true',
        default=False,
        help=_('Hides Guake main window')
    )

    parser.add_option(
        '-p',
        '--preferences',
        dest='show_preferences',
        action='store_true',
        default=False,
        help=_('Shows Guake preference window')
    )

    parser.add_option(
        '-a',
        '--about',
        dest='show_about',
        action='store_true',
        default=False,
        help=_('Shows Guake\'s about info')
    )

    parser.add_option(
        '-n',
        '--new-tab',
        dest='new_tab',
        action='store',
        default='',
        help=_('Add a new tab (with current directory set to NEW_TAB)')
    )

    parser.add_option(
        '-s',
        '--select-tab',
        dest='select_tab',
        action='store',
        default='',
        help=_('Select a tab (SELECT_TAB is the index of the tab)')
    )

    parser.add_option(
        '-g',
        '--selected-tab',
        dest='selected_tab',
        action='store_true',
        default=False,
        help=_('Return the selected tab index.')
    )

    parser.add_option(
        '-l',
        '--selected-tablabel',
        dest='selected_tablabel',
        action='store_true',
        default=False,
        help=_('Return the selected tab label.')
    )

    parser.add_option(
        '-e',
        '--execute-command',
        dest='command',
        action='store',
        default='',
        help=_('Execute an arbitrary command in the selected tab.')
    )

    parser.add_option(
        '-i',
        '--tab-index',
        dest='tab_index',
        action='store',
        default='0',
        help=_('Specify the tab to rename. Default is 0.')
    )

    parser.add_option(
        '--bgcolor',
        dest='bgcolor',
        action='store',
        default='',
        help=_('Set the hexadecimal (#rrggbb) background color of '
               'the selected tab.')
    )

    parser.add_option(
        '--fgcolor',
        dest='fgcolor',
        action='store',
        default='',
        help=_('Set the hexadecimal (#rrggbb) foreground color of the '
               'selected tab.')
    )

    parser.add_option(
        '--rename-tab',
        dest='rename_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_('Rename the specified tab. Reset to default if TITLE is '
               'a single dash "-".')
    )

    parser.add_option(
        '-r',
        '--rename-current-tab',
        dest='rename_current_tab',
        metavar='TITLE',
        action='store',
        default='',
        help=_('Rename the current tab. Reset to default if TITLE is a '
               'single dash "-".')
    )

    parser.add_option(
        '-q',
        '--quit',
        dest='quit',
        action='store_true',
        default=False,
        help=_('Says to Guake go away =(')
    )

    parser.add_option(
        '-u',
        '--no-startup-script',
        dest='execute_startup_script',
        action='store_false',
        default=True,
        help=_('Do not execute the start up script')
    )

    options = parser.parse_args()[0]
    if options.version:
        print('Guake Terminal %s' % guake_version())
        sys.exit(0)

    instance = None

    # Trying to get an already running instance of guake. If it is not
    # possible, lets create a new instance. This function will return
    # a boolean value depending on this decision.
    try:
        bus = dbus.SessionBus()
        remote_object = bus.get_object(DBUS_NAME, DBUS_PATH)
        already_running = True
    except dbus.DBusException:
        # can now configure the logging
        setupLogging(True)

        # COLORTERM is an environment variable set by some terminal emulators such as
        # gnome-terminal.
        # To avoid confusing applications running inside Guake, clean up COLORTERM at startup.
        if "COLORTERM" in os.environ:
            del os.environ['COLORTERM']

        log.info("DBus not running, starting it")
        # late loading of the Guake object, to speed up dbus comm
        from guake.guake_app import Guake
        instance = Guake()
        remote_object = DbusManager(instance)
        already_running = False

    only_show_hide = True

    if options.fullscreen:
        remote_object.fullscreen()

    if options.show:
        remote_object.show_from_remote()

    if options.hide:
        remote_object.hide_from_remote()

    if options.show_preferences:
        remote_object.show_prefs()
        only_show_hide = False

    if options.new_tab:
        remote_object.add_tab(options.new_tab)
        only_show_hide = False

    if options.select_tab:
        selected = int(options.select_tab)
        i = remote_object.select_tab(selected)
        if i is None:
            sys.stdout.write('invalid index: %d\n' % selected)
        only_show_hide = False

    if options.selected_tab:
        selected = remote_object.get_selected_tab()
        sys.stdout.write('%d\n' % selected)
        only_show_hide = False

    if options.selected_tablabel:
        selectedlabel = remote_object.get_selected_tablabel()
        sys.stdout.write('%s\n' % selectedlabel)
        only_show_hide = False

    if options.command:
        remote_object.execute_command(options.command)
        only_show_hide = False

    if options.tab_index and options.rename_tab:
        try:
            remote_object.rename_tab_uuid(str(uuid.UUID(options.tab_index)), options.rename_tab)
        except ValueError:
            remote_object.rename_tab(int(options.tab_index), options.rename_tab)
        only_show_hide = False

    if options.bgcolor:
        remote_object.set_bgcolor(options.bgcolor)
        only_show_hide = False

    if options.fgcolor:
        remote_object.set_fgcolor(options.fgcolor)
        only_show_hide = False

    if options.rename_current_tab:
        remote_object.rename_current_tab(options.rename_current_tab)
        only_show_hide = False

    if options.show_about:
        remote_object.show_about()
        only_show_hide = False

    if options.quit:
        try:
            remote_object.quit()
            return True
        except dbus.DBusException:
            return True

    if already_running and only_show_hide:
        # here we know that guake was called without any parameter and
        # it is already running, so, lets toggle its visibility.
        remote_object.show_hide()

    if options.execute_startup_script:
        if not already_running:
            startup_script = instance.settings.general.get_string("startup-script")
            if startup_script:
                log.info("Calling startup script: %s", startup_script)
                pid = subprocess.Popen([startup_script],
                                       shell=True,
                                       stdin=None,
                                       stdout=None,
                                       stderr=None,
                                       close_fds=True)
                log.info("Startup script started with pid: %s", pid)
                # Please ensure this is the last line !!!!
    else:
        log.info("--no-startup-script argument defined, so don't execute the startup script")
    if already_running:
        log.info("Guake is already running")
    return already_running
Example #13
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")