Exemplo n.º 1
0
    def __init__(self):
        super(Guake, self).__init__(common.gladefile('guake.glade'))
        self.client = gconf.client_get_default()

        # default option in case of gconf fails:
        self.use_bgimage = False

        # setting global hotkey!
        globalhotkeys.init()
        key = self.client.get_string(GHOTKEYS[0][0])
        globalhotkeys.bind(key, self.show_hide)

        # trayicon!
        tray_icon = GuakeStatusIcon()
        tray_icon.connect('popup-menu', self.show_menu)
        tray_icon.connect('activate', self.show_hide)
        tray_icon.show_all()

        # adding images from a different path.
        ipath = common.pixmapfile('new_guakelogo.png')
        self.get_widget('image1').set_from_file(ipath)
        ipath = common.pixmapfile('add_tab.png')
        self.get_widget('image2').set_from_file(ipath)

        self.window = self.get_widget('window-root')
        self.notebook = self.get_widget('notebook-teminals')
        self.toolbar = self.get_widget('toolbar')
        self.mainframe = self.get_widget('mainframe')

        self.accel_group = gtk.AccelGroup()
        self.last_pos = -1
        self.term_list = []
        self.animation_speed = 30
        self.visible = False

        self.window.add_accel_group(self.accel_group)
        self.window.set_keep_above(True)
        self.window.set_geometry_hints(min_width=1, min_height=1)
        self.window.connect('focus-out-event', self.on_window_lostfocus)

        self.load_config()
        self.load_accelerators()
        self.refresh()
        self.add_tab()
Exemplo n.º 2
0
~~~~~~~~~~~~~~~~~~~~~~~
This script is a simple test that initializes globalhotkeys machinery and
bindings a key to a simple function. So after running this program, you shoud
se a message 'great =D' or 'bad =('. If every thing goes right, when you press
the F12 key, you should see ('F12',) on your terminal otherwise, you will see a
warning saying that binding has failed.

A really important thing is that globalhotkeys.bind returns boolean values, so
if you want to know if binding works properly, only test this with a simple if.

A cool test
~~~~~~~~~~~
if you want to test your program when it shoud say to the user that the binding
failed, you can simply use this program to bind the key that you're running.
Because you can bind a key once.
"""
import gtk
import globalhotkeys

def hammer(*args):
    print args

globalhotkeys.init()
binded = globalhotkeys.bind('F12', hammer)
if binded:
    print 'great =D'
else:
    print 'bad =('

gtk.main()
Exemplo n.º 3
0
bindings a key to a simple function. So after running this program, you shoud
se a message 'great =D' or 'bad =('. If every thing goes right, when you press
the F12 key, you should see ('F12',) on your terminal otherwise, you will see a
warning saying that binding has failed.

A really important thing is that globalhotkeys.bind returns boolean values, so
if you want to know if binding works properly, only test this with a simple if.

A cool test
~~~~~~~~~~~
if you want to test your program when it shoud say to the user that the binding
failed, you can simply use this program to bind the key that you're running.
Because you can bind a key once.
"""
import globalhotkeys
import gtk


def hammer(*args):
    print args


globalhotkeys.init()
binded = globalhotkeys.GlobalHotkey().bind('F12', hammer)
if binded:
    print 'great =D'
else:
    print 'bad =('

gtk.main()
Exemplo n.º 4
0
    def __init__(self):
        super(Guake, self).__init__(gladefile("guake.glade"))
        self.client = gconf.client_get_default()

        # setting global hotkey and showing a pretty notification =)
        globalhotkeys.init()

        # trayicon!
        img = pixmapfile("guake-tray.png")
        self.tray_icon = gtk.status_icon_new_from_file(img)
        self.tray_icon.set_tooltip(_("Guake Terminal"))
        self.tray_icon.connect("popup-menu", self.show_menu)
        self.tray_icon.connect("activate", self.show_hide)

        # adding images from a different path.
        ipath = pixmapfile("guake.png")
        self.get_widget("image1").set_from_file(ipath)
        ipath = pixmapfile("add_tab.png")
        self.get_widget("image2").set_from_file(ipath)

        # important widgets
        self.window = self.get_widget("window-root")
        self.notebook = self.get_widget("notebook-teminals")
        self.tabs = self.get_widget("hbox-tabs")
        self.toolbar = self.get_widget("toolbar")
        self.mainframe = self.get_widget("mainframe")
        self.resizer = self.get_widget("resizer")

        # check and set ARGB for real transparency
        screen = self.window.get_screen()
        colormap = screen.get_rgba_colormap()
        if colormap != None and screen.is_composited():
            self.window.set_colormap(colormap)
            self.has_argb = True
        else:
            self.has_argb = False

        # List of vte.Terminal widgets, it will be useful when needed
        # to get a widget by the current page in self.notebook
        self.term_list = []

        # This is the pid of shells forked by each terminal. Will be
        # used to kill the process when closing a tab
        self.pid_list = []

        # It's intended to know which tab was selected to
        # close/rename. This attribute will be set in
        # self.show_tab_menu
        self.selected_tab = None

        # holds the number of created tabs. This counter will not be
        # reset to avoid problems of repeated tab names.
        self.tab_counter = 0

        # holds fullscreen status
        self.fullscreen = False

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

        # double click stuff
        def double_click(hbox, event):
            """Handles double clicks on tabs area and when receive
            one, calls add_tab.
            """
            if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
                self.add_tab()

        evtbox = self.get_widget("event-tabs")
        evtbox.connect("button-press-event", double_click)

        # Flag to prevent guake hide when window_losefocus is true and
        # user tries to use the context menu.
        self.showing_context_menu = False

        def hide_context_menu(menu):
            """Turn context menu flag off to make sure it is not being
            shown.
            """
            self.showing_context_menu = False

        self.get_widget("context-menu").connect("hide", hide_context_menu)
        self.get_widget("tab-menu").connect("hide", hide_context_menu)
        self.window.connect("focus-out-event", self.on_window_losefocus)

        # this line is important to resize the main window and make it
        # smaller.
        self.window.set_geometry_hints(min_width=1, min_height=1)

        # resizer stuff
        self.resizer.connect("motion-notify-event", self.on_resizer_drag)

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

        # loading and setting up configuration stuff
        GConfHandler(self)
        GConfKeyHandler(self)
        self.hotkeys = globalhotkeys.GlobalHotkey()
        self.load_config()

        key = self.client.get_string(GKEY("show_hide"))
        keyval, mask = gtk.accelerator_parse(key)
        label = gtk.accelerator_get_label(keyval, mask)
        filename = pixmapfile("guake-notification.png")

        if not self.hotkeys.bind(key, self.show_hide):
            notification = pynotify.Notification(
                _("Guake!"),
                _(
                    "A problem happened when binding <b>%s</b> key.\n"
                    "Please use Guake Preferences dialog to choose another "
                    "key (The trayicon was enabled)"
                )
                % label,
                filename,
            )
            self.client.set_bool(KEY("/general/use_trayicon"), True)
            notification.show()

        elif self.client.get_bool(KEY("/general/use_popup")):
            # Pop-up that shows that guake is working properly (if not
            # unset in the preferences windows)
            notification = pynotify.Notification(
                _("Guake!"), _("Guake is now running,\n" "press <b>%s</b> to use it.") % label, filename
            )
            notification.show()
Exemplo n.º 5
0
    def __init__(self):
        super(Guake, self).__init__(gladefile('guake.glade'))
        self.client = gconf.client_get_default()

        # setting global hotkey and showing a pretty notification =)
        globalhotkeys.init()

        # trayicon!
        img = pixmapfile('guake-tray.png')
        self.tray_icon = gtk.status_icon_new_from_file(img)
        self.tray_icon.set_tooltip(_('Guake-Terminal'))
        self.tray_icon.connect('popup-menu', self.show_menu)
        self.tray_icon.connect('activate', self.show_hide)

        # adding images from a different path.
        ipath = pixmapfile('guake.png')
        self.get_widget('image1').set_from_file(ipath)
        ipath = pixmapfile('add_tab.png')
        self.get_widget('image2').set_from_file(ipath)

        # important widgets
        self.window = self.get_widget('window-root')
        self.notebook = self.get_widget('notebook-teminals')
        self.tabs = self.get_widget('hbox-tabs')
        self.toolbar = self.get_widget('toolbar')
        self.mainframe = self.get_widget('mainframe')
        self.resizer = self.get_widget('resizer')

        # check and set ARGB for real transparency
        screen = self.window.get_screen()
        colormap = screen.get_rgba_colormap()
        if colormap != None and screen.is_composited():
            self.window.set_colormap(colormap)
            self.has_argb = True
        else:
            self.has_argb = False

        # List of vte.Terminal widgets, it will be useful when needed
        # to get a widget by the current page in self.notebook
        self.term_list = []

        # This is the pid of shells forked by each terminal. Will be
        # used to kill the process when closing a tab
        self.pid_list = []

        # It's intended to know which tab was selected to
        # close/rename. This attribute will be set in
        # self.show_tab_menu
        self.selected_tab = None

        # holds the number of created tabs. This counter will not be
        # reset to avoid problems of repeated tab names.
        self.tab_counter = 0

        # holds fullscreen status
        self.fullscreen = False

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

        # double click stuff
        def double_click(hbox, event):
            """Handles double clicks on tabs area and when receive
            one, calls add_tab.
            """
            if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
                self.add_tab()
        evtbox = self.get_widget('event-tabs')
        evtbox.connect('button-press-event', double_click)

        # Flag to prevent guake hide when window_losefocus is true and
        # user tries to use the context menu.
        self.showing_context_menu = False
        def hide_context_menu(menu):
            """Turn context menu flag off to make sure it is not being
            shown.
            """
            self.showing_context_menu = False
        self.get_widget('context-menu').connect('hide', hide_context_menu)
        self.get_widget('tab-menu').connect('hide', hide_context_menu)
        self.window.connect('focus-out-event', self.on_window_losefocus)

        # this line is important to resize the main window and make it
        # smaller.
        self.window.set_geometry_hints(min_width=1, min_height=1)

        # resizer stuff
        self.resizer.connect('motion-notify-event', self.on_resizer_drag)

        # loading and setting up configuration stuff
        GConfHandler(self)
        GConfKeyHandler(self)
        self.hotkeys = globalhotkeys.GlobalHotkey()
        self.load_config()

        key = self.client.get_string(GKEY('show_hide'))
        keyval, mask = gtk.accelerator_parse(key)
        self.notification_label = gtk.accelerator_get_label(keyval, mask)
        self.notification_pixmapfile = pixmapfile('guake-notification.png')

        if not self.hotkeys.bind(key, self.show_hide):
            self.show_notification('A problem happened when binding <b>%s</b> key.\n'
                  'Please use Guake Preferences dialog to choose another '
                  'key (The trayicon was enabled)')
            self.client.set_bool(KEY('/general/use_trayicon'), True)
            
        # add tabs remembered from last session
        try:
            guake_tabs = open(os.path.expanduser('~/.guake_tabs'), 'r')
            for line in guake_tabs:
                tname, tdir = line.rstrip('\n').split('\t')
                self.add_tab(tdir, tname)
            guake_tabs.close()
        except:
            # not there? not readable? add failed?
            pass
        
        if not self.term_list:
            self.add_tab()