예제 #1
0
    def setup_controls(self):
        self.controls = MTWidget()
        self.controls.parent = self

        self.btn_fullscreen = MTImageButton(
            filename=pymt_icons_dir + 'fullscreen.png',
            scale=self.control_scale, cls='innerwindow-fullscreen')
        self.btn_fullscreen.push_handlers(on_release=self.fullscreen)
        self.controls.add_widget(self.btn_fullscreen)

        self.btn_close = MTImageButton(
            filename=pymt_icons_dir + 'stop.png',
            scale=self.control_scale, cls='innerwindow-close')
        self.btn_close.push_handlers(on_release=self.close)
        self.controls.add_widget(self.btn_close)

        self.update_controls()
예제 #2
0
    def setup_controls(self):
        self.controls = MTWidget()
        self.controls.parent = self

        self.btn_fullscreen = MTImageButton(filename=pymt_icons_dir +
                                            'fullscreen.png',
                                            scale=self.control_scale,
                                            cls='innerwindow-fullscreen')
        self.btn_fullscreen.push_handlers(on_release=self.fullscreen)
        self.controls.add_widget(self.btn_fullscreen)

        self.btn_close = MTImageButton(filename=pymt_icons_dir + 'stop.png',
                                       scale=self.control_scale,
                                       cls='innerwindow-close')
        self.btn_close.push_handlers(on_release=self.close)
        self.controls.add_widget(self.btn_close)

        self.update_controls()
예제 #3
0
파일: borders.py 프로젝트: estemenson/CMAP
class MyInnerWindowWithTrash(MyInnerWindow):
    def __init__(self, **kwargs):
        self.btn_trash = MTImageButton(filename=_trash_icon_path,
                                            scale=1,
                                            cls='innerwindow-close')
        self.btn_trash.my_padding = 12
        sz = self.ctrls_buttons_size = kwargs.setdefault('ctrls_button_size', 
                                                         (0,48))
        kwargs['ctrls_button_size'] = (sz[0] + self.btn_trash.width + \
                                       self.btn_trash.my_padding, sz[1])
        self.ctrls_buttons_size = kwargs['ctrls_button_size'] 
        super(MyInnerWindowWithTrash,self).__init__(**kwargs)
        self.btn_trash.scale = self.control_scale
        self.btn_trash.push_handlers(on_release=self.trash)
        self.controls.add_widget(self.btn_trash)
        self.update_controls()
       
    def trash(self, touch=None, *largs, **kwargs):
        pass
예제 #4
0
파일: borders.py 프로젝트: estemenson/CMAP
class MyInnerWindowWithSaveAndTrash(MyInnerWindowWithTrash):
    def __init__(self, **kwargs):
        self.ctrl_buttons_width = None
        self.btn_save = MTImageButton(filename=_save_icon_path,
                                            scale=1,
                                            cls='innerwindow-close')
        self.btn_save.my_padding = 5
        sz = self.ctrls_buttons_size = kwargs.setdefault('ctrls_button_size',
                                                         (0,48))
        kwargs['ctrls_button_size'] = (sz[0] + self.btn_save.width +
                                       self.btn_save.my_padding, sz[1])
        self.ctrls_buttons_size = kwargs['ctrls_button_size'] 
        super(MyInnerWindowWithSaveAndTrash,self).__init__(**kwargs)
        self.btn_save.scale = self.control_scale
        self.btn_save.push_handlers(on_release=self.save)
        self.controls.add_widget(self.btn_save)
        self.update_controls()
       
    def save(self, touch=None):
        pass
예제 #5
0
파일: borders.py 프로젝트: estemenson/CMAP
 def __init__(self, **kwargs):
     ctrl_scale = kwargs.setdefault('control_scale', 1.0)
     self.btn_minimize = MTImageButton(filename=_minimize_icon_path,
                                         scale=ctrl_scale,
                                         cls='innerwindow-close')
     self.btn_minimize.my_padding = 5
     self.isMinimized = False
     sz = self.ctrls_buttons_size = kwargs.setdefault('ctrls_button_size', 
                                                      (0,48*ctrl_scale))
     kwargs['ctrls_button_size'] = (sz[0] + (3* self.btn_minimize.width) + \
                                 2* self.btn_minimize.my_padding , sz[1])
     self.ctrls_buttons_size = kwargs['ctrls_button_size'] 
     super(MyInnerWindow,self).__init__(**kwargs)
     self.minimized_label =kwargs.setdefault('minimized_label','test label')
     self.old_pos = self.pos
     self.old_size = (0,0)
     self.old_minimize_pos = None
     self.ctrl_buttons_width = self.ctrls_buttons_size[0] 
     self.btn_minimize.push_handlers(on_release=self.minimize)
     #remove the close control button and addit again after the minimize
     btn = self.controls.children.pop()
     self.controls.add_widget(self.btn_minimize)
     self.controls.add_widget(btn)
     self.update_controls()
예제 #6
0
파일: scrible.py 프로젝트: estemenson/CMAP
 def __init__(self, **kwargs):
     kwargs.setdefault('cls', 'scribbleBordercss')
     super(MyScribbleWidget,self).__init__(**kwargs)
     self.session = uuid()
     self.is_pen_active = True
     self.sessions = kwargs.setdefault('sessions',{self.session:{}})
     self.press_and_hold_distance = \
         kwargs.setdefault('activate_keyboard_distance',10 /1000.0)
     self.delete_distance = kwargs.setdefault('delete_distance',12)
     self.potential_deleted_lines  = None
     self.potential_deleted_text  = None
     self.touch_time = {}
     self.old_touches = {}
     self.old_colors = {}
     self.touch_positions = {}
     self.touch_keys = {}
     self.touch_positions = kwargs.get('scribbles',{})
     self.travel_limit = 5
     self.keyboard = MTVKeyboard()
     tf = kwargs.get('TextFields', {})
     if tf:
         args = {'group':self.session,
                 'keyboard':self.keyboard,
                 'cls':'scribbleKeyboardcss'}
         for txt in tf.values():
             # we need to create and add the following textfields
             args['Id']=txt['Id'] 
             args['pos']=eval(txt['pos'])
             args['size']=eval(txt['size'])
             args['color']=txt['Color']
             args['font-size']=eval(txt['Font-Size'])
             args['label']=txt['Cdata']
             stw = ScribbleTextWidget(**args) #IGNORE:W0142
             stw.push_handlers(on_transform=curry(self.on_transform,stw))
             self.add_widget(stw)
     self.ctrls_container = MySidePanel(layout=MTGridLayout(cols=1),
                                        use_root=False,#duration=0.1,
                                     corner=MTImageButton(padding=5,
                             image=Loader.image(OPEN_SIDE_ICON),
                                                     size=(48,48)),
                                     corner_open=MTImageButton(padding=5,
                             image=Loader.image(CLOSE_SIDE_ICON),
                                                     size=(48,48)),
                                     align='middle',
                                     side='right',
                                     pos=(0,0),cls='mybtn')
     btn_pen = MTImageButton(padding=5,image=Loader.image(PEN_ICON))
     btn_pen.connect('on_press', self.pen)
     self.ctrls_container.add_widget(btn_pen)
     btn_erase = MTImageButton(padding=5,image=Loader.image(ERASER_ICON))
     btn_erase.connect('on_press', self.eraser)
     self.ctrls_container.add_widget(btn_erase)
     btn_color = MTImageButton(padding=5,image=Loader.image(COLOR_ICON))
     btn_color.connect('on_press', self.color)
     self.ctrls_container.add_widget(btn_color)
     self.add_widget(self.ctrls_container)
     self.current_color = DEFAULT_COLOR
     self.bg_color = self.style['bg-color']
     self.new_color = None
     self.border_color = self.style['border-color']
     self.border_width = self.style['border-width']
     self.register_event_type('on_change')
     self.register_event_type('on_text_change')
예제 #7
0
class MTInnerWindow(MTScatterWidget):
    '''InnerWindow are a wrapper to render an application inside another
    application, and work like a multitouch window manager. With innerwindow,
    you can move / rotate / fullscreen an application.

    Checkout the `desktop` example to check how it work !

    :Parameters:
        `control_scale`: float, default to 1.0
            Scale of controls widget. 1.0 mean 100%.

    :Styles:
        `bg-color`
            Background color of innerwindow + border
        `bg-color-move`
            Background color when only move (one touch)
        `bg-color-full`
            Background color when rotate/scale/move (multitouch)
        `border-width`
            Size of border
    '''
    def __init__(self, **kwargs):
        kwargs.setdefault('control_scale', 1.0)
        super(MTInnerWindow, self).__init__(**kwargs)
        self.container = MTInnerWindowContainer(pos=(0, 0), size=self.size)
        super(MTInnerWindow, self).add_widget(self.container)
        self.control_scale = kwargs.get('control_scale')
        self.setup_controls()

    def setup_controls(self):
        self.controls = MTWidget()
        self.controls.parent = self

        self.btn_fullscreen = MTImageButton(
            filename=pymt_icons_dir + 'fullscreen.png',
            scale=self.control_scale, cls='innerwindow-fullscreen')
        self.btn_fullscreen.push_handlers(on_release=self.fullscreen)
        self.controls.add_widget(self.btn_fullscreen)

        self.btn_close = MTImageButton(
            filename=pymt_icons_dir + 'stop.png',
            scale=self.control_scale, cls='innerwindow-close')
        self.btn_close.push_handlers(on_release=self.close)
        self.controls.add_widget(self.btn_close)

        self.update_controls()

    def fullscreen(self, *largs, **kwargs):
        root_win = self.parent.get_parent_window()

        # save state for restore
        self.old_children = root_win.children
        self.old_size = self.size

        # set new children
        root_win.children = SafeList()
        root_win.add_widget(self.container)

        btn_unfullscreen = MTButton(pos=(root_win.width-50, root_win.height-50),
                                    size=(50, 50), label='Back')
        btn_unfullscreen.push_handlers(on_release=self.unfullscreen)
        root_win.add_widget(btn_unfullscreen)
        self.size = root_win.size
        self.container.size = self.size

    def unfullscreen(self, *largs, **kwargs):
        # restore old widget
        root_win = self.parent.get_parent_window()
        root_win.children = self.old_children

        # reset container parent
        self.container.parent = self

        # set old size
        self.size = self.old_size
        self.container.size = self.size

    def close(self, touch):
        self.parent.remove_widget(self)

    def add_widget(self, w):
        self.container.add_widget(w)

    def remove_widget(self, w):
        self.container.remove_widget(w)

    def get_parent_window(self):
        return self.container

    def get_scaled_border(self):
        return self.style.get('border-width') * (1.0 / self.scale)

    def update_controls(self):
        scaled_border = self.get_scaled_border()
        center_x = self.width / 2
        center_y = - scaled_border
        for button in self.controls.children:
            button.scale = self.control_scale / self.scale
        self.btn_fullscreen.pos = \
                center_x - (self.btn_fullscreen.width) - 2, \
                center_y - (self.btn_fullscreen.height / 2)
        self.btn_close.pos = \
                center_x + 2, \
                center_y - (self.btn_close.height / 2)

    def on_touch_down(self, touch):
        touch.push()
        touch.apply_transform_2d(super(MTInnerWindow, self).to_local)
        if self.controls.dispatch_event('on_touch_down', touch):
            touch.pop()
            touch.grab(self)
            return True
        touch.pop()

        if super(MTInnerWindow, self).on_touch_down(touch):
            return True

    def on_touch_move(self, touch):
        if touch.grab_current == self:
            touch.push()
            touch.apply_transform_2d(super(MTInnerWindow, self).to_local)
            if self.controls.dispatch_event('on_touch_move', touch):
                touch.pop()
                return True
            touch.pop()
        return super(MTInnerWindow, self).on_touch_move(touch)

    def on_touch_up(self, touch):
        if touch.grab_current == self:
            touch.push()
            touch.apply_transform_2d(super(MTInnerWindow, self).to_local)
            if self.controls.dispatch_event('on_touch_up', touch):
                touch.pop()
                touch.ungrab(self)
                return True
            touch.pop()
        return super(MTInnerWindow, self).on_touch_up(touch)

    def collide_point(self, x, y):
        scaled_border = self.get_scaled_border()
        local_coords = super(MTInnerWindow, self).to_local(x, y)
        left, right = -scaled_border, self.width + scaled_border
        bottom, top = -scaled_border, self.height + scaled_border
        if local_coords[0] > left and local_coords[0] < right \
           and local_coords[1] > bottom and local_coords[1] < top:
            return True
        else:
            return False

    def draw(self):
        # select color from number of touch
        if len(self._touches) == 0:
            set_color(*self.style.get('bg-color'))
        elif len(self._touches) == 1:
            set_color(*self.style.get('bg-color-move'))
        else:
            set_color(*self.style.get('bg-color-full'))

        # draw border
        scaled_border = self.get_scaled_border()
        self.update_controls()
        drawRoundedRectangle(
            pos=(-scaled_border, -scaled_border),
            size=(self.width+scaled_border*2, self.height+scaled_border*2),
            radius=15. / self.scale
        )

        # draw control background
        control_width = self.btn_fullscreen.width + self.btn_close.width
        drawRoundedRectangle(
            pos=((self.width/2)-(scaled_border + control_width / 2), -scaled_border * 2),
            size=(scaled_border*2 + control_width, scaled_border),
            radius=15. / self.scale,
            corners=(True, True, False, False)
        )

    def on_draw(self):
        with gx_matrix:
            glMultMatrixf(self.transform_gl)

            self.draw()
            self.controls.dispatch_event('on_draw')

            # use stencil for container
            with gx_stencil:
                drawRectangle((0, 0), size=self.size)
                stencilUse()
                self.container.dispatch_event('on_draw')

    def on_move(self, x, y):
        # no move on children
        pass

    def on_resize(self, w, h):
        # no resize of children
        pass
예제 #8
0
def main():
    global Log
    # This must be done BEFORE trying to import any PYMT stuff since PyMT
    # messes with the arguments
    from agileConfig import AgiConfig
    config = AgiConfig(Log)
    if config.noDatastore:
        Log.critical('No data store defined or accessible')
        sys.exit(2)
    if config.pymtUnavailable:
        Log.critical('PyMT is not available')
        sys.exit(2)
    if config.args.loglevel:
        Log.level = config.args.loglevel
    from agileConfig import AsyncHandler
    from pymt.ui.window import MTWindow
    from pymt.base import runTouchApp, stopTouchApp
    from cmap.controller.storyapp import StoryApp
    from cmap.tools.myTools import get_min_screen_size, scale_tuple
    from cmap.view.stories.storyViews import TestController
    import os
    
    
    Log.debug('current directory: %s' % os.path.abspath(os.path.curdir))
    if config.args.startdir:
        os.chdir(config.args.startdir)
        Log.debug('current directory: %s' % os.path.abspath(os.path.curdir))
    # Get the PyMT window    
    w = MTWindow()

    
    b = None
    try:
        if config.args.storycard:
            if config.args.storycard == 'flow':
                from pymt.ui.widgets.coverflow import MTCoverFlow
                from glob import glob
                from pymt.ui.widgets.button import MTImageButton
                from pymt.loader import Loader
                base_image = os.path.join(os.path.dirname(__file__),'examples',
                                           'framework','images')
                coverflow = MTCoverFlow(size=w.size)
                for filename in glob(os.path.join(base_image, '*.png')):
                    button = MTImageButton(image=Loader.image(filename))
                    button.title = os.path.basename(filename)
                    coverflow.add_widget(button)
            
                runTouchApp(coverflow)
                return
            else:            
                Log.debug('Testing stories only...')
                b = TestController(w, config.args.storycard)
        elif not config.args.fullscreen:
            Log.debug('Running in non fullscreen mode...')
            #Setup our application window
            size = get_min_screen_size()
            w.size = scale_tuple(size,0.045)
            scale = .13
            size = scale_tuple(w.size, scale)
            pos = (w.size[0] - (size[0] +55), w.size[1] - (size[1] +35))
            b = StoryApp(root_window=w,size=size, pos=pos,
                                   control_scale=0.7)
        else:
            Log.debug('Fullscreen mode...')
            b = StoryApp(root_window=w,size=w.size, pos=(0,0), 
                                  control_scale=0.7)
        w.add_widget(b)
        b.fullscreen()
        # Run the application
        Log.debug("About to run CMAP")
        runTouchApp()
        b.close(None)
        Log.debug('CMAP normal exit')
        return
    except Exception:
        Log.exception('Exception causing premature CMAP exit')
        # We need to make sure that everything shuts down cleanly
        stopTouchApp()
        if AsyncHandler() is not None:
            AsyncHandler().shutdown()
        Log.debug('CMAP exception exit')
        raise
예제 #9
0
파일: borders.py 프로젝트: estemenson/CMAP
class MyInnerWindow(MTInnerWindow):
    def __init__(self, **kwargs):
        ctrl_scale = kwargs.setdefault('control_scale', 1.0)
        self.btn_minimize = MTImageButton(filename=_minimize_icon_path,
                                            scale=ctrl_scale,
                                            cls='innerwindow-close')
        self.btn_minimize.my_padding = 5
        self.isMinimized = False
        sz = self.ctrls_buttons_size = kwargs.setdefault('ctrls_button_size', 
                                                         (0,48*ctrl_scale))
        kwargs['ctrls_button_size'] = (sz[0] + (3* self.btn_minimize.width) + \
                                    2* self.btn_minimize.my_padding , sz[1])
        self.ctrls_buttons_size = kwargs['ctrls_button_size'] 
        super(MyInnerWindow,self).__init__(**kwargs)
        self.minimized_label =kwargs.setdefault('minimized_label','test label')
        self.old_pos = self.pos
        self.old_size = (0,0)
        self.old_minimize_pos = None
        self.ctrl_buttons_width = self.ctrls_buttons_size[0] 
        self.btn_minimize.push_handlers(on_release=self.minimize)
        #remove the close control button and addit again after the minimize
        btn = self.controls.children.pop()
        self.controls.add_widget(self.btn_minimize)
        self.controls.add_widget(btn)
        self.update_controls()
        
    def update_controls(self):
        scaled_border = self.get_scaled_border()
        center_x = self.width/ 2
        center_y = - scaled_border 
        if self.isMinimized:
            center_y = scaled_border
        ctrls  = self.controls.children
        pos =(center_x-self.ctrls_buttons_size[0]/2 -
              (scaled_border/2*self.scale),# if self.scale != 1 else scaled_border,
                   center_y)
        start_pos_x = pos[0]
        for button in ctrls:
            button.scale = self.control_scale / self.scale
            #button.scale = self.scale * self.control_scale
            button.pos = start_pos_x,center_y - (button.height / (2*self.scale))
            try:
                my_padding = button.my_padding
            except Exception: #IGNORE:W0703
                my_padding = button.my_padding = 5 # set a default
            start_pos_x += (button.width + my_padding)
                
       
    def minimize(self):
        if self.isMinimized:
            self.restore()
        else: 
            self.isMinimized = True
            self.container.hide()
            self.old_pos = self.pos
            self.pos = self.get_minimize_pos()
            self.old_size = self.size
            self.size = (self.ctrls_buttons_size[0] * self.scale,
                         self.ctrls_buttons_size[1] * self.scale)
            

    def get_minimize_pos(self):
        if self.old_minimize_pos: return self.old_minimize_pos
        scaled_border = self.get_scaled_border()
        center_x = self.width / 2
        center_y = scaled_border
        return (center_x, center_y) 

        
    def restore(self):
        self.isMinimized = False
        self.container.show()
        self.old_minimize_pos = self.pos
        self.pos = self.old_pos
        self.size = self.old_size
        
        
    def fullscreen(self, *largs, **kwargs):
        if self.isMinimized:
            self.restore()
        super(MyInnerWindow,self).fullscreen(*largs, **kwargs)
        
        
    def draw(self):
        scaled_border = self.get_scaled_border()
        border_color=self.style.get('border-color')
        if not self.isMinimized:
            # select color from number of touch
            if len(self._touches) == 0:
                set_color(*self.style.get('bg-color'))
            elif len(self._touches) == 1:
                border_color = self.style.get('bg-color-move') 
                set_color(*border_color) #IGNORE:W0142
            else:
                border_color = self.style.get('bg-color-full') 
                set_color(*border_color) #IGNORE:W0142

            # draw border
            drawRoundedRectangle(
                pos=(-scaled_border, -scaled_border*2*self.scale),
                size=(self.width+scaled_border*2, self.height+scaled_border*3*self.scale),
                #size=(self.width+scaled_border*2, self.height+control_height*2),
                radius=15. / self.scale
            )
#            pos = ((self.width/2 - control_width/2),
#                   -scaled_border * 2)
#            size=(control_width, 
#                  control_height) 
#            corners=(True, True, False, False)
        else:
            pos = (0,-scaled_border)
            size=scale_tuple(self.size,-.1,-.5)
            l_pos = (size[0]/2, size[1] - 15 - scaled_border)
            corners=(True, True, True, True)
            drawLabel(label=self.minimized_label, pos=l_pos, 
                      color=self.style.get('font-color'))
            border_color=parse_color(self.style.get('min-border-color'))
            # draw control background
            drawRoundedRectangle(
                pos=pos,
                size=size,
                radius=15. / self.scale,
                corners=corners, color=border_color
            )
        #self.update_controls()
        

    def collide_point(self,x,y):
        return super(MyInnerWindow,self).collide_point(x,y) or \
                self.collide_controls(x,y)       
    def collide_controls(self, x,y):
        scaled_border = self.get_scaled_border()
        if not self.isMinimized:
            #now calculate the rectangle size and pos of the rectangle that
            #surrounds the controls based on their size
#            _ctrl_w,_ctrl_h= ((self.width/2)-(control_size[0]/2),\
#                   -scaled_border * 2)
#            _ctrl_x,_ctrl_y=scale_tuple(control_size, x_ctrl_border_scale,
#                                        y_ctrl_border_scale) 
            #now calculate the bounding box using the controls rectangle
            #and the innerWindow's position
            x,y = super(MyInnerWindow, self).to_local(x, y)  
            _x,_y =(-scaled_border, -scaled_border*2*self.scale)
            _w,_h =(self.width+scaled_border*2, self.height+scaled_border*3*self.scale)
#            _x = self.x + _ctrl_x -scaled_border*2 -2
#            _w = _ctrl_w + scaled_border*2
#            _y = self.y + _ctrl_h
#            _h = abs(_ctrl_h) +scaled_border
        else:
            _x = self.x #-scaled_border*2 -2
            _w = self.width + scaled_border*2
            _y = self.y #+ self.height
            _h = abs(self.height) +scaled_border
            
        if x >= _x \
                and x <= (_x + _w) \
                and y >= _y \
                and y <= (_y + _h):
            return True
        return False 
예제 #10
0
class MTInnerWindow(MTScatterWidget):
    '''InnerWindow are a wrapper to render an application inside another
    application, and work like a multitouch window manager. With innerwindow,
    you can move / rotate / fullscreen an application.

    Checkout the `desktop` example to check how it work !

    :Parameters:
        `control_scale`: float, default to 1.0
            Scale of controls widget. 1.0 mean 100%.

    :Styles:
        `bg-color`
            Background color of innerwindow + border
        `bg-color-move`
            Background color when only move (one touch)
        `bg-color-full`
            Background color when rotate/scale/move (multitouch)
        `border-width`
            Size of border
    '''
    def __init__(self, **kwargs):
        kwargs.setdefault('control_scale', 1.0)
        super(MTInnerWindow, self).__init__(**kwargs)
        self.container = MTInnerWindowContainer(pos=(0, 0), size=self.size)
        super(MTInnerWindow, self).add_widget(self.container)
        self.control_scale = kwargs.get('control_scale')
        self.setup_controls()

    def setup_controls(self):
        self.controls = MTWidget()
        self.controls.parent = self

        self.btn_fullscreen = MTImageButton(filename=pymt_icons_dir +
                                            'fullscreen.png',
                                            scale=self.control_scale,
                                            cls='innerwindow-fullscreen')
        self.btn_fullscreen.push_handlers(on_release=self.fullscreen)
        self.controls.add_widget(self.btn_fullscreen)

        self.btn_close = MTImageButton(filename=pymt_icons_dir + 'stop.png',
                                       scale=self.control_scale,
                                       cls='innerwindow-close')
        self.btn_close.push_handlers(on_release=self.close)
        self.controls.add_widget(self.btn_close)

        self.update_controls()

    def fullscreen(self, *largs, **kwargs):
        root_win = self.parent.get_parent_window()

        # save state for restore
        self.old_children = root_win.children
        self.old_size = self.size

        # set new children
        root_win.children = SafeList()
        root_win.add_widget(self.container)

        btn_unfullscreen = MTButton(pos=(root_win.width - 50,
                                         root_win.height - 50),
                                    size=(50, 50),
                                    label='Back')
        btn_unfullscreen.push_handlers(on_release=self.unfullscreen)
        root_win.add_widget(btn_unfullscreen)
        self.size = root_win.size
        self.container.size = self.size

    def unfullscreen(self, *largs, **kwargs):
        # restore old widget
        root_win = self.parent.get_parent_window()
        root_win.children = self.old_children

        # reset container parent
        self.container.parent = self

        # set old size
        self.size = self.old_size
        self.container.size = self.size

    def close(self, touch):
        self.parent.remove_widget(self)

    def add_widget(self, w):
        self.container.add_widget(w)

    def remove_widget(self, w):
        self.container.remove_widget(w)

    def get_parent_window(self):
        return self.container

    def get_scaled_border(self):
        return self.style.get('border-width') * (1.0 / self.scale)

    def update_controls(self):
        scaled_border = self.get_scaled_border()
        center_x = self.width / 2
        center_y = -scaled_border
        for button in self.controls.children:
            button.scale = self.control_scale / self.scale
        self.btn_fullscreen.pos = \
                center_x - (self.btn_fullscreen.width) - 2, \
                center_y - (self.btn_fullscreen.height / 2)
        self.btn_close.pos = \
                center_x + 2, \
                center_y - (self.btn_close.height / 2)

    def on_touch_down(self, touch):
        touch.push()
        touch.apply_transform_2d(super(MTInnerWindow, self).to_local)
        if self.controls.dispatch_event('on_touch_down', touch):
            touch.pop()
            touch.grab(self)
            return True
        touch.pop()

        if super(MTInnerWindow, self).on_touch_down(touch):
            return True

    def on_touch_move(self, touch):
        if touch.grab_current == self:
            touch.push()
            touch.apply_transform_2d(super(MTInnerWindow, self).to_local)
            if self.controls.dispatch_event('on_touch_move', touch):
                touch.pop()
                return True
            touch.pop()
        return super(MTInnerWindow, self).on_touch_move(touch)

    def on_touch_up(self, touch):
        if touch.grab_current == self:
            touch.push()
            touch.apply_transform_2d(super(MTInnerWindow, self).to_local)
            if self.controls.dispatch_event('on_touch_up', touch):
                touch.pop()
                touch.ungrab(self)
                return True
            touch.pop()
        return super(MTInnerWindow, self).on_touch_up(touch)

    def collide_point(self, x, y):
        scaled_border = self.get_scaled_border()
        local_coords = super(MTInnerWindow, self).to_local(x, y)
        left, right = -scaled_border, self.width + scaled_border
        bottom, top = -scaled_border, self.height + scaled_border
        if local_coords[0] > left and local_coords[0] < right \
           and local_coords[1] > bottom and local_coords[1] < top:
            return True
        else:
            return False

    def draw(self):
        # select color from number of touch
        if len(self._touches) == 0:
            set_color(*self.style.get('bg-color'))
        elif len(self._touches) == 1:
            set_color(*self.style.get('bg-color-move'))
        else:
            set_color(*self.style.get('bg-color-full'))

        # draw border
        scaled_border = self.get_scaled_border()
        self.update_controls()
        drawRoundedRectangle(pos=(-scaled_border, -scaled_border),
                             size=(self.width + scaled_border * 2,
                                   self.height + scaled_border * 2),
                             radius=15. / self.scale)

        # draw control background
        control_width = self.btn_fullscreen.width + self.btn_close.width
        drawRoundedRectangle(
            pos=((self.width / 2) - (scaled_border + control_width / 2),
                 -scaled_border * 2),
            size=(scaled_border * 2 + control_width, scaled_border),
            radius=15. / self.scale,
            corners=(True, True, False, False))

    def on_draw(self):
        with gx_matrix:
            glMultMatrixf(self.transform_gl)

            self.draw()
            self.controls.dispatch_event('on_draw')

            # use stencil for container
            with gx_stencil:
                drawRectangle((0, 0), size=self.size)
                stencilUse()
                self.container.dispatch_event('on_draw')

    def on_move(self, x, y):
        # no move on children
        pass

    def on_resize(self, w, h):
        # no resize of children
        pass
예제 #11
0
def getControls():
    l = []
    b = MTImageButton(
            filename=pymt_icons_dir + 'fullscreen.png',
            cls='innerwindow-fullscreen')
    b.push_handlers(on_release=fullscreen)
    l.append(b)
    b = MTImageButton(
            filename=pymt_icons_dir + 'stop.png',
            cls='innerwindow-close')
    b.push_handlers(on_release=close)
    l.append(b)
    b = MTImageButton(filename=_minimize_icon_path,
                                        scale=1,
                                        cls='innerwindow-close')
    b.my_padding = 5
    b.push_handlers(on_release=minimize)
    l.append(b)
    b = MTImageButton(filename=_trash_icon_path,
                                        scale=1,
                                        cls='innerwindow-close')
    b.my_padding = 12
    b.push_handlers(on_release=trash)
    l.append(b)
    b = MTImageButton(filename=_save_icon_path,
                                        scale=1,
                                        cls='innerwindow-close')
    b.my_padding = 5 
    b.push_handlers(on_release=save)
    l.append(b)
#    b1.push_handlers('on_press', lambda x: x)
    c = Controls(None,l)
    return c