Example #1
0
def init():
    pyui.init(width, height, 'p3d', fullscreen = 0, title = "CodeWorld")
    getRenderer().setBackMethod(render)
    getDesktop().registerHandler(pyui.locals.KEYDOWN, keyDown)
    pygame.key.set_repeat(500, 30)
    
    initGL()
Example #2
0
File: test2.py Project: burito/PyUI
    def __init__(self):

        # create gui objects
        self.grid = None
        self.makeWindow()
	#self.dbutton = pyui.widgets.Button("Delete!", self.onDelete)
        getDesktop().registerHandler(DIALOGCLOSED, self.onDialogClosed)
Example #3
0
File: base.py Project: burito/PyUI
 def setDirty(self, collide = 1):
     self.dirty = 1
     if self.dirty:
         return
     if collide:
         getDesktop().dirtyCollidingWindows(self.rect)
     Base.setDirty(self)
Example #4
0
File: base.py Project: colshag/ANW
 def setDirty(self, collide=1):
     self.dirty = 1
     if self.dirty:
         return
     if collide:
         getDesktop().dirtyCollidingWindows(self.rect)
     Base.setDirty(self)
Example #5
0
def init():
    pyui.init(width, height, "p3d", fullscreen=0, title="CodeWorld")
    getRenderer().setBackMethod(render)
    getDesktop().registerHandler(pyui.locals.KEYDOWN, keyDown)
    pygame.key.set_repeat(500, 30)

    initGL()
Example #6
0
File: base.py Project: burito/PyUI
 def setShow(self,value):
     self.show = value
     self.setDirty()
     for child in self.children:
         child.setShow(value)
     if not value:
         getDesktop().getTheme().setArrowCursor()            
Example #7
0
    def onKeyDown(self, key, x, y):
        if ord(key) < 128:
            getDesktop().postUserEvent(pyui.locals.CHAR, 0, 0, key,
                                       self.getModifiers())

        getDesktop().postUserEvent(pyui.locals.KEYDOWN, 0, 0, ord(key),
                                   self.getModifiers())
Example #8
0
File: base.py Project: colshag/ANW
 def setShow(self, value):
     self.show = value
     self.setDirty()
     for child in self.children:
         child.setShow(value)
     if not value:
         getDesktop().getTheme().setArrowCursor()
    def __init__(self):
        Window.__init__(self, 0, getDesktop().height - 24, getDesktop().width, 24, topmost=1)
        self.setLayout(pyui.layouts.BorderLayoutManager())

        self.command = Edit("Enter commands here.", 255, self.enter)
        self.addChild(self.command, pyui.locals.CENTER)
        self.pack()
Example #10
0
 def write(self, text):
     text = string.rstrip(text)
     if len(text) < 1:
         return
     text = string.replace(text, "\n", " ")
     text = string.replace(text, "\r", " ")      
     self.append(text)
     getDesktop().postUserEvent(pyui.dialogs.EVENT_OUTPUT)
Example #11
0
 def write(self, text):
     text = string.rstrip(text)
     if len(text) < 1:
         return
     text = string.replace(text, "\n", " ")
     text = string.replace(text, "\r", " ")
     self.append(text)
     getDesktop().postUserEvent(pyui.dialogs.EVENT_OUTPUT)
Example #12
0
 def close(self, value = 1):
     #print "closed - " , value
     self.modal = value
     getDesktop().setModal(None)
     self.setShow(0)
     self.loseFocus()
     self.postEvent(locals.DIALOGCLOSED)
     if self.cb:
         self.cb(value)
Example #13
0
 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)
Example #14
0
def update():
    getDesktop().draw()
    getDesktop().update()

    r, w, e = Network.multiplex()
    for sock in r:
        try:
            sock.handleInput()
        except Exception, exc:
            print "Unhandled exception:", exc
Example #15
0
def update():
    getDesktop().draw()
    getDesktop().update()
    
    r, w, e = Network.multiplex()
    for sock in r:
        try:
            sock.handleInput()
        except Exception, exc:
            print "Unhandled exception:", exc
Example #16
0
 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
     pyui.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 __init__(self):
        Window.__init__(self,
                        0,
                        getDesktop().height - 24,
                        getDesktop().width,
                        24,
                        topmost=1)
        self.setLayout(pyui.layouts.BorderLayoutManager())

        self.command = Edit("Enter commands here.", 255, self.enter)
        self.addChild(self.command, pyui.locals.CENTER)
        self.pack()
Example #18
0
    def __init__(self):
        Window.__init__(self, 0, 0, getDesktop().width, \
                        getDesktop().height/4, topmost = 1)
        self.setLayout(pyui.layouts.BorderLayoutManager())
        self.outputBox = LineDisplay()
        self.addChild(self.outputBox, pyui.locals.CENTER)
        self.pack()

        Events.addCallbacks('keyDown', self.keyDown)

        self.oldout = sys.stdout
        sys.stdout = self
Example #19
0
    def __init__(self):
        Window.__init__(self, 0, 0, getDesktop().width, \
                        getDesktop().height/4, topmost = 1)
        self.setLayout(pyui.layouts.BorderLayoutManager())
        self.outputBox = LineDisplay()
        self.addChild(self.outputBox, pyui.locals.CENTER)
        self.pack()

	Events.addCallbacks('keyDown', self.keyDown)
	
        self.oldout = sys.stdout
        sys.stdout = self
Example #20
0
    def ReSizeGLScene(self, Width, Height):
        # Prevent A Divide By Zero If The Window Is Too Small     
        if Height == 0:	
            Height = 1

        # Reset The Current Viewport And Perspective Transformation
        glViewport(0, 0, Width, Height)		
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0)
        glMatrixMode(GL_MODELVIEW)
        getDesktop().width = self.width = Width
        getDesktop().height = self.height = Height
Example #21
0
 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)
Example #22
0
File: base.py Project: burito/PyUI
 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)
Example #23
0
    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_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
Example #24
0
    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)
Example #25
0
 def __init__(self, x, y, w, h, topmost = 0):
     self._panel = Panel()
     Base.__init__(self)
     self.topMost = topmost
     self._panel.moveto(0,0)
     # 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.drawCommands = []
     # these are drawing callbacks to draw _after_ all the widgets are drawn
     self.drawLastCallbacks = [] 
     if self.__dict__.has_key("title"):
         self.handle = getRenderer().createWindow(self.title)
     else:
         self.handle = getRenderer().createWindow("")
     self.moveto(x, y)
     self.resize(w, h)
     getDesktop().addWindow(self)
Example #26
0
    def _pyuiKeyUp(self, event):
        if getDesktop().getFocus() != self.id:
            return 0

        if event.key == pyui.locals.K_SHIFT:
            self.shifting = 0
            return 1

        return 0
Example #27
0
 def __init__(self, x, y, w, h, topmost = 0):
     self._panel = Panel()
     Base.__init__(self)
     self.topMost = topmost
     self._panel.moveto(0,0)
     # 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.drawCommands = []
     # these are drawing callbacks to draw _after_ all the widgets are drawn
     self.drawLastCallbacks = [] 
     if self.__dict__.has_key("title"):
         self.handle = getRenderer().createWindow(self.title)
     else:
         self.handle = getRenderer().createWindow("")
     self.moveto(x, y)
     self.resize(w, h)
     getDesktop().addWindow(self)
Example #28
0
 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 = ""
Example #29
0
File: base.py Project: burito/PyUI
 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 = ""
Example #30
0
    def update(self):
        """PyGame event handling.
        """
        desktop = getDesktop()
        ## process all pending system events.
        event = pygame.event.poll()
        while event.type != locals.NOEVENT:

            # special case to handle multiple mouse buttons!
            if event.type == locals.MOUSEBUTTONDOWN:
                if event.dict['button'] == 1:
                    desktop.postUserEvent(pyui.locals.LMOUSEBUTTONDOWN,
                                          event.pos[0], event.pos[1])
                elif event.dict['button'] == 3:
                    desktop.postUserEvent(pyui.locals.RMOUSEBUTTONDOWN,
                                          event.pos[0], event.pos[1])

            elif event.type == locals.MOUSEBUTTONUP:
                if event.dict['button'] == 1:
                    desktop.postUserEvent(pyui.locals.LMOUSEBUTTONUP,
                                          event.pos[0], event.pos[1])
                elif event.dict['button'] == 3:
                    desktop.postUserEvent(pyui.locals.RMOUSEBUTTONUP,
                                          event.pos[0], event.pos[1])

            elif event.type == locals.MOUSEMOTION:
                self.mousePosition = event.pos
                desktop.postUserEvent(pyui.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
                    #code = event.key, code
                desktop.postUserEvent(pyui.locals.KEYDOWN, 0, 0, code,
                                      pygame.key.get_mods())
                #if code >= 32 and code < 128:
                #    desktop.postUserEvent(pyui.locals.CHAR, 0, 0, character, pygame.key.get_mods())
            elif event.type == locals.KEYUP:
                code = event.key
                desktop.postUserEvent(pyui.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()
Example #31
0
 def runMe(self):
     if not getDesktop().running:
         sys.exit()
     pyui.update()
     pyui.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
Example #32
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().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)
Example #33
0
 def __init__(self):
     Dockable.__init__(self, getDesktop().width, 20)
     self.setShow(1)
     self.menus = []
     self.hitList = []
     self.active = None
     self.highlight = None
     self.registerEvent(pyui.locals.LMOUSEBUTTONDOWN, self._pyuiMouseDown)
     self.registerEvent(pyui.locals.LMOUSEBUTTONUP, self._pyuiMouseUp)
     self.registerEvent(pyui.locals.MOUSEMOVE, self._pyuiMouseMotion)
     self.registerEvent(pyui.locals.MENU_EXIT, self._pyuiMenuExit)
Example #34
0
 def runMe(self):
     if not getDesktop().running:
         sys.exit()
     pyui.update()
     pyui.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
Example #35
0
    def update(self):
        """PyGame event handling.
        """
        desktop = getDesktop()
        ## process all pending system events.
        event = pygame.event.poll()
        while event.type != locals.NOEVENT:

            # special case to handle multiple mouse buttons!
            if event.type == locals.MOUSEBUTTONDOWN:
                # print "Mausssssssssssssssssssssssssssssssssss"
                if event.dict["button"] == 1:
                    desktop.postUserEvent(pyui.locals.LMOUSEBUTTONDOWN, event.pos[0], event.pos[1])
                elif event.dict["button"] == 3:
                    desktop.postUserEvent(pyui.locals.RMOUSEBUTTONDOWN, event.pos[0], event.pos[1])
                elif event.dict["button"] == 4:
                    desktop.postUserEvent(pyui.locals.MOUSEWHEEL, event.pos[0], event.pos[1], "UP")
                elif event.dict["button"] == 5:
                    desktop.postUserEvent(pyui.locals.MOUSEWHEEL, event.pos[0], event.pos[1], "DOWN")

            elif event.type == locals.MOUSEBUTTONUP:
                if event.dict["button"] == 1:
                    desktop.postUserEvent(pyui.locals.LMOUSEBUTTONUP, event.pos[0], event.pos[1])
                elif event.dict["button"] == 3:
                    desktop.postUserEvent(pyui.locals.RMOUSEBUTTONUP, event.pos[0], event.pos[1])

            elif event.type == locals.MOUSEMOTION:
                desktop.postUserEvent(pyui.locals.MOUSEMOVE, event.pos[0], event.pos[1])

            elif event.type == pygame.VIDEORESIZE:
                desktop.postUserEvent(pygame.VIDEORESIZE, event.w, event.h)

            elif event.type == locals.KEYDOWN:
                character = event.unicode
                code = 0
                if len(character) > 0:
                    code = ord(character)
                else:
                    code = event.key
                    # code = event.key, code
                desktop.postUserEvent(pyui.locals.KEYDOWN, 0, 0, code, pygame.key.get_mods())
                # if code >= 32 and code < 128:
                #    desktop.postUserEvent(pyui.locals.CHAR, 0, 0, character, pygame.key.get_mods())
            elif event.type == locals.KEYUP:
                code = event.key
                desktop.postUserEvent(pyui.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()
Example #36
0
 def onMouse(self, button, state, x, y):
     if button == 1:
         return
     if state == 0:
         # mouse button down
         if button == 0:
             getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONDOWN, x, y)
         else:
             getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONDOWN, x, y)
     else:
         # mouse button up
         if button == 0:
             getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONUP, x, y)
         else:
             getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONUP, x, y)
Example #37
0
 def onMouse(self, button, state, x, y):
     if button == 1:
         return
     if state == 0:
         #mouse button down
         if button == 0:
             getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONDOWN, x, y)
         else:
             getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONDOWN, x, y)
     else:
         #mouse button up
         if button == 0:
             getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONUP, x, y)
         else:
             getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONUP, x, y)
Example #38
0
 def getFocus(self):
     """Acquire the gui system's focus. only one Base may have the focus
     """
     if isinstance(self, Window):
         getDesktop().activateWindow(self)
     else:            
         getDesktop().activateWindow(self.window)
     getDesktop().setFocus(self)
     self.setDirty()
Example #39
0
File: base.py Project: burito/PyUI
 def getFocus(self):
     """Acquire the gui system's focus. only one Base may have the focus
     """
     if isinstance(self, Window):
         getDesktop().activateWindow(self)
     else:            
         getDesktop().activateWindow(self.window)
     getDesktop().setFocus(self)
     self.setDirty()
Example #40
0
    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
Example #41
0
    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
Example #42
0
 def onKeyReleased(self, key):
     if not self.active:
         return
     x = self.mouseX
     y = self.mouseY
     if key == sylphis.kMOUSELEFT:
         getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONUP, x, y)
         return
     if key == sylphis.kMOUSERIGHT:
         getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONUP, x, y)
         return
     getDesktop().postUserEvent(pyui.locals.KEYUP, 0, 0, key, self.getModifiers())
Example #43
0
 def onKeyReleased(self, key):
     if not self.active:
         return
     x = self.mouseX
     y = self.mouseY
     if key == sylphis.kMOUSELEFT:
         getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONUP, x, y)
         return
     if key == sylphis.kMOUSERIGHT:
         getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONUP, x, y)
         return
     getDesktop().postUserEvent(pyui.locals.KEYUP, 0, 0, key,
                                self.getModifiers())
Example #44
0
 def onKeyPressed(self, key):
     #print "pressed ", key, sylphis.kENTER
     if not self.active:
         if key == sylphis.kF9:
             self.activate()
         return
      
     if key == sylphis.kF9:
         self.deactivate()
                
     x = self.mouseX
     y = self.mouseY
     if key == sylphis.kMOUSELEFT:
         getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONDOWN, x, y)
         return
     if key == sylphis.kMOUSERIGHT:
         getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONDOWN, x, y)
         return
     if key < 0:
         getDesktop().postUserEvent(pyui.locals.CHAR, 0, 0, chr(-key), self.getModifiers() )
     if key > 0 and key < 46:
         getDesktop().postUserEvent(pyui.locals.KEYDOWN, 0, 0, key, self.getModifiers() )
Example #45
0
    def __init__(self, renderer, fontFace="times", fontSize=12, fontFlags=0):
        self.renderer = renderer
        self.desktop = getDesktop()

        self.fgColor = renderer.packColor(255,255,255)
        self.bgColor = renderer.packColor(0,0,0)
        
        # setup default font
        self.defaultFontFace = fontFace
        self.defaultFontSize = fontSize
        self.defaultFontFlags = fontFlags
        self.defaultFont = renderer.createFont(fontFace, fontSize, fontFlags)
        (self.defaultTextWidth, self.defaultTextHeight) = renderer.getTextSize("M", self.defaultFont)

        # setup widget offsets
        self.frameBorderLeft = 4
        self.frameBorderRight = 4
        self.frameBorderTop = self.defaultTextHeight + 4
        self.frameBorderBottom = 4
        self.tabsHeight = int(self.defaultTextHeight * 1.3)
        self.scrollerSize = 10
Example #46
0
    def tick(self):
        try:
            pyui.core.update()
            pyui.core.draw()
        except:
            #TODO: handle exceptions properly!
            print "Exception in pyui"
            raise
        
        main.addTimeout(self.tick, 0.001)
        
        if not getDesktop().running:
            main.shutDown()
            pyui.quit()

        now = time.time()
        if  now - self.last > 1:
            print "FPS:", self.frames
            self.frames = 0
            self.last = now
        self.frames = self.frames + 1
Example #47
0
    def onKeyPressed(self, key):
        #print "pressed ", key, sylphis.kENTER
        if not self.active:
            if key == sylphis.kF9:
                self.activate()
            return

        if key == sylphis.kF9:
            self.deactivate()

        x = self.mouseX
        y = self.mouseY
        if key == sylphis.kMOUSELEFT:
            getDesktop().postUserEvent(pyui.locals.LMOUSEBUTTONDOWN, x, y)
            return
        if key == sylphis.kMOUSERIGHT:
            getDesktop().postUserEvent(pyui.locals.RMOUSEBUTTONDOWN, x, y)
            return
        if key < 0:
            getDesktop().postUserEvent(pyui.locals.CHAR, 0, 0, chr(-key),
                                       self.getModifiers())
        if key > 0 and key < 46:
            getDesktop().postUserEvent(pyui.locals.KEYDOWN, 0, 0, key,
                                       self.getModifiers())
Example #48
0
    def run(self, callback=None):
        if not self.active:
            return
        self.mouseX += input.getPointerDeltaX()
        self.mouseY += input.getPointerDeltaY()
        if self.mouseX < 0:
            self.mouseX = 0
        if self.mouseY < 0:
            self.mouseY = 0
        if self.mouseX > self.width:
            self.mouseX = self.width    
        if self.mouseY > self.height:
            self.mouseY = self.height    
            
        getDesktop().postUserEvent(pyui.locals.MOUSEMOVE, self.mouseX,self.mouseY)
        getDesktop().draw()
        getDesktop().update()

        self.drawImage((self.mouseX, self.mouseY, 32, 32), self.pointer)
    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 = time.time()
            #if now - self.last >= 1:
                #self.last = now
                #print "FPS: %d" % self.frame
                #self.frame = 0
            
            if callback:
                callback()
            else:
                getDesktop().draw()
                getDesktop().update()
Example #50
0
    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 = time.time()
            if now - self.last >= 1:
                self.last = now
                print "FPS: %d" % self.frame
                self.frame = 0

            if callback:
                callback()
            else:
                getDesktop().draw()
                getDesktop().update()
Example #51
0
    def run(self, callback=None):
        if not self.active:
            return
        self.mouseX += input.getPointerDeltaX()
        self.mouseY += input.getPointerDeltaY()
        if self.mouseX < 0:
            self.mouseX = 0
        if self.mouseY < 0:
            self.mouseY = 0
        if self.mouseX > self.width:
            self.mouseX = self.width
        if self.mouseY > self.height:
            self.mouseY = self.height

        getDesktop().postUserEvent(pyui.locals.MOUSEMOVE, self.mouseX,
                                   self.mouseY)
        getDesktop().draw()
        getDesktop().update()

        self.drawImage((self.mouseX, self.mouseY, 32, 32), self.pointer)
Example #52
0
    def _pyuiKeyDown(self, event):
            
        if getDesktop().getFocus() != self:
            return 0

        if event.key == pyui.locals.K_LEFT:
            if self.caretPos > 0:
                self.caretPos -= 1
            if (event.mods & pyui.locals.MOD_CONTROL):
                while self.caretPos > 0 and self.text[self.caretPos - 1].isspace():
                    self.caretPos -= 1
                while self.caretPos > 0 and not self.text[self.caretPos - 1].isspace():
                    self.caretPos -= 1
            if not (event.mods & pyui.locals.MOD_SHIFT):
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1

        if event.key == pyui.locals.K_RIGHT:
            if self.caretPos < len(self.text):
                self.caretPos += 1
            if (event.mods & pyui.locals.MOD_CONTROL):
                while self.caretPos < len(self.text) and not self.text[self.caretPos].isspace():
                    self.caretPos += 1
                while self.caretPos < len(self.text) and self.text[self.caretPos].isspace():
                    self.caretPos += 1
            if not (event.mods & pyui.locals.MOD_SHIFT):
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1

        if event.key == pyui.locals.K_UP:
            try:
                start = self.text.rindex( '\n', 0, self.caretPos )
                prev_start = self.text.rfind( '\n', 0, start - 1 )
                self.caretPos = min( prev_start - start + self.caretPos, start )
            except:
                return 1
            
            if not (event.mods & pyui.locals.MOD_SHIFT):
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1
        
        if event.key == pyui.locals.K_DOWN:
            try:
                start = self.text.rfind( '\n', 0, self.caretPos )
                next_start = self.text.index( '\n', self.caretPos )
                try: next_end = self.text.index( '\n', next_start + 1 )
                except: next_end = len( self.text )
                self.caretPos = min( next_start - start + self.caretPos, next_end )
            except:
                return 1
            
            if not (event.mods & pyui.locals.MOD_SHIFT):
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1

        if event.key == pyui.locals.K_HOME:
            try: self.caretPos = self.text.rindex( '\n', 0, self.caretPos ) + 1
            except: self.caretPos = 0
            if not (event.mods & pyui.locals.MOD_SHIFT):
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1

        if event.key == pyui.locals.K_END:
            try: self.caretPos = self.text.index( '\n', self.caretPos )
            except: self.caretPos = len(self.text)
            if not (event.mods & pyui.locals.MOD_SHIFT):
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1
        
        if self.readonly:
            return 1
        
        if event.key == pyui.locals.K_BACKSPACE:
            if self.selectPos != self.caretPos:
                self.deleteSelected()
            elif self.caretPos > 0:
                self.text = self.text[:self.caretPos-1] + self.text[self.caretPos:]
                self.caretPos = self.caretPos - 1
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1

        if event.key == pyui.locals.K_DELETE:
            if self.selectPos != self.caretPos:
                self.deleteSelected()
            elif self.caretPos < len(self.text):
                self.text = self.text[:self.caretPos] + self.text[self.caretPos+1:]
                self.selectPos = self.caretPos
            self.scrollToCursor()
            self.setDirty(1)
            return 1

        if event.key == pyui.locals.K_RETURN:
            self.text = self.text[:self.caretPos] + '\n' + self.text[self.caretPos:]
            self.caretPos += 1
            self.selectPos = self.caretPos
            self.setDirty(1)
            return 1

        if event.key < 0 or event.key > 255 or chr( event.key ) not in string.printable:
            return 0
        
        if self.caretPos != self.selectPos:
            self.deleteSelected()
            return 1

        return 0
Example #53
0
 def onKeyUp(self, key, x, y):
     getDesktop().postUserEvent(pyui.locals.KEYUP, 0, 0, ord(key),
                                self.getModifiers())
Example #54
0
File: base.py Project: burito/PyUI
 def postEvent(self, eventType):
     """Post an event to be processed next time through the event loop
     """
     return getDesktop().postEvent(eventType, self.id)