Mercurial > libervia-web
comparison browser_side/panels.py @ 86:6c3b3254605f
browser side: widget removing is now managed
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 27 Jun 2011 04:11:58 +0200 |
parents | a8f027738c16 |
children | 50b480fd0605 |
comparison
equal
deleted
inserted
replaced
85:a8f027738c16 | 86:6c3b3254605f |
---|---|
154 button_group.setStyleName('widgetHeader_buttonGroup') | 154 button_group.setStyleName('widgetHeader_buttonGroup') |
155 setting_button = Image("media/icons/misc/settings.png") | 155 setting_button = Image("media/icons/misc/settings.png") |
156 setting_button.setStyleName('widgetHeader_settingButton') | 156 setting_button.setStyleName('widgetHeader_settingButton') |
157 close_button = Image("media/icons/misc/close.png") | 157 close_button = Image("media/icons/misc/close.png") |
158 close_button.setStyleName('widgetHeader_closeButton') | 158 close_button.setStyleName('widgetHeader_closeButton') |
159 close_button.addClickListener(getattr(self,"onClose")) | |
159 button_group.add(setting_button) | 160 button_group.add(setting_button) |
160 button_group.add(close_button) | 161 button_group.add(close_button) |
161 button_group_wrapper.setWidget(button_group) | 162 button_group_wrapper.setWidget(button_group) |
162 header.add(button_group_wrapper) | 163 header.add(button_group_wrapper) |
163 self.add(header) | 164 self.add(header) |
169 self.host.registerWidget(self) | 170 self.host.registerWidget(self) |
170 | 171 |
171 def onClick(self, sender): | 172 def onClick(self, sender): |
172 self.host.select(self) | 173 self.host.select(self) |
173 | 174 |
175 def onClose(self, sender): | |
176 print "onClose:", sender | |
177 _widgetpanel = self.getParent().getParent() | |
178 _widgetpanel.removeWidget(self) | |
179 | |
174 def setTitle(self, text): | 180 def setTitle(self, text): |
175 """change the title in the header of the widget | 181 """change the title in the header of the widget |
176 @param text: text of the new title""" | 182 @param text: text of the new title""" |
177 self.__title.setText(text) | 183 self.__title.setText(text) |
178 | 184 |
201 else: | 207 else: |
202 body_wid = widget | 208 body_wid = widget |
203 self.add(body_wid) | 209 self.add(body_wid) |
204 self.setCellHeight(body_wid, '100%') | 210 self.setCellHeight(body_wid, '100%') |
205 | 211 |
212 def doDetachChildren(self): | |
213 #We need to force the use of a panel subclass method here, | |
214 #for the same reason as doAttachChildren | |
215 VerticalPanel.doDetachChildren(self) | |
216 | |
217 def doAttachChildren(self): | |
218 #We need to force the use of a panel subclass method here, else | |
219 #the event will not propagate to children | |
220 VerticalPanel.doAttachChildren(self) | |
206 | 221 |
207 class ScrollPanelWrapper(SimplePanel): | 222 class ScrollPanelWrapper(SimplePanel): |
208 """Scroll Panel like component, wich use the full available space | 223 """Scroll Panel like component, wich use the full available space |
209 to work around percent size issue, it use some of the ideas found | 224 to work around percent size issue, it use some of the ideas found |
210 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 | 225 here: http://code.google.com/p/google-web-toolkit/issues/detail?id=316 |
671 self.flextable.setWidget(last_row, 0, LeftBorderWidget(self.host)) | 686 self.flextable.setWidget(last_row, 0, LeftBorderWidget(self.host)) |
672 self.flextable.setWidget(last_row, 1, wid) | 687 self.flextable.setWidget(last_row, 1, wid) |
673 self.flextable.setWidget(last_row, 2, RightBorderWidget(self.host)) | 688 self.flextable.setWidget(last_row, 2, RightBorderWidget(self.host)) |
674 cellFormatter.setHorizontalAlignment(last_row, 2, HasAlignment.ALIGN_RIGHT) | 689 cellFormatter.setHorizontalAlignment(last_row, 2, HasAlignment.ALIGN_RIGHT) |
675 row = last_row | 690 row = last_row |
676 last_row+=1 | |
677 | 691 |
678 elif isinstance(prev_wid, LeftBorderWidget): | 692 elif isinstance(prev_wid, LeftBorderWidget): |
679 if col!=0: | 693 if col!=0: |
680 print "ERROR: LeftBorderWidget must be on the first column !" | 694 print "ERROR: LeftBorderWidget must be on the first column !" |
681 return | 695 return |
693 prev_wid.removeFromParent() | 707 prev_wid.removeFromParent() |
694 self.flextable.setWidget(row, col, wid) | 708 self.flextable.setWidget(row, col, wid) |
695 | 709 |
696 _max_cols = max(self._max_cols, self.flextable.getCellCount(row)) | 710 _max_cols = max(self._max_cols, self.flextable.getCellCount(row)) |
697 if _max_cols != self._max_cols: | 711 if _max_cols != self._max_cols: |
698 #we hage to adjust sizes | |
699 self._max_cols = _max_cols | 712 self._max_cols = _max_cols |
700 width = 100.0/max(1, self._max_cols-2) #we don't count the borders | 713 self._sizesAdjust() |
701 for row_idx in range(self.flextable.getRowCount()): | 714 |
702 for col_idx in range(self.flextable.getCellCount(row_idx)): | 715 def _sizesAdjust(self): |
703 _widget = self.flextable.getWidget(row_idx, col_idx) | 716 cellFormatter = self.flextable.getFlexCellFormatter() |
704 if not isinstance(_widget, BorderWidget): | 717 width = 100.0/max(1, self._max_cols-2) #we don't count the borders |
705 td_elt = _widget.getElement().parentNode | 718 |
706 DOM.setStyleAttribute(td_elt, "width", "%.2f%%" % width) | 719 for row_idx in xrange(self.flextable.getRowCount()): |
707 | 720 for col_idx in xrange(self.flextable.getCellCount(row_idx)): |
708 cellFormatter.setColSpan(last_row, 0, self._max_cols) | 721 _widget = self.flextable.getWidget(row_idx, col_idx) |
709 | 722 if not isinstance(_widget, BorderWidget): |
723 td_elt = _widget.getElement().parentNode | |
724 DOM.setStyleAttribute(td_elt, "width", "%.2f%%" % width) | |
725 | |
726 last_row = max(0, self.flextable.getRowCount()-1) | |
727 cellFormatter.setColSpan(last_row, 0, self._max_cols) | |
710 | 728 |
711 def addWidget(self, wid): | 729 def addWidget(self, wid): |
712 """Add a widget to a new cell on the next to last row""" | 730 """Add a widget to a new cell on the next to last row""" |
713 last_row = max(0, self.flextable.getRowCount()-1) | 731 last_row = max(0, self.flextable.getRowCount()-1) |
714 print "putting widget %s at %d, %d" % (wid, last_row, 0) | 732 print "putting widget %s at %d, %d" % (wid, last_row, 0) |
715 self.changeWidget(last_row, 0, wid) | 733 self.changeWidget(last_row, 0, wid) |
734 | |
735 def removeWidget(self, wid): | |
736 """Remove a widget and the cell where it is""" | |
737 _row, _col = self.flextable.getIndex(wid) | |
738 self.flextable.remove(wid) | |
739 self.flextable.removeCell(_row, _col) | |
740 if self.flextable.getCellCount(_row) == 2: #we have only the borders left, we remove the row | |
741 self.flextable.removeRow(_row) | |
742 _max_cols = 1 | |
743 for row_idx in xrange(self.flextable.getRowCount()): | |
744 _max_cols = max(_max_cols, self.flextable.getCellCount(row_idx)) | |
745 if _max_cols != self._max_cols: | |
746 self._max_cols = _max_cols | |
747 self._sizesAdjust() | |
716 | 748 |
717 class MainDiscussionPanel(HorizontalPanel): | 749 class MainDiscussionPanel(HorizontalPanel): |
718 | 750 |
719 def __init__(self, host): | 751 def __init__(self, host): |
720 self.host=host | 752 self.host=host |