Ticket #158: guake.py.patch

File guake.py.patch, 3.6 KB (added by makism, 4 years ago)

updated patch. 1) hides the main window when prompting and 2) showing again on cancel. finally, 3) raises the prompt dialog on top of everything (at least in theory)

  • src/guake.py

    old new  
    3535import sys 
    3636from thread import start_new_thread 
    3737from time import sleep 
     38import posix 
    3839 
    3940import globalhotkeys 
    4041from simplegladeapp import SimpleGladeApp, bindtextdomain 
     
    5051bindtextdomain(name, locale_dir) 
    5152 
    5253 
     54class PromptQuitDialog(SimpleGladeApp): 
     55    """Prompts the user whether to quit or not if there are procs running. 
     56    """ 
     57    def __init__ (self, parent, runningProcs): 
     58        super(PromptQuitDialog, self).__init__(gladefile('prompt_on_quit.glade'), 
     59                                             root='promptdialog') 
     60        self.parent = parent 
     61        self.dialog = self.get_widget('promptdialog') 
     62        self.dialog.set_keep_above (True) 
     63 
     64        self.parent.show_hide () 
     65 
     66        if runningProcs == 1: 
     67            self.get_widget("labelNumberOfProcs").set_markup( 
     68                "<b>There is one process still running.</b>" 
     69            ) 
     70        elif runningProcs > 1: 
     71            self.get_widget("labelNumberOfProcs").set_markup( 
     72                "<b>There are %d processes running...</b>" % runningProcs 
     73            ) 
     74 
     75    def on_buttonQuit_clicked(self, Button, *data): 
     76        gtk.main_quit () 
     77 
     78    def on_buttonCancel_clicked(self, Button, *data): 
     79        self.parent.show_hide () 
     80        self.dialog.destroy() 
     81        return gtk.FALSE 
     82 
     83 
    5384class AboutDialog(SimpleGladeApp): 
    5485    """The About Guake dialog class 
    5586    """ 
     
    337368        key, mask = gtk.accelerator_parse(gets('quit')) 
    338369        if key > 0: 
    339370            self.accel_group.connect_group(key, mask, gtk.ACCEL_VISIBLE, 
    340                                            gtk.main_quit) 
     371                                           self.guake.accel_quit) 
    341372 
    342373        key, mask = gtk.accelerator_parse(gets('new_tab')) 
    343374        if key > 0: 
     
    731762        window_rect.height = window_rect.height * height / 100 
    732763        return window_rect 
    733764 
     765    def get_running_fg_processes(self): 
     766        """Get the number processes for each terminal/tab. The code is taken 
     767        from gnome-terminal. 
     768        """ 
     769        total_procs = 0 
     770 
     771        term_idx = 0 
     772        for terminal in self.term_list: 
     773            fdpty    = terminal.get_pty () 
     774            term_pid = self.pid_list [term_idx] 
     775 
     776            fgpid = posix.tcgetpgrp(fdpty) 
     777            if fgpid == -1 or fgpid == term_pid: 
     778                pass 
     779            else: 
     780                total_procs += 1 
     781 
     782            term_idx += 1 
     783 
     784        return total_procs 
     785 
    734786    # -- configuration -- 
    735787 
    736788    def load_config(self): 
    737789        """"Just a proxy for all the configuration stuff. 
    738790        """ 
    739791        self.client.notify(KEY('/general/use_trayicon')) 
     792        self.client.notify(KEY('/general/prompt_on_quit')) 
    740793        self.client.notify(KEY('/general/window_tabbar')) 
    741794        self.client.notify(KEY('/general/window_ontop')) 
    742795        self.client.notify(KEY('/general/window_size')) 
     
    750803        self.client.notify(KEY('/style/background/transparency')) 
    751804        self.client.notify(KEY('/general/use_default_font')) 
    752805 
     806    def accel_quit(self, *args): 
     807        """Callback to prompt the user whether to quit Guake or not. 
     808        """ 
     809        if self.client.get_bool(KEY('/general/prompt_on_quit')): 
     810            procs = self.get_running_fg_processes() 
     811 
     812            if procs >= 1: 
     813                PromptQuitDialog (self, procs) 
     814            else: 
     815                gtk.main_quit () 
     816        else: 
     817            gtk.main_quit () 
     818 
    753819    def accel_add(self, *args): 
    754820        """Callback to add a new tab. Called by the accel key. 
    755821        """