Пример #1
0
    def get_items(self):
        """return the list of items inside the folder"""

        list_dir = glob(os.path.join(self.folder, '*/'))

        for extention in self.extentions:
            list_dir.extend(glob(os.path.join(self.folder, '*' + extention)))

        folder_list = []
        file_list = []

        for el in list_dir:
            extention = Path(el).suffix
            if extention == '':
                icon = 'mdi-folder-outline'
                color = 'amber'
            elif extention in ['.csv', '.txt']:
                icon = 'mdi-border-all'
                color = 'green accent-4'
            elif extention in ['.tiff', '.tif']:
                icon = "mdi-image-outline"
                color = "deep-purple"
            else:
                icon = 'mdi-file-outline'
                color = 'light-blue'

            children = [
                v.ListItemAction(
                    children=[v.Icon(color=color, children=[icon])]),
                v.ListItemContent(children=[
                    v.ListItemTitle(children=[Path(el).stem + Path(el).suffix])
                ])
            ]

            if os.path.isdir(el):
                folder_list.append(v.ListItem(value=el, children=children))
            else:
                file_list.append(v.ListItem(value=el, children=children))

        folder_list = sorted(folder_list, key=lambda x: x.value)
        file_list = sorted(file_list, key=lambda x: x.value)

        parent_path = str(Path(self.folder).parent)
        parent_item = v.ListItem(
            value=parent_path,
            children=[
                v.ListItemAction(children=[
                    v.Icon(color='black',
                           children=['mdi-folder-upload-outline'])
                ]),
                v.ListItemContent(
                    children=[v.ListItemTitle(children=[f'..{parent_path}'])])
            ])

        folder_list.extend(file_list)
        folder_list.insert(0, parent_item)

        return folder_list
Пример #2
0
def DrawerItem(title, icon=None, card='', href=''):
    """ 
    create a drawer item using the user input
    
    Args:
        title (str): the title to display in the drawer,
        icon (str, optional): the icon id following the mdi code. folder icon if None
        card (str), optional): the tile metadata linked to the drawer
        href(str, optional): the link targeted by the button
    
    Returns:
        item (v.ListItem): the item to display
    """

    if not icon:
        icon = 'mdi-folder-outline'

    item = v.ListItem(
        link=True,
        children=[
            v.ListItemAction(
                children=[v.Icon(class_="white--text", children=[icon])]),
            v.ListItemContent(children=[
                v.ListItemTitle(class_="white--text", children=[title])
            ])
        ])

    if not href == '':
        item.href = href
        item.target = "_blank"

    if not card == '':
        item._metadata = {'card_id': card}

    return item
Пример #3
0
    def __init__(self, state, remove=True, **kwargs):
        """
        Create a state item from the default states defined by the test case
        or by those defined by the user.

        This state item is then added into a v.List and can be clicked to modify
        its values using a dialog box.

        Parameters
        ==========

        state: dict
            the state used to create a state item.

        remove: bool
            add a remove button if yes.

        """
        self.state = state.copy()
        super().__init__(state, **kwargs)

        self.content.children = [f'{self}']

        # add a remove button if state defined by the user
        if remove:
            action = v.ListItemAction(children=[self.btn])
        else:
            action = v.ListItemAction(children=[])

        self.stab_status = v.Card(children=['uncheck'], class_='pa-2')

        self.children=[
            action,
            v.ListItemContent(
            children=[
                v.Card(children=[self.content],
                        flat=True,
                        color='transparent',
                        light=True,
                ),
            self.update_dialog
            ]),
            v.ListItemAction(children=[self.stab_status])
        ]
Пример #4
0
    def add_element(self, icon, controller):
        link = v.ListItem(
            href="#",
            children=[
                v.ListItemAction(children=[v.Icon(children=[icon])]),
                v.ListItemContent(
                    children=[v.ListItemTitle(children=[controller.name])])
            ])

        def on_click(*change):
            self.trigger("change_view", controller)

        link.on_event("click", on_click)

        self.__elements.append(link)
        self.__controllers.append(controller)
Пример #5
0
    def __init__(self, *args, **kwargs):
        self.form = self.form_class(*args, **kwargs)

        update_btn = v.Btn(children=['update'], color='success')
        close_btn = v.Btn(children=['close'], color='error')

        self.update_dialog = v.Dialog(
            width='500',
            v_model=False,
            children=[
                v.Card(children=[
                    v.CardTitle(class_='headline gray lighten-2',
                                primary_title=True,
                                children=[self.update_text]),
                    v.CardText(children=[self.form]),
                    v.CardActions(children=[v.Spacer(), update_btn, close_btn])
                ]),
            ])

        update_btn.on_event('click', self.update_click)
        close_btn.on_event('click', self.close_click)

        self.content = v.CardText(children=[f'{self}'])

        self.btn = v.Btn(
            children=[v.Icon(children=['mdi-close'])],
            fab=True,
            color='error',
            dark=True,
            x_small=True,
        )

        super().__init__(children=[
            v.ListItemAction(children=[self.btn]),
            v.ListItemContent(children=[
                v.Card(
                    children=[self.content],
                    flat=True,
                    color='transparent',
                    light=True,
                ), self.update_dialog
            ]),
        ],
                         **kwargs)
Пример #6
0
    def __init__(self, title, icon=None, card=None, href=None, **kwargs):

        icon = icon if icon else 'mdi-folder-outline'

        children = [
            v.ListItemAction(
                children=[v.Icon(class_="white--text", children=[icon])]),
            v.ListItemContent(children=[
                v.ListItemTitle(class_="white--text", children=[title])
            ])
        ]

        super().__init__(link=True, children=children, **kwargs)

        if href:
            self.href = href
            self.target = "_blank"
        elif card:
            self._metadata = {'card_id': card}
Пример #7
0
    def __init__(self, session=None, output_widget=None):

        self.output = output_widget
        self.session = session

        self.modes = [
            ("replace", icon_replace, ReplaceMode),
            ("add", icon_or, OrMode),
            ("and", icon_and, AndMode),
            ("xor", icon_xor, XorMode),
            ("remove", icon_andnot, AndNotMode),
        ]

        items = []
        for mode in self.modes:
            item = v.ListItem(children=[v.ListItemAction(children=[mode[1]]),
                                        v.ListItemTitle(children=[mode[0]])])
            items.append(item)

        for item in items:
            item.on_event('click', self._sync_state_from_ui)

        mylist = v.List(children=items)

        self.main = v.Btn(icon=True,
                          children=[self.modes[0][1]], v_on="menu.on")

        super().__init__(
            v_slots=[{
                'name': 'activator',
                'variable': 'menu',
                'children': self.main
            }],
            children=[mylist])

        self.session.hub.subscribe(self, msg.EditSubsetMessage,
                                   handler=self._on_edit_subset_msg)

        self._sync_ui_from_state(self.session.edit_subset_mode.mode)
Пример #8
0
    def __init__(self, viewer):

        self.output = viewer.output_widget
        self.session = viewer.session

        self.modes = viewer.toolbar_selection_mode.selection_modes

        items = []
        for mode in self.modes:
            item = v.ListItem(children=[
                v.ListItemAction(children=[mode[1]]),
                v.ListItemTitle(children=[mode[0]])
            ])
            items.append(item)

        for item in items:
            item.on_event('click', self._sync_state_from_ui)

        mylist = v.List(children=items)

        self.main = v.Btn(icon=True,
                          children=[self.modes[0][1]],
                          v_on="menu.on")

        super().__init__(v_slots=[{
            'name': 'activator',
            'variable': 'menu',
            'children': self.main
        }],
                         children=[mylist])

        self.session.hub.subscribe(self,
                                   msg.EditSubsetMessage,
                                   handler=self._on_edit_subset_msg)

        self._sync_ui_from_state(self.session.edit_subset_mode.mode)
Пример #9
0
    def get_items(self):
        """return the list of items inside the folder"""

        self.loading.indeterminate = not self.loading.indeterminate

        folder = Path(self.folder)

        list_dir = [
            el for el in folder.glob('*/') if not el.name.startswith('.')
        ]

        if self.extentions:
            list_dir = [
                el for el in list_dir
                if el.is_dir() or el.suffix in self.extentions
            ]

        folder_list = []
        file_list = []

        for el in list_dir:

            if el.suffix in ICON_TYPES.keys():
                icon = ICON_TYPES[el.suffix]['icon']
                color = ICON_TYPES[el.suffix]['color']
            else:
                icon = ICON_TYPES['DEFAULT']['icon']
                color = ICON_TYPES['DEFAULT']['color']

            children = [
                v.ListItemAction(
                    children=[v.Icon(color=color, children=[icon])]),
                v.ListItemContent(
                    children=[v.ListItemTitle(children=[el.stem +
                                                        el.suffix])]),
            ]

            if el.is_dir():
                folder_list.append(v.ListItem(value=str(el),
                                              children=children))
            else:
                file_size = str(
                    round(Path(el).stat().st_size / (1024 * 1024), 2)) + ' MB'
                children.append(v.ListItemActionText(children=[file_size]))
                file_list.append(v.ListItem(value=str(el), children=children))

        folder_list = sorted(folder_list, key=lambda x: x.value)
        file_list = sorted(file_list, key=lambda x: x.value)

        parent_path = str(folder.parent)
        parent_item = v.ListItem(
            value=parent_path,
            children=[
                v.ListItemAction(children=[
                    v.Icon(color=ICON_TYPES['PARENT']['color'],
                           children=[ICON_TYPES['PARENT']['icon']])
                ]),
                v.ListItemContent(
                    children=[v.ListItemTitle(children=[f'..{parent_path}'])]),
            ])

        folder_list.extend(file_list)
        folder_list.insert(0, parent_item)

        self.loading.indeterminate = not self.loading.indeterminate
        return folder_list