def resize(self, w, h): pyui.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 self.numVisible = self.height / locals.TEXT_HEIGHT self.rewrap = 1
def resize(self, w, h): pyui.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 self.numVisible = self.height / getRenderer().getTextSize("x")[1] self.rewrap = 1
def draw(self, renderer): if self.show: getTheme().drawMenu(self.windowRect) y = self.windowRect[1] for item in self.items: rect = getTheme().drawMenuItem( (self.posX+self.border+4, y+4, self.width - self.border*2, 0), item.text, item == self.active, item.icon ) item.rect = (rect[0], rect[1], rect[2], rect[3]) y += rect[3]
def drawEntry(self, renderer, rect, text, hasFocus, caretPos, selectPos, scroll): (x, y, w, h) = rect renderer.setClipping((x + 2, y + 2, w - 4, h - 4)) getTheme().draw3DRect(rect, getTheme().bgColor2, 0) font_width, font_heigth = renderer.getTextSize(' ', self.font) grid_width, grid_height = ((w - 6) / font_width), ((h - 6) / font_heigth) r, i = 0, 0 selFrom, selTo = caretPos > selectPos and (selectPos, caretPos) or ( caretPos, selectPos) for line in text.split('\n'): line_len = len(line) if scroll[1] <= r: ly = (r - scroll[1]) * font_heigth # draw selection haveSelStart = 0 <= (selFrom - i) <= line_len haveSelEnd = 0 <= (selTo - i) <= line_len sx1, sx2 = 0, w if haveSelStart: sx1 = max((selFrom - i - scroll[0]) * font_width, 0) if haveSelEnd: sx2 = (selTo - i - scroll[0]) * font_width elif not haveSelStart and (0 > (selTo - i) or (selFrom - i) > line_len): sx2 = -1 if sx2 > 0: renderer.drawRect( getTheme().bgSelect, (x + 3 + sx1, y + 3 + ly, sx2 - sx1, font_heigth)) # draw caret if 0 <= (caretPos - i) <= line_len: caret = (caretPos - i - scroll[0]) * font_width if 0 <= caret <= w: renderer.drawRect( getTheme().fgColor, (x + 3 + caret, y + 3 + ly, 1, font_heigth)) # draw text if line_len > scroll[0]: renderer.drawText(line[scroll[0]:scroll[0] + grid_width], (x + 4, y + ly), self.fgColor) i += line_len + 1 r += 1 if r >= scroll[1] + grid_height: break renderer.setClipping(None) return rect
def draw(self, renderer): if self.show: getTheme().drawMenu(self.windowRect) y = self.windowRect[1] for item in self.items: rect = getTheme().drawMenuItem( (self.posX + self.border + 4, y + 4, self.width - self.border * 2, 0), item.text, item == self.active, item.icon) item.rect = (rect[0], rect[1], rect[2], rect[3]) y += rect[3]
def draw(self, renderer): if self.show: getTheme().drawMenu( (self.rect[0], rect[1], self.width, self.height)) y = self.border for item in self.items: rect = getTheme().drawMenuItem( (self.border, y, self.width - self.border * 2, 0), item.text, item == self.active, item.icon) item.rect = (rect[0], rect[1], rect[2], rect[3]) y += rect[3]
def draw(self, renderer): if self.show: getTheme().drawMenuBar(self.windowRect) h = self.height-4 x = self.border+4 y = self.windowRect[1] + 2 for menu in self.menus: rect = getTheme().drawMenuBarItem( (x, y, menu.width, h), menu.menuTitle, menu == self.highlight) #menu.moveto(self.posX + rect[0] - self.border, self.posY + self.height) x += menu.width for m in self.menus: m.draw(renderer)
def draw(self, renderer): if self.cleared == 1: if self.neighbors > 0: renderer.drawText( "%d" % self.neighbors, (self.windowRect[0]+2, self.windowRect[1]+2), pyui.colors.black) renderer.drawText( "%d" % self.neighbors, (self.windowRect[0], self.windowRect[1]), pyui.colors.white) return if self.status == pyui.widgets.Button.DOWN: getTheme().draw3DRect( self.windowRect, pyui.colors.grey, 1) else: getTheme().draw3DRect( self.windowRect, pyui.colors.white, 1) if self.flagged: renderer.drawText( "X", (self.windowRect[0], self.windowRect[1]), self.bgColor)
def draw(self, renderer): if self.show: getTheme().drawMenuBar(self.windowRect) h = self.height - 4 x = self.border + 4 y = self.windowRect[1] + 2 for menu in self.menus: rect = getTheme().drawMenuBarItem((x, y, menu.width, h), menu.menuTitle, menu == self.highlight) #menu.moveto(self.posX + rect[0] - self.border, self.posY + self.height) x += menu.width for m in self.menus: m.draw(renderer)
def drawEntry(self, renderer, rect, text, hasFocus, caretPos, selectPos, scroll): (x,y,w,h) = rect renderer.setClipping( (x+2,y+2,w-4,h-4) ) getTheme().draw3DRect(rect, getTheme().bgColor2, 0) font_width, font_heigth = renderer.getTextSize( ' ', self.font ) grid_width, grid_height = ((w-6) / font_width), ((h-6) / font_heigth) r, i = 0, 0 selFrom, selTo = caretPos > selectPos and ( selectPos, caretPos ) or ( caretPos, selectPos ) for line in text.split( '\n' ): line_len = len( line ) if scroll[1] <= r: ly = ( r - scroll[1] ) * font_heigth # draw selection haveSelStart = 0 <= ( selFrom - i ) <= line_len haveSelEnd = 0 <= ( selTo - i ) <= line_len sx1, sx2 = 0, w if haveSelStart: sx1 = max( (selFrom - i - scroll[0]) * font_width, 0 ) if haveSelEnd: sx2 = (selTo - i - scroll[0]) * font_width elif not haveSelStart and ( 0 > ( selTo - i ) or ( selFrom - i ) > line_len ): sx2 = -1 if sx2 > 0: renderer.drawRect(getTheme().bgSelect, (x+3+sx1, y+3+ly, sx2 - sx1, font_heigth)) # draw caret if 0 <= ( caretPos - i ) <= line_len: caret = (caretPos - i - scroll[0]) * font_width if 0 <= caret <= w: renderer.drawRect(getTheme().fgColor, (x+3+caret, y+3+ly, 1, font_heigth)) # draw text if line_len > scroll[0]: renderer.drawText( line[scroll[0]:scroll[0]+grid_width],( x+4, y+ly ), self.fgColor ) i += line_len + 1 r += 1 if r >= scroll[1] + grid_height: break renderer.setClipping( None ) return rect
def __init__(self, x, y, w, h, title, topmost=0): self.theme = getTheme() self.innerWidth = w self.innerHeight = h self.title = title self.dockables = { } # map of dockable positions to list of docked items self.interiorRect = (0, 0, w, h) Window.__init__(self, x, y, w, h, topmost) self.setTitle(self.title) #setup interior self.placeInteriorObjects() self.registerEvent(pyui.locals.LMOUSEBUTTONDOWN, self._pyuiMouseDown) self.registerEvent(pyui.locals.LMOUSEBUTTONUP, self._pyuiMouseUp) self.registerEvent(pyui.locals.MOUSEMOVE, self._pyuiMouseMotion) self.moving = 0 self.resizing = 0 self.startX = 0 self.startY = 0 self.resizingCursor = 0 self.movingCursor = 0 self.backImage = None
def draw(self, renderer): #print "manu bar:", self.rect if self.show: getTheme().drawMenuBar(self.rect) h = self.height - 2 * self.border x = self.border self.hitList = [] for menu in self.menus: rect = getTheme().drawMenuBarItem( (x, self.parent.rect[1] + self.border + self.rect[1], 1, h), menu.menuTitle, menu == self.highlight) menu.moveto(self.posX + rect[0] - self.border, self.posY + self.height) print "drawing hit list at ", rect, self.rect self.hitList.append((menu, rect)) x += rect[2]
def draw(self, renderer): """Draws to the actual frame if the renderer requires it. """ if not self.show: return self.hitList = getTheme().drawFrame( (0,0,self.width, self.height), self.title, self.backImage) self._panel.draw(renderer) if self._menuBar: self._menuBar.draw(renderer)
def __init__(self, handler, text, subMenu): self.handler = handler self.text = text (width, height) = getRenderer().getTextSize(text, getTheme().defaultFont) self.width = width self.subMenu = subMenu self.icon = None self.rect = (0,0,0,0) self.canActivate = handler or subMenu
def draw(self, renderer): """Draws to the actual frame if the renderer requires it. """ if not self.show: return self.hitList = getTheme().drawFrame((0, 0, self.width, self.height), self.title, self.backImage) self._panel.draw(renderer) if self._menuBar: self._menuBar.draw(renderer)
def __init__(self, handler, text, subMenu): self.handler = handler self.text = text (width, height) = getRenderer().getTextSize(text, getTheme().defaultFont) self.width = width self.subMenu = subMenu self.icon = None self.rect = (0, 0, 0, 0) self.canActivate = handler or subMenu
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 draw(self, renderer): renderer.drawRect(pyui.colors.white, self.windowRect) (w,h) = self.getWidthAndHeightFor(0,0) getTheme().drawButton( (self.windowRect[0],self.windowRect[1],w, h), "", 0,0,1) # draw column titles and lines posX = self.getColumnWidth(0) for x in range(1, self.visibleColumns): (w,h) = self.getWidthAndHeightFor(x+self.hscroll.currentItem,0) getTheme().drawButton( (self.windowRect[0] + posX, self.windowRect[1], w, h), self.getColumnTitle(x+self.hscroll.currentItem), 0,0,1) renderer.drawLine(self.windowRect[0] + posX - 1, self.windowRect[1], self.windowRect[0] + posX - 1, self.windowRect[1] + self.windowRect[3]-12, pyui.colors.grey) if self.getColumnReadOnly(x+self.hscroll.currentItem): renderer.drawRect( renderer.packColor(200,200,180), (self.windowRect[0]+posX,self.windowRect[1]+h, self.getColumnWidth(x+self.hscroll.currentItem),self.windowRect[3]-12-h) ) posX = posX + w renderer.drawLine(self.windowRect[0] + posX - 1, self.windowRect[1], self.windowRect[0] + posX - 1, self.windowRect[1] + self.windowRect[3]-12, pyui.colors.grey) # draw row titles and lines posY = self.getRowHeight(self.vscroll.currentItem) for y in range(1, self.visibleRows): (w,h) = self.getWidthAndHeightFor(0,y+self.vscroll.currentItem) getTheme().drawButton( (self.windowRect[0], self.windowRect[1] + posY, w, h), self.getRowTitle(y+self.vscroll.currentItem), 0,0,1) renderer.drawLine(self.windowRect[0], self.windowRect[1] + posY, self.windowRect[0] + self.windowRect[2]-12, self.windowRect[1] + posY, pyui.colors.grey) posY = posY + h renderer.drawLine(self.windowRect[0],self.windowRect[1] + posY, self.windowRect[0] + self.windowRect[2]-12, self.windowRect[1] + posY, pyui.colors.grey) # draw cell contents posY = self.getRowHeight(self.vscroll.currentItem) for y in range(1, self.visibleRows): posX = self.getColumnWidth(0) for x in range(1, self.visibleColumns): value = self.cells.get( (x+self.hscroll.currentItem,y+self.vscroll.currentItem) ) if value: renderer.drawText( "%s"%value, (self.windowRect[0]+posX+2, self.windowRect[1]+posY), pyui.colors.black) posX += self.getColumnWidth(x+self.hscroll.currentItem) posY += self.getRowHeight(y+self.vscroll.currentItem) if self.entryBox.show: self.entryBox.draw(renderer) self.vscroll.draw(renderer) self.hscroll.draw(renderer)
def addItem(self, title, handler=None, subMenu=None): """Add an item to the menu. """ if subMenu: title = title + "..." newItem = MenuItem(handler, title, subMenu) self.items.append(newItem) h = getTheme().defaultTextHeight * 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) self.setDirty() return newItem
def addItem(self, title, handler = None, subMenu = None): """Add an item to the menu. NOTE: submenus dont work for now... """ if subMenu: raise "Submenus not functioning yet..." newItem = FrameMenuItem(handler, title, subMenu) self.items.append(newItem) h = getTheme().defaultTextHeight * 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) self.setDirty() return newItem
def addItem(self, title, handler=None, subMenu=None): """Add an item to the menu. NOTE: submenus dont work for now... """ if subMenu: raise "Submenus not functioning yet..." newItem = FrameMenuItem(handler, title, subMenu) self.items.append(newItem) h = getTheme().defaultTextHeight * 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) self.setDirty() return newItem
def __init__(self): """Initialize and register the base widget. widgets are added to the global widget list initially. """ self.parent = None self.window = None self.posX = 0 self.posY = 0 self.width = 1 self.height = 1 self.show = 1 self.dirty = 1 self.fgColor = getDesktop().theme.getFgColor() self.bgColor = getTheme().getBgColor() self.children = [] self.eventMap = {} self.calcSize() getDesktop().registerWidget(self) self.popup = None self.tooltipText = ""
def draw(self, renderer): """Draws to the actual frame if the renderer requires it. """ if not self.show: return # draw frame border self.hitList = getTheme().drawFrame((0, 0, self.width, self.height), self.title, None) if self.backImage: renderer.drawImage(self.interiorRect, self.backImage) # draw interior widgets Window.draw(self, renderer) # draw dockables. this allows dockables to overdraw the interior area for dockSlot in self.dockables.values(): if dockSlot: dockSlot.draw(renderer)
def activateSubmenu(self, item): self.subActive = item.subMenu (x, y) = (self.posX + item.rect[2], self.posY + item.rect[1] - self.border) if x + item.subMenu.width > getDesktop().width: # try moving to left of menu x -= self.width + item.subMenu.width if x < 0: # the menu won't fit, nor to the left of the parent menu, nor to the right. What to do? # Align the submenu to the right margin. x = getDesktop().width - item.subMenu.width item.subMenu.moveto( getDesktop().width - item.subMenu.width, self.posY + item.subMenu.height * getTheme().defaultTextHeight) if y + item.subMenu.height > getDesktop().height: y = getDesktop().height - item.subMenu.height if y < 0: raise "No room for submenu!" item.subMenu.moveto(x, y) item.subMenu.setShow(1)
def __init__(self, x, y, w, h, title, topmost = 0): self.theme = getTheme() self.title = title self._menuBar = None self.innerRect = (0,0,w,h) Window.__init__(self, x, y, w, h, topmost) self.setTitle(self.title) self.resize(w, h) self.registerEvent(pyui.locals.LMOUSEBUTTONDOWN, self._pyuiMouseDown) self.registerEvent(pyui.locals.LMOUSEBUTTONUP, self._pyuiMouseUp) self.registerEvent(pyui.locals.MOUSEMOVE, self._pyuiMouseMotion) self.moving = 0 self.resizing = 0 self.startX = 0 self.startY = 0 self.hitList = [] self.resizingCursor=0 self.movingCursor=0 self.backImage=None self.calcInnerRect() self.placeInnerObjects()
def drawText(self, text, pos, color, font=None, flipped=0): """the flipped flag is for drawing text in the upside-down coordinate space of cartesian space, rather than UI space. It flips the Y axis before drawing. """ if not font: font = getTheme().defaultFont if flipped: glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho(0, self.width, self.height, 0, -1, 1) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() font.drawText(text, pos, color) if flipped: glPopMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW)
def __init__(self, x, y, w, h, title, topmost=0): self.theme = getTheme() self.title = title self._menuBar = None self.innerRect = (0, 0, w, h) Window.__init__(self, x, y, w, h, topmost) self.setTitle(self.title) self.resize(w, h) self.registerEvent(pyui.locals.LMOUSEBUTTONDOWN, self._pyuiMouseDown) self.registerEvent(pyui.locals.LMOUSEBUTTONUP, self._pyuiMouseUp) self.registerEvent(pyui.locals.MOUSEMOVE, self._pyuiMouseMotion) self.moving = 0 self.resizing = 0 self.startX = 0 self.startY = 0 self.hitList = [] self.resizingCursor = 0 self.movingCursor = 0 self.backImage = None self.calcInnerRect() self.placeInnerObjects()
def drawText(self, text, pos, color, font = None, flipped = 0): """the flipped flag is for drawing text in the upside-down coordinate space of cartesian space, rather than UI space. It flips the Y axis before drawing. """ if not font: font = getTheme().defaultFont if flipped: glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho( 0, self.width, self.height, 0, -1, 1 ) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() font.drawText(text, pos, color) if flipped: glPopMatrix() glMatrixMode(GL_PROJECTION) glPopMatrix() glMatrixMode(GL_MODELVIEW)
def getTextSize(self, text, font=None): if not font: font = getTheme().defaultFont return font.getTextSize(text)
def getTextSize(self, text, font = None): if not font: font = getTheme().defaultFont return font.getTextSize(text)
def draw(self, renderer): renderer.drawRect(pyui.colors.white, self.windowRect) (w, h) = self.getWidthAndHeightFor(0, 0) getTheme().drawButton((self.windowRect[0], self.windowRect[1], w, h), "", 0, 0, 1) # draw column titles and lines posX = self.getColumnWidth(0) for x in range(1, self.visibleColumns): (w, h) = self.getWidthAndHeightFor(x + self.hscroll.currentItem, 0) getTheme().drawButton( (self.windowRect[0] + posX, self.windowRect[1], w, h), self.getColumnTitle(x + self.hscroll.currentItem), 0, 0, 1) renderer.drawLine(self.windowRect[0] + posX - 1, self.windowRect[1], self.windowRect[0] + posX - 1, self.windowRect[1] + self.windowRect[3] - 12, pyui.colors.grey) if self.getColumnReadOnly(x + self.hscroll.currentItem): renderer.drawRect( renderer.packColor(200, 200, 180), (self.windowRect[0] + posX, self.windowRect[1] + h, self.getColumnWidth(x + self.hscroll.currentItem), self.windowRect[3] - 12 - h)) posX = posX + w renderer.drawLine(self.windowRect[0] + posX - 1, self.windowRect[1], self.windowRect[0] + posX - 1, self.windowRect[1] + self.windowRect[3] - 12, pyui.colors.grey) # draw row titles and lines posY = self.getRowHeight(self.vscroll.currentItem) for y in range(1, self.visibleRows): (w, h) = self.getWidthAndHeightFor(0, y + self.vscroll.currentItem) getTheme().drawButton( (self.windowRect[0], self.windowRect[1] + posY, w, h), self.getRowTitle(y + self.vscroll.currentItem), 0, 0, 1) renderer.drawLine(self.windowRect[0], self.windowRect[1] + posY, self.windowRect[0] + self.windowRect[2] - 12, self.windowRect[1] + posY, pyui.colors.grey) posY = posY + h renderer.drawLine(self.windowRect[0], self.windowRect[1] + posY, self.windowRect[0] + self.windowRect[2] - 12, self.windowRect[1] + posY, pyui.colors.grey) # draw cell contents posY = self.getRowHeight(self.vscroll.currentItem) for y in range(1, self.visibleRows): posX = self.getColumnWidth(0) for x in range(1, self.visibleColumns): value = self.cells.get((x + self.hscroll.currentItem, y + self.vscroll.currentItem)) if value: renderer.drawText("%s" % value, (self.windowRect[0] + posX + 2, self.windowRect[1] + posY), pyui.colors.black) posX += self.getColumnWidth(x + self.hscroll.currentItem) posY += self.getRowHeight(y + self.vscroll.currentItem) if self.entryBox.show: self.entryBox.draw(renderer) self.vscroll.draw(renderer) self.hscroll.draw(renderer)