예제 #1
0
파일: scrible.py 프로젝트: estemenson/CMAP
 def drawTextInput(self,touch):
     start, pos = self.touch_time[touch.id]
     start = start if start else time.time() 
     elaspsed_time = time.time() -  start
     idu = self.touch_keys[touch.id]
     Log.debug('Elapsed time:%s' % elaspsed_time)
     if elaspsed_time >= 1:
         distance = Vector.distance( Vector(pos.sx, pos.sy),
                                     Vector(touch.osxpos, touch.osypos))
         Log.debug('Screen coordinate Distance:%f vs %f' % (distance,self.press_and_hold_distance))
         _l = len(self.touch_positions[idu]['Cdata'])
         Log.debug('Num points:%d' % _l)
         _vd = Vector.distance(\
                         Vector(*self.touch_positions[idu]['Cdata'][0]),\
                         Vector(*self.touch_positions[idu]['Cdata'][_l-1]))
         Log.debug('touch distance :%f and %d' % (_vd, int(_vd)))
         if distance <= self.press_and_hold_distance and\
                     (_l < self.travel_limit or int(_vd) < self.travel_limit):                                            
             
             txt = ScribbleTextWidget(pos=touch.pos, group=self.session,
                                                keyboard=self.keyboard,
                                                cls='scribbleKeyboardcss')
             txt.push_handlers(on_transform=curry(self.on_transform,txt))
             self.add_widget(txt) 
             self.disable_all()
             txt.enable()
             d = txt.to_dic()
             self.dispatch_event('on_text_change', d)
             return True
예제 #2
0
파일: doubletap.py 프로젝트: bernt/pymt
 def find_double_tap(self, ref):
     """Find a double tap touch within self.touches.
     The touch must be not a previous double tap, and the distance must be
     ok"""
     for touchid in self.touches:
         if ref.id == touchid:
             continue
         type, touch = self.touches[touchid]
         if type != "up":
             continue
         if touch.is_double_tap:
             continue
         distance = Vector.distance(Vector(ref.sx, ref.sy), Vector(touch.osxpos, touch.osypos))
         if distance > self.double_tap_distance:
             continue
         touch.double_tap_distance = distance
         return touch
     return None
예제 #3
0
파일: doubletap.py 프로젝트: gavine199/pymt
 def find_double_tap(self, ref):
     '''Find a double tap touch within self.touches.
     The touch must be not a previous double tap, and the distance must be
     ok'''
     for touchid in self.touches:
         if ref.uid == touchid:
             continue
         type, touch = self.touches[touchid]
         if type != 'up':
             continue
         if touch.is_double_tap:
             continue
         distance = Vector.distance(Vector(ref.sx, ref.sy),
                                    Vector(touch.osxpos, touch.osypos))
         if distance > self.double_tap_distance:
             continue
         touch.double_tap_distance = distance
         return touch
     return None
예제 #4
0
파일: radial.py 프로젝트: Markitox/pymt
class MTVectorSlider(MTWidget):
    '''
    This is a slider that provides an arrow, and allows you to manipulate
    it just like any other vector, adjusting its angle and amplitude.

    :Parameters:
        `radius` : int, default to 200
            The radius of the whole widget

    :Events:
        `on_amplitude_change`: (amplitude)
            Fired when amplitude is changed
        `on_angle_change`: (angle)
            Fired when angle is changed
        `on_vector_change`: (amplitude, angle)
            Fired when vector is changed

    :Styles:
        `vector-color` : color
            Color of the vector
        `slider-color` : color
            Color of the triangle
        `bg-color` : color
            Background color of the slider
    '''

    def __init__(self, **kwargs):
        kwargs.setdefault('radius', 200)

        super(MTVectorSlider, self).__init__(**kwargs)

        self.radius = kwargs.get('radius')

        self.vector = Vector(self.x+self.radius, self.y)
        self.amplitude = 0
        self.angle = 0

        self.register_event_type('on_amplitude_change')
        self.register_event_type('on_angle_change')
        self.register_event_type('on_vector_change')

    def on_amplitude_change(self, *largs):
        pass

    def on_angle_change(self, *largs):
        pass

    def on_vector_change(self, *largs):
        pass

    def collide_point(self, x, y):
        '''Because this widget is a circle, and this method as
        defined in MTWidget is for a square, we have to override
        it.'''
        return _get_distance(self.pos, (x, y)) <= self.radius

    def _calc_stuff(self):
        '''Recalculated the args for the callbacks'''
        self.amplitude = self.vector.distance(self.pos)
        # Make a new vector relative to the origin
        tvec = [self.vector[0], self.vector[1]]
        tvec[0] -= self.pos[0]
        tvec[1] -= self.pos[1]

        # Incase python throws float div or div by zero exception,
        # ignore them, we will be close enough
        try:
            self.angle = degrees(atan((int(tvec[1])/int(tvec[0]))))
        except Exception:
            pass

        # Ajdust quadrants so we have 0-360 degrees
        if tvec[0] < 0 and tvec[1] > 0:
            self.angle = 90 + (90 + self.angle)
        elif tvec[0] < 0 and tvec[1] < 0:
            self.angle += 180
        elif tvec[0] > 0 and tvec[1] < 0:
            self.angle = 270 + (self.angle + 90)
        elif tvec[0] > 0 and tvec[1] > 0:
            pass

    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            self.vector[0], self.vector[1] = touch.x, touch.y
            self._calc_stuff()

            self.dispatch_event('on_aplitude_change', self.amplitude)
            self.dispatch_event('on_angle_change', self.angle)
            self.dispatch_event('on_vector_change', self.amplitude, self.angle)

            return True
    def on_touch_move(self, touch):
        if self.collide_point(touch.x, touch.y):
            self.vector[0], self.vector[1] = touch.x, touch.y
            self._calc_stuff()

            self.dispatch_event('on_aplitude_change', self.amplitude)
            self.dispatch_event('on_angle_change', self.angle)
            self.dispatch_event('on_vector_change', self.amplitude, self.angle)

            return True

    def draw(self):
        # Background
        set_color(*self.style.get('bg-color'))
        drawCircle(self.pos, self.radius)

        # A good size for the hand, proportional to the size of the widget
        hd = self.radius / 10
        # Draw center of the hand
        set_color(*self.style.get('vector-color'))
        drawCircle(self.pos, hd)
        # Rotate the triangle so its not skewed
        l = prot((self.pos[0] - hd, self.pos[1]), self.angle-90, self.pos)
        h = prot((self.pos[0] + hd, self.pos[1]), self.angle-90, self.pos)
        # Draw triable of the hand
        with gx_begin(GL_POLYGON):
            glVertex2f(*l)
            glVertex2f(*h)
            glVertex2f(self.vector[0], self.vector[1])
예제 #5
0
파일: scrible.py 프로젝트: estemenson/CMAP
 def should_delete(self,touch_p, line_p):    
     distance = Vector.distance( Vector(*line_p), #IGNORE:W0142
                                 Vector(*touch_p)) #IGNORE:W0142
     if distance <= self.delete_distance:
         return True
예제 #6
0
파일: scrible.py 프로젝트: estemenson/CMAP
class ScribbleText(MyTextArea):
    def __init__(self, **kwargs):
        kwargs.setdefault('padding_x', 3)
        kwargs.setdefault('autosize', True)
        kwargs.setdefault('cls', 'mytextinput')
        kwargs.setdefault('style',{'font-size': kwargs['font-size']})
        super(ScribbleText, self).__init__(**kwargs)
        self.orig = (0, 0)
        self.label_obj.options['font_size'] = self.style['font-size']
        self.label_obj.refresh()
    def _recalc_size(self):
        # We could do this as .size property I suppose, but then we'd
        # be calculating it all the time when .size is accessed.
        num = len(self.lines)
        if not num:
            return
        # The following two if statements ensure that the textarea remains
        # easily clickable even if there's no content.
        if self.autosize or self.autoheight:
            self.height = num * self.line_height + self.line_spacing * (num - 1)
        if (self.autosize or self.autowidth):
            self.width = max(label.content_width for label in self.line_labels)
            + 20

    def on_press(self, touch):
        self.orig = Vector(self.to_window(*touch.pos))

    def on_release(self, touch):
        final = Vector(self.to_window(*touch.pos))
        if self.orig.distance(final) <= 4:
            if not self.is_active_input:
                self.parent.disable_all() #IGNORE:E1101
                self._can_deactive = True
            super(ScribbleText, self).on_release(touch)
#    def show_keyboard(self):
#        super(MyTextArea,self).show_keyboard()
#        to_root = self.keyboard_to_root
#        if(to_root):
#            w = self.get_root_window() if to_root else self.get_parent_window()
#            w.remove_widget(self.keyboard)
#            #we want to add this keyboard to the innerwindow border
#            #self.parent.parent.parent.parent.show_keyboard(self.keyboard)
#            self.parent.parent.parent.parent.add_widget(self.keyboard)
#            #self.keyboard.pos = self.to_window(self.pos[0], self.pos[1] - self.height  - self.keyboard.height) #position of the text input field
#
#
#                                
#    def hide_keyboard(self):
#        if self._is_active_input:
#            self.parent.parent.parent.parent.set_button_image() 
#        super(ScribbleText, self).hide_keyboard()
#        p = self.parent
#        if(p):
#            pp = p.parent
#            if(pp):
#                ppp = pp.parent
#                if(ppp):
#                    p4 = ppp.parent
#                    if(p4):
#                        #p4.hide_keyboard(self.keyboard)
#                        p4.remove_widget(self.keyboard)

    def on_touch_down(self, touch):
        super(ScribbleText, self).on_touch_down(touch)
        return False
예제 #7
0
파일: scatter.py 프로젝트: gavine199/pymt
 def _get_scale(self):
     p1 = Vector(*self.to_parent(0, 0))
     p2 = Vector(*self.to_parent(1, 0))
     scale = p1.distance(p2)
     return float(scale)
예제 #8
0
파일: scatter.py 프로젝트: Markitox/pymt
 def _get_scale(self):
     p1 = Vector(*self.to_parent(0, 0))
     p2 = Vector(*self.to_parent(1, 0))
     scale = p1.distance(p2)
     return float(scale)
예제 #9
0
class MTVectorSlider(MTWidget):
    '''
    This is a slider that provides an arrow, and allows you to manipulate
    it just like any other vector, adjusting its angle and amplitude.

    :Parameters:
        `radius` : int, default to 200
            The radius of the whole widget

    :Events:
        `on_amplitude_change`: (amplitude)
            Fired when amplitude is changed
        `on_angle_change`: (angle)
            Fired when angle is changed
        `on_vector_change`: (amplitude, angle)
            Fired when vector is changed

    :Styles:
        `vector-color` : color
            Color of the vector
        `slider-color` : color
            Color of the triangle
        `bg-color` : color
            Background color of the slider
    '''
    def __init__(self, **kwargs):
        kwargs.setdefault('radius', 200)

        super(MTVectorSlider, self).__init__(**kwargs)

        self.radius = kwargs.get('radius')

        self.vector = Vector(self.x + self.radius, self.y)
        self.amplitude = 0
        self.angle = 0

        self.register_event_type('on_amplitude_change')
        self.register_event_type('on_angle_change')
        self.register_event_type('on_vector_change')

    def on_amplitude_change(self, *largs):
        pass

    def on_angle_change(self, *largs):
        pass

    def on_vector_change(self, *largs):
        pass

    def collide_point(self, x, y):
        '''Because this widget is a circle, and this method as
        defined in MTWidget is for a square, we have to override
        it.'''
        return _get_distance(self.pos, (x, y)) <= self.radius

    def _calc_stuff(self):
        '''Recalculated the args for the callbacks'''
        self.amplitude = self.vector.distance(self.pos)
        # Make a new vector relative to the origin
        tvec = [self.vector[0], self.vector[1]]
        tvec[0] -= self.pos[0]
        tvec[1] -= self.pos[1]

        # Incase python throws float div or div by zero exception,
        # ignore them, we will be close enough
        try:
            self.angle = degrees(atan((int(tvec[1]) / int(tvec[0]))))
        except Exception:
            pass

        # Ajdust quadrants so we have 0-360 degrees
        if tvec[0] < 0 and tvec[1] > 0:
            self.angle = 90 + (90 + self.angle)
        elif tvec[0] < 0 and tvec[1] < 0:
            self.angle += 180
        elif tvec[0] > 0 and tvec[1] < 0:
            self.angle = 270 + (self.angle + 90)
        elif tvec[0] > 0 and tvec[1] > 0:
            pass

    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            self.vector[0], self.vector[1] = touch.x, touch.y
            self._calc_stuff()

            self.dispatch_event('on_aplitude_change', self.amplitude)
            self.dispatch_event('on_angle_change', self.angle)
            self.dispatch_event('on_vector_change', self.amplitude, self.angle)

            return True

    def on_touch_move(self, touch):
        if self.collide_point(touch.x, touch.y):
            self.vector[0], self.vector[1] = touch.x, touch.y
            self._calc_stuff()

            self.dispatch_event('on_aplitude_change', self.amplitude)
            self.dispatch_event('on_angle_change', self.angle)
            self.dispatch_event('on_vector_change', self.amplitude, self.angle)

            return True

    def draw(self):
        # Background
        set_color(*self.style.get('bg-color'))
        drawCircle(self.pos, self.radius)

        # A good size for the hand, proportional to the size of the widget
        hd = self.radius / 10
        # Draw center of the hand
        set_color(*self.style.get('vector-color'))
        drawCircle(self.pos, hd)
        # Rotate the triangle so its not skewed
        l = prot((self.pos[0] - hd, self.pos[1]), self.angle - 90, self.pos)
        h = prot((self.pos[0] + hd, self.pos[1]), self.angle - 90, self.pos)
        # Draw triable of the hand
        with gx_begin(GL_POLYGON):
            glVertex2f(*l)
            glVertex2f(*h)
            glVertex2f(self.vector[0], self.vector[1])