Exemplo n.º 1
0
    def __init__(self):
        DBG('Init module')

        self.grab_key_func = None

        # set up default bindings
        section = 'keyboard'
        if not ini.has_section(section):
            ini.add_section(section)
            defs = EmcGui.instance().default_keymap_get()
            for key, event in defs.items():
                ini.set(section, key, event)

        # read mapping from config
        self.keys = dict()
        for key, event in ini.get_options(section):
            DBG('Map key "%s" to event %s' % (key, event))
            self.keys[key] = event

        # add an entry in the config gui section
        config_gui.root_item_add('keyb',
                                 50,
                                 _('Keyboard'),
                                 icon='icon/keyboard',
                                 callback=self.config_panel_cb)

        # ask the gui to forward key events to us
        EmcGui.instance().key_down_connect(self._key_down_cb)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def volume_set(vol: float) -> None:
    """ Set linear volume. Float, always between 0 and 100 """
    global _volume

    vol = utils.clamp(vol, 0, 100)
    vol = vol / 100.0 * ini.get_int('mediaplayer', 'volume_maximum')

    if vol == _volume:
        return

    _volume = vol
    EmcGui.instance().volume_set(vol)
    ini.set('mediaplayer', 'volume', _volume)
    # events.event_emit('VOLUME_CHANGED')

    if _player:
        _player.volume_set(volume_adjusted_get())
Exemplo n.º 5
0
    def __init__(self, *args, **kargs):
        super().__init__(*args, **kargs)
        print("INIT VIDEO PLAYER QT")

        self._gui = EmcGui.instance()

        self._audio_menu_model = AudioMenuModel()
        self._video_menu_model = VideoMenuModel()
        self._subs_menu_model = SubsMenuModel()

        self._gui.model_set('AudioMenuModel', self._audio_menu_model)
        self._gui.model_set('VideoMenuModel', self._video_menu_model)
        self._gui.model_set('SubsMenuModel', self._subs_menu_model)

        self._qml_obj = self._gui._qml_root.activate_section('videoplayer')
Exemplo n.º 6
0
    def __init__(self, *args, **kargs):
        super().__init__(*args, **kargs)

        print("INIT DIALOG QT")
        if self._style in self.list_styles:
            self._list_model = DialogListModel(self)
        else:
            self._list_model = None
        self._buttons = []
        self._gui = EmcGui.instance()
        self._qml_obj = self._gui._qml_root.build_dialog(
            self._title, self._style, self._text, self._content, self._spinner,
            self._list_model)
        self._qml_obj.emcQuitRequested.connect(self._quit_requested_cb)

        # automatic buttons
        self._create_auto_buttons()
Exemplo n.º 7
0
 def __shutdown__(self):
     DBG('Shutdown module')
     config_gui.root_item_del('keyb')
     EmcGui.instance().key_down_connect(None)
Exemplo n.º 8
0
def start_emc(standalone=False):
    # parse command line arguments
    parser = argparse.ArgumentParser(description='Emotion Media Center v%s' %
                                     emc_v)
    parser.add_argument('-a',
                        '--activity',
                        help='start directy in the given activity')
    parser.add_argument('-f',
                        '--fullscreen',
                        action='store_true',
                        help='start in fullscreen')
    parser.add_argument('-y',
                        '--youtube-dl',
                        action='store_true',
                        help='use youtube-dl to scrape and play mediaurl')
    parser.add_argument('--standalone',
                        action='store_true',
                        help='start in X without a WM (fullscreen)')
    parser.add_argument('mediaurl',
                        nargs='?',
                        help='local file or remote url to play')
    args = parser.parse_args()

    # tag for pulse audio... name not working here, icon yes  :/
    os.environ['PULSE_PROP_media.role'] = 'video'
    os.environ['PULSE_PROP_application.name'] = 'Emotion Media Center'
    os.environ['PULSE_PROP_application.icon_name'] = 'emc'

    # create config/cache dirs if necessary
    if not os.path.exists(utils.user_cache_dir):
        os.makedirs(utils.user_cache_dir)
    if not os.path.exists(utils.user_conf_dir):
        os.makedirs(utils.user_conf_dir)
    try:
        os.mkdir(os.path.join(utils.user_conf_dir, 'plugins'))
    except OSError:
        pass
    try:
        os.mkdir(os.path.join(utils.user_conf_dir, 'themes'))
    except OSError:
        pass
    try:
        os.mkdir(os.path.join(utils.user_conf_dir, 'channels'))
    except OSError:
        pass
    try:
        os.mkdir(os.path.join(utils.user_conf_dir, 'subtitles'))
    except OSError:
        pass

    # read config from file  # TODO add a system dir...but where??
    ini.read_from_files(
        ['nepymc.conf',
         os.path.join(utils.user_conf_dir, 'nepymc.conf')])
    ini.setup_defaults()

    # create the mainloop singleton instance
    loop = EmcMainLoop(sys.argv)

    # create the gui singleton instance
    gui = EmcGui()

    # init internal components
    sdb.init()
    # thumbnailer.init()
    browser.init()
    mainmenu.init()
    config_gui.init()
    mediaplayer.init()
    storage.init()

    # create and show the main gui
    # if not gui.init('qt', loop):  # TODO: backend by config
    #     ERR('Cannot create the GUI')
    #     return 1

    # load & init modules
    modules.load_all()
    modules.init_all_by_config()
    """
    # use youtube-dl to scrape and play the url given on command line
    if args.youtube_dl and args.mediaurl:
       from epymc.youtubedl import YoutubeDL
 
       ytdl = YoutubeDL()
 
       def ytdl_url_cb(real_url):
          if not real_url:
             gui.EmcDialog(style='error',
                           text=_('youtube-dl is unable to scrape the given url'))
          else:
             print('Real video url:',real_url)
             mediaplayer.play_url(real_url)
             mediaplayer.title_set('')
 
       def ytdl_update_cb(success, dialog):
          if dialog: dialog.delete()
          print('Scraping url:', args.mediaurl)
          ytdl.get_real_video_url(args.mediaurl, ytdl_url_cb)
 
       print('Checking for ytdl updates')
       if ini.get_bool('videochannels', 'autoupdate_ytdl') == True:
          ytdl.check_update(verbose=True, done_cb=ytdl_update_cb)
       else:
          ytdl_update_cb(True, None)
       
    # if mediaurl given on command line play it (must be a video file)
    elif args.mediaurl:
       if args.mediaurl.startswith(('http://', 'https://')):
          mediaplayer.play_url(args.mediaurl)
          mediaplayer.title_set('')
       elif os.path.exists(args.mediaurl):
          mediaplayer.play_url(os.path.abspath(args.mediaurl))
          mediaplayer.title_set(os.path.basename(args.mediaurl))
    # or autostart the give activity (ex: --activity movies)
    elif args.activity:
       mainmenu.item_activate(args.activity)
    # fullscreen requested from command line
    if args.fullscreen:
       gui.fullscreen_set(True)
 
    # run standalone (inside X without a WM)
    if standalone or args.standalone:
       from efl import ecore_x
       ecore_x.init()
       # set fullscreen
       x, y, w, h = gui.win.screen_size
       gui.win.size = (w, h)
       # give focus to the win
       ecore_x_win = ecore_x.Window_from_xid(gui.win.xwindow_xid)
       ecore_x_win.focus()
 
    # alert if run from python < 3 (lots of translation issue with 2.7)
    if utils.is_py2():
       txt = '<b>PYTHON 2 IS NOT SUPPORTED ANYMORE!</b><br><br>' \
             'You are using python2, it is old!<br>' \
             'EpyMC works much better with py3, even more if you are not ' \
             'using the english language.<br><br>' \
             '<b>YOU MUST SWITCH TO PYTHON 3 !!!</b>'
       gui.EmcDialog(style='warning', text=txt)
    """

    # create and show the main gui
    if not gui.create():
        ERR('Cannot create the GUI')
        return 1

    # start the main loop
    loop.run()

    # shutdown
    modules.save_enabled()
    modules.shutdown_all()
    storage.shutdown()
    config_gui.shutdown()
    ini.write_to_file(os.path.join(utils.user_conf_dir, 'nepymc.conf'))
    mediaplayer.shutdown()
    browser.shutdown()
    # thumbnailer.shutdown()
    sdb.shutdown()

    gui.delete()
    loop.delete()

    print('Bye Bye...')
    return 0
Exemplo n.º 9
0
 def hide(self):
     """ TODO Function doc """
     # input_events.listener_del('browser-' + self.name)
     EmcGui.instance().hide_section('browser')
Exemplo n.º 10
0
 def show(self):
     """ TODO Function doc """
     EmcGui.instance().activate_section('browser')
     EmcGui.instance().page_icon_set(self.icon)
Exemplo n.º 11
0
def hide():
    # input_events.listener_del('mainmenu')
    EmcGui.instance().hide_section('mainmenu')
    raise DeprecationWarning('should not explicitly hide the menu')
Exemplo n.º 12
0
def show():
    EmcGui.instance().activate_section('mainmenu')
    # input_events.listener_add('mainmenu', input_event_cb)
    raise DeprecationWarning('should not explicitly show the menu')
Exemplo n.º 13
0
 def __init__(self, *args, **kargs):
     super().__init__(*args, **kargs)
     self._model = EmcGui.instance()._notify_model
     self._model.insert_item(self)