Exemple #1
0
 def draw (self):
     x,y = list(self.pos)
     
     # Background
     if self.selected:
         bg_color = (0.965, 0.573, 0.118, 1) # Laranja do logotipo
     else:
         bg_color = (0.447,0.447,0.447,1) # Cinzento
     
     drawRoundedRectangle(pos = self.pos,
                          radius = 5,
                          precision = 0.3,
                          size = (self.size[0]-10, self.size[1]), 
                          color = bg_color,
                          corners=(False,True,True,False))
     
     # Bottom Line
     points = [x, y+100] + [x+self.size[0], y+100]
     colors = [(0.6,0.6,0.6,1),(0.439,0.439,0.439,1)]
     drawLine(points, 10, colors)
     
     # Label
     label_margin = CATEGORYLIST_LABEL_SIDES_MARGIN
     label_max_width = self.size[0] - label_margin*2
     label_obj, self.label = get_trimmed_label_widget(text = self.label,
                                                      position = (x+label_margin, y+8),
                                                      font_size = CATEGORYLIST_LABEL_FONT_SIZE,
                                                      max_width = label_max_width)
     label_obj.draw()
class AppButton(MTKineticItem):
    """Widget representing an application on main window. 
    
    Arguments:
        app -- Application object attached to this widget
        kwargs -- Button properties, most of them inherited from MTButton
    
    This widget should be added to AppsGrid on Menu's UI construction"""
    def __init__(self, app, **kwargs):
        kwargs.setdefault('label', unicode(app))
        kwargs.setdefault('deletable', False)
        kwargs.setdefault('size', APPSLIST_BTN_SIZE)

        self.app = app
        self.popups_currently_open = 0
        self.double_tap_detected = False

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

    """Execute application on double click
       Open popup on single click"""

    def on_press(self, touch):
        self.double_tap_detected = touch.is_double_tap
        if touch.is_double_tap:
            self.double_tap_detected = False
            self.open_app()
        else:
            # Give it time before open popup because it can be a double-click
            Timer(0.5, self.open_popup, args=[touch.pos]).start()

    def open_popup(self, touch_pos):
        # If max number of popups allowed reached, don't open one more
        # If double click, don't open one more
        if self.popups_currently_open == APPSLIST_BTN_POPUPS_PER_BTN or self.double_tap_detected:
            return

        self.popups_currently_open += 1
        self.get_root_window().add_widget(AppPopup(self.app, touch_pos, self))

    def popup_closed(self):
        self.popups_currently_open -= 1

    def open_app(self):
        logger.info('\nLoading %s...\n' % unicode(self.app))
        logger.info('ID: %i' % self.app.id)
        logger.info('Path: %s\n' % self.app.get_extraction_fullpath())
        logger.info('Boot file: %s\n' % self.app.get_boot_file())
        self.app.execute()

        #refresh cstegory in main thread
        from mtmenu import categories_list
        categories_list.refresh()
        self.parent.refresh(categories_list.current)

    def draw(self):
        # Outside line
        style = {
            'bg-color': (1, 1, 1, 1),
            'draw-background': 0,
            'draw-border': True,
            'border-radius': 10
        }
        set_color(*style.get('bg-color'))
        drawCSSRectangle(pos=self.pos, size=self.size, style=style)

        # Icon
        try:
            image = Image("../webmanager/media/%s" % str(self.app.icon))
            x, y = list(self.center)
            image.size = self.get_resized_size(image)
            image.pos = x - image.width / 2, y - image.height / 2
            image.draw()
        except Exception, e:
            logger.error("EXCEPTION loading icon\n%s" % e)

        # Label
        label_obj, self.label = get_trimmed_label_widget(
            text=self.label,
            position=(self.pos[0] / 2, self.size[1] - 50),
            font_size=APPSLIST_BTN_FONT_SIZE,
            max_width=self.size[0] - 5)
        label_obj.pos = (self.pos[0] + ((self.size[0] - label_obj.width) / 2),
                         self.pos[1] - APPSLIST_BTN_FONT_SIZE - 6)
        label_obj.draw()

        # Show star only if is configured to always appears or if order by 'Rating' is selected
        from mtmenu import apps_list

        if not APPSLIST_STAR_ONLY_WHEN_ORDER_BY_RATING or (
                APPSLIST_STAR_ONLY_WHEN_ORDER_BY_RATING
                and apps_list.criteria == 'value'):
            # Star
            star_size = (48, 48)
            star_pos_x = self.pos[0] + self.size[0] - star_size[0] / 3 * 2
            star_pos_y = self.pos[1] + self.size[1] - star_size[1] / 3 * 2

            image = Image("images/star.png")
            image.pos = (star_pos_x, star_pos_y)
            image.draw()

            # Star number
            drawLabel(label=int(self.app.stars()),
                      pos=(star_pos_x + star_size[0] / 2,
                           star_pos_y + star_size[1] / 2),
                      font_size=25,
                      center=True)
Exemple #3
0
    def draw(self):

        x, y = list(self.pos)
        a, b = list(self.size)
        margin = 20
        max_label_width = a - margin * 2

        # Background
        drawRoundedRectangle(pos=self.pos,
                             radius=10,
                             size=self.size,
                             precision=0.3,
                             color=(0, 0, 0, 0.9))

        # Title
        label_obj, self.label_app_name_text = get_trimmed_label_widget(
            text=self.label_app_name_text,
            position=(x + margin, y + b - 50),
            font_size=20,
            max_width=max_label_width)
        label_obj.draw()

        # Category
        label_obj, self.label_app_category_text = get_trimmed_label_widget(
            text=self.label_app_category_text,
            position=(x + margin, y + b - 90),
            font_size=15,
            max_width=max_label_width)
        label_obj.draw()

        # Owner
        label_obj, self.label_app_owner_text = get_trimmed_label_widget(
            text=self.label_app_owner_text,
            position=(x + margin, y + b - 115),
            font_size=15,
            max_width=max_label_width)
        label_obj.draw()

        # Runs
        label_obj, self.label_app_runs_text = get_trimmed_label_widget(
            text=self.label_app_runs_text,
            position=(x + margin, y + b - 140),
            font_size=15,
            max_width=max_label_width)
        label_obj.draw()

        # Last Updated
        label_obj, self.label_app_updated_text = get_trimmed_label_widget(
            text=self.label_app_updated_text,
            position=(x + margin, y + b - 165),
            font_size=15,
            max_width=max_label_width)
        label_obj.draw()

        # Buttons
        buttons_size = (self.size[0] / 2 - margin - 2, 45)
        button_play_pos = (x + margin, y + margin)
        button_close_pos = (x + margin + buttons_size[0] + 4, y + margin)

        self.btns_size = buttons_size
        self.play_btn_pos = button_play_pos
        self.close_btn_pos = button_close_pos

        # Play
        drawRoundedRectangle(pos=button_play_pos,
                             radius=8,
                             size=buttons_size,
                             precision=0.3,
                             color=(0.19, 0.19, 0.33, 1),
                             corners=(True, True, True, True))
        drawLabel(label='Play',
                  pos=(button_play_pos[0] + (buttons_size[0] / 2),
                       button_play_pos[1] + (buttons_size[1] / 2)),
                  font_size=22,
                  center=True)

        # Close
        drawRoundedRectangle(pos=button_close_pos,
                             radius=8,
                             size=buttons_size,
                             precision=0.3,
                             color=(0.192, 0.192, 0.192, 1),
                             corners=(True, True, True, True))
        drawLabel(label='Close',
                  pos=(button_close_pos[0] + (buttons_size[0] / 2),
                       button_close_pos[1] + (buttons_size[1] / 2)),
                  font_size=22,
                  center=True)
Exemple #4
0
 def draw(self):
     
     x,y = list(self.pos)
     a,b = list(self.size)
     margin = 20
     max_label_width = a - margin*2
     
     # Background
     drawRoundedRectangle(pos = self.pos,
                  radius = 10,
                  size = self.size,
                  precision = 0.3, 
                  color = (0,0,0,0.9))
     
     # Title
     label_obj, self.label_app_name_text = get_trimmed_label_widget(text = self.label_app_name_text,
                                                                    position = (x + margin, y + b - 50),
                                                                    font_size = 20,
                                                                    max_width = max_label_width)
     label_obj.draw()
     
     # Category
     label_obj, self.label_app_category_text = get_trimmed_label_widget(text = self.label_app_category_text,
                                                                        position = (x + margin, y + b - 90),
                                                                        font_size = 15,
                                                                        max_width = max_label_width)
     label_obj.draw()
     
     # Owner
     label_obj, self.label_app_owner_text = get_trimmed_label_widget(text = self.label_app_owner_text,
                                                                     position = (x + margin, y + b - 115),
                                                                     font_size = 15,
                                                                     max_width = max_label_width)
     label_obj.draw()
     
     # Runs
     label_obj, self.label_app_runs_text = get_trimmed_label_widget(text = self.label_app_runs_text,
                                                                    position = (x + margin, y + b - 140),
                                                                    font_size = 15,
                                                                    max_width = max_label_width)
     label_obj.draw()
     
     # Last Updated
     label_obj, self.label_app_updated_text = get_trimmed_label_widget(text = self.label_app_updated_text,
                                                                       position = (x + margin, y + b - 165),
                                                                       font_size = 15,
                                                                       max_width = max_label_width)
     label_obj.draw()
     
     # Buttons
     buttons_size = (self.size[0]/2 - margin - 2, 45)
     button_play_pos = (x+margin, y+margin)
     button_close_pos = (x+margin+buttons_size[0] + 4, y+margin)
     
     self.btns_size = buttons_size
     self.play_btn_pos = button_play_pos
     self.close_btn_pos = button_close_pos
     
     # Play
     drawRoundedRectangle(pos = button_play_pos,
                          radius = 8,
                          size = buttons_size,
                          precision = 0.3, 
                          color = (0.19, 0.19, 0.33,1),
                          corners=(True,True,True,True))
     drawLabel(label = 'Play',
               pos = (button_play_pos[0] + (buttons_size[0]/2), button_play_pos[1] + (buttons_size[1]/2)),
               font_size = 22,
               center = True)
     
     # Close
     drawRoundedRectangle(pos = button_close_pos,
                          radius = 8,
                          size = buttons_size,
                          precision = 0.3, 
                          color = (0.192, 0.192, 0.192, 1),
                          corners=(True,True,True,True))
     drawLabel(label = 'Close',
               pos = (button_close_pos[0] + (buttons_size[0]/2), button_close_pos[1] + (buttons_size[1]/2)),
               font_size = 22,
               center = True)