Browse files

add an info display example using split panel, treeview and grid sele…

…ction

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@183 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
1 parent fe67c13 commit be119eb3c40000e75a3afe032afadae67c039672 lkcl committed Jan 7, 2009
View
104 examples/infohierarchy/InfoDirectory.py
@@ -0,0 +1,104 @@
+from pyjamas.ui import RootPanel, HTML, Label, HasAlignment, Button
+from pyjamas.ui import HorizontalPanel, AbsolutePanel, ScrollPanel, Grid
+from pyjamas import Window
+
+from pyjamas.horizsplitpanel import HorizontalSplitPanel
+
+from Trees import Trees
+
+class MidPanel(Grid):
+
+ def __init__(self):
+ Grid.__init__(self)
+ self.resize(1, 1)
+
+ def set_items(self, items):
+
+ self.resizeRows(len(items))
+ for i in range(len(items)):
+ self.setHTML(i, 0, items[i])
+
+class InfoDirectory:
+
+ def onModuleLoad(self):
+
+ self.tree_width = 300
+
+ self.tp = HorizontalPanel()
+ self.tp.setWidth("%dpx" % (self.tree_width-20))
+ self.tp.setBorderWidth("1px")
+ self.treeview = Trees()
+ self.treeview.fTree.addTreeListener(self)
+ self.sp = ScrollPanel()
+ self.tp.add(self.treeview)
+ self.sp.add(self.tp)
+
+ self.horzpanel1 = HorizontalPanel()
+ self.horzpanel1.setSize("100%", "100%")
+ self.horzpanel1.setBorderWidth("1px")
+
+ self.hp = HorizontalPanel()
+ self.hp.setWidth("800px")
+ self.hp.setHeight("100%")
+ self.horzpanel2 = HorizontalSplitPanel()
+ self.horzpanel2.setSize("100%", "100%")
+ self.horzpanel2.setSplitPosition("200px")
+ self.hp.add(self.horzpanel2)
+ self.hp.setBorderWidth("1px")
+
+ randomText = ""
+ for i in range(200):
+ randomText += "hello %d " % i
+
+ self.horzpanel2.setLeftWidget(HTML(randomText))
+ self.horzpanel2.setRightWidget(HTML(randomText))
+
+ self.horzpanel1.add(self.sp)
+ self.horzpanel1.add(self.hp)
+
+ self.midpanel = MidPanel()
+
+ RootPanel().add(self.horzpanel1)
+
+ width = Window.getClientWidth()
+ height = Window.getClientHeight()
+
+ self.onWindowResized(width, height)
+ Window.addWindowResizeListener(self)
+
+ def onWindowResized(self, width, height):
+ self.hp.setWidth("%dpx" % (width - self.tree_width))
+ self.hp.setHeight("%dpx" % (height - 20))
+ self.sp.setHeight("%dpx" % (height - 20))
+
+ def onTreeItemStateChanged(self, item):
+ if item.isSelected():
+ self.onTreeItemSelected(item)
+
+ def onTreeItemSelected(self, item):
+
+ obj = item.getUserObject()
+ if len(obj.children) != 0:
+ self.clear_mid_panel()
+ return
+
+ self.set_mid_panel(obj.text)
+
+ def clear_right_panel(self):
+ self.horzpanel2.setRightWidget(HTML(""))
+
+ def clear_mid_panel(self):
+ self.clear_right_panel()
+ self.horzpanel2.setLeftWidget(HTML(""))
+
+ def set_mid_panel(self, fake_text):
+
+ fake_items = []
+ for i in range(len(fake_text)):
+ fake_item = "%d - " % (i+1) + fake_text
+ fake_items.append(fake_item)
+
+ self.midpanel.set_items(fake_items)
+
+ self.horzpanel2.setLeftWidget(self.midpanel)
+
View
119 examples/infohierarchy/Trees.py
@@ -0,0 +1,119 @@
+from pyjamas.ui import Tree, TreeItem, Composite
+
+class Trees(Composite):
+ def __init__(self):
+ Composite.__init__(self)
+
+ self.fProto = [
+ Proto("Beethoven", [
+ Proto("Concertos", [
+ Proto("No. 1 - C"),
+ Proto("No. 2 - B-Flat Major"),
+ Proto("No. 3 - C Minor"),
+ Proto("No. 4 - G Major"),
+ Proto("No. 5 - E-Flat Major")
+ ]),
+ Proto("Quartets", [
+ Proto("Six String Quartets"),
+ Proto("Three String Quartets"),
+ Proto("Grosse Fugue for String Quartets")
+ ]),
+ Proto("Sonatas", [
+ Proto("Sonata in A Minor"),
+ Proto("Sonata in F Major")
+ ]),
+ Proto("Symphonies", [
+ Proto("No. 1 - C Major"),
+ Proto("No. 2 - D Major"),
+ Proto("No. 3 - E-Flat Major"),
+ Proto("No. 4 - B-Flat Major"),
+ Proto("No. 5 - C Minor"),
+ Proto("No. 6 - F Major"),
+ Proto("No. 7 - A Major"),
+ Proto("No. 8 - F Major"),
+ Proto("No. 9 - D Minor")
+ ])
+ ]),
+
+ Proto("Brahms", [
+ Proto("Concertos", [
+ Proto("Violin Concerto"),
+ Proto("Double Concerto - A Minor"),
+ Proto("Piano Concerto No. 1 - D Minor"),
+ Proto("Piano Concerto No. 2 - B-Flat Major")
+ ]),
+ Proto("Quartets", [
+ Proto("Piano Quartet No. 1 - G Minor"),
+ Proto("Piano Quartet No. 2 - A Major"),
+ Proto("Piano Quartet No. 3 - C Minor"),
+ Proto("String Quartet No. 3 - B-Flat Minor")
+ ]),
+ Proto("Sonatas", [
+ Proto("Two Sonatas for Clarinet - F Minor"),
+ Proto("Two Sonatas for Clarinet - E-Flat Major")
+ ]),
+ Proto("Symphonies", [
+ Proto("No. 1 - C Minor"),
+ Proto("No. 2 - D Minor"),
+ Proto("No. 3 - F Major"),
+ Proto("No. 4 - E Minor")
+ ])
+ ]),
+
+ Proto("Mozart", [
+ Proto("Concertos", [
+ Proto("Piano Concerto No. 12"),
+ Proto("Piano Concerto No. 17"),
+ Proto("Clarinet Concerto"),
+ Proto("Violin Concerto No. 5"),
+ Proto("Violin Concerto No. 4")
+ ]),
+ ])
+ ]
+
+ self.fTree = Tree()
+
+ for i in range(len(self.fProto)):
+ self.createItem(self.fProto[i])
+ self.fTree.addItem(self.fProto[i].item)
+
+ self.fTree.addTreeListener(self)
+ self.initWidget(self.fTree)
+
+ def onTreeItemSelected(self, item):
+ pass
+
+ def onTreeItemStateChanged(self, item):
+ child = item.getChild(0)
+ if hasattr(child, "isPendingItem"):
+ item.removeItem(child)
+
+ proto = item.getUserObject()
+ for i in range(len(proto.children)):
+ self.createItem(proto.children[i])
+ item.addItem(proto.children[i].item)
+
+ def createItem(self, proto):
+ proto.item = TreeItem(proto.text)
+ proto.item.setUserObject(proto)
+ if len(proto.children) > 0:
+ proto.item.addItem(PendingItem())
+
+
+class Proto:
+ def __init__(self, text, children=None):
+ self.children = []
+ self.item = None
+ self.text = text
+
+ if children != None:
+ self.children = children
+
+
+class PendingItem(TreeItem):
+ def __init__(self):
+ TreeItem.__init__(self, "Please wait...")
+
+ def isPendingItem(self):
+ return True
+
View
1 examples/infohierarchy/build.sh
@@ -0,0 +1 @@
+python ../../builder/build.py InfoDirectory.py
View
BIN examples/infohierarchy/public/.SplitPanel.css.swp
Binary file not shown.
View
16 examples/infohierarchy/public/InfoDirectory.css
@@ -0,0 +1,16 @@
+.gwt-HorizontalSplitPanel {
+}
+
+.gwt-HorizontalSplitPanel .hsplitter {
+ cursor: move;
+ border: 0px;
+ background: #91c0ef url(images/vborder.png) repeat-x;
+}
+.gwt-VerticalSplitPanel {
+}
+
+.gwt-VerticalSplitPanel .vsplitter {
+ cursor: move;
+ border: 0px;
+ background: #91c0ef url(images/hborder.png) repeat-x;
+}
View
12 examples/infohierarchy/public/InfoDirectory.html
@@ -0,0 +1,12 @@
+<html>
+ <head>
+ <meta name="pygwt:module" content="InfoDirectory">
+ <title>InfoDirectory</title>
+ <link rel="stylesheet" href="InfoDirectory.css" />
+
+ </head>
+ <body bgcolor="white">
+ <script language="javascript" src="pygwt.js"></script>
+ </body>
+</html>
+
View
BIN examples/infohierarchy/public/images/hborder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN examples/infohierarchy/public/images/vborder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN examples/infohierarchy/public/splitPanelThumb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit be119eb

Please sign in to comment.