Exemple #1
0
def list_devices(filter_type=None):
    """ List all know devices.
    Args:
       filter_type: a single (or a tuple of) EmcDevType
    Returns:
       A filtered and sorted list of EmcDevice instances
    """
    li = []
    for key, device in _devices.items():
        if isinstance(filter_type, int):
            if device.type != filter_type:
                continue
        elif isinstance(filter_type, tuple):
            if device.type not in filter_type:
                continue
        if device.type == EmcDevType.SYSTEM:
            if device.mount_point == '/' and \
                    not ini.get_bool('storage', 'show_root'):
                continue
            if device.mount_point == os.getenv('HOME') and \
                    not ini.get_bool('storage', 'show_home'):
                continue
        li.append(device)
    li.sort(key=attrgetter('type', 'sort_key', 'label'))
    return li
Exemple #2
0
    def __init__(self):
        super().__init__(EmcMainLoop.instance())  # mainloop is the gui parent

        # setup default ini values
        ini.set_default('general', 'theme', 'blackmirror')
        ini.set_default('general', 'fps', 30)
        ini.set_default('general', 'scale', 1.0)
        ini.set_default('general', 'fullscreen', False)
        ini.set_default('general', 'hide_mouse', False)
        ini.set_default('general', 'time_format', '%H:%M')
        ini.set_default('general', 'date_format', '%A %d %B')
        ini.set_default('general', 'keyb_layouts', 'en_abc symbols')

        # public members
        self._theme_name = ini.get('general', 'theme')

        # protected memebrs
        self._boot_in_fullscreen = ini.get_bool('general', 'fullscreen')

        # private members
        self._key_down_func = None
        self._mouse_hide_timer = EmcTimer(3.0,
                                          self._mouse_hide_timer_cb,
                                          parent=self)

        # listen for input events
        input_events.listener_add('EmcGuiBase', self._input_events_cb)
Exemple #3
0
    def page_add(self, url, title, styles, populate_cb, *args, **kwargs):
        """
        When you create a page you need to give at least the url, the title
        and the populate callback. Every other arguments will be passed back
        in the callback. style can be None to use the default page style,
        usually the plain list.

        Args:
           url: A unique string id for the page
           title: Readable text for the user
           styles: A tuple with all the style that the page can show.
                   Available styles: 'List', 'PosterGrid', 'CoverGrid'
                   If set to None it default to the default style given at
                   the Browser instance creation.
                   The first item is the default one.
           populate_cb: Function to call when the page need to be populated.
                        Signature: func(browser, url, *args, **kwargs)
        """

        # choose the style of the new page
        if styles is None:
            styles = (self.default_style, )
        if _memorydb and _memorydb.id_exists(url):
            style = _memorydb.get_data(url)
        else:
            style = self._search_style_in_parent()
        if not style:
            style = styles[0]
        if ini.get_bool('general', 'ignore_views_restrictions') is False:
            if style not in styles:
                style = styles[0]

        # get the correct view instance
        view = self._create_or_get_view(style)  # TODO REMOVE ME ??

        # append the new page in the pages list
        page = {
            'view': view,
            'url': url,
            'title': title,
            'styles': styles,
            'cb': populate_cb,
            'args': args,
            'kwargs': kwargs
        }
        self.pages.append(page)

        # first time, we don't have a current_view, set it
        if not self.current_view:
            self.current_view = view

        # TODO is this the correct place for this???
        EmcGui.instance().model_set('browser',
                                    self._model)  # TODO needed every time ??

        # switch to the new page
        self._populate_page(page)
Exemple #4
0
    def _populate_page(self,
                       page,
                       is_back=False,
                       is_refresh=False,
                       is_unfreeze=False):
        full = ' > '.join([p['title'] for p in self.pages])
        EmcGui.instance().page_title_set(full)

        # clear the items list
        self.items = []

        view = page['view']
        """
        if view == self.current_view:
            # same style for the 2 pages, ask the view to perform the correct anim
            if is_refresh or is_unfreeze:
                view.page_show(page['title'], ANIM_NONE)
            elif is_back:
                view.page_show(page['title'], ANIM_BACK)
            elif len(self.pages) < 2:
                view.page_show(page['title'], ANIM_NONE)
            else:
                view.page_show(page['title'], ANIM_FORWARD)
        else:
            # different style...hide one view and show the other
            self.current_view.clear()
            self.current_view.hide()
            view.page_show(page['title'], ANIM_NONE)
            view.show()
        """

        # update state
        self.current_view = view

        # back item (optional)
        if ini.get_bool('general', 'back_in_lists'):
            self.item_add(BackItemClass(), 'emc://back', self)

        # use this for extra debug
        # print(self)

        # populate the page calling the page user callback
        url = page['url']
        cb = page['cb']
        args = page['args']
        kwargs = page['kwargs']
        cb(self, url, *args, **kwargs)

        # tell the view that data has been resetted
        self._model.view_reset()
        self._model.select_item(0)
Exemple #5
0
    def change_style(self, style):
        # the current page is always the last one
        page = self.pages[-1]

        # check if the style is valid (unless not explicitly ignored)
        if ini.get_bool('general', 'ignore_views_restrictions') is False:
            if not style in page['styles']:
                DBG('Style %s not available for this page' % style)
                EmcDialog(style='info', title=_('View restriction'),
                          text=_(
                              '<br><br>The requested view is not enabled for the current ' \
                              'page.<br><br><small><info>NOTE: You can ovveride this ' \
                              'restriction in the <i>Configuration → Views</i> ' \
                              'section.</info></small>'))
                return

        # change only if needed
        view = self._create_or_get_view(style)
        if view == self.current_view:
            return

        # remember the selected item
        self.autoselect_url = self.current_view.selected_url_get()

        # clear & hide the current view
        self.current_view.clear()
        self.current_view.hide()

        # set the new view in the current (always the last) page
        page['view'] = view

        # remember the user choice
        global _memorydb
        page_url = self.pages[-1]['url']
        _memorydb.set_data(page_url, style)

        # recreate the page
        self.refresh(hard=True)
Exemple #6
0
 def _mouse_hide_timer_cb(self):
     if ini.get_bool('general', 'hide_mouse'):
         self.mouse_cursor_hidden_set(True)
Exemple #7
0
 def icon_end_get(self, url, user_data):
     if ini.get_bool(self._sec, self._opt) is True:
         return 'icon/check_on'
     return 'icon/check_off'