def __init__(self, contentitem, onPublish, onLike, onDislike): """Create a ContentItemCell. Event handlers should be methods that take: sender, contentitem """ DisclosurePanel.__init__(self, header=ContentItemCell.create_title(contentitem), isOpen=False) self.getHeader().setStyleName(Styles.CONTENTITEM_CELL_HEADER) self.panel = VerticalPanel(StyleName=Styles.CONTENTITEM_CELL_CONTENT) self.add(self.panel) self.toolbar = ContentItemToolbar(contentitem, onPublish=lambda sndr: onPublish(self, self.contentitem), onLike=lambda sndr: onLike(self, self.contentitem), onDislike=lambda sndr: onDislike(self, self.contentitem)) self.panel.add(self.toolbar) self.panel.add(ContentItemComponent('ID', contentitem['id'])) self.panel.add(ContentItemComponent('Title', contentitem['title'])) self.panel.add(ContentItemComponent('Summary', contentitem['summary'])) self.panel.add(ContentItemComponent('Author', contentitem['author'])) self.panel.add(ContentItemComponent('Datetime', self.pretty_format_datetime(contentitem['datetime']))) self.panel.add(ContentItemComponent('Url', '<a href="%s">%s</a>' % (contentitem['url'], contentitem['url']))) self.panel.add(ContentItemComponent('Categories', contentitem['categories'])) self.panel.add(ContentItemComponent('Content', contentitem['html'])) self.contentitem = contentitem return
def __init__( self ) : # This is the service that will be used to communicate with the DAQ software self.rpcService = GlibRPCService.instance() # The main panel that everythings will be insided self.mainPanel = HorizontalPanel() self.mainPanel.setSpacing(10) self.i2cValueEntries = {} # The input boxes for all the registers self.statusValueEntries = {} # Displays the status of the i2cValueEntries self.stateValueEntries = {} # For load/save state self.fileName = {} # File name of the i2c registers # This is the list of available CBC chips. It will be populated by a call to the # server later. self.cbcList=ListBox(MultipleSelect=True, VisibleItemCount=10) self.cbcList.addItem( "waiting..." ) # Default text until I hear from the server what's connected self.cbcList.setEnabled( False ) self.cbcList.addChangeListener(self) self.rpcService.connectedCBCNames( None, I2CPanel.ConnectedCBCListener(self.cbcList) ) # Ask the server what's connected # This is the panel that will have the list of I2C registers. I'll split up the # registers into subjects to make them more manageable. self.mainSettings = DisclosurePanel("Main Control Registers") self.channelMasks = DisclosurePanel("Channel Masks") self.channelTrims = DisclosurePanel("Channel Trims") self.callSettings = VerticalPanel("Load/Save States") self.callSettings.setBorderWidth(1) self.callSettings.add(HTML("<center>Load/Save State</center>")) cbcListAndCallSettings=VerticalPanel() cbcListAndCallSettings.add(self.cbcList) cbcListAndCallSettings.add(self.callSettings) self.mainPanel.add(cbcListAndCallSettings) self.mainPanel.add(self.mainSettings) self.mainPanel.add(self.channelMasks) self.mainPanel.add(self.channelTrims) self.callSettings.add( self.createStatesPanel()) self.mainSettings.add( self.createRegisterPanel(["FrontEndControl","TriggerLatency","HitDetectSLVS","Ipre1","Ipre2","Ipsf","Ipa","Ipaos","Vpafb","Icomp","Vpc","Vplus","VCth","TestPulsePot","SelTestPulseDel&ChanGroup","MiscTestPulseCtrl&AnalogMux","TestPulseChargePumpCurrent","TestPulseChargeMirrCascodeVolt","CwdWindow&Coincid","MiscStubLogic"]) ) self.channelMasks.add( self.createRegisterPanel(["MaskChannelFrom008downto001","MaskChannelFrom016downto009","MaskChannelFrom024downto017","MaskChannelFrom032downto025","MaskChannelFrom040downto033","MaskChannelFrom048downto041","MaskChannelFrom056downto049","MaskChannelFrom064downto057","MaskChannelFrom072downto065","MaskChannelFrom080downto073","MaskChannelFrom088downto081","MaskChannelFrom096downto089","MaskChannelFrom104downto097","MaskChannelFrom112downto105","MaskChannelFrom120downto113","MaskChannelFrom128downto121","MaskChannelFrom136downto129","MaskChannelFrom144downto137","MaskChannelFrom152downto145","MaskChannelFrom160downto153","MaskChannelFrom168downto161","MaskChannelFrom176downto169","MaskChannelFrom184downto177","MaskChannelFrom192downto185","MaskChannelFrom200downto193","MaskChannelFrom208downto201","MaskChannelFrom216downto209","MaskChannelFrom224downto217","MaskChannelFrom232downto225","MaskChannelFrom240downto233","MaskChannelFrom248downto241","MaskChannelFrom254downto249"]) ) self.channelTrims.add( self.createRegisterPanel(["Channel001","Channel002","Channel003","Channel004","Channel005","Channel006","Channel007","Channel008","Channel009","Channel010","Channel011","Channel012","Channel013","Channel014","Channel015","Channel016","Channel017","Channel018","Channel019","Channel020","Channel021","Channel022","Channel023","Channel024","Channel025","Channel026","Channel027","Channel028","Channel029","Channel030","Channel031","Channel032","Channel033","Channel034","Channel035","Channel036","Channel037","Channel038","Channel039","Channel040","Channel041","Channel042","Channel043","Channel044","Channel045","Channel046","Channel047","Channel048","Channel049","Channel050","Channel051","Channel052","Channel053","Channel054","Channel055","Channel056","Channel057","Channel058","Channel059","Channel060","Channel061","Channel062","Channel063","Channel064","Channel065","Channel066","Channel067","Channel068","Channel069","Channel070","Channel071","Channel072","Channel073","Channel074","Channel075","Channel076","Channel077","Channel078","Channel079","Channel080","Channel081","Channel082","Channel083","Channel084","Channel085","Channel086","Channel087","Channel088","Channel089","Channel090","Channel091","Channel092","Channel093","Channel094","Channel095","Channel096","Channel097","Channel098","Channel099","Channel100","Channel101","Channel102","Channel103","Channel104","Channel105","Channel106","Channel107","Channel108","Channel109","Channel110","Channel111","Channel112","Channel113","Channel114","Channel115","Channel116","Channel117","Channel118","Channel119","Channel120","Channel121","Channel122","Channel123","Channel124","Channel125","Channel126","Channel127","Channel128","Channel129","Channel130","Channel131","Channel132","Channel133","Channel134","Channel135","Channel136","Channel137","Channel138","Channel139","Channel140","Channel141","Channel142","Channel143","Channel144","Channel145","Channel146","Channel147","Channel148","Channel149","Channel150","Channel151","Channel152","Channel153","Channel154","Channel155","Channel156","Channel157","Channel158","Channel159","Channel160","Channel161","Channel162","Channel163","Channel164","Channel165","Channel166","Channel167","Channel168","Channel169","Channel170","Channel171","Channel172","Channel173","Channel174","Channel175","Channel176","Channel177","Channel178","Channel179","Channel180","Channel181","Channel182","Channel183","Channel184","Channel185","Channel186","Channel187","Channel188","Channel189","Channel190","Channel191","Channel192","Channel193","Channel194","Channel195","Channel196","Channel197","Channel198","Channel199","Channel200","Channel201","Channel202","Channel203","Channel204","Channel205","Channel206","Channel207","Channel208","Channel209","Channel210","Channel211","Channel212","Channel213","Channel214","Channel215","Channel216","Channel217","Channel218","Channel219","Channel220","Channel221","Channel222","Channel223","Channel224","Channel225","Channel226","Channel227","Channel228","Channel229","Channel230","Channel231","Channel232","Channel233","Channel234","Channel235","Channel236","Channel237","Channel238","Channel239","Channel240","Channel241","Channel242","Channel243","Channel244","Channel245","Channel246","Channel247","Channel248","Channel249","Channel250","Channel251","Channel252","Channel253","Channel254","ChannelDummy"]) ) self.mainSettings.add() self.echo=Label() self.mainPanel.add(self.echo)
def __init__(self): Composite.__init__(self) self.albums = [] self.photos = [] self.grid = Grid(4, 4, CellPadding=4, CellSpacing=4) self.grid.addTableListener(self) self.drill = 0 self.pos = 0 self.up = Button("Up", self) self.next = Button("Next", self) self.prev = Button("Prev", self) self.timer = Timer(notify=self) self.userid = "jameskhedley" self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb" self.doRESTQuery(self.album_url, self.timer) self.vp = VerticalPanel() self.disclosure = DisclosurePanel( "Click for boring technical details.") self.disclosure.add( HTML( '''<p>OK so you want to write client JS to do a RESTful HTTP query from picasa right? Well you can't because of the Same Origin Policy. Basically this means that because the domain of the query and the domain of the hosted site are different, then that could well be a cross-site scripting (XSS) attack. So, the workaround is to do the call from a script tag so the JSON we get back is part of the document. But since we don't know what URL to hit yet, once we find out then we have to inject a new script tag dynamically which the browser will run as soon as we append it. To be honest I'm not 100% why Google use RESTful services and not JSON-RPC or somesuch, which would be easier. Well, easier for me.''')) self.IDPanel = HorizontalPanel() self.IDPanel.add(Label("Enter google account:")) self.IDButton = Button("Go", self) self.IDBox = TextBox() self.IDBox.setText(self.userid) self.IDPanel.add(self.IDBox) self.IDPanel.add(self.IDButton) self.vp.add(self.IDPanel) self.vp.add(self.disclosure) self.vp.add(self.grid) self.initWidget(self.vp)
def __init__(self): Composite.__init__(self) self.albums = [] self.photos = [] self.grid = Grid(4, 4, CellPadding=4, CellSpacing=4) self.grid.addTableListener(self) self.drill = 0 self.pos = 0 self.up = Button("Up", self) self.next = Button("Next", self) self.prev = Button("Prev", self) self.timer = Timer(notify=self) self.userid = "jameskhedley" self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb" self.doRESTQuery(self.album_url, self.timer) self.vp = VerticalPanel() self.disclosure = DisclosurePanel("Click for boring technical details.") self.disclosure.add(HTML('''<p>OK so you want to write client JS to do a RESTful HTTP query from picasa right? Well you can't because of the Same Origin Policy. Basically this means that because the domain of the query and the domain of the hosted site are different, then that could well be a cross-site scripting (XSS) attack. So, the workaround is to do the call from a script tag so the JSON we get back is part of the document. But since we don't know what URL to hit yet, once we find out then we have to inject a new script tag dynamically which the browser will run as soon as we append it. To be honest I'm not 100% why Google use RESTful services and not JSON-RPC or somesuch, which would be easier. Well, easier for me.''')) self.IDPanel = HorizontalPanel() self.IDPanel.add(Label("Enter google account:")) self.IDButton = Button("Go", self) self.IDBox = TextBox() self.IDBox.setText(self.userid) self.IDPanel.add(self.IDBox) self.IDPanel.add(self.IDButton) self.vp.add(self.IDPanel) self.vp.add(self.disclosure) self.vp.add(self.grid) self.initWidget(self.vp)
def finishgroup(): global curgroup, curgroupwidgets, curgrouphead, fp if curgroup == 0: for widget in curgroupwidgets: fp.add(widget) elif curgroup == 1: dp = DisclosurePanel("Definitions") dpflow = FlowPanel() dp.add(dpflow) for widget in curgroupwidgets: dpflow.add(widget) fp.add(dp) elif curgroup == 2: curgrouphead += " (%s steps)" % (len(curgroupwidgets), ) dp = DisclosurePanel(curgrouphead) dpflow = FlowPanel() dp.add(dpflow) for widget in curgroupwidgets[:-1]: dpflow.add(widget) fp.add(dp) fp.add(curgroupwidgets[-1]) curgroup = 0 curgroupwidgets = [] curgrouphead = None
def finishgroup(): global curgroup, curgroupwidgets, curgrouphead, fp if curgroup == 0: for widget in curgroupwidgets: fp.add(widget) elif curgroup == 1: dp = DisclosurePanel("Definitions") dpflow = FlowPanel() dp.add(dpflow) for widget in curgroupwidgets: dpflow.add(widget) fp.add(dp) elif curgroup == 2: curgrouphead += " (%s steps)" % (len(curgroupwidgets),) dp = DisclosurePanel(curgrouphead) dpflow = FlowPanel() dp.add(dpflow) for widget in curgroupwidgets[:-1]: dpflow.add(widget) fp.add(dp) fp.add(curgroupwidgets[-1]) curgroup = 0 curgroupwidgets = [] curgrouphead = None
class Photos(Composite): def __init__(self): Composite.__init__(self) self.albums = [] self.photos = [] self.grid = Grid(4, 4, CellPadding=4, CellSpacing=4) self.grid.addTableListener(self) self.drill = 0 self.pos = 0 self.up = Button("Up", self) self.next = Button("Next", self) self.prev = Button("Prev", self) self.timer = Timer(notify=self) self.userid = "jameskhedley" self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb" self.doRESTQuery(self.album_url, self.timer) self.vp = VerticalPanel() self.disclosure = DisclosurePanel( "Click for boring technical details.") self.disclosure.add( HTML( '''<p>OK so you want to write client JS to do a RESTful HTTP query from picasa right? Well you can't because of the Same Origin Policy. Basically this means that because the domain of the query and the domain of the hosted site are different, then that could well be a cross-site scripting (XSS) attack. So, the workaround is to do the call from a script tag so the JSON we get back is part of the document. But since we don't know what URL to hit yet, once we find out then we have to inject a new script tag dynamically which the browser will run as soon as we append it. To be honest I'm not 100% why Google use RESTful services and not JSON-RPC or somesuch, which would be easier. Well, easier for me.''')) self.IDPanel = HorizontalPanel() self.IDPanel.add(Label("Enter google account:")) self.IDButton = Button("Go", self) self.IDBox = TextBox() self.IDBox.setText(self.userid) self.IDPanel.add(self.IDBox) self.IDPanel.add(self.IDButton) self.vp.add(self.IDPanel) self.vp.add(self.disclosure) self.vp.add(self.grid) self.initWidget(self.vp) def doRESTQuery(self, url, timer): """this is a totally different from an RPC call in that we have to dynamically add script tags to the DOM when we want to query the REST API. These rely on callbacks in the DOM so we can either add them dynamically or pre-define them in public/Main.html. Once we've done that have to wait for the response. Which means we need to provide a listener for the timer""" new_script = DOM.createElement("script") DOM.setElemAttribute(new_script, "src", url) DOM.setElemAttribute(new_script, "type", "text/javascript") doc().body.appendChild(new_script) self.timer.schedule(100) def onCellClicked(self, sender, row, col): if self.drill == 0: self.drill += 1 self.vp.clear() self.grid.clear() self.vp.add(self.up) self.vp.add(self.grid) gridcols = self.grid.getColumnCount() album = self.albums[row + col + (row * (gridcols - 1))] url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "/albumid/" + album[ "id"] + "?alt=json-in-script&kind=photo&hl=en_US&callback=restCb" self.doRESTQuery(url, self.timer) elif self.drill == 1: self.drill += 1 gridcols = self.grid.getColumnCount() self.pos = row + col + (row * (gridcols - 1)) photo = self.photos[self.pos] self.vp.clear() self.fullsize = HTML('<img src="' + photo["full"] + '"/>') hp = HorizontalPanel() hp.add(self.up) hp.add(self.prev) hp.add(self.next) hp.setSpacing(8) self.vp.add(hp) self.vp.add(self.fullsize) def onClick(self, sender): if sender == self.IDButton: self.userid = self.IDBox.getText() if self.userid == "" or self.userid.isdigit(): return self.drill = 0 self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb" self.grid.clear() self.doRESTQuery(self.album_url, self.timer) else: if self.drill == 2: if sender == self.up: self.drill = 1 self.vp.clear() self.vp.add(self.up) self.vp.add(self.grid) self.fillGrid(self.photos, "photos") else: if sender == self.next: if self.pos >= len(self.photos): return self.pos += 1 elif sender == self.prev: if self.pos < 1: return self.pos -= 1 photo = self.photos[self.pos] self.fullsize.setHTML('<img src="' + photo["full"] + '"/>') elif self.drill == 1: self.drill = 0 self.vp.clear() self.vp.add(self.IDPanel) self.vp.add(self.disclosure) self.vp.add(self.grid) self.fillGrid(self.albums, "albums") def onTimer(self, timer): fd = doc().getElementById("__pygwt_hiddenData") receiver = fd.innerHTML if receiver == 'wait': self.timer.schedule(1000) return fd.innerHTML = 'wait' if self.drill == 0: self.parseAlbums(receiver) self.fillGrid(self.albums, "albums") elif self.drill == 1: self.parsePhotos(receiver) self.fillGrid(self.photos, "photos") def fillGrid(self, items, type): self.grid.clear() cols = self.grid.getColumnCount() self.grid.resizeRows((len(items) / cols) + 1) rows = self.grid.getRowCount() for i in range(len(items)): vp = VerticalPanel() if type == 'photos': vp.add(items[i]['thumb']) else: vp.add(items[i]['thumb']) vp.add(items[i]['title']) self.grid.setWidget(int(i / cols), i % cols, vp) def parsePhotos(self, items): photo_list = json.loads(items) self.photos = [] for ph in photo_list: aphoto = {} aphoto['thumb'] = HTML( '<img src="' + ph[u"media$group"][u"media$thumbnail"][1][u"url"] + '"/>') aphoto['full'] = ph[u"media$group"][u"media$content"][0][u"url"] self.photos.append(aphoto) def parseAlbums(self, items): album_list = json.loads(items) self.albums = [] for al in album_list: analbum = {} analbum['title'] = HTML(al[u"title"][u"$t"]) analbum['thumb'] = HTML( '<img src="' + al[u"media$group"][u"media$thumbnail"][0][u"url"] + '"/>') url = al[u"id"][u"$t"] analbum['id'] = url.split(u'albumid/')[1].split(u'?alt')[0] self.albums.append(analbum)
sb.addClickListener(self) self.header.setWidget(0, ncol, sb) cf.setWidth(0, ncol, "200px") self.sortbuttons.append(sb) def onClick(self, sender): for (ncol, b) in enumerate(self.sortbuttons): if sender == b: self.sortcol = ncol self.redraw() data = [["hello", "fred", 52], ["bye", "joe", 98], ["greetings", "alien", 0], ["sayonara", "jun", 1], ["gutentaag", "volker", 2], ["bonjour", "francois", 5], ["au reservoir", "fabrice", 8], ["go away", "mary", 73] ] if __name__ == '__main__': pyjd.setup("public/SortedGridThing.html") ogw = OddGridWidget(Width="600px", Height="200px", StyleName="ogw") ogw.setData(data) dp = DisclosurePanel("Click to disclose / hide", True, Width="602px") dp.add(ogw) RootPanel().add(dp) pyjd.run()
class Photos(Composite): def __init__(self): Composite.__init__(self) self.albums = [] self.photos = [] self.grid = Grid(4, 4, CellPadding=4, CellSpacing=4) self.grid.addTableListener(self) self.drill = 0 self.pos = 0 self.up = Button("Up", self) self.next = Button("Next", self) self.prev = Button("Prev", self) self.timer = Timer(notify=self) self.userid = "jameskhedley" self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb" self.doRESTQuery(self.album_url, self.timer) self.vp = VerticalPanel() self.disclosure = DisclosurePanel("Click for boring technical details.") self.disclosure.add(HTML('''<p>OK so you want to write client JS to do a RESTful HTTP query from picasa right? Well you can't because of the Same Origin Policy. Basically this means that because the domain of the query and the domain of the hosted site are different, then that could well be a cross-site scripting (XSS) attack. So, the workaround is to do the call from a script tag so the JSON we get back is part of the document. But since we don't know what URL to hit yet, once we find out then we have to inject a new script tag dynamically which the browser will run as soon as we append it. To be honest I'm not 100% why Google use RESTful services and not JSON-RPC or somesuch, which would be easier. Well, easier for me.''')) self.IDPanel = HorizontalPanel() self.IDPanel.add(Label("Enter google account:")) self.IDButton = Button("Go", self) self.IDBox = TextBox() self.IDBox.setText(self.userid) self.IDPanel.add(self.IDBox) self.IDPanel.add(self.IDButton) self.vp.add(self.IDPanel) self.vp.add(self.disclosure) self.vp.add(self.grid) self.initWidget(self.vp) def doRESTQuery(self, url, timer): """this is a totally different from an RPC call in that we have to dynamically add script tags to the DOM when we want to query the REST API. These rely on callbacks in the DOM so we can either add them dynamically or pre-define them in public/Main.html. Once we've done that have to wait for the response. Which means we need to provide a listener for the timer""" JS("$wnd.receiver = 'wait'") new_script = DOM.createElement("script") DOM.setElemAttribute(new_script, "src", url) DOM.setElemAttribute(new_script, "type","text/javascript") JS("$wnd.document.body.appendChild(@{{new_script}})") self.timer.schedule(100) def onCellClicked(self, sender, row, col): if self.drill==0: self.drill += 1 self.vp.clear() self.grid.clear() self.vp.add(self.up) self.vp.add(self.grid) gridcols = self.grid.getColumnCount() album = self.albums[row+col+(row*(gridcols-1))] url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "/albumid/" + album["id"] + "?alt=json-in-script&kind=photo&hl=en_US&callback=restCb" self.doRESTQuery(url, self.timer) elif self.drill==1: self.drill += 1 gridcols = self.grid.getColumnCount() self.pos =row+col+(row*(gridcols-1)) photo = self.photos[self.pos] self.vp.clear() self.fullsize = HTML('<img src="' + photo["full"] + '"/>') hp = HorizontalPanel() hp.add(self.up) hp.add(self.prev) hp.add(self.next) hp.setSpacing(8) self.vp.add(hp) self.vp.add(self.fullsize) def onClick(self, sender): if sender == self.IDButton: self.userid = self.IDBox.getText() if self.userid == "" or self.userid.isdigit(): return self.drill = 0 self.album_url = "http://picasaweb.google.com/data/feed/base/user/" + self.userid + "?alt=json-in-script&kind=album&hl=en_US&callback=restCb" self.grid.clear() self.doRESTQuery(self.album_url, self.timer) else: if self.drill == 2: if sender == self.up: self.drill=1 self.vp.clear() self.vp.add(self.up) self.vp.add(self.grid) self.fillGrid(self.photos, "photos") else: if sender == self.next: if self.pos >= len(self.photos): return self.pos +=1 elif sender == self.prev: if self.pos < 1: return self.pos -=1 photo = self.photos[self.pos] self.fullsize.setHTML('<img src="' + photo["full"] + '"/>') elif self.drill == 1: self.drill=0 self.vp.clear() self.vp.add(self.IDPanel) self.vp.add(self.disclosure) self.vp.add(self.grid) self.fillGrid(self.albums, "albums") def onTimer(self, timer): receiver = JS("$wnd.receiver") if receiver == 'wait': self.timer.schedule(1000) return JS("$wnd.receiver = 'wait'") if self.drill == 0: self.parseAlbums(receiver) self.fillGrid(self.albums, "albums") elif self.drill == 1: self.parsePhotos(receiver) self.fillGrid(self.photos, "photos") def fillGrid(self, items, type): self.grid.clear() cols = self.grid.getColumnCount() self.grid.resizeRows((len(items)/cols)+1) rows = self.grid.getRowCount() for i in range(len(items)): vp = VerticalPanel() if type == 'photos': vp.add(items[i]['thumb']) else: vp.add(items[i]['thumb']) vp.add(items[i]['title']) self.grid.setWidget(int(i/cols), i%cols, vp) def parsePhotos(self, items): photo_list = JSONParser().jsObjectToPyObject(items) self.photos = [] for i in range(len(photo_list)): index = "%s" % i aphoto = {} aphoto['thumb'] = HTML('<img src="' + photo_list[index]["media$group"]["media$thumbnail"]["1"]["url"] + '"/>') aphoto['full'] = photo_list[index]["media$group"]["media$content"]["0"]["url"] self.photos.append(aphoto) def parseAlbums(self, items): album_list = JSONParser().jsObjectToPyObject(items) self.albums = [] for i in range(len(album_list)): index = "%s" % i analbum = {} analbum['title'] = HTML(album_list[index]["title"]["$t"]) analbum['thumb'] = HTML('<img src="' + album_list[index]["media$group"]["media$thumbnail"]["0"]["url"] + '"/>') url = album_list[index]["id"]["$t"] analbum['id'] = url.split('albumid/')[1].split('?alt')[0] self.albums.append(analbum)
def __init__(self): Sink.__init__(self) text="""This is a <code>ScrollPanel</code> contained at the center of a <code>DockPanel</code>. By putting some fairly large contents in the middle and setting its size explicitly, it becomes a scrollable area within the page, but without requiring the use of an IFRAME. Here's quite a bit more meaningless text that will serve primarily to make this thing scroll off the bottom of its visible area. Otherwise, you might have to make it really, really small in order to see the nifty scroll bars!""" contents = HTML(text) scroller = ScrollPanel(contents, StyleName="ks-layouts-Scroller") dock = DockPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER, Spacing=10) north0 = HTML("This is the <i>first</i> north component", True) east = HTML("<center>This<br>is<br>the<br>east<br>component</center>", True) south = HTML("This is the south component") west = HTML("<center>This<br>is<br>the<br>west<br>component</center>", True) north1 = HTML("This is the <b>second</b> north component", True) dock.add(north0, DockPanel.NORTH) dock.add(east, DockPanel.EAST) dock.add(south, DockPanel.SOUTH) dock.add(west, DockPanel.WEST) dock.add(north1, DockPanel.NORTH) dock.add(scroller, DockPanel.CENTER) #Logger.write("Layouts", "TODO: flowpanel") flow = FlowPanel() for i in range(8): flow.add(CheckBox("Flow %d" % i)) horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_MIDDLE) horz.add(Button("Button")) horz.add(HTML("<center>This is a<br>very<br>tall thing</center>", True)) horz.add(Button("Button")) vert = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER) vert.add(Button("Small")) vert.add(Button("--- BigBigBigBig ---")) vert.add(Button("tiny")) menu = MenuBar() menu0 = MenuBar(True) menu1 = MenuBar(True) menu.addItem("menu0", menu0) menu.addItem("menu1", menu1) menu0.addItem("child00") menu0.addItem("child01") menu0.addItem("child02") menu1.addItem("child10") menu1.addItem("child11") menu1.addItem("child12") #Logger.write("Layouts", "TODO: htmlpanel") id = HTMLPanel.createUniqueId() text="""This is an <code>HTMLPanel</code>. It allows you to add components inside existing HTML, like this: <span id='%s' /> Notice how the menu just fits snugly in there? Cute.""" % id html = HTMLPanel(text) DOM.setStyleAttribute(menu.getElement(), "display", "inline") html.add(menu, id) disclose = DisclosurePanel("Click to disclose") disclose.add(HTML("""<b>Ta-daaaaa!</b><br />Ok - it could have been<br />more of a surprise.""")) panel = VerticalPanel(Spacing=8, HorizontalAlignment=HasAlignment.ALIGN_CENTER) panel.add(self.makeLabel("Dock Panel")) panel.add(dock) panel.add(self.makeLabel("Flow Panel")) panel.add(flow) panel.add(self.makeLabel("Horizontal Panel")) panel.add(horz) panel.add(self.makeLabel("Vertical Panel")) panel.add(vert) panel.add(self.makeLabel("HTML Panel")) panel.add(html) panel.add(self.makeLabel("Disclosure Panel")) panel.add(disclose) self.initWidget(panel) self.setStyleName("ks-layouts")
def __init__(self): Sink.__init__(self) text = """This is a <code>ScrollPanel</code> contained at the center of a <code>DockPanel</code>. By putting some fairly large contents in the middle and setting its size explicitly, it becomes a scrollable area within the page, but without requiring the use of an IFRAME. Here's quite a bit more meaningless text that will serve primarily to make this thing scroll off the bottom of its visible area. Otherwise, you might have to make it really, really small in order to see the nifty scroll bars!""" contents = HTML(text) scroller = ScrollPanel(contents, StyleName="ks-layouts-Scroller") dock = DockPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER, Spacing=10) north0 = HTML("This is the <i>first</i> north component", True) east = HTML("<center>This<br>is<br>the<br>east<br>component</center>", True) south = HTML("This is the south component") west = HTML("<center>This<br>is<br>the<br>west<br>component</center>", True) north1 = HTML("This is the <b>second</b> north component", True) dock.add(north0, DockPanel.NORTH) dock.add(east, DockPanel.EAST) dock.add(south, DockPanel.SOUTH) dock.add(west, DockPanel.WEST) dock.add(north1, DockPanel.NORTH) dock.add(scroller, DockPanel.CENTER) #Logger.write("Layouts", "TODO: flowpanel") flow = FlowPanel() for i in range(8): flow.add(CheckBox("Flow %d" % i)) horz = HorizontalPanel(VerticalAlignment=HasAlignment.ALIGN_MIDDLE) horz.add(Button("Button")) horz.add(HTML("<center>This is a<br>very<br>tall thing</center>", True)) horz.add(Button("Button")) vert = VerticalPanel(HorizontalAlignment=HasAlignment.ALIGN_CENTER) vert.add(Button("Small")) vert.add(Button("--- BigBigBigBig ---")) vert.add(Button("tiny")) menu = MenuBar() menu0 = MenuBar(True) menu1 = MenuBar(True) menu.addItem("menu0", menu0) menu.addItem("menu1", menu1) menu0.addItem("child00") menu0.addItem("child01") menu0.addItem("child02") menu1.addItem("child10") menu1.addItem("child11") menu1.addItem("child12") #Logger.write("Layouts", "TODO: htmlpanel") id = HTMLPanel.createUniqueId() text = """This is an <code>HTMLPanel</code>. It allows you to add components inside existing HTML, like this: <span id='%s' /> Notice how the menu just fits snugly in there? Cute.""" % id html = HTMLPanel(text) DOM.setStyleAttribute(menu.getElement(), "display", "inline") html.add(menu, id) disclose = DisclosurePanel("Click to disclose") disclose.add( HTML("""<b>Ta-daaaaa!</b><br />Ok - it could have been<br />more of a surprise.""")) panel = VerticalPanel(Spacing=8, HorizontalAlignment=HasAlignment.ALIGN_CENTER) panel.add(self.makeLabel("Dock Panel")) panel.add(dock) panel.add(self.makeLabel("Flow Panel")) panel.add(flow) panel.add(self.makeLabel("Horizontal Panel")) panel.add(horz) panel.add(self.makeLabel("Vertical Panel")) panel.add(vert) panel.add(self.makeLabel("HTML Panel")) panel.add(html) panel.add(self.makeLabel("Disclosure Panel")) panel.add(disclose) self.initWidget(panel) self.setStyleName("ks-layouts")
cf = self.header.getCellFormatter() self.sortbuttons = [] for ncol in range(cols): sb = Button("sort col %d" % ncol) sb.addClickListener(self) self.header.setWidget(0, ncol, sb) cf.setWidth(0, ncol, "200px") self.sortbuttons.append(sb) def onClick(self, sender): for (ncol, b) in enumerate(self.sortbuttons): if sender == b: self.sortcol = ncol self.redraw() data = [["hello", "fred", 52], ["bye", "joe", 98], ["greetings", "alien", 0], ["sayonara", "jun", 1], ["gutentaag", "volker", 2], ["bonjour", "francois", 5], ["au reservoir", "fabrice", 8], ["go away", "mary", 73]] if __name__ == '__main__': pyjd.setup("public/SortedGridThing.html") ogw = OddGridWidget(Width="600px", Height="200px", StyleName="ogw") ogw.setData(data) dp = DisclosurePanel("Click to disclose / hide", True, Width="602px") dp.add(ogw) RootPanel().add(dp) pyjd.run()
class I2CPanel : class saveStateListener : def __init__(self, panel) : self._saveStatePanel=panel def onRemoteResponse(self, response, request_info): self._saveStatePanel.returnStatement.setText("File saved:" + response) def onRemoteError(self, code, message, request_info): ErrorMessage( "Unable to contact server" ) class loadStateListener : def __init__(self, panel) : self._saveStatePanel=panel def onRemoteResponse(self, response, request_info): self._saveStatePanel.returnStatement.setText("File loaded:" + response) self._saveStatePanel.rpcService.I2CRegisterValues( self._saveStatePanel.getTotalCBCs(), I2CPanel.ReadRegisterValueListener(self._saveStatePanel) ) #refresh of text boxes def onRemoteError(self, code, message, request_info): ErrorMessage( "Unable to contact server" ) class ConnectedCBCListener : """ A class to listen for the response to the connectedCBCNames call """ def __init__(self, listBox) : self.listBox=listBox def onRemoteResponse(self, response, request_info): self.listBox.clear() if response == None: self.listBox.addItem("<none>") self.listBox.setEnabled( False ) else : for name in response : self.listBox.addItem(name) #e.g FE0CBC0 self.listBox.setEnabled(True) def onRemoteError(self, code, message, request_info): ErrorMessage( "Unable to contact server" ) class ReadRegisterValueListener : """ A class to listen for the response to the call to get the register values """ def __init__(self, panel) : self._I2Cpanel=panel self.textBoxes=self._I2Cpanel.i2cValueEntries def onRemoteResponse(self, response, request_info): #Call is now made for all connected CBCs for better stability of status box- fb for cbcName in self._I2Cpanel.getActiveCBCs(): if cbcName=='FE0CBC0': valuesTuple = response[response.keys()[0]] elif cbcName=='FE0CBC1': valuesTuple = response[response.keys()[1]] # For this chip loop over all the register and set the text box values for registerName in valuesTuple : box=self.textBoxes[registerName] status=self._I2Cpanel.statusValueEntries[registerName] box.setText( "0x%02x"%valuesTuple[registerName] ) box.setStyleAttribute( "background-color", "#FFFFFF" ) box.setEnabled( True ) #for some reason pyjas likes these separated - fb for registerName in valuesTuple: if response['FE0CBC0'][registerName]==response['FE0CBC1'][registerName]: self._I2Cpanel.statusValueEntries[registerName].setText("==") else: self._I2Cpanel.statusValueEntries[registerName].setText(" //") def onRemoteError(self, code, message, request_info): ErrorMessage( "Unable to contact server" ) class RefreshListener : """ A class that will wait for a response before refreshing the status box """ def __init__(self, panel) : self._Refresh = panel def onRemoteResponse(self, response, request_info): self._Refresh.rpcService.I2CRegisterValues( self._Refresh.getTotalCBCs(), I2CPanel.ReadRegisterValueListener(self._Refresh) ) #Live refresh of the status box def onRemoteError(self, code, message, request_info): ErrorMessage( "Unable to contact server" ) def __init__( self ) : # This is the service that will be used to communicate with the DAQ software self.rpcService = GlibRPCService.instance() # The main panel that everythings will be insided self.mainPanel = HorizontalPanel() self.mainPanel.setSpacing(10) self.i2cValueEntries = {} # The input boxes for all the registers self.statusValueEntries = {} # Displays the status of the i2cValueEntries self.stateValueEntries = {} # For load/save state self.fileName = {} # File name of the i2c registers # This is the list of available CBC chips. It will be populated by a call to the # server later. self.cbcList=ListBox(MultipleSelect=True, VisibleItemCount=10) self.cbcList.addItem( "waiting..." ) # Default text until I hear from the server what's connected self.cbcList.setEnabled( False ) self.cbcList.addChangeListener(self) self.rpcService.connectedCBCNames( None, I2CPanel.ConnectedCBCListener(self.cbcList) ) # Ask the server what's connected # This is the panel that will have the list of I2C registers. I'll split up the # registers into subjects to make them more manageable. self.mainSettings = DisclosurePanel("Main Control Registers") self.channelMasks = DisclosurePanel("Channel Masks") self.channelTrims = DisclosurePanel("Channel Trims") self.callSettings = VerticalPanel("Load/Save States") self.callSettings.setBorderWidth(1) self.callSettings.add(HTML("<center>Load/Save State</center>")) cbcListAndCallSettings=VerticalPanel() cbcListAndCallSettings.add(self.cbcList) cbcListAndCallSettings.add(self.callSettings) self.mainPanel.add(cbcListAndCallSettings) self.mainPanel.add(self.mainSettings) self.mainPanel.add(self.channelMasks) self.mainPanel.add(self.channelTrims) self.callSettings.add( self.createStatesPanel()) self.mainSettings.add( self.createRegisterPanel(["FrontEndControl","TriggerLatency","HitDetectSLVS","Ipre1","Ipre2","Ipsf","Ipa","Ipaos","Vpafb","Icomp","Vpc","Vplus","VCth","TestPulsePot","SelTestPulseDel&ChanGroup","MiscTestPulseCtrl&AnalogMux","TestPulseChargePumpCurrent","TestPulseChargeMirrCascodeVolt","CwdWindow&Coincid","MiscStubLogic"]) ) self.channelMasks.add( self.createRegisterPanel(["MaskChannelFrom008downto001","MaskChannelFrom016downto009","MaskChannelFrom024downto017","MaskChannelFrom032downto025","MaskChannelFrom040downto033","MaskChannelFrom048downto041","MaskChannelFrom056downto049","MaskChannelFrom064downto057","MaskChannelFrom072downto065","MaskChannelFrom080downto073","MaskChannelFrom088downto081","MaskChannelFrom096downto089","MaskChannelFrom104downto097","MaskChannelFrom112downto105","MaskChannelFrom120downto113","MaskChannelFrom128downto121","MaskChannelFrom136downto129","MaskChannelFrom144downto137","MaskChannelFrom152downto145","MaskChannelFrom160downto153","MaskChannelFrom168downto161","MaskChannelFrom176downto169","MaskChannelFrom184downto177","MaskChannelFrom192downto185","MaskChannelFrom200downto193","MaskChannelFrom208downto201","MaskChannelFrom216downto209","MaskChannelFrom224downto217","MaskChannelFrom232downto225","MaskChannelFrom240downto233","MaskChannelFrom248downto241","MaskChannelFrom254downto249"]) ) self.channelTrims.add( self.createRegisterPanel(["Channel001","Channel002","Channel003","Channel004","Channel005","Channel006","Channel007","Channel008","Channel009","Channel010","Channel011","Channel012","Channel013","Channel014","Channel015","Channel016","Channel017","Channel018","Channel019","Channel020","Channel021","Channel022","Channel023","Channel024","Channel025","Channel026","Channel027","Channel028","Channel029","Channel030","Channel031","Channel032","Channel033","Channel034","Channel035","Channel036","Channel037","Channel038","Channel039","Channel040","Channel041","Channel042","Channel043","Channel044","Channel045","Channel046","Channel047","Channel048","Channel049","Channel050","Channel051","Channel052","Channel053","Channel054","Channel055","Channel056","Channel057","Channel058","Channel059","Channel060","Channel061","Channel062","Channel063","Channel064","Channel065","Channel066","Channel067","Channel068","Channel069","Channel070","Channel071","Channel072","Channel073","Channel074","Channel075","Channel076","Channel077","Channel078","Channel079","Channel080","Channel081","Channel082","Channel083","Channel084","Channel085","Channel086","Channel087","Channel088","Channel089","Channel090","Channel091","Channel092","Channel093","Channel094","Channel095","Channel096","Channel097","Channel098","Channel099","Channel100","Channel101","Channel102","Channel103","Channel104","Channel105","Channel106","Channel107","Channel108","Channel109","Channel110","Channel111","Channel112","Channel113","Channel114","Channel115","Channel116","Channel117","Channel118","Channel119","Channel120","Channel121","Channel122","Channel123","Channel124","Channel125","Channel126","Channel127","Channel128","Channel129","Channel130","Channel131","Channel132","Channel133","Channel134","Channel135","Channel136","Channel137","Channel138","Channel139","Channel140","Channel141","Channel142","Channel143","Channel144","Channel145","Channel146","Channel147","Channel148","Channel149","Channel150","Channel151","Channel152","Channel153","Channel154","Channel155","Channel156","Channel157","Channel158","Channel159","Channel160","Channel161","Channel162","Channel163","Channel164","Channel165","Channel166","Channel167","Channel168","Channel169","Channel170","Channel171","Channel172","Channel173","Channel174","Channel175","Channel176","Channel177","Channel178","Channel179","Channel180","Channel181","Channel182","Channel183","Channel184","Channel185","Channel186","Channel187","Channel188","Channel189","Channel190","Channel191","Channel192","Channel193","Channel194","Channel195","Channel196","Channel197","Channel198","Channel199","Channel200","Channel201","Channel202","Channel203","Channel204","Channel205","Channel206","Channel207","Channel208","Channel209","Channel210","Channel211","Channel212","Channel213","Channel214","Channel215","Channel216","Channel217","Channel218","Channel219","Channel220","Channel221","Channel222","Channel223","Channel224","Channel225","Channel226","Channel227","Channel228","Channel229","Channel230","Channel231","Channel232","Channel233","Channel234","Channel235","Channel236","Channel237","Channel238","Channel239","Channel240","Channel241","Channel242","Channel243","Channel244","Channel245","Channel246","Channel247","Channel248","Channel249","Channel250","Channel251","Channel252","Channel253","Channel254","ChannelDummy"]) ) self.mainSettings.add() self.echo=Label() self.mainPanel.add(self.echo) def getPanel( self ) : return self.mainPanel def onChange( self, sender ) : if sender == self.cbcList : # Make a call to the RPC service to get the register values self.rpcService.I2CRegisterValues( self.getTotalCBCs(), I2CPanel.ReadRegisterValueListener(self) )#fb - sends all CBCs self.load.setEnabled(True) self.save.setEnabled(True) elif sender == self.save: msg = self.saveFileName.getText() self.rpcService.saveI2cRegisterValues(msg, I2CPanel.saveStateListener(self) ) elif sender == self.load: msg = self.loadFileName.getText() self.rpcService.loadI2cRegisterValues(msg, I2CPanel.loadStateListener(self) ) self.rpcService.I2CRegisterValues( self.getTotalCBCs(), I2CPanel.ReadRegisterValueListener(self) )# # Sender must be a text box. Need to format the input. else : try: # For some reason the '0x' at the start of the string is causing exceptions, # even though it works fine with interactive python. I'll take it off anyway. string=sender.getText() if( len(string)>=2 ) : if string[0]=='0' and string[1]=='x' : string=string[2:] value=int( string, 16 ) # convert as hex # Cap values at 255 if value<0 : value=0 if value>255 : value=255 sender.setStyleAttribute( "background-color", "#FFFFFF" ) # Convert to the same format as everything else sender.setText( "0x%02x"%value ) # Send the change to the RPC service messageParameters = {} for cbcName in self.getActiveCBCs() : messageParameters[cbcName]={ sender.getTitle():value } self.rpcService.setI2CRegisterValues( messageParameters, I2CPanel.RefreshListener(self) ) except ValueError: sender.setStyleAttribute( "background-color", "#FF3333" ) #self.echoSelection() def echoSelection(self): #fb - a good "print screen" method msg = " File saved: " for names in self.getCheckedStates(): msg += names self.echo.setText(msg) def getList(self): selectCBCs = [] for i in range(self.cbcList.getItemCount()) : if self.cbcList.isItemSelected(i): selectedCBCs.append(self.cbcList.getItemText(i)) def getTotalCBCs(self) : #fb totalCBCs = [] for i in range(self.cbcList.getItemCount()) : totalCBCs.append(self.cbcList.getItemText(i)) return totalCBCs def getSpecificCBC(self, i): #fb specificCBC = [] specificCBC.append(self.cbcList.getItemText(i)) return specificCBC def getActiveCBCs(self) : selectedCBCs = [] for i in range(self.cbcList.getItemCount()) : if self.cbcList.isItemSelected(i): selectedCBCs.append(self.cbcList.getItemText(i)) return selectedCBCs def getCheckedStates(self): # returns the checked boxes + filename selectedStates = [] #for names in self.stateValueEntries: #if str(self.stateValueEntries[names].isChecked())=="True": # selectedStates.append(names) selectedStates.append(self.saveFileName.getText()) return selectedStates def createRegisterPanel( self, registerNames ) : """ Creates panels and buttons for everything given in registerNames, and returns the main panel. """ flowPanel=FlowPanel() for buttonName in registerNames : newPanel=HorizontalPanel() label=Label(buttonName) newPanel.add( label ) newTextBox=TextBox() newTextBox.setEnabled(False) newTextBox.setWidth(80) statusBox=TextBox() statusBox.setEnabled(False) statusBox.setWidth(30) newPanel.add(newTextBox) newPanel.add(statusBox) newPanel.setCellHorizontalAlignment( newTextBox, HasHorizontalAlignment.ALIGN_RIGHT ) newPanel.setCellHorizontalAlignment( statusBox, HasHorizontalAlignment.ALIGN_RIGHT ) newPanel.setCellWidth( statusBox, "20px" ) newPanel.setWidth("100%") #newPanel.setStyleName("areaStyle"); #newPanel.setBorderWidth(5); newTextBox.setText("select chip...") newTextBox.addChangeListener(self) newTextBox.setTitle(buttonName) # This isn't displayed, but it's useful to have stored self.i2cValueEntries[buttonName]=newTextBox self.statusValueEntries[buttonName]=statusBox statusBox.setTitle(buttonName) statusBox.setText("...") flowPanel.add(newPanel) return flowPanel def createStatesPanel(self): vertPanel=VerticalPanel() vertPanel.setSpacing(10) selectionNames = (["Main Control", "Masks", "Trims"]) registerSelection = VerticalPanel() for name in selectionNames : checkBox = CheckBox(name) checkBox.setTitle(name) self.stateValueEntries[name]=checkBox registerSelection.add(checkBox) #Tidy up loadPanel = HorizontalPanel() loadFileTextBox = TextBox() loadFileTextBox.setText("MyI2cCfg") loadFileTextBox.setWidth(80) self.loadFileName = loadFileTextBox loadPanel.add(loadFileTextBox) self.load = Button("Load",getattr(self,"onChange")) #overrides default and sends it to onChange loadPanel.add(self.load) self.load.setEnabled(False) savePanel = HorizontalPanel() saveFileTextBox = TextBox() saveFileTextBox.setText("MyI2cCfg") saveFileTextBox.setWidth(80) self.saveFileName = saveFileTextBox savePanel.add(saveFileTextBox) self.save = Button("Save", getattr(self,"onChange")) savePanel.add(self.save) self.save.setEnabled(False) self.returnStatement = Label() vertPanel.add(registerSelection) vertPanel.add(loadPanel) vertPanel.add(savePanel) vertPanel.add(self.returnStatement) return vertPanel