changeset 90:9729ed7171a6

browser side: Widgets' setting (col & row span can be changed
author Goffi <goffi@goffi.org>
date Tue, 28 Jun 2011 01:54:36 +0200
parents 8d2c7be09eef
children 5f845345176e
files browser_side/dialog.py browser_side/panels.py
diffstat 2 files changed, 101 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/dialog.py	Mon Jun 27 20:10:29 2011 +0200
+++ b/browser_side/dialog.py	Tue Jun 28 01:54:36 2011 +0200
@@ -31,6 +31,7 @@
 from pyjamas.ui.Frame import Frame
 from pyjamas.ui import HasAlignment
 from pyjamas.ui.KeyboardListener import KEY_ESCAPE, KEY_ENTER
+from pyjamas import DOM
 
 class ContactsChooser(DialogBox):
 
@@ -249,3 +250,61 @@
         sender.setText('')
         self.list_box.setItemSelected(self.list_box.getItemCount()-1, "selected")
 
+class IntSetter(HorizontalPanel):
+    """This class show a bar with button to set an int value"""
+
+    def __init__(self, label, value=0, value_max=None, visible_len=3):
+        """initialize the intSetter
+        @param label: text shown in front of the setter
+        @param value: initial value
+        @param value_max: limit value, None or 0 for unlimited"""
+        HorizontalPanel.__init__(self)
+        self.value = value
+        self.value_max = value_max
+        _label = Label(label)
+        self.add(_label)
+        self.setCellWidth(_label, "100%")
+        minus_button = Button("-", self.onMinus)
+        self.box = TextBox()
+        self.box.setVisibleLength(visible_len)
+        self.box.setText(str(value))
+        self.box.addInputListener(self)
+        plus_button = Button("+", self.onPlus)
+        self.add(minus_button)
+        self.add(self.box)
+        self.add(plus_button)
+        self.valueChangedListener = []
+
+    def addValueChangeListener(self, listener):
+        self.valueChangedListener.append(listener)
+
+    def removeValueChangeListener(self, listener):
+        if listener in self.valueChangedListener:
+            self.valueChangedListener.remove(listener)
+
+    def _callListeners(self):
+        for listener in self.valueChangedListener:
+            listener(self.value)
+    
+    def onMinus(self, sender):
+        self.value=max(0,self.value-1)
+        self.box.setText(str(self.value))
+        self._callListeners()
+        
+    def onPlus(self, sender):
+        self.value+=1
+        if self.value_max:
+            self.value = min(self.value,value_max)
+        self.box.setText(str(self.value))
+        self._callListeners()
+
+    def onInput(self, sender):
+        """Accept only valid integer && normalize print (no leading 0)"""
+        try:
+            self.value = int(self.box.getText())
+        except ValueError:
+            pass
+        if self.value_max:
+            self.value = min(self.value,value_max)
+        self.box.setText(str(self.value))
+        self._callListeners()
--- a/browser_side/panels.py	Mon Jun 27 20:10:29 2011 +0200
+++ b/browser_side/panels.py	Tue Jun 28 01:54:36 2011 +0200
@@ -167,17 +167,38 @@
         if self.__selectable:
             self.addClickListener(self)
         self.host.registerWidget(self)
+
+    def _getWidgetsPanel(self):
+        return self.getParent().getParent().getParent() 
     
     def onClick(self, sender):
         self.host.select(self)
 
     def onClose(self, sender):
         print "onClose:", sender
-        _widgetspanel = self.getParent().getParent().getParent()
+        _widgetspanel = self._getWidgetsPanel()
         _widgetspanel.removeWidget(self)
 
     def onSetting(self, sender):
-        Window.alert('settings')
+        widpanel = self._getWidgetsPanel()
+        row, col = widpanel.getIndex(self)
+        body = VerticalPanel()
+        colspan = widpanel.getColSpan(row, col)
+        rowspan = widpanel.getRowSpan(row, col)
+        def onColSpanChange(value):
+            widpanel.setColSpan(row, col, value) 
+        def onRowSpanChange(value):
+            widpanel.setRowSpan(row, col, value) 
+        colspan_setter = dialog.IntSetter("Columns span", colspan)
+        colspan_setter.addValueChangeListener(onColSpanChange)
+        colspan_setter.setWidth('100%')
+        rowspan_setter = dialog.IntSetter("Rows span", rowspan)
+        rowspan_setter.addValueChangeListener(onRowSpanChange)
+        rowspan_setter.setWidth('100%')
+        body.add(colspan_setter)
+        body.add(rowspan_setter)
+        _dialog = dialog.GenericDialog("Widget setting", body)
+        _dialog.show()
 
     def setTitle(self, text):
         """change the title in the header of the widget
@@ -750,6 +771,25 @@
             self._max_cols = _max_cols
             self._sizesAdjust()
 
+    def getIndex(self, wid):
+        return self.flextable.getIndex(wid)
+
+    def getColSpan(self, row, col):
+        cellFormatter = self.flextable.getFlexCellFormatter()
+        return cellFormatter.getColSpan(row, col)
+    
+    def setColSpan(self, row, col, value):
+        cellFormatter = self.flextable.getFlexCellFormatter()
+        return cellFormatter.setColSpan(row, col, value)
+    
+    def getRowSpan(self, row, col):
+        cellFormatter = self.flextable.getFlexCellFormatter()
+        return cellFormatter.getRowSpan(row, col)
+    
+    def setRowSpan(self, row, col, value):
+        cellFormatter = self.flextable.getFlexCellFormatter()
+        return cellFormatter.setRowSpan(row, col, value)
+
 class MainDiscussionPanel(HorizontalPanel):
     
     def __init__(self, host):