def __init__(self, text=' ', left=None, top=None, width=100, height=25, bg_color=None, fg_color=None, selected_bg_color=None, selected_fg_color=None, border=None, bd_color=None, bd_width=None): handler = None Button.__init__(self, text, handler, left, top, width, height, bg_color, fg_color, selected_bg_color, selected_fg_color, border, bd_color, bd_width) self.max_visible = 5 self.h_spacing = 6 self.h_margin = 6 self.v_margin = 2 self.label.h_align = Align.LEFT self.list = ListBox(width=self.width, height=self.height*self.max_visible) self.add_child(self.list) self.list.visible = 0
class OptionBox(Button): """ left x coordinate. Integer top y coordinate. Integer width Integer height Integer text Letter to hold. bg_color Background color (Color) fg_color Foreground color (Color) selected_bg_color Background color (Color) selected_fg_color Foreground color (Color) border Border bd_color Border color (Color) bd_width Border width Integer """ def __init__(self, text=' ', left=None, top=None, width=100, height=25, bg_color=None, fg_color=None, selected_bg_color=None, selected_fg_color=None, border=None, bd_color=None, bd_width=None): handler = None Button.__init__(self, text, handler, left, top, width, height, bg_color, fg_color, selected_bg_color, selected_fg_color, border, bd_color, bd_width) self.max_visible = 5 self.h_spacing = 6 self.h_margin = 6 self.v_margin = 2 self.label.h_align = Align.LEFT self.list = ListBox(width=self.width, height=self.height*self.max_visible) self.add_child(self.list) self.list.visible = 0 def change_item(self, direction): self.list.sort_items() self.list.scroll(direction) if self.list.get_selected_index() >= 0: self.set_text(self.list.get_selected_item().text) def add_item(self, text, value=None): self.list.add_item(None, text, value, h_margin=10) def toggle_selected_index(self, i): if self.list: self.list.toggle_selected_index(i) def toggle_box(self): if self.list.is_visible(): self.list.visible = 0 self.selected = 1 else: self.list.visible = 1 self.selected = 0 def _draw(self): """ The actual internal draw function. """ if not self.width or not self.height or not self.text: raise TypeError, 'Not all needed variables set.' if self.selected: c = self.selected_bg_color.get_color_sdl() a = self.selected_bg_color.get_alpha() else: c = self.bg_color.get_color_sdl() a = self.bg_color.get_alpha() self.surface = self.osd.Surface(self.get_size(), 0, 32) self.surface.fill(c) self.surface.set_alpha(a) ar_1 = (self.width-18, 7) ar_2 = (self.width-8, 7) ar_3 = (self.width-13, 18) if self.selected: arrow_color = self.selected_fg_color.get_color_sdl() else: arrow_color = self.fg_color.get_color_sdl() self.osd.polygon(self.surface, arrow_color, [ar_1, ar_2, ar_3]) if isinstance(self.list, ListBox): self.list.set_position(self.left, self.top+self.height) Container._draw(self) self.blit_parent() if self.list: self.list.draw(self.parent.surface)
def writeContent(self): wr = self.writeln ses = self.session() req = self.request() if req.hasField('newLogin'): self.sendRedirectAndEnd('Main') return if req.hasField('archAddSuccess'): if req.field('archAddSuccess'): wr('Architecture Added Successfully.') wr('<BR><A HREF=QueryDB>Back</A>') return else: wr('''Architecture Addition Failed. One of three things happened:<br> -You attempted to add an architecture that does not exist in this product's foundation.<br> -You tried to add a released architecture for which the foundation is not released.<br> -You attempted to add a duplicate architecture.<br><br> There is a small chance that I screwed something up. Contact me if you think this page is in error. [email protected]<br> <BR><A HREF=addArch>Back</A>''') return archBox = ListBox.ListBox(1,'archToAdd', 'Choose an Arch:') releasedBox = ListBox.ListBox(1,'archReleased', 'Select:') knownArchs = map(lambda x: str(x['name']), self.db.Command("SELECT name FROM BuildCfg.archs GROUP BY name")) for choice in ["Yes", "No"]: releasedBox.addItem(choice) for arch in knownArchs: archBox.addItem(arch) wr('<H2 ALIGN=CENTER>Adding to %s %s (%s) <BR></H2>' % (ses.value('edition') , ses.value('version') , ses.value('tag'))) wr('<TABLE BORDER=0 WIDTH=100% CELLSPACING=0>') wr('<FORM METHOD=POST>') wr('<TR bgcolor=#c8c8c8><TD>') wr('Architecture to Add....</TD>') wr('<TD ALIGN=RIGHT>') wr(archBox) wr('</TD></TR>') wr('<TR bgcolor=#d8d8d8>') wr('<TD>Is this architecture released?</TD>') wr('<TD ALIGN=RIGHT>') wr(releasedBox) wr('</TD>') wr('</TR>') wr('<TR><TD><INPUT NAME="inputButton" TYPE="Submit" VALUE="Submit"</TR></TD>') wr('</FORM>') wr('</TABLE>') if DEBUG: #{{{ wr("<H2>Session Variables</H2>") for key in ses.values(): wr('%s : %s<BR>' % (key, ses.value(key))) wr("<H2>Request Variables</H2>") for key in req.fields(): wr('%s : %s<BR>' % (key, req.field(key))) #}}}
def writeContent(self): ses = self.session() req = self.request() wr = self.writeln adapterName = self.request().adapterName() if DEBUG: wr(ses.values()) wr('<BR>') wr(req.fields()) archID = req.field('archID') productID = req.field('productID') edition = req.field('edition') archName = self.releaseDB.Command( "SELECT name FROM BuildCfg.archs WHERE id='%s'" % archID) isReleased = self.releaseDB.Command( "SELECT released FROM BuildCfg.archs WHERE id='%s'" % archID) archName = archName[0]['name'] isReleased = isReleased[0]['released'] buildList = self.releaseDB.Command( "SELECT buildtag FROM Builds.builds WHERE products_id=%s" % ses.value('productID')) buildList = map(lambda x: str(x['buildtag']), buildList) archBox = ListBox.ListBox(1, 'originBuild', 'Select:') for build in buildList: archBox.addItem(build) isFoundation = 'foundation' in edition #The foundation check failed -- redirect user. if not isFoundation: foundationArchID = self.checkFoundation(productID, archName) if foundationArchID: #need -- productID of foundation, result = self.releaseDB.Command( "SELECT foundation FROM BuildCfg.products where id=%s" % productID) foundationID = result[0]['foundation'] result = self.releaseDB.Command( "SELECT tag_match,version FROM BuildCfg.products WHERE id=%s" % foundationID) foundationTag = result[0]['tag_match'] foundationVersion = result[0]['version'] wr('This architecture is not released in this edition' 's foundation. Would you like to \ <A HREF=QueryDB?archToChRelease=%s&productID=%s&edition=foundation&tag=%s&version=%s>Release it?</A>' % (foundationArchID, foundationID, foundationTag, foundationVersion)) return if isReleased == 'Y' and isFoundation: self.releaseDB.Command( "UPDATE BuildCfg.archs SET released='N' WHERE id='%s'" % archID) self.sendRedirectAndEnd('QueryDB') elif isReleased == 'Y': self.releaseDB.Command( "UPDATE BuildCfg.archs SET released='N' WHERE id='%s'" % archID) self.sendRedirectAndEnd('QueryDB') elif req.hasField( 'originBuild') and req.field('originBuild') != 'Select:': obuildID = req.field('originBuild')[-6:] self.releaseDB.Command( "UPDATE BuildCfg.archs SET released='Y',released_build_id='%s' WHERE id='%s'" % (obuildID, archID)) self.sendRedirectAndEnd('QueryDB') wr('<H2 ALIGN=CENTER>Releasing %s in %s %s (%s) <BR></H2>' % (archName, ses.value('edition'), ses.value('version'), ses.value('tag'))) wr('<TABLE BORDER=0 WIDTH=100% CELLSPACING=0>') wr('<FORM METHOD=POST>') wr('<TR bgcolor=#c8c8c8><TD>') wr('Build to release this arch from....</TD>') wr('<TD ALIGN=RIGHT>') wr(archBox) wr('</TD></TR>') wr('<TR><TD><INPUT NAME="inputButton" TYPE="Submit" VALUE="Submit"</TR></TD>' ) wr('</FORM>') wr('</TABLE>') if DEBUG: #{{{ wr("<H2>Session Variables</H2>") for key in ses.values(): wr('%s : %s<BR>' % (key, ses.value(key))) wr("<H2>Request Variables</H2>") for key in req.fields(): wr('%s : %s<BR>' % (key, req.field(key))) #}}}