class AdinfoIFACE(PanelIFACE): def __init__(self, parent = None): PanelIFACE.__init__(self, parent) self.panel = ScrollPanel() adinfo = HTML("", Size=("100%", parent.getHeight())) self.panel.setSize("100%", parent.getHeight()) self.panel.add(adinfo) self.adInfo = parent.adInfo = adinfo Window.addWindowResizeListener(self) return def onTreeItemSelected(self, item): pathdict = self.pathdict filename = item.getText() #check if already in if filename in pathdict: if pathdict[filename]["filetype"] == "fileEntry": url = "adinfo?filename=%s" % self.pathdict[item.getText()]["path"] HTTPRequest().asyncGet(url, ADInfoLoader(self), ) else: self.adInfo.setHTML(""" <b style="font-size:200%%">%s</b>""" % pathdict[filename]["filetype"]) def scroll(self, where): self.panel.setScrollPosition(where) def onWindowResized(self, width, height): self.panel.setSize("100%", self.parent.getHeight()) self.adInfo.setSize("100%", self.parent.getHeight())
def __init__(self): SimplePanel.__init__(self) vert = VerticalPanel() vert.setSpacing("10px") self.add(vert) panel = ScrollPanel(Size=("300px", "100px")) contents = HTML("<b>Tao Te Ching, Chapter One</b><p>" + "The Way that can be told of is not an unvarying " + "way;<p>The names that can be named are not " + "unvarying names.<p>It was from the Nameless that " + "Heaven and Earth sprang;<p>The named is but the " + "mother that rears the ten thousand creatures, " + "each after its kind.") panel.add(contents) vert.add(panel) container = SimplePanel(Width="400px", Height="200px") contents2 = HTML( 50 * "Dont forget to grab the css for SuperScrollPanel in Showcase.css! " ) panel2 = SuperScrollPanel(contents2) container.add(panel2) vert.add(container)
def panel ( ui ): """ Creates a panel-based user interface for a specified UI object. """ # Bind the context values to the 'info' object: ui.info.bind_context() # Get the content that will be displayed in the user interface: content = ui._groups nr_groups = len(content) if nr_groups == 0: panel = None if nr_groups == 1: panel = _GroupPanel(content[0], ui).control elif nr_groups > 1: panel = TabPanel() _fill_panel(panel, content, ui) panel.ui = ui # If the UI is scrollable then wrap the panel in a scroll area. if ui.scrollable and panel is not None: sp = ScrollPanel() sp.add(panel) panel = sp return panel
class HorizontalCollapsePanel(FlowPanel): def __init__(self, *args, **kwargs): # set defaults if not 'StyleName' in kwargs: kwargs['StyleName'] = "rjw-HorizontalCollapsePanel" FlowPanel.__init__(self, *args, **kwargs) self._containers = [ ScrollPanel(StyleName = self.getStylePrimaryName() + '-left'), ScrollPanel(StyleName = self.getStylePrimaryName() + '-right'), ] self._collapse_widget = ScrollPanel(StyleName = self.getStylePrimaryName() + '-collapse') collapse_button = ToggleButton(StyleName = self.getStylePrimaryName() + '-collapse-button') collapse_button.addClickListener(self._sync_collapse) self._collapse_widget.add(collapse_button) FlowPanel.add(self, self._containers[0]) FlowPanel.add(self, self._collapse_widget) FlowPanel.add(self, self._containers[1]) self._sync_collapse() def _sync_collapse(self, w=None): collapse_button = self._collapse_widget.getWidget(0) if collapse_button.isDown(): self.addStyleName(self.getStylePrimaryName() + '-collapsed') else: self.removeStyleName(self.getStylePrimaryName() + '-collapsed') def getWidget(self, index): if index >= 0 and index < len(self._containers): return self._containers[index].getWidget() console.error('HorizontalCollapsePanel.getWidget passed invalid index: ' + str(index)) raise IndexError('Index out of range') def setWidget(self, index, widget): if index >= 0 and index < len(self._containers): return self._containers[index].setWidget(widget) console.error('HorizontalCollapsePanel.setWidget passed invalid index: ' + str(index)) raise IndexError('Index out of range') # Adds a widget to a pane def add(self, widget): if self.getWidget(0) == None: self.setWidget(0, widget) elif self.getWidget(1) == None: self.setWidget(1, widget) else: console.error("HorizontalCollapsePanel can only contain two child widgets.") # Removes a child widget. def remove(self, widget): if self.getWidget(0) == widget: self._containers[0].remove(widget) elif self.getWidget(1) == widget: self._containers[1].remove(widget) else: AbsolutePanel.remove(self, widget)
def __init__(self): HorizontalPanel.__init__(self, Spacing=4) self.add(Label('Underway:', StyleName='section')) s = ScrollPanel() self.add(s) v = VerticalPanel() s.add(v) self.queued = Grid(StyleName='users') v.add(self.queued) self.button = Button('Refresh', self, StyleName='refresh') self.add(self.button) self.err = Label() self.add(self.err) self.update()
def __init__(self): HorizontalPanel.__init__(self, Spacing=4) self.add(Label("Queued:", StyleName="section")) s = ScrollPanel() self.add(s) v = VerticalPanel() s.add(v) self.queued = Grid(StyleName="users") v.add(self.queued) self.button = Button("Refresh", self, StyleName="refresh") self.add(self.button) self.err = Label() self.add(self.err) self.update()
def __init__(self): SimplePanel.__init__(self) panel = ScrollPanel(Size=("300px", "100px")) contents = HTML("<b>Tao Te Ching, Chapter One</b><p>" + "The Way that can be told of is not an unvarying " + "way;<p>The names that can be named are not " + "unvarying names.<p>It was from the Nameless that " + "Heaven and Earth sprang;<p>The named is but the " + "mother that rears the ten thousand creatures, " + "each after its kind.") panel.add(contents) self.add(panel)
def onModuleLoad(self): # build image display img = Image("babykatie_small.jpg", width="300px", height="300px") img.element.setAttribute("usemap", "#themap") img.element.setAttribute("ismap", "1") imagepanel = ScrollPanel() imagepanel.add(img) # build message display msgpanel = VerticalPanel() msgpanel.add( Label("move mouse over baby katie's eyes, nose and mouth.")) msgarea1 = Label("movement messages") msgpanel.add(msgarea1) msgarea2 = Label("click messages") msgpanel.add(msgarea2) imageClickHandler = MapClickHandler(msgarea1, msgarea2) # build imagemap map = ImageMap("themap", width="300px", height="300px") areas = [ \ NamedMapArea("right eye", "circle", "73, 97, 7"), NamedMapArea("left eye", "circle", "116, 88, 5"), NamedMapArea("nose", "rect", "88, 97, 115, 115", href="http://lkcl.net"), NamedMapArea("mouth", "polygon", "82, 129, 102, 124, 119, 119, 121, 125, 103, 132, 79, 133"), ] for nma in areas: nma.addMouseListener(imageClickHandler) nma.addClickListener(imageClickHandler) map.add(nma) # layout page hpanel = HorizontalPanel() hpanel.add(map) hpanel.add(imagepanel) hpanel.add(msgpanel) RootPanel().add(hpanel)
def onModuleLoad(self): # build image display img = Image("babykatie_small.jpg", width="300px", height="300px") img.element.setAttribute("usemap", "#themap") img.element.setAttribute("ismap", "1") imagepanel = ScrollPanel() imagepanel.add(img) # build message display msgpanel = VerticalPanel() msgpanel.add(Label("move mouse over baby katie's eyes, nose and mouth.")) msgarea1 = Label("movement messages") msgpanel.add(msgarea1) msgarea2 = Label("click messages") msgpanel.add(msgarea2) imageClickHandler = MapClickHandler(msgarea1, msgarea2) # build imagemap map = ImageMap("themap", width="300px", height="300px") areas = [ \ NamedMapArea("right eye", "circle", "73, 97, 7"), NamedMapArea("left eye", "circle", "116, 88, 5"), NamedMapArea("nose", "rect", "88, 97, 115, 115", href="http://lkcl.net"), NamedMapArea("mouth", "polygon", "82, 129, 102, 124, 119, 119, 121, 125, 103, 132, 79, 133"), ] for nma in areas: nma.addMouseListener(imageClickHandler) nma.addClickListener(imageClickHandler) map.add(nma) # layout page hpanel = HorizontalPanel() hpanel.add(map) hpanel.add(imagepanel) hpanel.add(msgpanel) RootPanel().add(hpanel)
def __init__(self): SimplePanel.__init__(self) vert = VerticalPanel() vert.setSpacing("10px") self.add(vert) panel = ScrollPanel(Size=("300px", "100px")) contents = HTML("<b>Tao Te Ching, Chapter One</b><p>" + "The Way that can be told of is not an unvarying " + "way;<p>The names that can be named are not " + "unvarying names.<p>It was from the Nameless that " + "Heaven and Earth sprang;<p>The named is but the " + "mother that rears the ten thousand creatures, " + "each after its kind.") panel.add(contents) vert.add(panel) container = SimplePanel(Width="400px", Height="200px") contents2 = HTML(50*"Dont forget to grab the css for SuperScrollPanel in Showcase.css! ") panel2 = SuperScrollPanel(contents2) container.add(panel2) vert.add(container)
class InfoDirectory: def onModuleLoad(self): self.remote = InfoServicePython() self.tree_width = 200 self.tp = HorizontalPanel() self.tp.setWidth("%dpx" % (self.tree_width)) self.treeview = Trees() self.treeview.fTree.addTreeListener(self) self.sp = ScrollPanel() self.tp.add(self.treeview) self.sp.add(self.tp) self.sp.setHeight("100%") self.horzpanel1 = HorizontalPanel() self.horzpanel1.setSize("100%", "100%") self.horzpanel1.setBorderWidth(1) self.horzpanel1.setSpacing("10px") self.rp = RightPanel() self.rps = ScrollPanel() self.rps.add(self.rp) self.rps.setWidth("100%") self.rp.setWidth("100%") self.cp1 = CollapserPanel(self) self.cp1.setWidget(self.sp) self.cp1.setHTML(" ") self.midpanel = MidPanel(self) self.cp2 = CollapserPanel(self) self.cp2.setWidget(self.midpanel) self.cp2.setHTML(" ") self.horzpanel1.add(self.cp1) self.horzpanel1.add(self.cp2) self.horzpanel1.add(self.rps) self.cp1.setInitialWidth("%dpx" % self.tree_width) self.cp2.setInitialWidth("200px") RootPanel().add(self.horzpanel1) width = Window.getClientWidth() height = Window.getClientHeight() self.onWindowResized(width, height) Window.addWindowResizeListener(self) def setCollapserWidth(self, widget, width): self.horzpanel1.setCellWidth(widget, width) def onWindowResized(self, width, height): #self.hp.setWidth("%dpx" % (width - self.tree_width)) #self.hp.setHeight("%dpx" % (height - 20)) self.cp1.setHeight("%dpx" % (height - 30)) self.cp2.setHeight("%dpx" % (height - 30)) self.rps.setHeight("%dpx" % (height - 30)) self.horzpanel1.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.remote.get_midpanel_data(obj.root + "/" + obj.text, self) self.cp2.setHTML(obj.text) self.clear_right_panel() def clear_right_panel(self): self.horzpanel1.remove(2) self.horzpanel1.insert(HTML(""), 2) self.rp.setTitle(" ") def clear_mid_panel(self): self.clear_right_panel() #self.horzpanel2.setLeftWidget(HTML("")) def set_mid_panel(self, response): self.midpanel.set_items(response) self.cp2.setWidget(self.midpanel) def select_right_grid(self, location, name): self.horzpanel1.remove(2) self.horzpanel1.insert(self.rps, 2) self.rp.setTitle(name) self.remote.get_rightpanel_datanames(location, self) def get_rightpanel_datasets(self, datasets): self.rp.clear_items() self.rp.setup_panels(datasets) for i in range(len(datasets)): item = datasets[i] fname = item[0] self.remote.get_rightpanel_data(fname, fname, i, self) def fill_right_grid(self, data): index = data.get('index') name = data.get('name') if data.has_key('items'): self.rp.add_items(data.get('items'), name, index) elif data.has_key('html'): self.rp.add_html(data.get('html'), name, index) def onRemoteResponse(self, response, request_info): method = request_info.method if method == "get_midpanel_data": self.set_mid_panel(response) elif method == "get_rightpanel_datanames": self.get_rightpanel_datasets(response) elif method == "get_rightpanel_data": self.fill_right_grid(response) def onRemoteError(self, code, message, request_info): RootPanel().add(HTML("Server Error or Invalid Response: ERROR " + code)) RootPanel().add(HTML(message))
class DataDictTree(Sink): pathdict = {} reduceFiles = None fTree = None def __init__(self, parent = None): Sink.__init__(self, parent) self.reduceFiles = [] if True: HTTPRequest().asyncGet("datadir.xml", DirDictLoader(self), ) dock = DockPanel(HorizontalAlignment=HasAlignment.ALIGN_LEFT, Spacing=10, Size=("100%","100%")) self.dock = dock self.fProto = [] self.fTree = Tree() self.treePanel = ScrollPanel() self.treePanel.setSize("100%", str( int( Window.getClientHeight()*.75 ) )+"px") Window.addWindowResizeListener(self) self.treePanel.add(self.fTree) dock.add(self.treePanel, DockPanel.WEST) #self.treePanel.setBorderWidth(1) #self.treePanel.setWidth("100%") prPanel = self.createRightPanel() dock.add(prPanel,DockPanel.EAST) dock.setCellWidth(self.treePanel, "50%") dock.setCellWidth(prPanel, "50%") 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.dock) if False: #self.parent.filexml != None: DirDictLoader(self).onCompletion(self.parent.filexml) def onWindowResized(self, width, height): self.treePanel.setSize("100%", str( int( height *.75 ) )+"px") def onRecipeSelected(self, event): self.updateReduceCL() def onClearReduceFiles(self, event): self.reduceFiles.clear() self.adInfo.setHTML("file info...") self.updateReduceCL() def updateReduceCL(self): recipe = self.recipeList.getItemText(self.recipeList.getSelectedIndex()) if recipe=="None": rstr = "" else: rstr = "-r "+recipe rfiles = [] for i in range(0, self.reduceFiles.getItemCount()): fname = self.reduceFiles.getItemText(i) rfiles.append(fname) filesstr = " ".join(rfiles) self.prepareReduce.setHTML('<b>reduce</b> %(recipe)s %(files)s' % { "recipe":rstr, "files":filesstr}) def onTreeItemSelected(self, item): pathdict = self.pathdict tfile = item.getText() #check if already in if tfile in pathdict: ftype = pathdict[tfile]["filetype"] if ftype != "fileEntry": item.setState(True) return else: return for i in range(0, self.reduceFiles.getItemCount()): fname = self.reduceFiles.getItemText(i) if fname == tfile: return self.reduceFiles.addItem(tfile) self.updateReduceCL() filename = tfile if filename in pathdict: if pathdict[filename]["filetype"] == "fileEntry": HTTPRequest().asyncGet("adinfo?filename=%s" % self.pathdict[item.getText()]["path"], ADInfoLoader(self), ) else: self.adInfo.setHTML(""" <b style="font-size:200%%">%s</b>""" % pathdict[filename]["filetype"]) else: self.adInfo.setHTML("unknown node") return # self.prepareReduce.setHTML('<a href="runreduce?p=-r&p=callen&p=%(fname)s">reduce -r callen %(fname)s</a>' % # {"fname":item.getText()}) 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]) index = self.getSortIndex(item, proto.children[i].text) # demonstrate insertItem. addItem is easy. item.insertItem(proto.children[i].item, index) item.setState(True) def getSortIndex(self, parent, text): nodes = parent.getChildCount() node = 0 text = text.lower() while node < nodes: item = parent.getChild(node) if cmp(text, item.getText().lower()) < 0: break; else: node += 1 return node def createProto(self, node, parent=None): #if node.nodeType != node.ELEMENT_NODE: # return pathdict = self.pathdict if not node.hasChildNodes(): if node.nodeType != 1: return None nname = node.getAttribute("name") newproto = None newproto = Proto(str(node.getAttribute("name"))) if node.tagName == "fileEntry": pathdict.update({node.getAttribute("name"): { "path":node.getAttribute("fullpath"), "filetype": node.tagName }}) elif node.tagName == "dirEntry": pathdict.update({node.getAttribute("name"): { "path":node.getAttribute("name"), "filetype": node.tagName}}) else: pathdict.update({node.getAttribute("name"): { "path": "NOPATH", "filetype": node.tagName}}) self.createItem(newproto) return newproto else: cprotos = [] for i in range(0, node.childNodes.length): childnode = node.childNodes.item(i) if hasattr(childnode,"getAttribute") and childnode.getAttribute("name") == "files": for j in range(0, childnode.childNodes.length): childnodej = childnode.childNodes.item(j) ncproto = self.createProto(childnodej) if ncproto != None: ncitem = self.createItem(ncproto) cprotos.append(ncproto) else: ncproto = self.createProto(childnode) if ncproto != None: ncitem = self.createItem(ncproto) cprotos.append(ncproto) if len(cprotos)>0: newproto = Proto(str(node.getAttribute("name")),cprotos) else: newproto = Proto(str(node.getAttribute("name"))) if node.tagName == "fileEntry": pathdict.update({node.getAttribute("name"): { "path":node.getAttribute("fullpath"), "filetype": node.tagName }}) elif node.tagName == "dirEntry": pathdict.update({node.getAttribute("name"): { "path":node.getAttribute("name"), "filetype": node.tagName}}) else: pathdict.update({node.getAttribute("name"): { "path": "NOPATH", "filetype": node.tagName}}) self.createItem(newproto) return newproto def fromXML(self,text): doc = create_xml_doc(text) #node = doc.firstChild #node = doc.getElementById("topDirectory") nodes = doc.getElementsByTagName("dirEntry") node = nodes.item(0) s = repr(node) newproto = self.createProto(node) plist = [newproto] #plist = [Proto(node.tagName)] for i in range(len(plist)): num = str(len(plist)) # self.createItem(plist[i]) self.fTree.addItem(plist[i].item) plist[i].item.setState(True) def onShow(self): if False: for item in self.fTree.treeItemIterator(): key = repr(item.tree) if key != "null": item.setState(True) else: JS("alert(item.getText())") pass def createItem(self, proto): proto.item = TreeItem(proto.text) proto.item.setUserObject(proto) if len(proto.children) > 0: proto.item.addItem(PendingItem())
class SongFrequency: def __init__(self): self.artist ='' self.start_date = '' self.end_date = '' self.period_search ='' self.search_option = 1 #declare the general interface widgets self.panel = DockPanel(StyleName = 'background') self.ret_area = TextArea() self.ret_area.setWidth("350px") self.ret_area.setHeight("90px") self.options = ListBox() self.search_button = Button("Search", getattr(self, "get_result"), StyleName = 'button') #set up the date search panel; it has different text boxes for #to and from search dates self.date_search_panel = VerticalPanel() self.date_search_start = TextBox() self.date_search_start.addInputListener(self) self.date_search_end = TextBox() self.date_search_end.addInputListener(self) self.date_search_panel.add(HTML("Enter as month/day/year", True, StyleName = 'text')) self.date_search_panel.add(HTML("From:", True, StyleName = 'text')) self.date_search_panel.add(self.date_search_start) self.date_search_panel.add(HTML("To:", True, StyleName = 'text')) self.date_search_panel.add(self.date_search_end) #set up the artist search panel self.artist_search = TextBox() self.artist_search.addInputListener(self) self.artist_search_panel = VerticalPanel() self.artist_search_panel.add(HTML("Enter artist's name:",True, StyleName = 'text')) self.artist_search_panel.add(self.artist_search) #Put together the list timespan search options self.period_search_panel = VerticalPanel() self.period_search_panel.add(HTML("Select a seach period:",True, StyleName = 'text')) self.period_search = ListBox() self.period_search.setVisibleItemCount(1) self.period_search.addItem("last week") self.period_search.addItem("last month") self.period_search.addItem("last year") self.period_search.addItem("all time") self.period_search_panel.add(self.period_search) #add the listeners to the appropriate widgets self.options.addChangeListener(self) self.period_search.addChangeListener(self) self.ret_area_scroll = ScrollPanel() self.search_panel = HorizontalPanel() self.options_panel = VerticalPanel() # A change listener for the boxes def onChange(self, sender): #switch the list box options if sender == self.options: self.search_panel.remove(self.period_search_panel) self.search_panel.remove(self.date_search_panel) self.search_panel.remove(self.artist_search_panel) index = self.options.getSelectedIndex() if index == 0: self.search_panel.add(self.artist_search_panel) self.search_option = 1 elif index == 1: self.search_panel.add(self.date_search_panel) self.search_option = 2 elif index == 2: self.search_panel.add(self.period_search_panel) self.search_option = 3 elif sender == self.period_search: index = self.period_search.getSelectedIndex() if index == 0: self.period_search = "last week" elif index == 1: self.period_search = "last month" elif index == 2: self.period_search = "last year" elif index == 3: self.period_search = "all time" #A listener for the text boxes def onInput(self, sender): if sender == self.artist_search: self.artist = sender.getText() elif sender == self.date_search_end: self.end_date = sender.getText() elif sender == self.date_search_start: self.start_date = sender.getText() #A listener for the buttons that, when the button is clicked, looks up the results and outputs them def get_result(self): return_str = " " if self.search_option == 1: return_str = self.artist elif self.search_option == 2: return_str = self.start_date elif self.search_option ==3: return_str = self.period_search else: return_str = "Find the most played artist, album, or song for a time period, or the number of songs played by a certain artist" self.ret_area.setText(return_str) def onModuleLoad(self): #Put together the list of options self.options.addItem("Artist") self.options.addItem("Date") self.options.addItem("Time Span") self.options.setVisibleItemCount(3) #put the text area together self.ret_area_scroll.add(self.ret_area) self.ret_area.setText("Find the most played artist, album, or song for a time period, or the number of songs played by a certain artist") #put the search items together self.search_panel.add(self.artist_search_panel) #Put together the options panel self.options_panel.add(HTML("Search By:", True, StyleName = 'text')) self.options_panel.add(self.options) #Add everything to the main panel self.panel.add(HTML("WQHS Song Search",True, StyleName = 'header'), DockPanel.NORTH) self.panel.add(self.options_panel, DockPanel.WEST) self.panel.add(self.ret_area_scroll, DockPanel.SOUTH) self.panel.setCellHeight(self.ret_area_scroll, "100px") self.panel.setCellWidth(self.ret_area_scroll, "300px") self.panel.add(self.search_button, DockPanel.EAST) self.panel.add(self.search_panel, DockPanel.CENTER) #Associate panel with the HTML host page RootPanel().add(self.panel)