def __init__(self, guake): """Constructor of Keyboard, only receives the guake instance to be used in internal methods. """ self.guake = guake self.accel_group = None # see reload_accelerators self.client = gconf.client_get_default() notify_add = self.client.notify_add # Setup global keys self.globalhotkeys = {} globalkeys = ['show_hide'] for key in globalkeys: notify_add(GKEY(key), self.reload_global) self.client.notify(GKEY(key)) # Setup local keys keys = [ 'toggle_fullscreen', 'new_tab', 'close_tab', 'rename_current_tab', 'previous_tab', 'next_tab', 'clipboard_copy', 'clipboard_paste', 'quit', 'zoom_in', 'zoom_out', 'increase_height', 'decrease_height', 'increase_transparency', 'decrease_transparency', 'toggle_transparency', "search_on_web", 'move_tab_left', 'move_tab_right', 'switch_tab1', 'switch_tab2', 'switch_tab3', 'switch_tab4', 'switch_tab5', 'switch_tab6', 'switch_tab7', 'switch_tab8', 'switch_tab9', 'switch_tab10', 'switch_tab_last', 'reset_terminal' ] for key in keys: notify_add(LKEY(key), self.reload_accelerators) self.client.notify(LKEY(key))
def __init__(self): super(Guake, self).__init__(gladefile('guake.glade')) self.client = gconf.client_get_default() # setting global hotkey and showing a pretty notification =) guake.globalhotkeys.init() # Cannot use "getattr(gtk.Window().get_style(), "base")[int(gtk.STATE_SELECTED)]" # since theme has not been applied before first show_all self.selected_color = None self.isPromptQuitDialogOpened = False self.hidden = True self.forceHide = False # trayicon! try: import appindicator except ImportError: 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) else: self.tray_icon = appindicator.Indicator( _("guake-indicator"), _("guake-tray"), appindicator.CATEGORY_OTHER) self.tray_icon.set_icon("guake-tray") 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) # 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.mainframe = self.get_widget('mainframe') self.mainframe.remove(self.get_widget('notebook-teminals')) self.notebook = GuakeNotebook() self.notebook.set_name("notebook-teminals") self.notebook.set_property("tab_pos", "bottom") self.notebook.set_property("show_tabs", False) self.notebook.set_property("show_border", False) self.notebook.set_property("visible", True) self.notebook.set_property("has_focus", True) self.notebook.set_property("can_focus", True) self.notebook.set_property("is_focus", True) self.notebook.set_property("enable_popup", True) self.notebook.connect("switch_page", self.select_current_tab) self.mainframe.add(self.notebook) self.set_tab_position() 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 is None: self.has_argb = False else: self.window.set_colormap(colormap) self.has_argb = self.window.get_screen().is_composited() def composited_changed(screen): self.has_argb = screen.is_composited() self.set_background_transparency( self.client.get_int(KEY('/style/background/transparency'))) self.set_background_image( self.client.get_string(KEY('/style/background/image'))) self.window.get_screen().connect("composited-changed", composited_changed) # 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 fullscreen status self.is_fullscreen = False # 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 # 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) # Handling the delete-event of the main window to avoid # problems when closing it. def destroy(*args): self.hide() return True self.window.connect('delete-event', destroy) # Flag to completely disable losefocus hiding self.disable_losefocus_hiding = False # this line is important to resize the main window and make it # smaller. 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(gtk.gdk.WINDOW_TYPE_HINT_DOCK) # Restore back to normal behavior self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL) # 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 = guake.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 self.client.get_bool(KEY('/general/start_fullscreen')): self.fullscreen() if not self.hotkeys.bind(key, self.show_hide): guake.notifier.show_message( _('Guake!'), _('A problem happened when binding <b>%s</b> key.\n' 'Please use Guake Preferences dialog to choose another ' 'key') % xml_escape(label), filename) self.client.set_bool(KEY('/general/use_trayicon'), True) 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) guake.notifier.show_message( _('Guake!'), _('Guake is now running,\n' 'press <b>%s</b> to use it.') % xml_escape(label), filename)
# Path to the shells file, it will be used to start to populate # interpreters combo, see the next variable, its important to fill the # rest of the combo too. SHELLS_FILE = '/etc/shells' # string to show in prefereces dialog for user shell option USER_SHELL_VALUE = _('<user shell>') # translating our types to vte types ERASE_BINDINGS = {'ASCII DEL': 'ascii-delete', 'Escape sequence': 'delete-sequence', 'Control-H': 'ascii-backspace'} HOTKEYS = [ {'label': 'General', 'keys': [{'key': GKEY('show_hide'), 'label': 'Toggle Guake visibility'}, {'key': LKEY('toggle_fullscreen'), 'label': 'Toggle Fullscreen'}, {'key': LKEY('toggle_hide_on_lose_focus'), 'label': 'Toggle Hide on Lose Focus'}, {'key': LKEY('quit'), 'label': 'Quit'}, {'key': LKEY('reset_terminal'), 'label': 'Reset terminal'}, ]}, {'label': 'Tab management', 'keys': [{'key': LKEY('new_tab'), 'label': 'New tab'}, {'key': LKEY('close_tab'),
USER_SHELL_VALUE = _('<user shell>') # translating our types to vte types ERASE_BINDINGS = { 'ASCII DEL': 'ascii-delete', 'Escape sequence': 'delete-sequence', 'Control-H': 'ascii-backspace' } HOTKEYS = [ { 'label': _('General'), 'keys': [ { 'key': GKEY('show_hide'), 'label': _('Toggle Guake visibility') }, { 'key': LKEY('toggle_fullscreen'), 'label': _('Toggle Fullscreen') }, { 'key': LKEY('toggle_hide_on_lose_focus'), 'label': _('Toggle Hide on Lose Focus') }, { 'key': LKEY('quit'), 'label': _('Quit') }, {