Changeset 48e43cb692421e90bb2294a6dc6d91df7633560c

Show
Ignore:
Timestamp:
06/12/08 02:19:38 (4 years ago)
Author:
Lincoln de Sousa <lincoln@…>
Children:
26344e17f2f3450a493eb32382f0395aac5dcda0
Parents:
b71e79590601d436af5201f690ba38fcf2f5126b
git-committer:
Lincoln de Sousa <lincoln@…> (06/12/08 02:19:38)
Message:

Fixing the close tab feature

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    rb71e795 r48e43cb  
    66 
    77        * src/guake.py (Guake): Adding a context menu to each tab with 
    8         rename and close options (close is broken for a while =). 
     8        rename and close options. 
    99 
    10102008-06-11  Lincoln de Sousa  <lincoln@minaslivre.org> 
  • src/guake.py

    rb71e795 r48e43cb  
    3535import sys 
    3636import warnings 
     37from thread import start_new_thread 
     38from time import sleep 
    3739import common 
    3840from common import _ 
     
    706708 
    707709    def on_terminal_exited(self, term, widget): 
    708         self.delete_tab(self.notebook.page_num(widget)) 
     710        self.delete_tab(self.notebook.page_num(widget), kill=False) 
    709711 
    710712    def on_rename_activate(self, *args): 
     
    738740 
    739741    def on_close_activate(self, *args): 
    740         self.on_context_close_tab_activate() 
     742        pagepos = self.tabs.get_children().index(self.selected_tab) 
     743        self.delete_tab(pagepos) 
    741744 
    742745    # -- Context menu callbacks -- 
     
    754757 
    755758    def on_context_close_tab_activate(self, *args): 
    756         current_pos = self.notebook.get_current_page() 
    757         pid = self.pid_list.pop(current_pos) 
    758         os.kill(pid, signal.SIGKILL) 
     759        pagepos = self.notebook.get_current_page() 
     760        self.delete_tab(pagepos) 
    759761 
    760762    def on_context_close_activate(self, widget): 
     
    835837        self.notebook.set_current_page(last_added) 
    836838 
    837     def delete_tab(self, pagepos): 
     839    def delete_tab(self, pagepos, kill=True): 
     840        """This function will destroy the notebook page, terminal and 
     841        tab widgets and will call the function to kill interpreter 
     842        forked by vte. 
     843        """ 
    838844        self.notebook.remove_page(pagepos) 
    839845        self.tabs.get_children()[pagepos].destroy() 
    840         self.clear_old_terms() 
     846        self.term_list.pop(pagepos).destroy() 
     847        pid = self.pid_list.pop(pagepos) 
     848 
     849        if kill: 
     850            start_new_thread(self.delete_shell, (pid,)) 
     851 
    841852        if not self.term_list: 
    842853            self.hide() 
     854 
     855    def delete_shell(self, pid): 
     856        """This function will kill the shell on a tab, trying to sent 
     857        a sigterm and if it doesn't work, a sigkill. Between these two 
     858        signals, we have a timeout of 3 seconds, so is recommended to 
     859        call this in another thread. This doesn't change any thing in 
     860        UI, so you can use python's start_new_thread. 
     861        """ 
     862        os.kill(pid, signal.SIGTERM) 
     863        os.wait() 
     864        sleep(3) 
     865 
     866        try: 
     867            os.kill(pid, signal.SIGKILL) 
     868        except OSError: 
     869            # if this part of code was reached, means that SIGTERM did 
     870            # the work and SIGKILL wasnt needed. 
     871            pass 
    843872 
    844873    def set_terminal_focus(self): 
     
    848877    def select_current_tab(self, notebook, user_data, page): 
    849878        self.tabs.get_children()[page].set_active(True) 
    850  
    851     def clear_old_terms(self): 
    852         for term in reversed(self.term_list): 
    853             term_page = term.get_parent() 
    854             if self.notebook.page_num(term_page) == -1: 
    855                 self.term_list.remove(term) 
    856                 del term 
    857879 
    858880def main():