Beispiel #1
0
def _vkeyb_layouts_list():
    dia = EmcDialog(title=_('Virtual keyboard layouts'),
                    style='list',
                    done_cb=_vkeyb_layouts_select_cb)
    dia.button_add(_('Close'),
                   selected_cb=_vkeyb_layouts_close_cb,
                   cb_data=dia)
    dia.button_add(_('Select'),
                   default=True,
                   selected_cb=_vkeyb_layouts_select_cb,
                   cb_data=dia)

    avail = ini.get_string_list('general', 'keyb_layouts')
    for k in sorted(gui.keyboard_layouts.keys()):
        name = gui.keyboard_layouts[k][0]
        end = 'icon/check_on' if k in avail else 'icon/check_off'
        it = dia.list_item_append(name, end=end)
        it.data['key'] = k
Beispiel #2
0
class Test_Exe(GenericItemClass):

    path = os.path.dirname(__file__)
    infinite_path = os.path.join(path, 'infinite.py')

    def __init__(self):
        super().__init__()
        self.dia = None
        self.exe = None

    def item_selected(self, url, user_data):
        self.dia = EmcDialog(title='EmcExe test',
                             text='Press a button to run a command')
        self.dia.button_add('Close', lambda b: self.dia.delete())
        self.dia.button_add('delete()', lambda b: self.exe.delete())
        self.dia.button_add('"wrong"', self.run_btn_cb, ('wrong', ))
        self.dia.button_add('"infinite.py"', self.run_btn_cb,
                            (sys.executable, self.infinite_path))
        self.dia.button_add('"ls -l"', self.run_btn_cb, ('ls', '-l'))
        self.dia.button_add('"ls"', self.run_btn_cb, ('ls', ))

    def run_btn_cb(self, btn, pars):
        cmd = pars[0]
        params = pars[1:]
        self.exe = EmcExe(cmd,
                          params,
                          grab_output=True,
                          done_cb=self.exe_done_cb,
                          parent=self.dia,
                          asd1='asd_1',
                          asd2='asd_2')
        self.dia.text_set('Running: "{} {}"<br><br>'.format(
            cmd, ' '.join(params)))

    def exe_done_cb(self, exit_code, output, asd1, asd2):
        assert asd1 == 'asd_1'
        assert asd2 == 'asd_2'
        print("OUT", exit_code, output)
        self.dia.text_append('Process completed<br>'
                             'exit_code: {}<br>'
                             'output: {}'.format(exit_code, repr(output)))
Beispiel #3
0
class StdConfigItemNumber(StdConfigItemBase):
    def __init__(self, fmt, udm, min, max, step, *args):
        self._fmt = fmt
        self._udm = udm
        self._min = min
        self._max = max
        self._step = step
        self._val = None
        self._dia = None
        StdConfigItemBase.__init__(self, *args)

    def label_end_get(self, url, user_data):
        if self._udm:
            return ini.get(self._sec, self._opt) + ' ' + self._udm
        else:
            return ini.get(self._sec, self._opt)

    def item_selected(self, url, user_data):
        self._val = ini.get_float(self._sec, self._opt)
        self._dia = EmcDialog(style='minimal', title=self._lbl, text='')
        self._dia.button_add(_('Ok'), self._btn_ok_cb)
        self._dia.button_add(None, self._btn_plus_cb, icon='icon/plus')
        self._dia.button_add(None, self._btn_minus_cb, icon='icon/minus')
        self._dia.button_add(_('Cancel'), self._btn_canc_cb)
        self._dia_text_update()

    def _dia_text_update(self):
        val = (self._fmt % self._val) + ' ' + self._udm
        self._dia.text_set('<br><br><br><center><bigger>%s</bigger></center>' %
                           val)

    def _btn_plus_cb(self, btn):
        self._val += self._step
        self._val = min(self._val, self._max)
        self._dia_text_update()

    def _btn_minus_cb(self, btn):
        self._val -= self._step
        self._val = max(self._val, self._min)
        self._dia_text_update()

    def _btn_canc_cb(self, btn):
        self._dia.delete()

    def _btn_ok_cb(self, btn):
        val = self._fmt % self._val
        ini.set(self._sec, self._opt, val)
        self._dia.delete()
        StdConfigItemBase.__done__(self)
Beispiel #4
0
class Test_Url(GenericItemClass):

    url1 = 'http://ipv4.download.thinkbroadband.com/5MB.zip'
    url2 = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/' \
           'resources/pdf/dummy.pdf'

    def __init__(self):
        super().__init__()
        self.dia = None
        self.dload = None

    def item_selected(self, url, user_data):
        self.dia = EmcDialog(style='progress',
                             title=user_data,
                             text='Press start to test a 5MB download')
        self.dia.button_add('Close', lambda b: self.dia.delete())
        self.dia.button_add('delete()', self.delete_btn_cb)
        self.dia.button_add('To file (5M)', self.start_btn_cb, self.url1)
        self.dia.button_add('To mem (13K)', self.start_btn_cb, self.url2)

    def start_btn_cb(self, btn, url):
        self.dia.text_set('Download started...')
        dest = '::tmp::' if url == self.url1 else '::mem::'
        self.dload = EmcUrl(url,
                            dest=dest,
                            done_cb=self.done_cb,
                            prog_cb=self.prog_cb,
                            decode=None,
                            parent=self.dia)

    def delete_btn_cb(self, btn):
        if self.dload:
            self.dload.delete()

    def done_cb(self, url, success, dest):
        print("DONE", success)
        if success and url.dest == '::mem::':
            size = len(dest)
            self.dia.text_set(
                'Download successfully completed to Memory<br>'
                'First bytes: {}<br>Download size: {} bytes'.format(
                    dest[:10], size))
        elif success and os.path.exists(dest):
            size = utils.hum_size(os.path.getsize(dest))
            self.dia.text_set('Download successfully completed to<br>{}<br>'
                              'File size: {} '.format(dest, size))
        else:
            self.dia.text_set("Error !!")
        self.dload = None

    def prog_cb(self, url, total, received):
        print("PROGRESS", url, total, received)
        self.dia.progress_set(received / total if total else 0)
Beispiel #5
0
class EmcFolderSelector(object):
    """
    Open a dialog that allow the user to choose a path on the filesystem.

    Args:
       title:
          The (optional) dialog title.
       done_cb:
          The (mandatory) function to call when the selection is done.
          Signature: func(path, **kargs)
       **kargs:
          Any other keyword arguments will be passed back in the done_cd func
    """

    def __init__(self, title=None, done_cb=None, **kargs):
        self._user_cb = done_cb
        self._user_kargs = kargs

        self._dialog = EmcDialog(title or _('Source Selector'), style='list')
        self._dialog.button_add(_('Select'), self._btn_select_cb)
        self._dialog.button_add(_('Browse'), self._btn_browse_cb, default=True)

        self.populate_devices()

    def populate_devices(self):
        self._dialog.list_clear()

        # other storage devices
        for dev in storage.list_devices():
            if dev.is_mounted:
                it = self._dialog.list_item_append(dev.label, dev.icon)
                it.data['root'] = it.data['path'] = dev.mount_point
        self._dialog.list_go()

    def populate_folder(self, root, folder):
        if folder == '':  # back in '/'
            self.populate_devices()
            return

        try:
            folders = os.listdir(folder)
        except PermissionError:
            EmcDialog(style='error', text=_('Permission denied'))
            return

        self._dialog.list_clear()

        # back item
        parent = os.path.normpath(os.path.join(folder, '..'))
        it = self._dialog.list_item_append(_('Back'), 'icon/back')
        it.data['root'] = root
        it.data['path'] = parent if parent != folder else ''  # back in '/'

        # folders
        for fname in utils.natural_sort(folders):
            fullpath = os.path.join(folder, fname)
            if fname[0] != '.' and os.path.isdir(fullpath):
                it = self._dialog.list_item_append(fname, 'icon/folder')
                it.data['root'] = root
                it.data['path'] = fullpath

        self._dialog.list_go()

    def _btn_browse_cb(self, btn):
        it = self._dialog.list_item_selected_get()
        if len(it.data['path']) < len(it.data['root']):
            self.populate_devices()
        else:
            self.populate_folder(it.data['root'], it.data['path'])

    def _btn_select_cb(self, btn):
        path = self._dialog.list_item_selected_get().data['path']
        if path and callable(self._user_cb):
            self._user_cb('file://' + path, **self._user_kargs)
        self._dialog.delete()
Beispiel #6
0
class CastPanel(object):
    def __init__(self, pid=None, name=None, lang=DEFAULT_INFO_LANG):
        self.pid = pid
        self.info = None

        tmdb = TMDBv3(lang=lang)
        if name:
            tmdb.person_search(name, self._search_done_cb)
        elif pid:
            tmdb.get_cast_info(self.pid, self._fetch_done_cb)
        self._dia = EmcDialog(style='minimal',
                              title=_('Fetching info'),
                              content='image/tmdb_logo.png',
                              spinner=True)

    def _search_done_cb(self, tmdb, result):
        # TODO manage errors
        self.pid = result['results'][0]['id']
        tmdb.get_cast_info(self.pid, self._fetch_done_cb)

    def _fetch_done_cb(self, tmdb, result):
        self.info = result
        self._dia.delete()

        text = ''
        if self.info.get('biography'):
            text += '%s<br><br>' % self.info['biography'].replace('\n', '<br>')
        if self.info.get('birthday'):
            text += '<name>%s:</name> %s<br>' % (_('Birthday'),
                                                 self.info['birthday'])
        if self.info.get('deathday'):
            text += '<name>%s:</name> %s<br>' % (_('Deathday'),
                                                 self.info['deathday'])
        if self.info.get('place_of_birth'):
            text += '<name>%s:</name> %s<br>' % (_('Place of birth'),
                                                 self.info['place_of_birth'])

        self._dia = EmcDialog(title=self.info['name'],
                              style='panel',
                              content=self.info['profile_path'],
                              text=text)

        # merge cast and crew in a single movies list
        movies = {}  # key: tmdbid val: tmdb-data-dict + 'jobs'
        for movie in self.info['credits']['crew']:
            tid = movie['id']
            if tid in movies:
                movies[tid]['jobs'].append(movie.get('job'))
            else:
                movie['jobs'] = [movie.get('job')]
                movies[tid] = movie

        for movie in self.info['credits']['cast']:
            tid = movie['id']
            if tid in movies:
                movies[tid]['character'] = movie.get('character')
            else:
                movies[tid] = movie

        self._dia.button_add(
            _('Movies (%s)') % len(movies),
            lambda b: self.movies_dialog(movies))
        num = len(self.info['images']['profiles'])
        self._dia.button_add(
            _('Photos (%s)') % num, lambda b: self.photos_dialog())

    def photos_dialog(self):
        dia = EmcDialog(style='image_list_portrait', title=self.info['name'])
        for image in self.info['images']['profiles']:
            dia.list_item_append(None, image['file_path'])
        dia.list_go()

    def movies_dialog(self, movies):
        dia = EmcDialog(style='list', title=self.info['name'])
        for movie in sorted(movies.values(), key=itemgetter('title')):
            label = '<big>{}</big>'.format(movie['title'])
            if 'character' in movie:
                label += ' <i>{} <big>{}</big></i>'.format(
                    _('as'), movie['character'])
            if 'jobs' in movie:
                label += ' <i>({})</i>'.format(', '.join(movie['jobs']))
            dia.list_item_append(label, movie.get('poster_path'))
        dia.list_go()
Beispiel #7
0
    def item_selected(self, url, user_data):
        # main item selected, create the subpage
        if url == 'uitest://dialog':
            _browser.page_add(url, user_data, None, self.populate_subpage)

        # Dialog - Info
        elif url.endswith('/info'):
            print("DIALOG INFO", url, user_data)
            EmcDialog(title='Dialog - Info', text=LOREM, style='info')

        # Dialog - Warning
        elif url.endswith('/warning'):
            text = 'This is an <br><br><b>Warning</><br>dialog<br>'
            EmcDialog(title='Dialog - Warning', text=text, style='warning')

        # Dialog - Warning (no title)
        elif url.endswith('/warning2'):
            text = 'This is an <br><br><b>Warning</><br>dialog<br>'
            EmcDialog(text=text, style='warning')

        # Dialog - Error
        elif url.endswith('/error'):
            text = 'This is an <br><br><b>Error</><br>dialog<br>'
            EmcDialog(title='Dialog - Error', text=text, style='error')

        # Dialog - YesNo (with callbacks)
        elif url.endswith('/yesno1'):
            text = 'This is an <br><br><b>Yes/No</><br>dialog<br>'
            EmcDialog(title='Dialog - YesNo',
                      text=text,
                      style='yesno',
                      done_cb=lambda dia: print('done', dia),
                      canc_cb=lambda dia: print('canc', dia))

        # Dialog - YesNo (without callbacks)
        elif url.endswith('/yesno2'):
            text = 'This is an <br><br><b>Yes/No</><br>dialog<br>'
            EmcDialog(title='Dialog - YesNo', text=text, style='yesno')

        # Dialog - Cancel
        elif url.endswith('/cancel'):
            text = 'This is an <br><br><b>Cancel operation</><br>dialog<br>'
            EmcDialog(title='Dialog - Cancel',
                      text=text,
                      style='cancel',
                      spinner=True)

        # Dialog - Progress
        elif url.startswith('uitest://dialog/progress'):

            def _canc_cb(dialog):
                t.delete()
                d.delete()

            def _progress_timer():
                d.progress_set(self._progress)
                self._progress += 0.01
                if self._progress > 1:
                    self._progress = 0

            text = 'This is a <br><br><b>Progress operation</><br>dialog<br>'
            d = EmcDialog(title='Dialog - Progress',
                          text=text,
                          style='progress',
                          done_cb=_canc_cb,
                          canc_cb=_canc_cb)
            if url.endswith('btn'):
                d.button_add("btn1",
                             selected_cb=lambda b: print('btn1 callback'))
                d.button_add("btn2",
                             selected_cb=lambda b: print('btn2 callback'))
                d.button_add("btn3",
                             selected_cb=lambda b: print('btn3 callback'))
            self._progress = 0.0
            t = EmcTimer(0.2, _progress_timer)

        # Dialog - List
        elif url.endswith('/list'):

            def _dia_list_cb(dia):
                item = dia.list_item_selected_get()
                print('Selected: ' + str(item))
                # dia.delete()

            d = EmcDialog(title='Dialog - List',
                          style='list',
                          done_cb=_dia_list_cb)
            d.list_item_append('item 1', 'icon/home')
            d.list_item_append('item 2', 'icon/star', 'icon/check_on')
            d.list_item_append(
                'item 3 <b>bold</> <info>info</> '
                '<success>success</> <failure>failure</> '
                '<i>etc...</>', 'icon/star', 'icon/check_on')
            d.list_item_append('item 4', 'icon/tag', 'text/End Text')
            d.list_item_append('item 5', 'icon/tag',
                               'text/Styled <b>End</> <info>Text</>')
            d.list_item_append('item 6 ' + ('A really long text, ' * 6))
            for i in range(7, 101):
                d.list_item_append('item #%d' % i)
            d.list_go()

        # Dialog - List with buttons
        elif url.endswith('/list-btn'):
            d = EmcDialog(title='Dialog - List with buttons', style='list')
            for i in range(1, 40):
                d.list_item_append('item %d' % i)

            def _btn_cb(b):
                item = d.list_item_selected_get()
                print('Selected:', item)
                d.delete()

            d.button_add('One', selected_cb=_btn_cb)
            d.button_add('Two', selected_cb=_btn_cb)
            d.button_add('Tree', selected_cb=_btn_cb)
            d.list_go()

        # Dialog - Image list (landscape)
        elif url.endswith('/list-img-landscape'):
            d = EmcDialog(title=user_data,
                          style='image_list_landscape',
                          done_cb=lambda x, t: print(t))
            for i in range(20):
                d.list_item_append('item #%d' % i, self.backdrop)
            d.list_go()

        # Dialog - Image list (portrait)
        elif url.endswith('/list-img-portrait'):
            d = EmcDialog(title=user_data,
                          style='image_list_portrait',
                          done_cb=lambda x, t: print(t))
            for i in range(20):
                d.list_item_append('item #%d' % i, self.poster)
            d.list_go()

        # Dialog - Panel full
        elif url.endswith('/panel1'):
            d = EmcDialog(title='Dialog - Panel full',
                          text=LOREM * 8,
                          style='panel',
                          spinner=True)
            d.button_add('One', selected_cb=lambda b: print('btn1 callback'))
            d.button_add('Two', selected_cb=lambda b: print('btn2 callback'))
            d.button_add('Tree', selected_cb=lambda b: print('btn3 callback'))

        # Dialog - Panel full more
        elif url.endswith('/panel4'):
            d = EmcDialog(title='Dialog - Panel full more',
                          text=LOREM * 8,
                          style='panel',
                          spinner=False,
                          content='image/dvd_cover_blank.png')
            d.button_add('One', selected_cb=lambda b: print('btn1 callback'))
            d.button_add('Two', selected_cb=lambda b: print('btn2 callback'))
            d.button_add('Tree', selected_cb=lambda b: print('btn3 callback'))

        # Dialog - Panel no buttons
        elif url.endswith('/panel2'):
            text = LOREM
            d = EmcDialog(title='Dialog - Panel full',
                          text=text,
                          style='panel',
                          spinner=True)

        # Dialog - Panel no title
        elif url.endswith('/panel3'):
            text = LOREM
            d = EmcDialog(text=text, style='panel', spinner=True)

        # Dialog - Buffering ** TODO **
        elif url.endswith('/buffering'):

            def _progress_timer2():
                self._progress += 0.05
                d.progress_set(self._progress)
                if self._progress >= 1.0:
                    d.delete()
                    return False  # stop the timer
                else:
                    return True  # renew the callback

            d = EmcDialog(style='buffering', title=_('Buffering'))
            self._progress = 0.0
            EmcTimer(0.2, _progress_timer2)