def getPreferredSize(self): font = getTheme().getAggProperty(("TABBUTTON", "font")) if font == None: font = getTheme().getProperty("DEFAULT FONT") (width, height) = font.getTextSize(self.text) return int(width * 1.5), int(height * 1.3)
def wrapLine(self, line, color): """Add a line of text to the display lines list with wrapping.""" (words, spaces) = self.splitLine(line) displayLine = "" width = 0 space = "" spaceWidth = 0 while words: word = words.pop(0) font = getTheme().getProperty("DEFAULT FONT") wordWidth = font.getTextSize(word)[0] if width + spaceWidth + wordWidth <= self.textWidth: displayLine = displayLine + space + word width += spaceWidth + wordWidth else: self.addDisplayLine(displayLine, color) displayLine = word width = wordWidth space = spaces.pop(0) font = getTheme().getProperty("DEFAULT FONT") spaceWidth = font.getTextSize(space)[0] if displayLine: self.addDisplayLine(displayLine, color)
def getPreferredSize(self): font = getTheme().getAggProperty(("CAPTIONBAR", "TITLE", "font")) if font == None: font = getTheme().getDefaultFont() (width, height) = font.getTextSize(self.text) return self.width, height
def resize(self, w, h): pyui2.widgets.Base.resize(self, w,h) self.vscroll.resize(getTheme().getScrollerSize(), h) self.vscroll.moveto(w-getTheme().getScrollerSize(), 0) self.textWidth = self.width - self.vscroll.width font = getTheme().getProperty("DEFAULT FONT") self.numVisible = self.height / font.getTextSize("x")[1] self.rewrap = 1
def resize(self, w, h): Base.resize(self, w, h) if self.font: font = self.font else: font = getTheme().defaultFont self.numVisible = int (self.height / font.getTextSize("x")[1] ) self.vscroll.setNumItems(self.numItems, self.numVisible) self.vscroll.resize(getTheme().getScrollerSize(), h) self.vscroll.moveto(self.posX + w - getTheme().getScrollerSize(), self.posY)
def draw(self, renderer): self.panel1.draw(renderer) if self.direction == SplitterPanel.HORIZONTAL: getTheme().drawSplitter( (self.windowRect[0], self.windowRect[1]+self.splitPos-self.PADDING, self.width, self.PADDING*2)) else: getTheme().drawSplitter( (self.windowRect[0]+self.splitPos-self.PADDING, self.windowRect[1], 2*self.PADDING, self.height)) self.panel2.draw(renderer)
def calcItemRects(self): font = getTheme().getAggProperty(("MENU","font")) if font == None: font = getTheme().getProperty("DEFAULT FONT") x = self.border y = self.border for item in self.items: (width, height) = font.getTextSize(item.text) item.rect = (x, self.posY + y, width, height) y = y + height
def recalcSize(self): font = getTheme().getAggProperty(("MENU","font")) if font == None: font = getTheme().getProperty("DEFAULT FONT") (width, height) = font.getTextSize("Wp") h = height * 1.3 * len(self.items) + self.border * 2 w = self.minWidth for item in self.items: if item.width > w: w = item.width self.resize(w + self.iconWidth * 2 + self.border * 2, h)
def __init__(self, handler, text, subMenu): self.handler = handler self.text = text font = getTheme().getAggProperty(("MENU","font")) if font == None: font = getTheme().getProperty("DEFAULT FONT") (width, height) = font.getTextSize(text) self.width = width self.subMenu = subMenu self.icon = None self.rect = (0,0,0,0) self.canActivate = handler or subMenu
def calcHitList(self): font = getTheme().getAggProperty(("MENU","font")) if font == None: font = getTheme().getProperty("DEFAULT FONT") height = self.height - (2 * self.border) x = self.posX + self.border print "We have %d menus"%len(self.menus) for menu in self.menus: width = int(font.getTextSize(menu.menuTitle)[0] * 1.33) rect = (x, self.posY, width, height) menu.moveto(x, self.posY + height) print "Calculating the menu at:", menu.posX, menu.posY self.hitList.append((menu, rect)) x = x + width
def getPreferredSize(self): if self.font: font = self.font else: font = getTheme().defaultFont return font.getTextSize(self.text)
def __init__( self, text = '' ): Base.__init__(self) self.text = text self.caretPos = 0 self.selectPos = 0 self.dragging = 0 self.readonly = 0 self.font = getTheme().getProperty("DEFAULT FONT") #self.font = getRenderer().createFont("courier", 12, 0) self.scroll = 0, 0 self.vscroll = pyui2.widgets.VScroll() self.addChild( self.vscroll ) self.hscroll = pyui2.widgets.HScroll() self.addChild( self.hscroll ) self.registerEvent(pyui2.locals.SCROLLPOS, self._pyui2ScrollPos) self.registerEvent(pyui2.locals.KEYDOWN, self._pyui2KeyDown) self.registerEvent(pyui2.locals.KEYUP, self._pyui2KeyUp) self.registerEvent(pyui2.locals.CHAR, self._pyui2Char) self.registerEvent(pyui2.locals.LMOUSEBUTTONDOWN, self._pyui2MouseDown) self.registerEvent(pyui2.locals.LMOUSEBUTTONUP, self._pyui2MouseUp) self.registerEvent(pyui2.locals.MOUSEMOVE, self._pyui2MouseMotion) self.registerEvent(pyui2.locals.CLICKED, self._pyui2Clicked) self.resize( 100, 100 )
def __init__(self, onSelected = None, onDouble = None): Base.__init__(self) self.items = [] if self.font: font = self.font else: font = getTheme().defaultFont self.numVisible = self.height / ( font.getTextSize("x")[1] ) self.numItems = 0 self.topItem = 0 self.selected = -1 self.vscroll = VScroll() self.addChild(self.vscroll) self.registerEvent(pyui2.locals.SCROLLPOS, self._pyui2ScrollPos) self.registerEvent(pyui2.locals.LMOUSEBUTTONDOWN, self._pyui2LButtonDown) self.registerEvent(pyui2.locals.RMOUSEBUTTONDOWN, self._pyui2LButtonDown) self.registerEvent(pyui2.locals.LMOUSEBUTTONUP, self._pyui2LButtonUp) self.registerEvent(pyui2.locals.RMOUSEBUTTONUP, self._pyui2LButtonUp) self.registerEvent(pyui2.locals.LMOUSEDBLCLICK, self._pyui2DoubleClick) self.registerEvent(pyui2.locals.LIST_SELECTED, self._pyui2SelectEvent) self.registerEvent(pyui2.locals.LIST_DBLCLICK, self._pyui2DoubleEvent) self.resize(100,100) self.selectHandler = onSelected self.doubleHandler = onDouble
def __init__(self): self._panel = Panel() Base.__init__(self) # this is identical to Window.__init__ self.topMost = 0 self._panel.moveto(0,0) Base.addChild(self, self._panel) self._panel.setWindow(self) getTheme().setArrowCursor() self.drawCommands = [] self.drawLastCallbacks = [] # this is different.. use the desktop self.moveto(0, 0) self.resize(getDesktop().width, getDesktop().height) getDesktop().windows.insert(0,self)
def clear(self): self.lines = [] self.displayLines = [] font = getTheme().getProperty("DEFAULT FONT") self.numVisible = self.height / font.getTextSize("x")[1] self.numItems = 0 self.topItem = 0 self.rewrap = 0
def setupBar(self): if self.alignment == "v": self.barSpace = self.height - (getTheme().getScrollerSize() * 2 + 2) else: self.barSpace = self.width - (getTheme().getScrollerSize() * 2 + 2) if self.barSpace < 1: self.barSpace = 1 if self.numItems < self.numVisible: self.barSize = self.barSpace else: self.barSize = self.barSpace * self.numVisible / self.numItems if self.barSize < 5: self.barSize = 5 if self.scrollPos > self.barSpace - self.barSize: self.scrollPos = max(self.barSpace - self.barSize, 0)
def getPreferredSize(self): if self.font: font = self.font else: font = getTheme().getDefaultFont() size = font.getTextSize(" "+self.text+" ") size = size[0], int(size[1] * 1.5) return size
def __init__(self): w = getDesktop().width font = getTheme().getAggProperty(("MENU","font")) if font == None: font = getTheme().getProperty("DEFAULT FONT") (width, height) = font.getTextSize("Wp") Window.__init__(self, 0,0, w, height * 1.3, topmost = 1) self.setShow(1) self.menus = [] self.hitList = [] self.active = None self.highlight = None self.registerEvent(pyui2.locals.LMOUSEBUTTONDOWN, self._pyui2MouseDown) self.registerEvent(pyui2.locals.LMOUSEBUTTONUP, self._pyui2MouseUp) self.registerEvent(pyui2.locals.MOUSEMOVE, self._pyui2MouseMotion) self.registerEvent(pyui2.locals.MENU_EXIT, self._pyui2MenuExit)
def setRowTitle(self, rowNum, title): if self.font: font = self.font else: font = getTheme().defaultFont (w,h) = font.getTextSize(title) self.rowTitleWidth = max(self.rowTitleWidth, w+2) self.rowTitles[rowNum] = title self.setDirty(1)
def clearAllItems(self): self.items = [] if self.font: font = self.font else: font = getTheme().defaultFont self.numVisible = self.height / (font.getTextSize("x")[1] ) self.numItems = 0 self.topItem = 0 self.selected = -1
def onMouseDown(self, event): if not self.hit(event.pos): return 0 # Adjust for window coordinates and get the x y point relative to the top left of the # tree widget. adjEvtPos = self.convertToWindowCoords(event.pos) (hitX, hitY) = (adjEvtPos[0] - self.posX, adjEvtPos[1] - self.posY) #print (hitX, hitY) font = getTheme().getProperty("font") if font == None: font = getTheme().getProperty("DEFAULT FONT") itemCount = 0 if self.CheckNodes(self.topNode, 0, hitX, hitY, font, itemCount, self.top): self.setDirty(1) self.countOpenNodes() return 1
def addLine(self, line, color = None): """This adds lines to the display. it does text wrapping.""" if not color: color = getTheme().fgColor self.lines.append((line, color)) self.wrapLine(line, color) numLines = len(self.displayLines) self.topItem = numLines - self.numVisible self.vscroll.setNumItems(numLines, self.numVisible) self.vscroll.scrollToItem(self.topItem)
def placeInnerObjects(self): btnJust = getTheme().getAggProperty(("CAPTIONBAR", "BUTTONS", "justified")) if btnJust == None: btnJust = "right" rect = (self.posX, self.posY, self.width, self.height) rect = self.setButton(self._closeBtn, rect, btnJust) rect = self.setButton(self._maximizeBtn, rect, btnJust) rect = self.setButton(self._minimizeBtn, rect, btnJust) self.textRect = rect
def setColumnTitle(self, colNum, title): if self.font: font = self.font else: font = getTheme().defaultFont (w,h) = font.getTextSize(title) if self.columnWidths.get(colNum): self.columnWidths[colNum] = max(self.columnWidths[colNum], w+12) else: self.columnWidths[colNum] = w+12 self.columnTitles[colNum] = title self.setDirty(1)
def __init__(self): Base.__init__(self) self.resize( 0, getTheme().defaultTextHeight + 4 ) self.setShow(1) self.menus = [] self.hitList = [] self.active = None self.highlight = None self.registerEvent(pyui2.locals.LMOUSEBUTTONDOWN, self._pyui2MouseDown) self.registerEvent(pyui2.locals.LMOUSEBUTTONUP, self._pyui2MouseUp) self.registerEvent(pyui2.locals.MOUSEMOVE, self._pyui2MouseMotion) self.registerEvent(pyui2.locals.MENU_EXIT, self._pyui2MenuExit)
def setText(self, text): """Set the text of the label. sets the dirty flag. """ if self.font: font = self.font else: font = getTheme().defaultFont self.text = text if len(text) == 0: text = " " (self.width,self.height) = font.getTextSize(text) self.setDirty()
def __init__(self,text, maxSize, handler = None, readOnly = 0): Base.__init__(self) self.handler = handler self.caretPos = None self.selectPos = None self.setText(text) self.dragging = 0 self.maxSize = maxSize self.readOnly = readOnly self.font = getTheme().getAggProperty(("EDIT", "font")) if self.font == None: self.font = getTheme().getProperty("DEFAULT FONT") self.resize(self.width, int(self.font.getTextSize("x")[1] * 1.5) ) #print "Edit widget sized to", self.width, self.height self.registerEvent(pyui2.locals.KEYDOWN, self._pyui2KeyDown) self.registerEvent(pyui2.locals.CHAR, self._pyui2Char) self.registerEvent(pyui2.locals.LMOUSEBUTTONDOWN, self._pyui2MouseDown) self.registerEvent(pyui2.locals.LMOUSEBUTTONUP, self._pyui2MouseUp) self.registerEvent(pyui2.locals.MOUSEMOVE, self._pyui2MouseMotion) self.registerEvent(pyui2.locals.CLICKED, self._pyui2Clicked)
def __init__(self): pyui2.widgets.Base.__init__(self) #self.bgColor = (0,0,49, 255) self.lines = [] self.displayLines = [] font = getTheme().getProperty("DEFAULT FONT") self.numVisible = self.height / font.getTextSize("x")[1] self.numItems = 0 self.topItem = 0 self.rewrap = 0 self.textWidth = 0 self.vscroll = pyui2.widgets.VScroll() self.addChild(self.vscroll) self.registerEvent(locals.SCROLLPOS, self._pyui2ScrollPos)
def _pyui2MouseDown(self, event): # print "_pyui2MouseDown:", event.pos, self.posX, self.posY, self.rect[2], self.rect[3] if not self.hit(event.pos): self.status = 0 return 0 adjEvtPos = self.convertToWindowCoords(event.pos) # localpos = (event.pos[0] - self.rect[0], event.pos[1] - self.rect[1]) localpos = (adjEvtPos[0] - self.posX, adjEvtPos[1] - self.posY) # print "_pyui2MouseDown - hit success, localPos:", localpos scrollerSize = getTheme().getScrollerSize() if self.alignment == "v": p = localpos[1] extent = self.height else: p = localpos[0] extent = self.width if p < scrollerSize: # up button scroll if self.currentItem > 0: self.scrollToItem(self.currentItem - 1) self.setDirty(1) return 1 if p > extent - scrollerSize: # down button scroll if self.currentItem < self.numItems: self.scrollToItem(self.currentItem + 1) self.setDirty(1) return 1 if self.pos < p < self.pos + self.barSize: # <-- *** Just cleaned comparsion self.status = 1 # we are scrolling self.start = p self.setDirty(1) return 1 else: # unoccupied bar space self.scrollPos = p - scrollerSize - 1 - self.barSize / 2 # center bar on cursor position if self.scrollPos < 0: self.scrollPos = 0 elif self.scrollPos > self.barSpace - self.barSize: self.scrollPos = self.barSpace - self.barSize self.setupPos() self.status = 1 self.start = p self.setDirty(1) return 1
def _pyui2DoubleClick(self, event): if not self.hit(event.pos): return 0 adjEvtPos = self.convertToWindowCoords(event.pos) if self.font: font = self.font else: font = getTheme().defaultFont item = int( (adjEvtPos[1] - self.posY) / font.getTextSize("x")[1] ) self.selected = item + self.topItem self.postEvent(pyui2.locals.LIST_DBLCLICK) self.setDirty() return 1