Mercurial > libervia-web
comparison browser_side/panels.py @ 326:36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
- unibox is disabled by default
- dynamic refresh of the concerned widgets
- use the generic method refresh instead of setUniBox
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 07 Jan 2014 15:36:18 +0100 |
parents | 0b7934e75e76 |
children | 9c6be29c714a |
comparison
equal
deleted
inserted
replaced
325:d07b54fdc60a | 326:36927be51481 |
---|---|
68 HorizontalPanel.__init__(self) | 68 HorizontalPanel.__init__(self) |
69 self.host = host | 69 self.host = host |
70 self.setStyleName('uniBoxPanel') | 70 self.setStyleName('uniBoxPanel') |
71 self.unibox = None | 71 self.unibox = None |
72 | 72 |
73 def setUniBox(self, enable): | 73 def refresh(self): |
74 """Enable or disable the unibox widget. | 74 """Enable or disable this panel. Contained widgets are created when necessary.""" |
75 @param enable: boolean | 75 enable = self.host.params_ui['unibox']['value'] |
76 @return: UniBox instance or None if disabled | 76 self.setVisible(enable) |
77 """ | 77 if enable and not self.unibox: |
78 if enable: | |
79 self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>') | 78 self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>') |
80 self.button.setTitle('Open the rich text editor') | 79 self.button.setTitle('Open the rich text editor') |
81 self.button.addStyleName('uniBoxButton') | 80 self.button.addStyleName('uniBoxButton') |
82 self.add(self.button) | 81 self.add(self.button) |
83 self.unibox = UniBox(self.host) | 82 self.unibox = UniBox(self.host) |
84 self.add(self.unibox) | 83 self.add(self.unibox) |
85 self.setCellWidth(self.unibox, '100%') | 84 self.setCellWidth(self.unibox, '100%') |
86 self.button.addClickListener(self.openRichTextEditor) | 85 self.button.addClickListener(self.openRichTextEditor) |
87 self.unibox.addKey("@@: ") | 86 self.unibox.addKey("@@: ") |
88 return self.unibox | |
89 else: | |
90 if self.unibox: | |
91 self.remove(self.unibox) | |
92 self.unibox = None | |
93 return None | |
94 | 87 |
95 def openRichTextEditor(self): | 88 def openRichTextEditor(self): |
96 """Open the rich text editor.""" | 89 """Open the rich text editor.""" |
97 self.button.setVisible(False) | 90 self.button.setVisible(False) |
98 self.unibox.setVisible(False) | 91 self.unibox.setVisible(False) |
622 self.comments = {} | 615 self.comments = {} |
623 self.selected_entry = None | 616 self.selected_entry = None |
624 self.vpanel = VerticalPanel() | 617 self.vpanel = VerticalPanel() |
625 self.vpanel.setStyleName('microblogPanel') | 618 self.vpanel.setStyleName('microblogPanel') |
626 self.setWidget(self.vpanel) | 619 self.setWidget(self.vpanel) |
627 self.setUniBox(self.host.uni_box) | 620 |
628 | 621 def refresh(self): |
629 def setUniBox(self, enable=False): | 622 """Refresh the display of this widget. If the unibox is disabled, |
630 """Enable or disable the unibox. If it is disabled, | |
631 display the 'New message' button on top of the panel""" | 623 display the 'New message' button on top of the panel""" |
632 if enable: | 624 enable_button = self.host.uni_box is None |
633 return | |
634 if hasattr(self, 'new_button'): | 625 if hasattr(self, 'new_button'): |
635 self.new_button.setVisible(True) | 626 self.new_button.setVisible(enable_button) |
636 else: | 627 return |
628 if enable_button: | |
637 def addBox(): | 629 def addBox(): |
638 self.new_button.setVisible(False) | 630 self.new_button.setVisible(False) |
639 data = {'id': str(time()), | 631 data = {'id': str(time()), |
640 'new': True, | 632 'new': True, |
641 'author': self.host.whoami.bare, | 633 'author': self.host.whoami.bare, |
1038 self.vpanel.add(self.__body) | 1030 self.vpanel.add(self.__body) |
1039 self.vpanel.setCellHeight(self.__body, '100%') | 1031 self.vpanel.setCellHeight(self.__body, '100%') |
1040 self.addStyleName('chatPanel') | 1032 self.addStyleName('chatPanel') |
1041 self.setWidget(self.vpanel) | 1033 self.setWidget(self.vpanel) |
1042 self.state_machine = ChatStateMachine(self.host, str(self.target)) | 1034 self.state_machine = ChatStateMachine(self.host, str(self.target)) |
1043 self.setUniBox(self.host.uni_box) | |
1044 | |
1045 def setUniBox(self, enable): | |
1046 """Enable or disable the unibox. If it is disabled, | |
1047 display a message box below the panel.""" | |
1048 if enable: | |
1049 return | |
1050 message_box = MessageBox(self.host) | |
1051 message_box.onSelectedChange(self) | |
1052 self.vpanel.add(message_box) | |
1053 | 1035 |
1054 """def doDetachChildren(self): | 1036 """def doDetachChildren(self): |
1055 #We need to force the use of a panel subclass method here, | 1037 #We need to force the use of a panel subclass method here, |
1056 #for the same reason as doAttachChildren | 1038 #for the same reason as doAttachChildren |
1057 base_widget.ScrollPanelWrapper.doDetachChildren(self) | 1039 base_widget.ScrollPanelWrapper.doDetachChildren(self) |
1073 _new_panel.historyPrint() | 1055 _new_panel.historyPrint() |
1074 host.setSelected(_new_panel) | 1056 host.setSelected(_new_panel) |
1075 return _new_panel | 1057 return _new_panel |
1076 | 1058 |
1077 def refresh(self): | 1059 def refresh(self): |
1078 """Refresh the display of this widget.""" | 1060 """Refresh the display of this widget. If the unibox is disabled, |
1061 add a message box at the bottom of the panel""" | |
1079 self.host.contact_panel.setContactMessageWaiting(self.target.bare, False) | 1062 self.host.contact_panel.setContactMessageWaiting(self.target.bare, False) |
1080 self.content_scroll.scrollToBottom() | 1063 self.content_scroll.scrollToBottom() |
1064 | |
1065 enable_box = self.host.uni_box is None | |
1066 if hasattr(self, 'message_box'): | |
1067 self.message_box.setVisible(enable_box) | |
1068 return | |
1069 if enable_box: | |
1070 self.message_box = MessageBox(self.host) | |
1071 self.message_box.onSelectedChange(self) | |
1072 self.vpanel.add(self.message_box) | |
1081 | 1073 |
1082 def matchEntity(self, entity): | 1074 def matchEntity(self, entity): |
1083 """ | 1075 """ |
1084 @param entity: target jid as a string or JID instance. | 1076 @param entity: target jid as a string or JID instance. |
1085 Could also be a couple with a type in the second element. | 1077 Could also be a couple with a type in the second element. |
1306 else: | 1298 else: |
1307 tab_bar_h = _elts.item(0).offsetHeight | 1299 tab_bar_h = _elts.item(0).offsetHeight |
1308 ideal_height = Window.getClientHeight() - tab_bar_h | 1300 ideal_height = Window.getClientHeight() - tab_bar_h |
1309 self.setHeight("%s%s" % (ideal_height, "px")) | 1301 self.setHeight("%s%s" % (ideal_height, "px")) |
1310 | 1302 |
1311 def setUniBoxPanel(self, enable): | 1303 def refresh(self): |
1312 """Enable or disable the unibox | 1304 """Refresh the main panel""" |
1313 @param enable: boolean | 1305 self.unibox_panel.refresh() |
1314 @return: UniBox instance or None if disabled | |
1315 """ | |
1316 self.unibox_panel.setVisible(enable) | |
1317 return self.unibox_panel.setUniBox(enable) |