def _pyui2MouseMotion(self, event): if self.capture: if self.hit(event.pos): if self.status != Button.DOWN: self.status = Button.DOWN self.setDirty() else: if self.status == Button.DOWN: self.status = Button.ROLLOVER self.setDirty() return 1 if self.hit(event.pos): #print "button got mouse move:", event.pos, self.rect, self.posX, self.posY if self.status != Button.ROLLOVER: getDesktop().getTheme().setButtonCursor() self.status = Button.ROLLOVER self.setDirty() return 0 else: if self.status == Button.ROLLOVER: getDesktop().getTheme().setArrowCursor() self.status = Button.IDLE self.setDirty() return 0 return 0
def setShow(self,value): self.show = value self.setDirty() for child in self.children: child.setShow(value) if not value: getDesktop().getTheme().setArrowCursor()
def setDirty(self, collide = 1): #self.dirty = 1 if self.dirty: return if collide: getDesktop().dirtyCollidingWindows(self.rect) Base.setDirty(self)
def write(self, text): self.oldout.write("%s" % text) text = string.rstrip(text) if len(text) < 1: return text = string.replace(text, "\n", " ") text = string.replace(text, "\r", " ") self.lines.append(text) getDesktop().postUserEvent(EVENT_OUTPUT)
def close(self, value = 1): #print "closed - " , value self.modal = value getDesktop().setModal(None) self.setShow(0) self.loseFocus() self.postEvent(locals.DIALOGCLOSED) pyui2.desktop.getTheme().setArrowCursor() if self.cb: self.cb(value)
def __init__(self, x = -1, y = -1, w = 300, h = 200, title = None): # center if position not specified if x < 0: x = (getDesktop().width - w) / 2 if y < 0: y = (getDesktop().height - h) / 2 pyui2.widgets.Frame.__init__(self, x, y, w, h, title) self.modal = -1 # this is set to the return value of the dialog self.setShow(1) self.setDirty() self.cb = None
def destroy(self): """Call this to remove all references to the widget from the system. """ #print "destroying %s (%d)" % (self, self.id) self.window = None self.setParent(None) if self.popup: self.popup.destroy() self.popup = None if self.children: for child in self.children: child.destroy() self.children = [] self.eventMap.clear() getDesktop().destroyWidget(self)
def present(self, windows): desktop = getDesktop() if desktop and desktop.running: if self.backDraw != None: self.backDraw() else: pyui2.system.getDeviceContext().clearScreen() pyui2.system.getDeviceContext().prepare() for window in reversed(windows): if window.show: if window.dirty or self.mustFill == 1: window.beginDraw() window.present(self) window.endDraw() window.clearDirty() window.render() self.drawMouseCursor() if self.mustFill == 1: self.mustFill = 0 pyui2.system.getDeviceContext().present()
def setup2D(self): """Setup everything on the opengl Stack to draw in 2D in a way that can be torn down later. """ glMatrixMode(GL_PROJECTION) glPushMatrix() glLoadIdentity() glOrtho( 0, getDesktop().width, getDesktop().height, 0, -1, 1 ) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() glDisable(GL_DEPTH_TEST) glEnable(GL_SCISSOR_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
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 _pyui2KeyUp(self, event): if getDesktop().getFocus() != self.id: return 0 if event.key == pyui2.locals.K_SHIFT: self.shifting = 0 return 1 return 0
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().getStyle("menu").getTextHeight()) 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, topmost = 0): self._panel = Panel() Base.__init__(self) self.topMost = topmost # the content panel is added as a child through Base::addChild to avoid recursively adding it to itself Base.addChild(self, self._panel) self._panel.setWindow(self) self._panel.setParent(self) self.placeInnerObjects() self.drawCommands = [] # these are drawing callbacks to draw _after_ all the widgets are drawn self.drawLastCallbacks = [] self.moveto(x, y) self.resize(w, h) getDesktop().addWindow(self) # Create the graphics context that will be used to display this window self.graphicsContext = getPresenter().getDeviceContext().createGraphicsContext((w, h))
def __init__(self): """Initialize and register the base widget. widgets are added to the global widget list initially. """ self.canTab = 0 # this widget acts as a tab stop self.widgetID = "" 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.children = [] self.eventMap = {} self.calcSize() getDesktop().registerWidget(self) self.popup = None self.tooltipText = "" self.font = None
def runMe(self): if not getDesktop().running: sys.exit() pyui2.update() pyui2.draw() self.frame = self.frame + 1 now = time.time() if now - self.last >= 1: self.last = now print "FPS: %d" % self.frame self.frame = 0
def update(self): """PyGame event handling. """ desktop = getDesktop() if pygame.mouse.get_focused() == False: # The mouse is no longer over the application getPresenter().setMousePosition(None) ## process all pending system events. event = pygame.event.poll() while event.type != NOEVENT: if event.type == pygame.QUIT: desktop.postUserEvent(pyui2.locals.QUIT) # special case to handle multiple mouse buttons! elif event.type == MOUSEBUTTONDOWN: if event.dict['button'] == 1: desktop.postUserEvent(pyui2.locals.LMOUSEBUTTONDOWN, event.pos[0], event.pos[1]) elif event.dict['button'] == 3: desktop.postUserEvent(pyui2.locals.RMOUSEBUTTONDOWN, event.pos[0], event.pos[1]) elif event.type == MOUSEBUTTONUP: if event.dict['button'] == 1: desktop.postUserEvent(pyui2.locals.LMOUSEBUTTONUP, event.pos[0], event.pos[1]) elif event.dict['button'] == 3: desktop.postUserEvent(pyui2.locals.RMOUSEBUTTONUP, event.pos[0], event.pos[1]) elif event.type == MOUSEMOTION: desktop.postUserEvent(pyui2.locals.MOUSEMOVE, event.pos[0], event.pos[1]) self.mousePosition = event.pos getPresenter().setMousePosition(event.pos) elif event.type == KEYDOWN: character = event.unicode code = 0 if len(character) > 0: code = ord(character) else: code = event.key desktop.postUserEvent(pyui2.locals.KEYDOWN, 0, 0, code, pygame.key.get_mods()) if code >= 32 and code < 128: desktop.postUserEvent(pyui2.locals.CHAR, 0, 0, character.encode(), pygame.key.get_mods()) elif event.type == KEYUP: code = event.key desktop.postUserEvent(pyui2.locals.KEYUP, 0, 0, code, pygame.key.get_mods()) else: try: desktop.postUserEvent(event.type) except: print "Error handling event %s" % repr(event) event = pygame.event.poll()
def onMouse(self, button, state, x, y): if button==1: return if state==0: #mouse button down if button==0: getDesktop().postUserEvent(pyui2.locals.LMOUSEBUTTONDOWN,x,y) else: getDesktop().postUserEvent(pyui2.locals.RMOUSEBUTTONDOWN,x,y) else: #mouse button up if button==0: getDesktop().postUserEvent(pyui2.locals.LMOUSEBUTTONUP ,x,y) else: getDesktop().postUserEvent(pyui2.locals.RMOUSEBUTTONUP ,x,y)
def update(self): """PyGame event handling. """ desktop = getDesktop() ## process all pending system events. event = pygame.event.poll() while event.type != locals.NOEVENT: if event.type == pygame.QUIT: desktop.postUserEvent(pyui2.locals.QUIT) # special case to handle multiple mouse buttons! elif event.type == MOUSEBUTTONDOWN: if event.dict['button'] == 1: desktop.postUserEvent(pyui2.locals.LMOUSEBUTTONDOWN, event.pos[0], event.pos[1]) elif event.dict['button'] == 3: desktop.postUserEvent(pyui2.locals.RMOUSEBUTTONDOWN, event.pos[0], event.pos[1]) elif event.type == locals.MOUSEBUTTONUP: if event.dict['button'] == 1: desktop.postUserEvent(pyui2.locals.LMOUSEBUTTONUP, event.pos[0], event.pos[1]) elif event.dict['button'] == 3: desktop.postUserEvent(pyui2.locals.RMOUSEBUTTONUP, event.pos[0], event.pos[1]) elif event.type == locals.MOUSEMOTION: self.mousePosition = event.pos desktop.postUserEvent(pyui2.locals.MOUSEMOVE, event.pos[0], event.pos[1]) elif event.type == locals.KEYDOWN: character = event.unicode code = 0 if len(character) > 0: code = ord(character) else: code = event.key desktop.postUserEvent(pyui2.locals.KEYDOWN, 0, 0, code, pygame.key.get_mods()) #if code >= 32 and code < 128: # desktop.postUserEvent(pyui2.locals.CHAR, 0, 0, character, pygame.key.get_mods()) elif event.type == locals.KEYUP: code = event.key desktop.postUserEvent(pyui2.locals.KEYUP, 0, 0, code, pygame.key.get_mods()) else: try: desktop.postUserEvent(event.type) except: print "Error handling event %s" % repr(event) event = pygame.event.poll() self.mousePosition = pygame.mouse.get_pos()
def getFocus(self): """Acquire the gui system's focus. only one Base may have the focus """ #if isinstance(self, Window): if self.isWindow(): getDesktop().activateWindow(self) else: getDesktop().activateWindow(self.window) getDesktop().setFocus(self) self.setDirty()
def setClipping(self, rect = None): """set the clipping rectangle for the main screen. defaults to clearing the clipping rectangle. NOTE: isn't working...""" return if rect: offsets = glGetIntegerv( GL_MODELVIEW_MATRIX ) corrected = (offsets[3][0] + rect[0], getDesktop().height - offsets[3][1] - rect[3] - rect[1], rect[2], rect[3]) self.clip_stack.append( corrected ) elif len( self.clip_stack ): self.clip_stack = self.clip_stack[0:-1] if len( self.clip_stack ) and self.clip_stack[-1][2] > 0 and self.clip_stack[-1][3] > 0: glEnable(GL_SCISSOR_TEST) apply( glScissor, self.clip_stack[-1] ) else: glDisable(GL_SCISSOR_TEST) pass
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 run(self, callback=None, trackFPS=True): lastTime = 0 frameCounter = 0 desktop = getDesktop() while desktop and desktop.running: if trackFPS == True: frameCounter = frameCounter + 1 now = time.time() if now - lastTime >= 1: lastTime = now print "FPS: %d" % frameCounter frameCounter = 0 if callback: callback() desktop.update() desktop.draw()
def determinePlacement(self, alignment): self.alignment = alignment (width, height) = getDesktop().getSize() if alignment == Toolbar.ALIGN_TOP or alignment == Toolbar.ALIGN_BOTTOM: self.width = width self.height = 32 elif alignment == Toolbar.ALIGN_LEFT or alignment == Toolbar.ALIGN_RIGHT: self.width = 32 self.height = height if alignment == Toolbar.ALIGN_TOP or alignment == Toolbar.ALIGN_LEFT: self.posX = 0 self.posY = 0 elif alignment == Toolbar.ALIGN_BOTTOM: self.posX = 0 self.posY = height - self.height elif alignment == Toolbar.ALIGN_RIGHT: self.posX = width - self.width self.posY = 0
def runMe(self): print "glut::runMe" lastTime = 0 frameCounter = 0 desktop = getDesktop() while desktop and desktop.running: if self.trackFPS == True: frameCounter = frameCounter + 1 now = time.time() if now - lastTime >= 1: lastTime = now print "FPS: %d" % frameCounter frameCounter = 0 if self.callback: self.callback() desktop.update() desktop.draw() sys.exit()
def run(self, callback=None): """This is a default way of _running_ an application using the current renderer. """ while getDesktop() and getDesktop().running: self.frame = self.frame + 1 now = self.readTimer() if now - self.last >= 1: self.last = now print "FPS: %d" % self.frame self.frame = 0 if callback: callback() getDesktop().draw() getDesktop().update()
def onKeyUp(self,key,x,y): getDesktop().postUserEvent(pyui2.locals.KEYUP , 0, 0, ord(key), self.getModifiers() )
def onKeyDown(self,key,x,y): if ord(key) < 128: getDesktop().postUserEvent(pyui2.locals.CHAR, 0, 0, key, self.getModifiers() ) getDesktop().postUserEvent(pyui2.locals.KEYDOWN, 0, 0, ord(key), self.getModifiers() )
def onSpecialUp(self, key, x, y): k = self.keyMap.get(key, key) getDesktop().postUserEvent(pyui2.locals.KEYUP, 0, 0, k, self.getModifiers() )
def onSpecialDown(self, key, x, y): k = self.keyMap.get(key, key) print "down: ", k, key getDesktop().postUserEvent(pyui2.locals.KEYDOWN, 0, 0, k, self.getModifiers() )
def onMotion(self, x, y): print "glut::onMotion" getDesktop().postUserEvent(pyui2.locals.MOUSEMOVE, x,y) self.mousePosition = (x,y)