Changeset 9155 for branches/one_window/src/message_window.py
- Timestamp:
- 12/16/07 01:01:13 (11 months ago)
- Files:
-
- 1 modified
-
branches/one_window/src/message_window.py (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/one_window/src/message_window.py
r8965 r9155 7 7 ## Nikos Kouremenos <kourem@gmail.com> 8 8 ## Dimitur Kirov <dkirov@gmail.com> 9 ## Travis Shirk <travis@pobox.com>10 9 ## Norman Rasmussen <norman@rasmussen.co.za> 11 ## Copyright (C) 200 6Travis Shirk <travis@pobox.com>12 ## Geobert Quach <geobert@gmail.com>10 ## Copyright (C) 2005-2007 Travis Shirk <travis@pobox.com> 11 ## Copyright (C) 2006 Geobert Quach <geobert@gmail.com> 13 12 ## Copyright (C) 2007 Stephan Erb <steve-e@h3c.de> 14 13 ## … … 40 39 #################### 41 40 42 class MessageWindow :41 class MessageWindow(object): 43 42 '''Class for windows which contain message like things; chats, 44 43 groupchats, etc.''' … … 54 53 CLOSE_CTRL_KEY 55 54 ) = range(5) 56 57 def __init__(self, acct, type ):55 56 def __init__(self, acct, type, parent_window=None, parent_paned=None): 58 57 # A dictionary of dictionaries where _contacts[account][jid] == A MessageControl 59 58 self._controls = {} … … 69 68 self.xml = gtkgui_helpers.get_glade('%s.glade' % self.widget_name) 70 69 self.window = self.xml.get_widget(self.widget_name) 70 self.notebook = self.xml.get_widget('notebook') 71 self.parent_paned = None 72 73 if parent_window: 74 orig_window = self.window 75 self.window = parent_window 76 self.parent_paned = parent_paned 77 self.notebook.reparent(self.parent_paned) 78 self.parent_paned.pack2(self.notebook, resize=True, shrink=True) 79 orig_window.destroy() 80 del orig_window 81 71 82 id = self.window.connect('delete-event', self._on_window_delete) 72 83 self.handlers[id] = self.window … … 92 103 self.alignment = self.xml.get_widget('alignment') 93 104 94 self.notebook = self.xml.get_widget('notebook')95 105 id = self.notebook.connect('switch-page', 96 106 self._on_notebook_switch_page) … … 144 154 n += len(dict) 145 155 return n 156 157 def resize(self, width, height): 158 gtkgui_helpers.resize_window(self.window, width, height) 146 159 147 160 def _on_window_focus(self, widget, event): … … 211 224 id = widget.connect('clicked', self._on_close_button_clicked, control) 212 225 control.handlers[id] = widget 213 214 id = tab_label_box.connect('button-press-event', self.on_tab_eventbox_button_press_event, control.widget) 226 227 id = tab_label_box.connect('button-press-event', self.on_tab_eventbox_button_press_event, 228 control.widget) 215 229 control.handlers[id] = tab_label_box 216 230 self.notebook.append_page(control.widget, tab_label_box) … … 264 278 # No more control in this window 265 279 return 266 280 267 281 # CTRL mask 268 282 if modifier & gtk.gdk.CONTROL_MASK: … … 287 301 if keyval == gtk.keysyms.Right: # ALT + RIGHT 288 302 new = self.notebook.get_current_page() + 1 289 if new >= self.notebook.get_n_pages(): 303 if new >= self.notebook.get_n_pages(): 290 304 new = 0 291 305 self.notebook.set_current_page(new) … … 371 385 ctrl_page = self.notebook.page_num(ctrl.widget) 372 386 self.notebook.set_current_page(ctrl_page) 373 387 374 388 def remove_tab(self, ctrl, method, reason = None, force = False): 375 389 '''reason is only for gc (offline status message) … … 543 557 # if no others controls have awaiting events 544 558 # loop until finding an unread tab or having done a complete cycle 545 while True: 559 while True: 546 560 if forward == True: # look for the first unread tab on the right 547 561 ind = ind + 1 … … 591 605 old_ctrl = self._widget_to_control(notebook.get_nth_page(old_no)) 592 606 old_ctrl.set_control_active(False) 593 607 594 608 new_ctrl = self._widget_to_control(notebook.get_nth_page(page_num)) 595 609 new_ctrl.set_control_active(True) … … 599 613 control = self.get_active_control() 600 614 # Ctrl+PageUP / DOWN has to be handled by notebook 601 if event.state & gtk.gdk.CONTROL_MASK and event.keyval in (602 gtk.keysyms.Page_Down, gtk.keysyms.Page_Up):615 if (event.state & gtk.gdk.CONTROL_MASK and 616 event.keyval in (gtk.keysyms.Page_Down, gtk.keysyms.Page_Up)): 603 617 return False 604 618 if isinstance(control, ChatControlBase): … … 610 624 '''Set tab label as drag source and connect the drag_data_get signal''' 611 625 tab_label = self.notebook.get_tab_label(child) 612 tab_label.dnd_handler = tab_label.connect('drag_data_get', 626 tab_label.dnd_handler = tab_label.connect('drag_data_get', 613 627 self.on_tab_label_drag_data_get_cb) 614 628 self.handlers[tab_label.dnd_handler] = tab_label … … 631 645 if dest_page_num != source_page_num: 632 646 self.notebook.reorder_child(source_child, dest_page_num) 633 647 634 648 def get_tab_at_xy(self, x, y): 635 649 '''Thanks to Gaim 636 650 Return the tab under xy and 637 if its nearer from left or right side of the tab 651 if its nearer from left or right side of the tab 638 652 ''' 639 653 page_num = -1 … … 656 670 (y <= (tab_alloc.y + tab_alloc.height)): 657 671 page_num = i 658 672 659 673 if y > tab_alloc.y + (tab_alloc.height / 2.0): 660 674 to_right = True … … 687 701 ONE_MSG_WINDOW_NEVER, 688 702 ONE_MSG_WINDOW_ALWAYS, 703 ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER, 689 704 ONE_MSG_WINDOW_PERACCT, 690 ONE_MSG_WINDOW_PERTYPE 691 ) = range( 4)692 # A key constant for the main window for all messages705 ONE_MSG_WINDOW_PERTYPE, 706 ) = range(5) 707 # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS mode 693 708 MAIN_WIN = 'main' 694 695 def __init__(self): 709 # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER mode 710 ROSTER_MAIN_WIN = 'roster' 711 712 def __init__(self, parent_window, parent_paned): 696 713 ''' A dictionary of windows; the key depends on the config: 697 714 ONE_MSG_WINDOW_NEVER: The key is the contact JID 698 ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN 715 ONE_MSG_WINDOW_ALWAYS: The key is MessageWindowMgr.MAIN_WIN 716 ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: The key is MessageWindowMgr.MAIN_WIN 699 717 ONE_MSG_WINDOW_PERACCT: The key is the account name 700 718 ONE_MSG_WINDOW_PERTYPE: The key is a message type constant''' 701 719 self._windows = {} 720 702 721 # Map the mode to a int constant for frequent compares 703 722 mode = gajim.config.get('one_message_window') 704 723 self.mode = common.config.opt_one_window_types.index(mode) 705 724 725 self.parent_win = parent_window 726 self.parent_paned = parent_paned 727 706 728 def change_account_name(self, old_name, new_name): 707 729 for win in self.windows(): … … 709 731 710 732 def _new_window(self, acct, type): 711 win = MessageWindow(acct, type) 733 parent_win = None 734 parent_paned = None 735 if self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 736 parent_win = self.parent_win 737 parent_paned = self.parent_paned 738 win = MessageWindow(acct, type, parent_win, parent_paned) 739 # FIXME: how are these done for roster combo 712 740 # we track the lifetime of this window 713 741 win.window.connect('delete-event', self._on_window_delete) … … 740 768 if not gajim.config.get('saveposition'): 741 769 return 742 743 if self.mode == self.ONE_MSG_WINDOW_ALWAYS: 770 771 if self.mode in (self.ONE_MSG_WINDOW_ALWAYS, 772 self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER): 744 773 size = (gajim.config.get('msgwin-width'), 745 774 gajim.config.get('msgwin-height')) 775 if self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 776 parent_size = win.window.get_size() 777 size = (parent_size[0] + size[0], size[1]) 746 778 elif self.mode == self.ONE_MSG_WINDOW_PERACCT: 747 779 size = (gajim.config.get_per('accounts', acct, 'msgwin-width'), … … 755 787 else: 756 788 return 757 758 gtkgui_helpers.resize_window(win.window, size[0], size[1]) 759 789 win.resize(size[0], size[1]) 790 760 791 def _position_window(self, win, acct, type): 761 792 '''Moves window according to config settings''' 762 if not gajim.config.get('saveposition') or\ 763 self.mode == self.ONE_MSG_WINDOW_NEVER: 793 if (not gajim.config.get('saveposition') or 794 self.mode in [self.ONE_MSG_WINDOW_NEVER, 795 self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER]): 764 796 return 765 797 … … 783 815 if resource: 784 816 key += '/' + resource 817 return key 785 818 elif self.mode == self.ONE_MSG_WINDOW_ALWAYS: 786 key = self.MAIN_WIN 819 return self.MAIN_WIN 820 elif self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 821 return self.ROSTER_MAIN_WIN 787 822 elif self.mode == self.ONE_MSG_WINDOW_PERACCT: 788 key =acct823 return acct 789 824 elif self.mode == self.ONE_MSG_WINDOW_PERTYPE: 790 key = type 791 return key 825 return type 792 826 793 827 def create_window(self, contact, acct, type, resource = None): 794 key = None795 828 win_acct = None 796 829 win_type = None 797 win_role = 'messages'798 799 key = self._mode_to_key(contact, acct, type, resource)830 win_role = None # X11 window role 831 832 win_key = self._mode_to_key(contact, acct, type, resource) 800 833 if self.mode == self.ONE_MSG_WINDOW_PERACCT: 801 834 win_acct = acct … … 807 840 win_type = type 808 841 win_role = contact.jid 842 elif self.mode == self.ONE_MSG_WINDOW_ALWAYS: 843 win_role = 'messages' 809 844 810 845 win = None 811 846 try: 812 win = self._windows[ key]847 win = self._windows[win_key] 813 848 except KeyError: 814 849 win = self._new_window(win_acct, win_type) 815 850 816 win.window.set_role(win_role) 851 if win_role: 852 win.window.set_role(win_role) 817 853 818 854 # Position and size window based on saved state and window mode … … 821 857 self._resize_window(win, acct, type) 822 858 823 self._windows[ key] = win859 self._windows[win_key] = win 824 860 return win 825 861 … … 881 917 if not gajim.config.get('saveposition'): 882 918 return 883 919 884 920 # Save window size and position 885 921 pos_x_key = 'msgwin-x-position' … … 908 944 size_width_key = type + '-msgwin-width' 909 945 size_height_key = type + '-msgwin-height' 946 elif self.mode == self.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER: 947 width -= msg_win.parent_paned.get_position() 910 948 911 949 if acct: … … 916 954 gajim.config.set_per('accounts', acct, pos_x_key, x) 917 955 gajim.config.set_per('accounts', acct, pos_y_key, y) 918 956 919 957 else: 920 958 gajim.config.set(size_width_key, width) 921 959 gajim.config.set(size_height_key, height) 922 960 923 961 if self.mode != self.ONE_MSG_WINDOW_NEVER: 924 962 gajim.config.set(pos_x_key, x) … … 945 983 page.unparent() 946 984 controls.append(ctrl) 947 # Must clear _controls from window to prevent 948 # MessageControl.shutdown calls 985 # Must clear _controls from window to prevent MessageControl.shutdown calls 949 986 w._controls = {} 950 987 w.window.destroy()
