Example #1
0
 def test2(self, text):
     self.session, self.headers, search_result = self.tag_search(text)
     screen = App.get_running_app().sm
     while screen.get_screen('Test').children[0].children:
         screen.get_screen('Test').children[0].remove_widget(
             screen.get_screen('Test').children[0].children[0])
     layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
     layout.bind(minimum_height=layout.setter('height'))
     search_bar = Builder.template('Search_Bar', size_hint=(1, 0.06))
     screen.get_screen('Test').children[0].add_widget(search_bar)
     if search_result != []:
         for novel in search_result:
             novel_info_view = Builder.template('Novel_Info',
                                                **novel,
                                                cols=1,
                                                size_hint_y=None)
             layout.add_widget(novel_info_view)
             tag_box = GridLayout(cols=4, size_hint=(1, None))
             for tag in novel['tags']:
                 tag_button = Button(text=tag)
                 tag_box.add_widget(tag_button)
             layout.add_widget(tag_box)
         scrollView_page = ScrollView(size=(Window.width,
                                            Window.height * 0.94))
         scrollView_page.add_widget(layout)
     else:
         scrollView_page = ScrollView(size=(Window.width,
                                            Window.height * 0.94))
         scrollView_page.add_widget(info_display)
     self.add_widget(scrollView_page)
Example #2
0
 def __init__(self, **kwargs):
     super(main_display, self).__init__(**kwargs)
     resource_add_path('./fonts')
     LabelBase.register(DEFAULT_FONT, 'ARIALUNI.TTF')
     Window.clearcolor = (1, 1, 1, 1)
     session = ObjectProperty()
     headers = ObjectProperty()
     self.cols = 1
     search_bar = Builder.template('Search_Bar', size_hint=(1, 0.06))
     self.add_widget(search_bar)
     info_display = GridLayout(cols=1, spacing=10, size_hint_y=None)
     info_display.bind(minimum_height=info_display.setter('height'))
     self.session, self.headers, search_result = self.search('')
     if search_result != []:
         for novel in search_result:
             novel_info_view = Builder.template('Novel_Info',
                                                **novel,
                                                cols=1,
                                                size_hint_y=None)
             info_display.add_widget(novel_info_view)
             tag_box = GridLayout(cols=4, size_hint=(1, None))
             for tag in novel['tags']:
                 tag_button = Button(text=tag)
                 tag_box.add_widget(tag_button)
             info_display.add_widget(tag_box)
         scrollView_page = ScrollView(size=(Window.width,
                                            Window.height * 0.94))
         scrollView_page.add_widget(info_display)
     else:
         scrollView_page = ScrollView(size=(Window.width,
                                            Window.height * 0.94))
         scrollView_page.add_widget(info_display)
     self.add_widget(scrollView_page)
Example #3
0
    def _update_files(self, *args):
        # Clear current files
        self.dispatch("on_entries_cleared")

        # Add the components that are always needed
        if platform == "win32":
            is_root = splitdrive(self.path)[1] in (sep, altsep)
        elif platform in ("darwin", "linux2"):
            is_root = normpath(expanduser(self.path)) == sep
        else:
            # Unknown file system; Just always add the .. entry but also log
            Logger.warning("Filechooser: Unsupported OS: %r" % platform)
            is_root = False
        if not is_root:
            back = ".." + sep
            pardir = Builder.template(
                self._ENTRY_TEMPLATE,
                **dict(
                    name=back,
                    size="",
                    path=back,
                    controller=self,
                    isdir=True,
                    parent=None,
                    sep=sep,
                    get_nice_size=lambda: "",
                )
            )
            self.dispatch("on_entry_added", pardir)
        try:
            self._add_files(self.path)
        except OSError, e:
            Logger.exception("Unable to open directory <%s>" % self.path)
Example #4
0
    def _update_files(self, *args):
        # Clear current files
        self.dispatch('on_entries_cleared')
        self._items = []

        # Add the components that are always needed
        if platform == 'win':
            is_root = splitdrive(self.path)[1] in (sep, altsep)
        elif platform in ('macosx', 'linux', 'android', 'ios'):
            is_root = normpath(expanduser(self.path)) == sep
        else:
            # Unknown file system; Just always add the .. entry but also log
            Logger.warning('Filechooser: Unsupported OS: %r' % platform)
            is_root = False
        if not is_root:
            back = '..' + sep
            pardir = Builder.template(
                self._ENTRY_TEMPLATE,
                **dict(name=back,
                       size='',
                       path=back,
                       controller=self,
                       isdir=True,
                       parent=None,
                       sep=sep,
                       get_nice_size=lambda: ''))
            self._items.append(pardir)
            self.dispatch('on_entry_added', pardir)
        try:
            self._add_files(self.path)
        except OSError:
            Logger.exception('Unable to open directory <%s>' % self.path)
Example #5
0
    def show_contacts(self, info_contacts):
        '''
        :type info_contacts: dict;
        :param info_contacts: {
            'Name contact': ['Number contact\nMail contact', 'path/to/avatar']
        };

        '''
        if not self._contacts_items:
            # Создаем список контактов.
            self._contacts_list = ContactsList()
            self._contacts_items = Lists(
                dict_items=info_contacts,
                flag='three_list_custom_icon',
                right_icons=self.data.right_icons,
                events_callback=self._event_contact_item)

            button_add_contact = Builder.template(
                'ButtonAdd',
                disabled=False,
                events_callback=self.show_form_create_contact)
            self._contacts_list.add_widget(self._contacts_items)
            self._contacts_list.add_widget(button_add_contact)
            self.add_screens('contact_list', self.manager_tab_contacts,
                             self._contacts_list)
        else:
            # Добавляет контакт к существующему списку
            # и выводит список на экран.
            self._add_contact_item(info_contacts)
            self.manager_tab_contacts.current = 'contact_list'
Example #6
0
    def _update_files(self, *args):
        # Clear current files
        self.dispatch('on_entries_cleared')
        self._items = []

        # Add the components that are always needed
        if platform == 'win':
            is_root = splitdrive(self.path)[1] in (sep, altsep)
        elif platform in ('macosx', 'linux', 'android', 'ios'):
            is_root = normpath(expanduser(self.path)) == sep
        else:
            # Unknown file system; Just always add the .. entry but also log
            Logger.warning('Filechooser: Unsupported OS: %r' % platform)
            is_root = False
        if not is_root:
            back = '..' + sep
            pardir = Builder.template(self._ENTRY_TEMPLATE, **dict(name=back,
                size='', path=back, controller=self, isdir=True, parent=None,
                sep=sep, get_nice_size=lambda: ''))
            self._items.append(pardir)
            self.dispatch('on_entry_added', pardir)
        try:
            self._add_files(self.path)
        except OSError:
            Logger.exception('Unable to open directory <%s>' % self.path)
Example #7
0
    def load_document(self, doc, filename):
        view = self.view

        def thumb_texture(thumb):
            w, h, pixels = thumb
            texture = Texture.create((w, h), 'rgb', 'ubyte')
            texture.blit_buffer(pixels, colorfmt='rgb')
            return texture

        slides = list(doc.slides)
        title = ''
        texs = [thumb_texture(s.thumb) for s in slides[0:3]]
        texs.extend([None, None, None])
        tex0, tex1, tex2 = texs[0:3]
        dt = datetime.fromtimestamp(doc.infos.time_modification)

        if tex0 is None:
            title = 'No preview available'

        item = Builder.template('SelectorItem',
            app=self,
            title=title,
            time=dt.strftime('%d/%m/%y %H:%M'),
            tex0=tex0, tex1=tex1, tex2=tex2,
            slide_count=len(slides),
            obj_count=len(list(doc.objects)),
            filename=filename)
        self.view.add_widget(item)
Example #8
0
    def on_Query(self,who,query):    
        if query=="" or query is None:
            return

        conn=self.DataBase
        process=self.DataProc
        print "*** Query:",query
        print "*** Prams:",self.searchPrams
        
        process.execute(query,self.searchPrams)

        # clear result view
        self.ClearResults()
                
        results=process.fetchall()
        for row in results:
            #print row
            # Populate into result view
            info={
                'name'   : row[0],
                'width'  : int(row[1]),
                'height' : int(row[2]),
                'pixels' : FormatPixels(int(row[3])),
                'size'   : FormatBytes(int(row[4])),
                'tags'   : '',
                'hash'   : row[5],
                'path'   : row[6]
            }
            iTags=self.GetImageTags(info)
            info['tags']=','.join(iTags)
            ctx={'field':info}
            resultEntry=Builder.template('ResultRow',**ctx)
            self.add_widget(resultEntry)
Example #9
0
    def _add_files(self, path, parent=None):
        path = expanduser(path)

        files = self.file_system.listdir(path)
        # In the following, use fully qualified filenames
        files = [normpath(join(path, f)) for f in files]
        # Apply filename filters
        files = self._apply_filters(files)
        # Sort the list of files
        files = self.sort_func(files, self.file_system)
        is_hidden = self.file_system.is_hidden
        if not self.show_hidden:
            files = [x for x in files if not is_hidden(x)]
        self.files[:] = files
        total = len(files)
        wself = ref(self)
        for index, fn in enumerate(files):

            def get_nice_size():
                # Use a closure for lazy-loading here
                return self.get_nice_size(fn)

            ctx = {'name': basename(fn),
                   'get_nice_size': get_nice_size,
                   'path': fn,
                   'controller': wself,
                   'isdir': self.file_system.is_dir(fn),
                   'parent': parent,
                   'sep': sep}
            entry = Builder.template(self._ENTRY_TEMPLATE, **ctx)
            yield index, total, entry
Example #10
0
    def get_view(self, index):  # pragma: no cover
        item_args = self.args_converter(self.data)

        if self.cls:
            instance = self.cls(**item_args)
            return instance
        else:
            return Builder.template(self.template, **item_args)
    def get_view(self, index):  # pragma: no cover
        item_args = self.args_converter(self.data)

        if self.cls:
            instance = self.cls(**item_args)
            return instance
        else:
            return Builder.template(self.template, **item_args)
Example #12
0
 def updateDrives(self):
     drives=[c+':\\' for c in string.lowercase if os.path.isdir(c+':\\')]
     drivesParent=self.registry['drives']
     if (drivesParent is not None):
         drivesParent.clear_widgets()
         for drive in drives:
             ctx={'text':drive,'target':self.registry['files']}
             drivesParent.add_widget(Builder.template('DriveButton',**ctx))
Example #13
0
 def _update_title(self, dt):
     if not self.container_title:
         self._trigger_title()
         return
     c = self.container_title
     c.clear_widgets()
     instance = Builder.template(self.title_template, title=self.title, item=self, **self.title_args)
     c.add_widget(instance)
Example #14
0
    def get_view(self, index):  # pragma: no cover
        item_args = self.args_converter(self.data)

        cls = self.get_cls()
        if cls:
            return cls(**item_args)
        else:
            return Builder.template(self.template, **item_args)
Example #15
0
    def get_view(self, index):  # pragma: no cover
        item_args = self.args_converter(self.data)

        cls = self.get_cls()
        if cls:
            return cls(**item_args)
        else:
            return Builder.template(self.template, **item_args)
 def build(self):
     root = BoxLayout()
     for idx, word in enumerate(('Hello', 'World')):
         wid = Builder.template('BlehItem', **{
             'idx': idx, 'word': word,
         })
         root.add_widget(wid)
     return root
Example #17
0
def input_dialog(title='Title', hint_text='Write something',
                 text_button_ok='OK', text_button_cancel='CANCEL',
                 events_callback=None):
    input_dialog = Builder.template('InputText', title=title,
        hint_text=hint_text, text_button_ok=text_button_ok,
        text_button_cancel=text_button_cancel, events_callback=events_callback)
    input_dialog.open()

    return input_dialog
Example #18
0
    def build(self):
        # import pprint
        self.main_data = self.load_json()
        with open('kv/manager.kv', encoding='utf8') as f:
            Builder.load_string(f.read())
        with open('kv/main_screen.kv', encoding='utf8') as f:
            Builder.load_string(f.read())
        with open('kv/ms_item.kv', encoding='utf8') as f:
            Builder.load_string(f.read())
        with open('kv/ms_item_2.kv', encoding='utf8') as f:
            Builder.load_string(f.read())
        with open('kv/sushi_screan.kv', encoding='utf8') as f:
            Builder.load_string(f.read())

        self.icon = 'Images/panda.png'
        root = PandaManager(transition=NoTransition())
        # прорисовка меню
        main_menu = self.main_data['main_menu']
        for i in range(1, len(main_menu)):
            wid = Builder.template(
                'PictButton', **{
                    'img': main_menu[str(i)]['img'],
                    'link': main_menu[str(i)]['lnk'],
                })

            root.ids['Menu'].ids['main_screen_container'].add_widget(wid)


# прорисовка списка товаров
        sushi = self.main_data['second_level']['Sushi']

        for i in range(1, len(sushi)):
            wid = Builder.template(
                'PictButtonMenu', **{
                    'img': sushi[str(i)]['img'],
                    'txt': sushi[str(i)]['txt'],
                    'price': sushi[str(i)]['price'],
                    'lnk': sushi[str(i)]['lnk']
                })
            root.ids['Sushi'].ids['sushi_container'].add_widget(wid)

        self.bind(on_start=self.post_build_init)

        return root
Example #19
0
    def _save_show_filenames(self, fnames):
        layout = self.save_particle_popup.content.blayout

        self._reset_layout(layout)
        self.save_particle_popup.content.blayout_height = 2*layout.padding[0] + len(fnames)*(layout.spacing + self.save_particle_popup.content.label_height)

        for f in fnames:
            ctx = {'text': f, 'icon': os.path.join('user_effects', os.path.splitext(f)[0] + '.png') ,'height': self.save_particle_popup.content.label_height, 'callback': self.save_filename}
            button = Builder.template('FilenameButton', **ctx)
            layout.add_widget(button)
Example #20
0
    def _save_show_filenames(self, fnames):
        layout = self.save_particle_popup.content.blayout

        self._reset_layout(layout)
        self.save_particle_popup.content.blayout_height = 2*layout.padding[0] + len(fnames)*(layout.spacing + self.save_particle_popup.content.label_height)

        for f in fnames:
            ctx = {'text': f, 'icon': os.path.join(self.get_user_effects_path(), os.path.splitext(f)[0] + '.png') ,'height': self.save_particle_popup.content.label_height, 'callback': self.save_filename}
            button = Builder.template('FilenameButton', **ctx)
            layout.add_widget(button)
Example #21
0
    def show_empty_screen(self,
                          text='',
                          name_screen='add_contact',
                          screen_manager=None,
                          disabled=False,
                          callback=None):
        if not screen_manager:
            screen_manager = self.screen.ids.screen_manager_tab_contacts

        empty_screen = Builder.template('EmptyScreen',
                                        image='data/images/contacts.png',
                                        text=text)
        button_add = Builder.template('ButtonAdd',
                                      events_callback=callback,
                                      disabled=disabled)
        empty_screen.add_widget(button_add)
        self.add_screens(name_screen, screen_manager, empty_screen)

        return empty_screen, button_add
Example #22
0
def input_dialog(title='Title', hint_text='Write something',
                 text_button_ok='OK', text_button_cancel='CANCEL',
                 events_callback=None):
    input_dialog = Builder.template(
        'InputText', title=title, hint_text=hint_text,
        text_button_ok=text_button_ok, text_button_cancel=text_button_cancel,
        events_callback=events_callback
     )
    input_dialog.open()

    return input_dialog
Example #23
0
 def _update_title(self, dt):
     if not self.container_title:
         self._trigger_title()
         return
     c = self.container_title
     c.clear_widgets()
     instance = Builder.template(self.title_template,
                                 title=self.title,
                                 item=self,
                                 **self.title_args)
     c.add_widget(instance)
Example #24
0
def dialog_progress(text_button_cancel='Cancel', text_wait='Wait',
                    events_callback=None):
    if not isinstance(events_callback, types.FunctionType) or \
            isinstance(events_callback, types.MethodType):
        events_callback = lambda x: None
    spinner = Builder.template(
        'Progress', text_button_cancel=text_button_cancel, text_wait=text_wait,
        events_callback=events_callback
    )
    spinner.open()

    return spinner, spinner.ids.label
Example #25
0
    def create_view(self, index):
        '''This method is more complicated than the ones in the
        :class:`~kivy.adapters.adapter.Adapter` and
        :class:`~kivy.adapters.simplelistadapter.SimpleListAdapter` classes
        because here we create bindings for the data items and their children
        back to the *self.handle_selection()* event. We also perform
        other selection-related tasks to keep item views in sync with the data.
        '''
        item = self.get_data_item(index)
        if item is None:
            return None

        item_args = self.args_converter(index, item)

        item_args['index'] = index

        cls = self.get_cls()
        if cls:
            view_instance = cls(**item_args)
        else:
            view_instance = Builder.template(self.template, **item_args)

        if self.propagate_selection_to_data:
            # The data item must be a subclass of SelectableDataItem, or must
            # have an is_selected boolean or function, so it has is_selected
            # available. If is_selected is unavailable on the data item, an
            # exception is raised.
            #
            if isinstance(item, SelectableDataItem):
                if item.is_selected:
                    self.handle_selection(view_instance)
            elif type(item) == dict and 'is_selected' in item:
                if item['is_selected']:
                    self.handle_selection(view_instance)
            elif hasattr(item, 'is_selected'):
                if (inspect.isfunction(item.is_selected)
                        or inspect.ismethod(item.is_selected)):
                    if item.is_selected():
                        self.handle_selection(view_instance)
                else:
                    if item.is_selected:
                        self.handle_selection(view_instance)
            else:
                msg = "ListAdapter: unselectable data item for {0}"
                raise Exception(msg.format(index))

        view_instance.bind(on_release=self.handle_selection)

        for child in view_instance.children:
            child.bind(on_release=self.handle_selection)

        return view_instance
Example #26
0
    def create_view(self, index):
        '''This method is more complicated than the ones in the
        :class:`~kivy.adapters.adapter.Adapter` and
        :class:`~kivy.adapters.simplelistadapter.SimpleListAdapter` classes
        because here we create bindings for the data items and their children
        back to the *self.handle_selection()* event. We also perform
        other selection-related tasks to keep item views in sync with the data.
        '''
        item = self.get_data_item(index)
        if item is None:
            return None

        item_args = self.args_converter(index, item)

        item_args['index'] = index

        cls = self.get_cls()
        if cls:
            view_instance = cls(**item_args)
        else:
            view_instance = Builder.template(self.template, **item_args)

        if self.propagate_selection_to_data:
            # The data item must be a subclass of SelectableDataItem, or must
            # have an is_selected boolean or function, so it has is_selected
            # available. If is_selected is unavailable on the data item, an
            # exception is raised.
            #
            if isinstance(item, SelectableDataItem):
                if item.is_selected:
                    self.handle_selection(view_instance)
            elif type(item) == dict and 'is_selected' in item:
                if item['is_selected']:
                    self.handle_selection(view_instance)
            elif hasattr(item, 'is_selected'):
                if (inspect.isfunction(item.is_selected) or
                        inspect.ismethod(item.is_selected)):
                    if item.is_selected():
                        self.handle_selection(view_instance)
                else:
                    if item.is_selected:
                        self.handle_selection(view_instance)
            else:
                msg = "ListAdapter: unselectable data item for {0}"
                raise Exception(msg.format(index))

        view_instance.bind(on_release=self.handle_selection)

        for child in view_instance.children:
            child.bind(on_release=self.handle_selection)

        return view_instance
Example #27
0
    def get_view(self, index):
        item = self.get_data_item(index)

        if item is None:
            return None

        item_args = self.args_converter(index, item)

        if self.cls:
            instance = self.cls(**item_args)
            return instance
        else:
            return Builder.template(self.template, **item_args)
Example #28
0
def dialog_progress(text_button_cancel='Cancel', text_wait='Wait',
                    events_callback=None, text_color=None):
    if not text_color:
        text_color = [0, 0, 0, 1]

    spinner = Builder.template(
        'Progress', text_button_cancel=text_button_cancel,
        text_wait=text_wait, events_callback=events_callback,
        text_color=text_color
    )
    spinner.open()

    return spinner, spinner.ids.label
Example #29
0
    def get_view(self, index):
        item = self.get_data_item(index)

        if item is None:
            return None

        item_args = self.args_converter(index, item)

        if self.cls:
            instance = self.cls(**item_args)
            return instance
        else:
            return Builder.template(self.template, **item_args)
Example #30
0
    def _generate_file_entries(self, *args, **kwargs):
        # Generator that will create all the files entries.
        # the generator is used via _update_files() and _create_files_entries()
        # don't use it directly.
        is_root = True
        path = kwargs.get("path", self.path)
        have_parent = kwargs.get("parent", None) is not None

        # Add the components that are always needed
        if self.rootpath:
            rootpath = realpath(self.rootpath)
            path = realpath(path)
            if not path.startswith(rootpath):
                self.path = rootpath
                return
            elif path == rootpath:
                is_root = True
        else:
            if platform == "win":
                is_root = splitdrive(path)[1] in (sep, altsep)
            elif platform in ("macosx", "linux", "android", "ios"):
                is_root = normpath(expanduser(path)) == sep
            else:
                # Unknown fs, just always add the .. entry but also log
                Logger.warning("Filechooser: Unsupported OS: %r" % platform)
                is_root = False
        # generate an entries to go back to previous
        if not is_root and not have_parent:
            back = ".." + sep
            pardir = Builder.template(
                self._ENTRY_TEMPLATE,
                **dict(
                    name=back,
                    size="",
                    path=back,
                    controller=ref(self),
                    isdir=True,
                    parent=None,
                    sep=sep,
                    get_nice_size=lambda: "",
                )
            )
            yield 0, 1, pardir

        # generate all the entries for files
        try:
            for index, total, item in self._add_files(path):
                yield index, total, item
        except OSError:
            Logger.exception("Unable to open directory <%s>" % self.path)
            self.files[:] = []
Example #31
0
    def create_view(self, index):
        item = self.get_data_item(index)
        if item is None:
            return None

        item_args = self.args_converter(index, item)

        item_args['index'] = index

        cls = self.get_cls()
        if cls:
            view_instance = cls(**item_args)
        else:
            view_instance = Builder.template(self.template, **item_args)

        if self.propagate_selection_to_data:
            if isinstance(item, SelectableDataItem):
                if item.is_selected:
                    self.handle_selection(view_instance)
            elif type(item) == dict and 'is_selected' in item:
                if item['is_selected']:
                    self.handle_selection(view_instance)
            elif hasattr(item, 'is_selected'):
                if (inspect.isfunction(item.is_selected)
                        or inspect.ismethod(item.is_selected)):
                    if item.is_selected():
                        self.handle_selection(view_instance)
                else:
                    if item.is_selected:
                        self.handle_selection(view_instance)
            else:
                msg = "ListAdapter: unselectable data item for {0}"
                raise Exception(msg.format(index))
        view_instance.bind(on_release=self.handle_selection)

        for child in view_instance.children:
            child.bind(on_release=self.handle_selection)

        # Set checkbox
        chains = item.pdbFile.chains
        for chain in chains:
            itemCB = ItemCheckBox()
            itemCB.chainName.text = chain.chain_name
            itemCB.chainBox.id = item.list_id + '-_-' + str(
                index) + '-_-' + str(
                    chain.chain_id) + '-_-' + item.pdbFile.file_path
            itemCB.chainBox.bind(active=self.on_check_active)
            itemCB.chainBox.active = chain.is_selected
            view_instance.cbLayout.add_widget(itemCB)
        return view_instance
    def _create_entry_widget(self, ctx):
        # instantiate the widget
        if ctx['isdir'] == True:
            widget = Builder.template("FileThumbEntryFolder", **ctx)
        else:
            widget = super(FileChooserThumbView, self)._create_entry_widget(ctx)

        kctx = QueryDict(ctx)
        # default icon
        widget.image.source = FOLDER_ICON if kctx.isdir else FILE_ICON
        # schedule generation for later execution
        self.thumbnail_generator.append(widget.image, kctx, self._get_image)
        self.thumbnail_generator.run()
        return widget
Example #33
0
    def on_items(self, *args):
        self.clear_widgets()
        print("Building account page")

        selected = AccountStorage().get_selected()

        for account_id, item in enumerate(self.items):
            print("bbb")
            print(item)
            item["account_id"] = str(account_id)
            if int(selected) == int(account_id):
                item["url"] += " (selected)"
            w = Builder.template(self.item_template, **item)

            self.add_widget(w)
    def _create_entry_widget(self, ctx):
        # instantiate the widget
        if ctx['isdir'] == True:
            widget = Builder.template("FileThumbEntryFolder", **ctx)
        else:
            widget = super(FileChooserThumbView,
                           self)._create_entry_widget(ctx)

        kctx = QueryDict(ctx)
        # default icon
        widget.image.source = FOLDER_ICON if kctx.isdir else FILE_ICON
        # schedule generation for later execution
        self.thumbnail_generator.append(widget.image, kctx, self._get_image)
        self.thumbnail_generator.run()
        return widget
Example #35
0
def dialog_progress(text_button_cancel='Cancel',
                    text_wait='Wait',
                    events_callback=None,
                    text_color=None):
    if not text_color:
        text_color = [0, 0, 0, 1]

    spinner = Builder.template('Progress',
                               text_button_cancel=text_button_cancel,
                               text_wait=text_wait,
                               events_callback=events_callback,
                               text_color=text_color)
    spinner.open()

    return spinner, spinner.ids.label
Example #36
0
    def create_view(self, index):
        item = self.get_data_item(index)
        if item is None:
            return None

        item_args = self.args_converter(index, item)

        item_args['index'] = index

        cls = self.get_cls()
        if cls:
            view_instance = cls(**item_args)
        else:
            view_instance = Builder.template(self.template, **item_args)

        if self.propagate_selection_to_data:
            if isinstance(item, SelectableDataItem):
                if item.is_selected:
                    self.handle_selection(view_instance)
            elif type(item) == dict and 'is_selected' in item:
                if item['is_selected']:
                    self.handle_selection(view_instance)
            elif hasattr(item, 'is_selected'):
                if (inspect.isfunction(item.is_selected)
                        or inspect.ismethod(item.is_selected)):
                    if item.is_selected():
                        self.handle_selection(view_instance)
                else:
                    if item.is_selected:
                        self.handle_selection(view_instance)
            else:
                msg = "ListAdapter: unselectable data item for {0}"
                raise Exception(msg.format(index))
        view_instance.bind(on_release=self.handle_selection)

        for child in view_instance.children:
            child.bind(on_release=self.handle_selection)

        # Set checkbox
        chains = item.pdbFile.chains
        for chain in chains:
            itemCB = ItemCheckBox()
            itemCB.chainName.text = chain.chain_name
            itemCB.chainBox.id = item.list_id + '-_-' + str(index) + '-_-' + str(chain.chain_id) + '-_-' + item.pdbFile.file_path
            itemCB.chainBox.bind(active = self.on_check_active)
            itemCB.chainBox.active = chain.is_selected
            view_instance.cbLayout.add_widget(itemCB)
        return view_instance
Example #37
0
    def _generate_file_entries(self, *args, **kwargs):
        # Generator that will create all the files entries.
        # the generator is used via _update_files() and _create_files_entries()
        # don't use it directly.
        is_root = True
        path = kwargs.get('path', self.path)
        have_parent = kwargs.get('parent', None) is not None

        # Add the components that are always needed
        if self.rootpath:
            rootpath = realpath(self.rootpath)
            path = realpath(path)
            if not path.startswith(rootpath):
                self.path = rootpath
                return
            elif path == rootpath:
                is_root = True
        else:
            if platform == 'win':
                is_root = splitdrive(path)[1] in (sep, altsep)
            elif platform in ('macosx', 'linux', 'android', 'ios'):
                is_root = normpath(expanduser(path)) == sep
            else:
                # Unknown fs, just always add the .. entry but also log
                Logger.warning('Filechooser: Unsupported OS: %r' % platform)
                is_root = False
        # generate an entries to go back to previous
        if not is_root and not have_parent:
            back = '..' + sep
            pardir = Builder.template(
                self._ENTRY_TEMPLATE,
                **dict(name=back,
                       size='',
                       path=back,
                       controller=ref(self),
                       isdir=True,
                       parent=None,
                       sep=sep,
                       get_nice_size=lambda: ''))
            yield 0, 1, pardir

        # generate all the entries for files
        try:
            for index, total, item in self._add_files(path):
                yield index, total, item
        except OSError:
            Logger.exception('Unable to open directory <%s>' % self.path)
            self.files[:] = []
Example #38
0
def dialog_progress(
    text_button_cancel="Cancel", text_wait="Wait", events_callback=None, text_color=None
):
    if not text_color:
        text_color = [0, 0, 0, 1]

    spinner = Builder.template(
        "Progress",
        text_button_cancel=text_button_cancel,
        text_wait=text_wait,
        events_callback=events_callback,
        text_color=text_color,
    )
    spinner.open()

    return spinner, spinner.ids.label
Example #39
0
    def _add_files(self, path, parent=None):
        force_unicode = self._force_unicode
        # Make sure we're using unicode in case of non-ascii chars in
        # filenames.  listdir() returns unicode if you pass it unicode.
        try:
            path = expanduser(path)
            path = force_unicode(path)
        except ForceUnicodeError:
            pass

        files = []
        fappend = files.append
        for fn in listdir(path):
            try:
                fappend(force_unicode(fn))
            except ForceUnicodeError:
                pass
        # In the following, use fully qualified filenames
        files = [normpath(join(path, f)) for f in files]
        # Apply filename filters
        files = self._apply_filters(files)
        # Sort the list of files
        files = self.sort_func(files)
        is_hidden = self.is_hidden
        if not self.show_hidden:
            files = [x for x in files if not is_hidden(x)]
        self.files[:] = files
        total = len(files)
        wself = ref(self)
        for index, fn in enumerate(files):

            def get_nice_size():
                # Use a closure for lazy-loading here
                return self.get_nice_size(fn)

            ctx = {
                "name": basename(fn),
                "get_nice_size": get_nice_size,
                "path": fn,
                "controller": wself,
                "isdir": isdir(fn),
                "parent": parent,
                "sep": sep,
            }
            entry = Builder.template(self._ENTRY_TEMPLATE, **ctx)
            yield index, total, entry
Example #40
0
    def _add_files(self, path, parent=None):
        force_unicode = self._force_unicode
        # Make sure we're using unicode in case of non-ascii chars in
        # filenames.  listdir() returns unicode if you pass it unicode.
        try:
            path = expanduser(path)
            path = force_unicode(path)
        except ForceUnicodeError:
            pass

        files = []
        fappend = files.append
        for fn in self.file_system.listdir(path):
            try:
                fappend(force_unicode(fn))
            except ForceUnicodeError:
                pass
        # In the following, use fully qualified filenames
        files = [normpath(join(path, f)) for f in files]
        # Apply filename filters
        files = self._apply_filters(files)
        # Sort the list of files
        files = self.sort_func(files, self.file_system)
        is_hidden = self.file_system.is_hidden
        if not self.show_hidden:
            files = [x for x in files if not is_hidden(x)]
        self.files[:] = files
        total = len(files)
        wself = ref(self)
        for index, fn in enumerate(files):

            def get_nice_size():
                # Use a closure for lazy-loading here
                return self.get_nice_size(fn)

            ctx = {
                'name': basename(fn),
                'get_nice_size': get_nice_size,
                'path': fn,
                'controller': wself,
                'isdir': self.file_system.is_dir(fn),
                'parent': parent,
                'sep': sep
            }
            entry = Builder.template(self._ENTRY_TEMPLATE, **ctx)
            yield index, total, entry
Example #41
0
def input_dialog(
    title="Title",
    hint_text="Write something",
    text_button_ok="OK",
    text_button_cancel="CANCEL",
    events_callback=None,
):
    input_dialog = Builder.template(
        "InputText",
        title=title,
        hint_text=hint_text,
        text_button_ok=text_button_ok,
        text_button_cancel=text_button_cancel,
        events_callback=events_callback,
    )
    input_dialog.open()

    return input_dialog
Example #42
0
    def _add_files(self, path, parent=None):
        path = expanduser(path)
        # Make sure we're using unicode in case of non-ascii chars in filenames.
        # listdir() returns unicode if you pass it unicode.
        files = listdir(unicode(path))
        # In the following, use fully qualified filenames
        files = [normpath(join(path, f)) for f in files]
        # Apply filename filters
        files = self._apply_filters(files)
        # Sort the list of files
        files = self.sort_func(files)
        # Add the files
        if parent:
            parent.entries = []
        is_hidden = self.is_hidden
        if not self.show_hidden:
            files = [x for x in files if not is_hidden(x)]
        for fn in files:

            def get_nice_size():
                # Use a closure for lazy-loading here
                return self.get_nice_size(fn)

            ctx = {
                'name': basename(fn),
                'get_nice_size': get_nice_size,
                'path': fn,
                'controller': self,
                'isdir': isdir(fn),
                'parent': parent,
                'sep': sep
            }
            entry = Builder.template(self._ENTRY_TEMPLATE, **ctx)
            if not parent:
                self.dispatch('on_entry_added', entry, parent)
            else:
                parent.entries.append(entry)

        self.files = files
        if parent:
            return parent.entries
Example #43
0
    def _add_files(self, path, parent=None):
        path = expanduser(path)
        # Make sure we're using unicode in case of non-ascii chars in filenames.
        # listdir() returns unicode if you pass it unicode.
        files = listdir(unicode(path))
        # In the following, use fully qualified filenames
        files = [normpath(join(path, f)) for f in files]
        # Apply filename filters
        files = self._apply_filters(files)
        # Sort the list of files
        files = self.sort_func(files)
        # Add the files
        if parent:
            parent.entries = []
        is_hidden = self.is_hidden
        if not self.show_hidden:
            files = [x for x in files if not is_hidden(x)]
        for file in files:

            def get_nice_size():
                # Use a closure for lazy-loading here
                return self.get_nice_size(file)

            ctx = {
                "name": basename(file),
                "get_nice_size": get_nice_size,
                "path": file,
                "controller": self,
                "isdir": isdir(file),
                "parent": parent,
                "sep": sep,
            }
            entry = Builder.template(self._ENTRY_TEMPLATE, **ctx)
            if not parent:
                self.dispatch("on_entry_added", entry, parent)
            else:
                parent.entries.append(entry)

        self.files = files
        if parent:
            return parent.entries
Example #44
0
    def _add_files(self, path, parent=None):
        path = expanduser(path)

        files = []
        fappend = files.append
        for f in self.file_system.listdir(path):
            try:
                # In the following, use fully qualified filenames
                fappend(normpath(join(path, f)))
            except UnicodeDecodeError:
                Logger.exception('unable to decode <{}>'.format(f))
            except UnicodeEncodeError:
                Logger.exception('unable to encode <{}>'.format(f))
        # Apply filename filters
        files = self._apply_filters(files)
        # Sort the list of files
        files = self.sort_func(files, self.file_system)
        is_hidden = self.file_system.is_hidden
        if not self.show_hidden:
            files = [x for x in files if not is_hidden(x)]
        self.files[:] = files
        total = len(files)
        wself = ref(self)
        for index, fn in enumerate(files):

            def get_nice_size():
                # Use a closure for lazy-loading here
                return self.get_nice_size(fn)

            ctx = {
                'name': basename(fn),
                'get_nice_size': get_nice_size,
                'path': fn,
                'controller': wself,
                'isdir': self.file_system.is_dir(fn),
                'parent': parent,
                'sep': sep
            }
            entry = Builder.template(self._ENTRY_TEMPLATE, **ctx)
            yield index, total, entry
Example #45
0
 def show_expos(self, online=None):
     # get offline expo
     offline = self.get_offline_expos()
     if online is not None and type(offline) in (list, tuple):
         # mix with online expo
         result = self.mix_expos(offline, online)
     else:
         result = offline
     # show them.
     layout = ExpoPopupChoice()
     for expo in result:
         # convert to string key, python 2.6.
         expo = dict([(str(x), y) for x, y in expo.iteritems()])
         zipfiles = [x['fichier'] for x in expo['data'] if
                 x['fichier'].rsplit('.', 1)[-1] == 'zip']
         data = [x['fichier'] for x in expo['data'] if
                 x['fichier'].rsplit('.', 1)[-1].lower() in ('jpg', 'png')]
         expo['data'] = data
         expo['__zipfiles__'] = zipfiles
         item = Builder.template('ExpoItem', selector=self, **expo)
         layout.add_expo(item)
     self.popup(content=layout, title='Liste des expositions',
             size=(1000, 800))
Example #46
0
    def review_pop(self, session, headers, novel_id):
        pop_layout = GridLayout(cols=1)
        info_layout = GridLayout(cols=1, spacing=5, size_hint=(1, None))
        pop_scrollView_page = ScrollView(size_hint=(1, 1))

        pop_scrollView_page.add_widget(info_layout)
        info_layout.bind(minimum_height=info_layout.setter('height'))
        review_list = novel_reviews_get_content(novel_id, session, headers)
        for review in review_list:
            novel_review_view = Builder.template('Novel_Review',
                                                 **review,
                                                 rows=2,
                                                 cols=1,
                                                 size_hint_y=None)
            info_layout.add_widget(novel_review_view)

        pop_layout.add_widget(pop_scrollView_page)
        popup = Popup(title='Top5 评论',
                      content=pop_layout,
                      size_hint=(.8, .6),
                      auto_dismiss=True)
        # bind the on_press event of the button to the dismiss function
        # content.bind(on_press=popup.dismiss)
        popup.open()
Example #47
0
 def _create_entry_widget(self, ctx):
     template = self.layout._ENTRY_TEMPLATE\
         if self.layout else self._ENTRY_TEMPLATE
     return Builder.template(template, **ctx)
Example #48
0
    def add_label(self, template: str, ctx):
        # Add the widget
        widget = Builder.template(template, **ctx)
        self.ids.scroll_view_content.add_widget(widget)

        return widget
Example #49
0
 def on_items(self, *args):
     self.clear_widgets()
     for item in self.items:
         w = Builder.template(self.item_template, **item)
         self.add_widget(w)
Example #50
0
    def create_view(self, index):
        item = self.get_data_item(index)
        if item is None:
            return None

        item_args = self.args_converter(index, item)

        item_args['index'] = index

        cls = self.get_cls()
        if cls:
            view_instance = cls(**item_args)
        else:
            view_instance = Builder.template(self.template, **item_args)

        if self.propagate_selection_to_data:
            if isinstance(item, SelectableDataItem):
                if item.is_selected:
                    self.handle_selection(view_instance)
            elif type(item) == dict and 'is_selected' in item:
                if item['is_selected']:
                    self.handle_selection(view_instance)
            elif hasattr(item, 'is_selected'):
                if (inspect.isfunction(item.is_selected)
                        or inspect.ismethod(item.is_selected)):
                    if item.is_selected():
                        self.handle_selection(view_instance)
                else:
                    if item.is_selected:
                        self.handle_selection(view_instance)
            else:
                msg = "ListAdapter: unselectable data item for {0}"
                raise Exception(msg.format(index))
        view_instance.bind(on_release=self.handle_selection)

        for child in view_instance.children:
            child.bind(on_release=self.handle_selection)

        # Set checkbox
        chains = item.pdbFile.chains
        filename = os.path.basename(item.pdbFile.file_path)
        chainname = os.path.splitext(filename)[0]
        for chain in chains:
            if chain.is_selected == False or chain.chain_type == 'ligand':
                continue
            itemCB = GroupCheckBox()
            itemCB.chainName.text = chain.chain_name
            itemCB.chainBox.id = item.list_id + '-_-' + str(
                index) + '-_-' + str(
                    chain.chain_id) + '-_-' + item.pdbFile.file_path
            itemCB.chainBox.bind(active=self.on_check_active)
            itemCB.chainBox.active = chain.is_selected

            itemCB.resdiueFrom.id = '0-_-' + item.list_id + '-_-' + str(
                index) + '-_-' + str(
                    chain.chain_id) + '-_-' + item.pdbFile.file_path
            itemCB.resdiueFrom.text = chain.resindices
            itemCB.resdiueFrom.multiline = False
            itemCB.resdiueFrom.bind(text=self.on_text_change)
            # itemCB.resdiueTo.id = '1-_-' + item.list_id + '-_-' + str(index) + '-_-' + str(chain.chain_id)
            # itemCB.resdiueTo.text = str(chain.resindices[1])
            # itemCB.resdiueTo.multiline=False
            # itemCB.resdiueTo.bind(text=self.on_text_change)

            view_instance.cbLayout.add_widget(itemCB)
        return view_instance
Example #51
0
 def _create_entry_widget(self, ctx):
     return [Builder.template(view._ENTRY_TEMPLATE, **ctx)
             for view in self._views]
Example #52
0
    def create_view(self, index):
        item = self.get_data_item(index)
        if item is None:
            return None

        item_args = self.args_converter(index, item)

        item_args['index'] = index

        cls = self.get_cls()
        if cls:
            view_instance = cls(**item_args)
        else:
            view_instance = Builder.template(self.template, **item_args)

        if self.propagate_selection_to_data:
            if isinstance(item, SelectableDataItem):
                if item.is_selected:
                    self.handle_selection(view_instance)
            elif type(item) == dict and 'is_selected' in item:
                if item['is_selected']:
                    self.handle_selection(view_instance)
            elif hasattr(item, 'is_selected'):
                if (inspect.isfunction(item.is_selected)
                        or inspect.ismethod(item.is_selected)):
                    if item.is_selected():
                        self.handle_selection(view_instance)
                else:
                    if item.is_selected:
                        self.handle_selection(view_instance)
            else:
                msg = "ListAdapter: unselectable data item for {0}"
                raise Exception(msg.format(index))
        view_instance.bind(on_release=self.handle_selection)

        for child in view_instance.children:
            child.bind(on_release=self.handle_selection)

        # Set checkbox
        chains = item.pdbFile.chains
        filename = os.path.basename(item.pdbFile.file_path)
        chainname = os.path.splitext(filename)[0]
        for chain in chains:
            if chain.is_selected == False or chain.chain_type == 'ligand': 
                continue
            itemCB = GroupCheckBox()
            itemCB.chainName.text = chain.chain_name
            itemCB.chainBox.id = item.list_id + '-_-' + str(index) + '-_-' + str(chain.chain_id) + '-_-' + item.pdbFile.file_path
            itemCB.chainBox.bind(active = self.on_check_active)
            itemCB.chainBox.active = chain.is_selected

            itemCB.resdiueFrom.id = '0-_-' + item.list_id + '-_-' + str(index) + '-_-' + str(chain.chain_id) + '-_-' + item.pdbFile.file_path
            itemCB.resdiueFrom.text = chain.resindices
            itemCB.resdiueFrom.multiline=False
            itemCB.resdiueFrom.bind(text=self.on_text_change)
            # itemCB.resdiueTo.id = '1-_-' + item.list_id + '-_-' + str(index) + '-_-' + str(chain.chain_id)
            # itemCB.resdiueTo.text = str(chain.resindices[1])
            # itemCB.resdiueTo.multiline=False
            # itemCB.resdiueTo.bind(text=self.on_text_change)

            view_instance.cbLayout.add_widget(itemCB)
        return view_instance
Example #53
0
 def _create_entry_widget(self, ctx):
     template = self.layout._ENTRY_TEMPLATE\
         if self.layout else self._ENTRY_TEMPLATE
     return Builder.template(template, **ctx)