Esempio n. 1
0
class Spinner(PopupPanel):
    def __init__(self, text=''):
        PopupPanel.__init__(self)

        self.width       = 15
        self.r1          = 35
        self.r2          = 60
        self.cx          = self.r2 + self.width
        self.cy          = self.r2 + self.width
        self.numSectors  = 12
        self.size        = self.r2*2 + self.width*2
        self.speed       = 1.5  # seconds per rotation
        self._timer      = None

        self.canvas = Raphael(self.size, self.size)
        self.sectors = []
        self.opacity = []
        vp = VerticalPanel()
        vp.add(self.canvas)
        blurb = HTML(text)
        blurb.setStyleAttribute('text-align', 'center')
        vp.add(blurb)
        self.add(vp)


    def draw(self):
        colour           = "#000000"
        beta             = 2 * math.pi / self.numSectors

        pathParams = {'stroke'         : colour,
                      'stroke-width'   : self.width,
                      'stroke-linecap' : "round"}

        for i in range(self.numSectors):
            alpha = beta * i - math.pi/2
            cos   = math.cos(alpha)
            sin   = math.sin(alpha)
            data  = ','.join(['M',
                              str(self.cx + self.r1 * cos),
                              str(self.cy + self.r1 * sin),
                              'L',
                              str(self.cx + self.r2 * cos),
                              str(self.cy + self.r2 * sin)])
            path  = self.canvas.path(data=data, attrs=pathParams)
            self.opacity.append(1.0 * i / self.numSectors )
            self.sectors.append(path)

        period = (self.speed * 1000) / self.numSectors
        self._timer = Timer(notify=self)
        self._timer.scheduleRepeating(period)        


    def onTimer(self, _):
        self.opacity.insert(0, self.opacity.pop())
        for i in range(self.numSectors):
            self.sectors[i].setAttr("opacity", self.opacity[i])
Esempio n. 2
0
class Spinner(SimplePanel):
    """ Our testing panel.
    """
    def __init__(self, width=600, height=300):
        """ Standard initialiser.
        """
        SimplePanel.__init__(self)

        # Taken from the "spinner" Raphael demo:
        self.width = 15
        self.r1 = 35
        self.r2 = 60
        self.cx = self.r2 + self.width
        self.cy = self.r2 + self.width
        self.numSectors = 12
        self.canvas = Raphael(self.r2 * 2 + self.width * 2,
                              self.r2 * 2 + self.width * 2)
        self.sectors = []
        self.opacity = []
        self.add(self.canvas)

    def draw(self):
        colour = "#000000"
        beta = 2 * math.pi / self.numSectors

        pathParams = {
            'stroke': colour,
            'stroke-width': self.width,
            'stroke-linecap': "round"
        }

        for i in range(self.numSectors):
            alpha = beta * i - math.pi / 2
            cos = math.cos(alpha)
            sin = math.sin(alpha)
            data = ','.join([
                'M',
                str(self.cx + self.r1 * cos),
                str(self.cy + self.r1 * sin), 'L',
                str(self.cx + self.r2 * cos),
                str(self.cy + self.r2 * sin)
            ])
            path = self.canvas.path(data=data, attrs=pathParams)
            self.opacity.append(1.0 * i / self.numSectors)
            self.sectors.append(path)

        period = 1000 / self.numSectors
        self._timer = Timer(notify=self)
        self._timer.scheduleRepeating(period)

    def onTimer(self, timerID):
        """ Respond to our timer firing.
        """
        self.opacity.insert(0, self.opacity.pop())
        for i in range(self.numSectors):
            self.sectors[i].setAttr("opacity", self.opacity[i])
Esempio n. 3
0
class TestPanel(SimplePanel):
    """ Our testing panel.
    """
    def __init__(self):
        """ Standard initialiser.
        """
        SimplePanel.__init__(self)

        # Taken from the "spinner" Raphael demo:

        colour = "#000000"
        width = 15
        r1 = 35
        r2 = 60
        cx = r2 + width
        cy = r2 + width
        self.numSectors = 12
        self.canvas = Raphael(r2 * 2 + width * 2, r2 * 2 + width * 2)
        self.sectors = []
        self.opacity = []
        beta = 2 * math.pi / self.numSectors

        pathParams = {
            'stroke': colour,
            'stroke-width': width,
            'stroke-linecap': "round"
        }

        for i in range(self.numSectors):
            alpha = beta * i - math.pi / 2
            cos = math.cos(alpha)
            sin = math.sin(alpha)
            path = self.canvas.path(data=None, attrs=pathParams)
            path.moveTo(cx + r1 * cos, cy + r1 * sin)
            path.lineTo(cx + r2 * cos, cy + r2 * sin)
            self.opacity.append(1 / self.numSectors * i)
            self.sectors.append(path)

        period = 1000 / self.numSectors

        self._timer = Timer(notify=self)
        self._timer.scheduleRepeating(period)

        self.add(self.canvas)

    def onTimer(self, timer):
        """ Respond to our timer firing.
        """
        self.opacity.insert(0, self.opacity.pop())
        for i in range(self.numSectors):
            self.sectors[i].setAttr("opacity", self.opacity[i])
Esempio n. 4
0
File: test.py Progetto: Afey/pyjs
class TestPanel(SimplePanel):
    """ Our testing panel.
    """
    def __init__(self):
        """ Standard initialiser.
        """
        SimplePanel.__init__(self)

        # Taken from the "spinner" Raphael demo:

        colour           = "#000000"
        width            = 15
        r1               = 35
        r2               = 60
        cx               = r2 + width
        cy               = r2 + width
        self.numSectors  = 12
        self.canvas      = Raphael(r2*2 + width*2, r2*2 + width*2)
        self.sectors     = []
        self.opacity     = []
        beta             = 2 * math.pi / self.numSectors

        pathParams = {'stroke'         : colour,
                      'stroke-width'   : width,
                      'stroke-linecap' : "round"}

        for i in range(self.numSectors):
            alpha = beta * i - math.pi/2
            cos   = math.cos(alpha)
            sin   = math.sin(alpha)
            path  = self.canvas.path(data=None, attrs=pathParams)
            path.moveTo(cx + r1 * cos, cy + r1 * sin)
            path.lineTo(cx + r2 * cos, cy + r2 * sin)
            self.opacity.append(1 / self.numSectors * i)
            self.sectors.append(path)

        period = 1000/self.numSectors

        self._timer = Timer(notify=self)
        self._timer.scheduleRepeating(period)

        self.add(self.canvas)


    def onTimer(self, timer):
        """ Respond to our timer firing.
        """
        self.opacity.insert(0, self.opacity.pop())
        for i in range(self.numSectors):
            self.sectors[i].setAttr("opacity", self.opacity[i])
Esempio n. 5
0
class Spinner(SimplePanel):
    """ Our testing panel.
    """
    def __init__(self,width=600,height=300):
        """ Standard initialiser.
        """
        SimplePanel.__init__(self)

        # Taken from the "spinner" Raphael demo:
        self.width            = 15
        self.r1               = 35
        self.r2               = 60
        self.cx               = self.r2 + self.width
        self.cy               = self.r2 + self.width
        self.numSectors  = 12
        self.canvas      = Raphael(self.r2*2 + self.width*2, self.r2*2 + self.width*2)
        self.sectors     = []
        self.opacity     = []
        self.add(self.canvas)

    def draw(self):
        colour           = "#000000"
        beta             = 2 * math.pi / self.numSectors

        pathParams = {'stroke'         : colour,
                      'stroke-width'   : self.width,
                      'stroke-linecap' : "round"}

        for i in range(self.numSectors):
            alpha = beta * i - math.pi/2
            cos   = math.cos(alpha)
            sin   = math.sin(alpha)
            data=','.join(['M',str(self.cx + self.r1 * cos),str(self.cy + self.r1 * sin),'L',str(self.cx + self.r2 * cos),str(self.cy + self.r2 * sin)])
            path  = self.canvas.path(data=data,attrs=pathParams)
            self.opacity.append(1.0 * i / self.numSectors )
            self.sectors.append(path)

        period = 1000/self.numSectors
        self._timer = Timer(notify=self)
        self._timer.scheduleRepeating(period)        

    def onTimer(self, timerID):
        """ Respond to our timer firing.
        """
        self.opacity.insert(0, self.opacity.pop())
        for i in range(self.numSectors):
            self.sectors[i].setAttr("opacity", self.opacity[i])
Esempio n. 6
0
class GUI(VerticalPanel,GUI_Event):
    def __init__(self):
        """ Standard initialiser.
        """
        VerticalPanel.__init__(self)
        GUI_Event.__init__(self)
        self.canvas = Raphael(900,700)
        #self.canvas.addListener('mousedown',self.test)
        #self.canvas.addListener('contextmenu',self.test)
        #self.tb = TextArea()
        #self.tb.setName("textBoxFormElement")
        #self.tb.setStyleAttribute({'position':'absolute',
        #    'top':'175px','left':'158px'
        #    ,'color':COLOR['maroon']
        #    ,'background':COLOR['peachpuff']
        #    ,'background-color':COLOR['peachpuff']})
        #self.tb.setSize(450,100)
        #self.tb.setReadonly('readonly')
        self.add(self.canvas)
        #self.add(self.tb)
        x = DOM.getAbsoluteLeft(self.canvas.getElement())
        y = DOM.getAbsoluteTop(self.canvas.getElement())
        self.offset = (x,y)
        '''
    
        Empacotador.init()
        Menu.init()
        
        self.click_listeners = []
        self.drag_listeners = []
        self.drop_listeners = []
        self.roll_listeners = []
        self.act_listeners = []
        self.do_up = self._do_up
        self.do_move = self._do_nothing
        self.do_down = self._do_down #self._do_nothing
        self._create()
        '''
        
    def _inicia(self,game):
        self.game = game
    def _decorate(self,element):
        element.avatar = element
        return element
    def talk(self,msg='foi'):
        alert (msg)
    def test(self,elm,event,msg='foi'):
        location = None
        JS('''
           location = window.location.hostname;

           ''')
        if 'localhost' == location: location +=':8004'
        return location
        x = DOM.eventGetClientX(event)
        y = DOM.eventGetClientY(event)
        alert ('%s %s %s'%(msg,x,y))
    def create_game(self,game,title):
        self.game = game
        RootPanel().add(self)
        return self.inicia()
    def remove(self, element):
        if element in self.drop_listeners:
            self.drop_listeners.remove(element)
        element.remove()
        
    def text(self,x,y,texto,color='navajo white', size =16):
        t = self.canvas.text(x,y,texto)
        t.setAttrs({'fill':COLOR[color],'stroke':COLOR[color],'font-size':'%d'%size})
        return t
    def path(self,path, width = 1, color='navajo white', background ='white'):
        #color:#000000;fill:#462813;fill-opacity:1;stroke:#d08554;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate
        pathParams = {'stroke'         : COLOR[color],
                      'color'           : color,
                      'fill'            : COLOR[background],
                      #'stroke-width'   : width, #"%dpx"%width,
                      'stroke-linecap' : "round"}

        t  = self.canvas.path(data=path,attrs=pathParams)
        return t
    def textarea(self,x,y,w,h,texto,color='navajo white', background ='white'):
        t = Text_Area(self,texto,x,y,w,h,color, background)
        return t
        #return self._decorate(t)
    def rect(self,x,y,dx,dy,color='navajo white', line =None):
        r = self.canvas.rect(x,y,dx-x,dy-y)
        r.setAttrs({'fill':COLOR[color],'stroke':line and COLOR[line] or COLOR[color]})
        #r.addListener('click',self.test)
        #r.addListener('mousedown',self.test)
        #r.addListener('contextmenu',self.test)
        #return r
        return self._decorate(r)
    def image(self,glyph,x,y,dx,dy, l=None, f='png', buff=''):
        return Empacotador(self.canvas,glyph,x,y,dx,dy, l)
    def score(self,score,houses):
        score =  j_p.encode(score)
        houses =  j_p.encode(houses)
        DOM.setAttribute(self.scored,"value",score)
        DOM.setAttribute(self.housed,"value",houses)
        #self.talk(str((score,houses)))
        frm = self.__form
        JS("""
            frm.submit()
        """)
        #self.__form.submit()
        return score
    def send(self,uid,**kwargs):
        score =  j_p.encode(uid)
        message = dict(line= uid, _xsrf= self.x)
        message.update(kwargs)
        message =  j_p.encode(message)
        self._socket.sending(message)
    def inicia(self):
        global IMAGEREPO
        self.__form = f = DOM.getElementById('mainform')
        self.x = DOM.getChild(f,0).value #DOM.getElementByName('_xsrf').value
        g = DOM.getChild(f,1).value
        self.scored = DOM.getChild(f,2)
        self.housed = DOM.getChild(f,3)
        if g == '12de6b622cbfe4d8f5c8d3347e56ae8c': IMAGEREPO = 'imagens/'
        #self.talk(self.scored.value+self.housed.value+IMAGEREPO)
        self._socket = NullSocket() #WebSocket("ws://%s/chatsocket"%self.test())
        self._socket.register_receiver(self.game.receive)
        obj = j_p.wdecode(self.housed.value)
        #self.text(400,85, str(obj) ,'darkbrown',10)
        #obj = [dict(body='nonono')]
        return obj
    def receive(self,message = 'nono'):
        self.talk(message.line+ ':'+ message.body)
    def slate(self,source,x,y,w,h, element = None, l=None, f=None, buff= None):
        return Slate(self.canvas,source,x,y,w,h, l, f, buff)
    def icon(self):#,source,x,y,w,h, l=None, f=None, buff= None):
        return Menu(self.canvas)#source,x,y,w,h, l, f, buff)
    def flyer(self,source,x,y,w=16,h=16):#, l=None, f=None, buff= None):
        return Flyer(self.canvas,source,x,y,w,h)#source,x,y,w,h, l, f, buff)