class TrayIcon: state = RecordingState.STOPPED current_screencast = None popup_menu = TrayPopupMenu() event_box = Screen().event_box def __init__(self): gtk.window_set_default_icon_name(gtk.STOCK_MEDIA_RECORD) self.tray_image = gtk.Image() self.tray_image.set_from_stock(gtk.STOCK_MEDIA_RECORD, gtk.ICON_SIZE_SMALL_TOOLBAR) self.event_box.add(self.tray_image) self.tooltips = gtk.Tooltips() self.tooltips.set_tip(self.event_box, _("Left click to start screencast. Right click for menu.")) self.tray_container = egg.trayicon.TrayIcon("istanbul") self.tray_container.add(self.event_box) self.event_box.connect("button-press-event", self._trayicon_clicked) self.tray_container.show_all() def _trayicon_clicked(self, widget, event): """ left click triggers record/stop right click shows popup menu """ if event.button == 1: if self.state == RecordingState.STOPPED: self.tray_image.set_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_SMALL_TOOLBAR) self.tooltips.set_tip(self.event_box, _("Left click to stop recording screencast.")) self.state = RecordingState.RECORDING self.current_screencast = Screencast(self.stop_handler) self.current_screencast.selector = self.popup_menu.selector self.current_screencast.start_recording() elif self.state == RecordingState.RECORDING: self.tray_image.set_from_stock(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_SMALL_TOOLBAR) self.state = RecordingState.SAVING self.tooltips.set_tip(self.event_box, _("In process of saving to disk.")) self.current_screencast.stop_recording() # only show popup if in idle state elif event.button == 3 and self.state == RecordingState.STOPPED: self.popup_menu.show() def stop_handler(self, event): self.tray_image.set_from_stock(gtk.STOCK_MEDIA_RECORD, gtk.ICON_SIZE_SMALL_TOOLBAR) self.state = RecordingState.STOPPED self.tooltips.set_tip(self.event_box, _("Left click to start screencast. Right click for menu.")) return False
def _trayicon_clicked(self, widget, event): """ left click triggers record/stop right click shows popup menu """ if event.button == 1: if self.state == RecordingState.STOPPED: self.tray_image.set_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_SMALL_TOOLBAR) self.tooltips.set_tip(self.event_box, _("Left click to stop recording screencast.")) self.state = RecordingState.RECORDING self.current_screencast = Screencast(self.stop_handler) self.current_screencast.selector = self.popup_menu.selector self.current_screencast.start_recording() elif self.state == RecordingState.RECORDING: self.tray_image.set_from_stock(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_SMALL_TOOLBAR) self.state = RecordingState.SAVING self.tooltips.set_tip(self.event_box, _("In process of saving to disk.")) self.current_screencast.stop_recording() # only show popup if in idle state elif event.button == 3 and self.state == RecordingState.STOPPED: self.popup_menu.show()