Changeset 48e43cb692421e90bb2294a6dc6d91df7633560c
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rb71e795
|
r48e43cb
|
|
| 6 | 6 | |
| 7 | 7 | * 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. |
| 9 | 9 | |
| 10 | 10 | 2008-06-11 Lincoln de Sousa <lincoln@minaslivre.org> |
-
|
rb71e795
|
r48e43cb
|
|
| 35 | 35 | import sys |
| 36 | 36 | import warnings |
| | 37 | from thread import start_new_thread |
| | 38 | from time import sleep |
| 37 | 39 | import common |
| 38 | 40 | from common import _ |
| … |
… |
|
| 706 | 708 | |
| 707 | 709 | 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) |
| 709 | 711 | |
| 710 | 712 | def on_rename_activate(self, *args): |
| … |
… |
|
| 738 | 740 | |
| 739 | 741 | 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) |
| 741 | 744 | |
| 742 | 745 | # -- Context menu callbacks -- |
| … |
… |
|
| 754 | 757 | |
| 755 | 758 | 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) |
| 759 | 761 | |
| 760 | 762 | def on_context_close_activate(self, widget): |
| … |
… |
|
| 835 | 837 | self.notebook.set_current_page(last_added) |
| 836 | 838 | |
| 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 | """ |
| 838 | 844 | self.notebook.remove_page(pagepos) |
| 839 | 845 | 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 | |
| 841 | 852 | if not self.term_list: |
| 842 | 853 | 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 |
| 843 | 872 | |
| 844 | 873 | def set_terminal_focus(self): |
| … |
… |
|
| 848 | 877 | def select_current_tab(self, notebook, user_data, page): |
| 849 | 878 | 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 |
| 857 | 879 | |
| 858 | 880 | def main(): |