Mercurial > libervia-web
changeset 83:68d360caeecb
New widget system: first draft
- adaptation of Adrien's design
- widgets are now based on a flextable
- widgets now use a base class LiberviaWidget (the name is to avoid confustion with pyjamas' widgets)
- widgets have a title, and setting/close buttons
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Jun 2011 03:04:17 +0200 |
parents | bd575203d456 |
children | 8f35e9970e7f |
files | browser_side/panels.py libervia.py |
diffstat | 2 files changed, 103 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/panels.py Sun Jun 26 03:02:10 2011 +0200 +++ b/browser_side/panels.py Sun Jun 26 03:04:17 2011 +0200 @@ -27,13 +27,17 @@ from pyjamas.ui.ScrollPanel import ScrollPanel from pyjamas.ui.TabPanel import TabPanel from pyjamas.ui.HTMLPanel import HTMLPanel +from pyjamas.ui.FlexTable import FlexTable from pyjamas.ui.Grid import Grid from pyjamas.ui.TextArea import TextArea from pyjamas.ui.Label import Label +from pyjamas.ui.Button import Button from pyjamas.ui.HTML import HTML +from pyjamas.ui.Image import Image from pyjamas.ui.DropWidget import DropWidget from pyjamas.ui.ClickListener import ClickHandler from pyjamas.ui.KeyboardListener import KEY_ENTER +from pyjamas.ui import HasAlignment from pyjamas.Timer import Timer from pyjamas import Window from pyjamas import DOM @@ -51,6 +55,7 @@ def __init__(self): DropWidget.__init__(self) + self.setStyleName('dropCell') def onDragEnter(self, event): self.addStyleName('dragover') @@ -120,6 +125,58 @@ DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width) #FIXME: delete object ? Check the right way with pyjamas +class LiberviaWidget(DropCell, VerticalPanel): + """Libervia's widget which can replace itself with a dropped widget on DnD""" + + def __init__(self, title=''): + VerticalPanel.__init__(self) + DropCell.__init__(self) + self.title_id = HTMLPanel.createUniqueId() + self.setting_button_id = HTMLPanel.createUniqueId() + self.close_button_id = HTMLPanel.createUniqueId() + header = AbsolutePanel() + self.title = Label(title) + self.title.setStyleName('widgetHeader_title') + header.add(self.title) + #header.setCellVerticalAlignment(self.title, HasAlignment.ALIGN_MIDDLE) + #header.setCellWidth(self.title, '100%') + button_group_wrapper = SimplePanel() + button_group_wrapper.setStyleName('widgetHeader_buttonsWrapper') + button_group = HorizontalPanel() + button_group.setStyleName('widgetHeader_buttonGroup') + setting_button = Image("media/icons/misc/settings.png") + setting_button.setStyleName('widgetHeader_settingButton') + close_button = Image("media/icons/misc/close.png") + close_button.setStyleName('widgetHeader_closeButton') + button_group.add(setting_button) + button_group.add(close_button) + button_group_wrapper.setWidget(button_group) + header.add(button_group_wrapper) + self.add(header) + header.addStyleName('widgetHeader') + self.setSize('100%', '100%') + self.addStyleName('widget') + + def setTitle(self, text): + """change the title in the header of the widget + @param text: text of the new title""" + self.title.setText(text) + + def setWidget(self, widget, scrollable=True): + """Set the widget that will be in the body of the LiberviaWidget + @param widget: widget to put in the body + @param scrollable: if true, the widget will be in a ScrollPanelWrapper""" + if scrollable: + _scrollpanelwrapper = ScrollPanelWrapper() + _scrollpanelwrapper.setStyleName('widgetBody') + _scrollpanelwrapper.setWidget(widget) + body_wid = _scrollpanelwrapper + else: + body_wid = widget + self.add(body_wid) + self.setCellHeight(body_wid, '100%') + + class ScrollPanelWrapper(SimplePanel): """Scroll Panel like component, wich use the full available space to work around percent size issue, it use some of the ideas found @@ -154,10 +211,9 @@ def __init__(self, host): SimplePanel.__init__(self) self.host = host - _panel = HTMLPanel("") - self.add(_panel) - self.setHeight('100%') + self.setSize('100%','100%') DropCell.__init__(self) + self.setWidget(HTML(' ')) class UniBoxPanel(SimplePanel): """Panel containing the UniBox""" @@ -179,6 +235,7 @@ self._timer = Timer(notify=self._timeCb) self.host = host self.setStyleName('uniBox') + self.addKeyboardListener(self) def addKey(self, key): return @@ -267,7 +324,8 @@ self._timer.schedule(2000) - if keycode == KEY_ENTER and not self.visible: + #if keycode == KEY_ENTER and not self.visible: + if keycode == KEY_ENTER: if _txt: if _txt.startswith('@'): self.host.bridge.call('sendMblog', None, self.getText()) @@ -301,26 +359,21 @@ panel.setStyleName('microblogEntry') self.add(panel) -class MicroblogPanel(DropCell, ScrollPanelWrapper): +class MicroblogPanel(LiberviaWidget): - def __init__(self,host, title=' ', accept_all=False): + def __init__(self, host, title='', accept_all=False): """Panel used to show microblog @param title: title of the panel @param accept_all: if true, show every message, without filtering jids""" - ScrollPanelWrapper.__init__(self) - DropCell.__init__(self) + LiberviaWidget.__init__(self, title) + #ScrollPanelWrapper.__init__(self) + #DropCell.__init__(self) self.host = host self.accept_all = accept_all - title=html_sanitize(title) self.accepted_groups = [] self.entries = {} - _class = ['mb_panel_header'] - if title == ' ': - _class.append('empty_header') self.vpanel = VerticalPanel() - self.vpanel.add(HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),title))) - self.vpanel.setWidth('100%') - self.setStyleName('microblogPanel') + self.vpanel.setStyleName('microblogPanel') self.setWidget(self.vpanel) def addEntry(self, mblog_entry): @@ -333,7 +386,7 @@ return _entry = MicroblogEntry(mblog_entry) self.entries[mblog_entry.id] = _entry - self.vpanel.insert(_entry,1) + self.vpanel.insert(_entry,0) def setAcceptedGroup(self, group): """Set the group which can be displayed in this panel @@ -548,23 +601,49 @@ if game_type=="Tarot": return self.tarot_panel +class WidgetsPanel(SimplePanel): + + def __init__(self): + SimplePanel.__init__(self) + self.flextable = FlexTable() + self.flextable.setSize('100%','100%') + self.add(self.flextable) + self.setStyleName('widgetsPanel') + + def addWidget(self, wid): + """Add a widget to a new cell""" + row = max(0, self.flextable.getRowCount()-1) + try: + col = self.flextable.getCellCount(0) + except AttributeError: + col = 0 + print "putting widget %s at %d, %d" % (wid, row, col) + self.flextable.setWidget(row, col, wid) + class MainDiscussionPanel(HorizontalPanel): def __init__(self, host): self.host=host HorizontalPanel.__init__(self) self._left = self.host.contact_panel - self._right = Grid(1,3) + self._right = WidgetsPanel() self._right.setWidth('100%') self._right.setHeight('100%') self.add(self._left) - self.setCellWidth(self._left, "15%") + #self.setCellWidth(self._left, "15%") self.add(self._right) - self.setCellWidth(self._right, "85%") + #self.setCellWidth(self._right, "85%") + self.setCellWidth(self._right, "100%") + + def addWidget(self, wid): + """Add a widget to the WidgetsPanel""" + print "main addWidget", wid + self._right.addWidget(wid) def changePanel(self, idx, panel): - self._right.setWidget(0,idx,panel) - self._right.getCellFormatter().setWidth(0, idx, '5%' if isinstance(panel, EmptyPanel) else '90%') + pass + #self._right.setWidget(0,idx,panel) + #self._right.getCellFormatter().setWidth(0, idx, '5%' if isinstance(panel, EmptyPanel) else '90%') class MainTabPanel(TabPanel):
--- a/libervia.py Sun Jun 26 03:02:10 2011 +0200 +++ b/libervia.py Sun Jun 26 03:04:17 2011 +0200 @@ -107,9 +107,9 @@ self.other_panels = [] #panels not on the main tab #FIXME: temporary, need to be changed self.room_list = set() #set of rooms self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel - self.discuss_panel.changePanel(0,self.mpanels[0]) - self.discuss_panel.changePanel(1,self.mpanels[1]) - self.discuss_panel.changePanel(2,self.mpanels[2]) + self.discuss_panel.addWidget(self.mpanels[0]) + self.discuss_panel.addWidget(self.mpanels[1]) + self.discuss_panel.addWidget(self.mpanels[2]) self._register_box = None RootPanel().add(self.panel) DOM.addEventPreview(self)