Ticket #148: guake_with_notification_on_trayicon.py.patch

File guake_with_notification_on_trayicon.py.patch, 4.1 KB (added by makism, 3 years ago)

Updated, implement "ignore output" option

  • src/guake.py

    old new  
    553553        # resizer stuff 
    554554        self.resizer.connect('motion-notify-event', self.on_resizer_drag) 
    555555 
     556                # supress the notification when creating the first tab 
     557        self.notification_supress = True 
     558 
     559                # notification interval 
     560        self.notification_interval = 5 * 1000 
     561 
     562                # terminals emitting notification ;) 
     563        self.notification_terms = list () 
     564 
     565        # ignore terminals 
     566        self.notification_ignore = list() 
     567 
     568                # add a callback :-) 
     569        gobject.timeout_add(self.notification_interval, self.notification_for_contents_changes) 
     570 
    556571        # adding the first tab on guake 
    557572        self.add_tab() 
    558573 
     
    612627            self.losefocus_time = gtk.gdk.x11_get_server_time(self.window.window) 
    613628            self.hide() 
    614629 
     630    def on_ignore_output_toggled(self, CheckMenuItem): 
     631        state = CheckMenuItem.get_active() 
     632        tab   = self.selected_tab 
     633 
     634        if state: 
     635            if tab not in self.notification_ignore: 
     636                self.notification_ignore.append (tab) 
     637        else: 
     638            for idx, t in enumerate(self.notification_ignore): 
     639                if tab is t: 
     640                    del self.notification_ignore[idx] 
     641                    return 
     642         
    615643    def show_menu(self, *args): 
    616644        """Show the tray icon menu. 
    617645        """ 
     
    644672            self.showing_context_menu = True 
    645673            self.selected_tab = target 
    646674            menu = self.get_widget('tab-menu') 
     675 
     676            if self.selected_tab in self.notification_ignore: 
     677                menu.get_children()[0].set_active(True) 
     678            else: 
     679                menu.get_children()[0].set_active(False) 
     680 
    647681            menu.popup(None, None, None, 3, event.get_time()) 
    648682        self.set_terminal_focus() 
    649683 
     
    664698    def show_hide(self, *args): 
    665699        """Toggles the main window visibility 
    666700        """ 
     701        if len (self.notification_terms) > 0: 
     702            self.notification_terms = list () 
     703        if self.tray_icon.get_blinking(): 
     704            self.tray_icon.set_blinking(False) 
     705         
    667706        event_time = self.hotkeys.get_current_event_time() 
    668707 
    669708        if self.losefocus_time and \ 
     
    923962 
    924963        return params 
    925964 
     965    def on_contents_change(self, terminalWidget, terminalId): 
     966        if self.notification_supress: 
     967            self.notification_supress = False 
     968            return 
     969 
     970        for idx, term in enumerate(self.term_list): 
     971            if term is terminalWidget: 
     972                target_tab = self.tabs.get_children()[idx] 
     973                if target_tab in self.notification_ignore: 
     974                            return 
     975                break 
     976 
     977        if self.window.get_property('visible') == False: 
     978            #print "Something happened on terminal %d!" % terminalId 
     979            if terminalId not in self.notification_terms: 
     980                self.notification_terms.append (terminalId) 
     981        else: 
     982            self.notification_supress = True 
     983 
     984    def notification_for_contents_changes(self, *args): 
     985        if self.notification_supress: 
     986            return True 
     987          
     988        l = len(self.notification_terms) 
     989        if l > 0: 
     990            str = "" 
     991 
     992            if self.tray_icon.get_blinking() == False: 
     993                self.tray_icon.set_blinking(True) 
     994                gobject.timeout_add (30 * 1000, lambda: self.tray_icon.set_blinking(False)) 
     995                self.notification_terms = list () 
     996         
     997        return True 
     998 
    926999    def add_tab(self, *args): 
    9271000        """Adds a new tab to the terminal notebook. 
    9281001        """ 
     1002        if len (self.term_list) == 0: 
     1003            self.notification_supress = True 
     1004 
    9291005        box = GuakeTerminalBox() 
    9301006        box.terminal.grab_focus() 
    9311007        box.terminal.connect('button-press-event', self.show_context_menu) 
    9321008        box.terminal.connect('child-exited', self.on_terminal_exited, box) 
     1009        box.terminal.connect('contents-changed', self.on_contents_change, len(self.term_list)) 
    9331010        box.show() 
    9341011 
    9351012        last_added = len(self.term_list)