def createWidgets (self): "Creates all widgets for the dialog." # create the buttons for the next and previous buttons self.wm.register ( Button ( properties.path_dialogs + "butt-back-moff.png", properties.path_dialogs + "butt-back-mover.png", (850, 30 ), {widget.MOUSEBUTTONUP : self.prevScreen } ) ) # labels self.wm.register ( Label (self.titlefont, "Scenario order of battle ", (10,10), color=(255, 0, 0)) ) unionlabel = Label (self.smallfont, "Union brigades", (50, 80), color=(255, 255, 0) ) self.wm.register ( unionlabel ) # create the label summarizing the units of the union side unionlabel = self.createSummary ( organization.UNION, 200, 83 ) self.wm.register ( unionlabel ) # create labels for all union brigades and store the coordinate of the last used y-position lasty = self.createBrigadeLabels ( organization.UNION, 80 + unionlabel.getHeight () + 30 ); rebellabel = Label (self.smallfont, "Rebel brigades", (50, lasty + 30), color=(255, 255, 0)) self.wm.register ( rebellabel ) # create the label summarizing the units of the rebel side rebellabel = self.createSummary ( organization.REBEL, 200, lasty + 30 + 3 ) self.wm.register ( rebellabel ) # create labels for all rebel brigades unionBrigades = self.createBrigadeLabels ( organization.REBEL, lasty + 30 + rebellabel.getHeight () + 30 );
def createWidgets (self): "Creates all widgets for the dialog." # labels self.wm.register ( Label (self.titlefont, "Select a scenario", (10, 10), color=(255, 0, 0))) # start index for the labels x = 100 y = 100 # create a scenario manager if we don't already have one. This will read the scenarios from # the server if scenario.scenario_manager == None: scenario.scenario_manager = ServerScenarioManager () # read in all scenario info:s scenario.scenario_manager.loadScenarioIndex ( properties.path_scenarios ) # start from index 0 index = 0 # loop over all infos we got for info in scenario.scenario_manager.getScenarios (): # get the name and location name = info.getName () location = info.getLocation () # get the date and create a string (year, month, day, hour, minute) = info.getDate () date = `year` + "." + `month` + "." + `day` + " " + `hour` + ":" + `minute` # create a label text = name + ", " + location + ", " + date # create a label label = Label (self.smallfont, text, (x, y), color=(255, 255, 255), callbacks = {widget.MOUSEBUTTONUP : self.select } ) # register it self.wm.register ( label ) # make sure we know the filename from the label later self.namemap [text] = ( index, info ) # increment the y-offset and index y += label.getHeight () + 5 index += 1 # buttons. We create only the Cancel button so far, the other are created later self.wm.register ( Button ( properties.path_dialogs + "butt-cancel-moff.png", properties.path_dialogs + "butt-cancel-mover.png", (650, 650 ), {widget.MOUSEBUTTONUP : self.cancel } ) )
class AutomataState(JCircle): def __init__(self, name): JCircle.__init__(self, 200) self._label = Label(name) self._label.translate(-self._label.getWidth() / 2.0, -self._label.getHeight() / 2.0) self._links_to = [] self._arcs = [] def get_name(self): return self._label.get_text() def add_arc(self, a): self._arcs.append(a) def translate(self, tx, ty, lock_control_points=False): JCircle.translate(self, tx, ty) if not lock_control_points: for arc in self._links_to: arc.translate_2central_points(tx, ty) def set_name(self, name): self._label.set_text(name) def get_selected(self, x, y): result = None if self._visible: if self.isSelected(x, y): return self return result def add_link_to(self, link): self._links_to.append(link) def paint(self, paintHidden=False): #self.setOpenGlColor() if self.getVisibility() or paintHidden: JCircle.paint(self) glPushMatrix() glTranslatef(self._tx, self._ty, 0) self._label.paint() glPopMatrix()
def createBrigadeLabels (self, owner, starty): """Creates labels for all brigades owned by 'owner'.""" index = starty # loop over all brigades owned by the correct player for brigade in scenario.brigades [owner].values (): # render a label and register it label = Label (self.smallfont, brigade.getName (), (150, index), color=(255, 0, 255)) # register label so that it gets managed self.wm.register ( label ) # also create a label with info about the brigade # increment the index index += label.getHeight () + 20 # we're done, return the last index we used return index
class Tab(BasicContainer,MouseListener): def __init__(self,caption=""): BasicContainer.__init__(self) self.mHasMouse=False self.mTabbedArea=None self.mLabel=Label() self.mLabel.setPosition(4,4) self.setCaption(caption) self.add(self.mLabel) self.addMouseListener(self) self.addFocusListener(self) def adjustSize(self): self.setSize(self.mLabel.getWidth()+8, self.mLabel.getHeight()+8) if self.mTabbedArea != None: self.mTabbedArea.adjustTabPositions() self.addDirtyRect() def setTabbedArea(self,tabbedArea): self.mTabbedArea=tabbedArea def getTabbedArea(self): return self.mTabbedArea def setCaption(self,caption): self.mLabel.setCaption(caption) self.mLabel.adjustSize() self.adjustSize() def getCaption(self): return self.mLabel.getCaption() def draw(self,graphics): faceColor = self.getBaseColor() alpha=faceColor.a highlightColor=faceColor+0x303030 highlightColor.a=alpha shadowColor=faceColor-0x303030 shadowColor.a=alpha borderColor, baseColor = None, None if (self.mTabbedArea != None and self.mTabbedArea.isTabSelected(self) == True) or self.mHasMouse: #Draw a border. graphics.setColor(highlightColor) graphics.drawLine(0, 0, self.getWidth()-1, 0) graphics.drawLine(0, 1, 0, self.getHeight()-1) graphics.setColor(shadowColor) graphics.drawLine(self.getWidth()-1, 1, self.getWidth()-1, self.getHeight()-1) borderColor=Color(highlightColor) baseColor=Color(self.getBaseColor()) else: #draw a border graphics.setColor(shadowColor) graphics.drawLine(0, 0, self.getWidth()-1, 0) graphics.drawLine(0, 1, 0, self.getHeight()-1) graphics.drawLine(self.getWidth()-1, 1, self.getWidth()-1, self.getHeight()-1) baseColor=self.getBaseColor() - 0x151515 baseColor.a=alpha #Push a clip area so the other drawings don't need to worry #about the border. graphics.pushClipArea( Rectangle(1, 1, self.getWidth() - 2, self.getHeight() - 1) ) currentClipArea=Rectangle( graphics.getCurrentClipArea() ) graphics.setColor(baseColor) graphics.fillRectangle( Rectangle(0,0,self.getWidth(), self.getHeight()) ) self.drawChildren(graphics) if self.mTabbedArea != None and self.mTabbedArea.isFocused() == True and self.mTabbedArea.isTabSelected(self) == True: graphics.setColor( self.getForegroundColor() ) graphics.drawRectangle( Rectangle(2,2,currentClipArea.width-4,currentClipArea.height-4) ) graphics.popClipArea() def mouseEntered(self,mouseEvent): self.mHasMouse=True self.addDirtyRect() def mouseExited(self,mouseEvent): self.mHasMouse=False self.addDirtyRect()