class GWTCanvasDemo: # can be overriden to use another canvas class def _get_canvas(self): return GWTCanvas(400,400) def onModuleLoad(self): self.layout = HorizontalPanel() # Each demo will set their own dimensions, so it doesn't matter # what we initialize the canvas to. Use the overrideable. canvas = self._get_canvas() canvas.addStyleName("gwt-canvas") self.demos = [] # Create demos self.demos.append(StaticDemo(canvas)) self.demos.append(LogoDemo(canvas)) self.demos.append(ParticleDemo(canvas)) self.demos.append(GradientDemo(canvas)) self.demos.append(SuiteDemo(canvas)) # Add them to the selection list box lb = ListBox() lb.setStyleName("listBox") for i in range(len(self.demos)): lb.addItem(self.demos[i].getName()) lb.addChangeListener(self) # start off with the first demo self.currentDemo = self.demos[0] # Add widgets to self.layout and RootPanel vp = VerticalPanel() vp.add(lb) vp.add(canvas) self.layout.add(vp) if self.currentDemo.getControls() is not None: self.layout.add(self.currentDemo.getControls()) RootPanel().add(self.layout) self.currentDemo.drawDemo() def onChange(self, listBox): choice = listBox.getSelectedIndex() self.swapDemo(self.demos[choice]) """ * Changes the current demo for the input demo """ def swapDemo(self, newDemo): self.currentDemo.stopDemo() self.layout.remove(self.currentDemo.getControls()) self.currentDemo = newDemo self.layout.add(self.currentDemo.getControls()) self.currentDemo.drawDemo()
class GWTCanvasDemo: # can be overriden to use another canvas class def _get_canvas(self): return GWTCanvas(400, 400) def onModuleLoad(self): self.layout = HorizontalPanel() # Each demo will set their own dimensions, so it doesn't matter # what we initialize the canvas to. Use the overrideable. canvas = self._get_canvas() canvas.addStyleName("gwt-canvas") self.demos = [] # Create demos self.demos.append(StaticDemo(canvas)) self.demos.append(LogoDemo(canvas)) self.demos.append(ParticleDemo(canvas)) self.demos.append(GradientDemo(canvas)) self.demos.append(SuiteDemo(canvas)) # Add them to the selection list box lb = ListBox() lb.setStyleName("listBox") for i in range(len(self.demos)): lb.addItem(self.demos[i].getName()) lb.addChangeListener(self) # start off with the first demo self.currentDemo = self.demos[0] # Add widgets to self.layout and RootPanel vp = VerticalPanel() vp.add(lb) vp.add(canvas) self.layout.add(vp) if self.currentDemo.getControls() is not None: self.layout.add(self.currentDemo.getControls()) RootPanel().add(self.layout) self.currentDemo.drawDemo() def onChange(self, listBox): choice = listBox.getSelectedIndex() self.swapDemo(self.demos[choice]) """ * Changes the current demo for the input demo """ def swapDemo(self, newDemo): self.currentDemo.stopDemo() self.layout.remove(self.currentDemo.getControls()) self.currentDemo = newDemo self.layout.add(self.currentDemo.getControls()) self.currentDemo.drawDemo()
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 TabBar(Composite): STYLENAME_DEFAULT = "gwt-TabBarItem" def __init__(self, **kwargs): if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-TabBar" # this is awkward: HorizontalPanel is the composite, # so we either the element here, and pass it in to HorizontalPanel. element = None if kwargs.has_key('Element'): element = kwargs.pop('Element') self.panel = HorizontalPanel(Element=element) self.selectedTab = None self.tabListeners = [] self.panel.setVerticalAlignment(HasAlignment.ALIGN_BOTTOM) first = HTML(" ", True) rest = HTML(" ", True) first.setStyleName("gwt-TabBarFirst") rest.setStyleName("gwt-TabBarRest") first.setHeight("100%") rest.setHeight("100%") self.panel.add(first) self.panel.add(rest) first.setHeight("100%") self.panel.setCellHeight(first, "100%") self.panel.setCellWidth(rest, "100%") Composite.__init__(self, self.panel, **kwargs) self.sinkEvents(Event.ONCLICK) def addTab(self, text, asHTML=False): self.insertTab(text, asHTML, self.getTabCount()) def addTabListener(self, listener): self.tabListeners.append(listener) def getSelectedTab(self): if self.selectedTab is None: return -1 return self.panel.getWidgetIndex(self.selectedTab) - 1 def getTabCount(self): return self.panel.getWidgetCount() - 2 def getTabHTML(self, index): if index >= self.getTabCount(): return None delPanel = self.panel.getWidget(index + 1) focusablePanel = delPanel.getFocusablePanel() widget = focusablePanel.getWidget() if hasattr(widget, "getHTML"): return widget.getHTML() elif hasattr(widget, "getText"): # assume it's a Label if it has getText return widget.getText() else: fpe = DOM.getParent(self.focusablePanel.getElement()) return DOM.getInnerHTML(fpe) def createTabTextWrapper(self): return None def insertTab(self, text, asHTML, beforeIndex=None): """ 1st arg can, instead of being 'text', be a widget. 1st arg can also be None, which results in a blank space between tabs. Use this to push subsequent tabs out to the right hand end of the TabBar. (the "blank" tab, by not being focussable, is not clickable). """ if beforeIndex is None: beforeIndex = asHTML asHTML = False if (beforeIndex < 0) or (beforeIndex > self.getTabCount()): #throw new IndexOutOfBoundsException(); pass if text is None: text = HTML(" ", True) text.setWidth("100%") text.setStyleName("gwt-TabBarRest") self.panel.insert(text, beforeIndex + 1) self.panel.setCellWidth(text, "100%") return istext = isinstance(text, basestring) if istext: if asHTML: item = HTML(text) else: item = Label(text) item.setWordWrap(False) else: # passing in a widget, it's expected to have its own style item = text self.insertTabWidget(item, beforeIndex) def insertTabWidget(self, widget, beforeIndex): delWidget = ClickDelegatePanel(self, widget, self, self) delWidget.setStyleName(self.STYLENAME_DEFAULT) focusablePanel = delWidget.getFocusablePanel() self.panel.insert(delWidget, beforeIndex + 1) self.setStyleName(DOM.getParent(delWidget.getElement()), self.STYLENAME_DEFAULT + "-wrapper", True) #print "insertTabWidget", DOM.getParent(delWidget.getElement()), DOM.getAttribute(DOM.getParent(delWidget.getElement()), "className") def onClick(self, sender=None): for i in range(1, self.panel.getWidgetCount() - 1): if DOM.isOrHasChild(self.panel.getWidget(i).getElement(), sender.getElement()): return self.selectTab(i - 1) return False def removeTab(self, index): self.checkTabIndex(index) toRemove = self.panel.getWidget(index + 1) if toRemove == self.selectedTab: self.selectedTab = None self.panel.remove(toRemove) def removeTabListener(self, listener): self.tabListeners.remove(listener) def selectTab(self, index): self.checkTabIndex(index) for listener in self.tabListeners: if not listener.onBeforeTabSelected(self, index): return False self.setSelectionStyle(self.selectedTab, False) if index == -1: self.selectedTab = None return True self.selectedTab = self.panel.getWidget(index + 1) self.setSelectionStyle(self.selectedTab, True) for listener in self.tabListeners: listener.onTabSelected(self, index) return True def checkTabIndex(self, index): if (index < -1) or (index >= self.getTabCount()): #throw new IndexOutOfBoundsException(); pass def setSelectionStyle(self, item, selected): if item is not None: if selected: item.addStyleName("gwt-TabBarItem-selected") self.setStyleName(DOM.getParent(item.getElement()), "gwt-TabBarItem-wrapper-selected", True) else: item.removeStyleName("gwt-TabBarItem-selected") self.setStyleName(DOM.getParent(item.getElement()), "gwt-TabBarItem-wrapper-selected", False)
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 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)