Esempio n. 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
Esempio n. 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
Esempio n. 3
0
    def tab_change(change):
        tab_id = tab.v_model

        items = []
        if tab_id < 6:
            items.extend(get_information(tab_id, mc, tc, lb))

        widget = tab_widgets[tab_id]
        items.extend([
            v.ListItem(
                children=[
                    v.ListItemContent(children=[m])
                ]
            ) for m in widget.menu
        ])

        menu.children = items
        content.children = widget.main

        if tab_id == 4:
            simulation.update_simu_cfg_list()

        if tab_id == 5:
            parametric.update_param_cfg_list()

        if tab_id == 6:
            posttreatment.update(None)
Esempio n. 4
0
    def tab_change(change):
        tab_id = tab.v_model
        widget = tab_widgets[tab_id]
        menu.children = [
            v.ListItem(children=[v.ListItemContent(children=[m])])
            for m in widget.menu
        ]
        content.children = widget.main

        if tab_id == 5:
            posttreatment.update(None)
Esempio n. 5
0
def get_information(tab_id, mc, tc, lb):
    if tab_id == 0:
        return []

    items = [
        v.ListItem(children=[
            v.ListItemContent(children=[
                f"{mc.select_category.v_model}: " + f"{mc.select_model.v_model}"
            ],
            class_='px-4 py-0'
            )
        ],
        class_='mb-0'),
        v.ListItem(children=[
            v.ListItemContent(children=[
                f"Test case: {tc.select_case.v_model}"
            ],
            class_='px-4 py-0',
            )
        ],
        class_='mb-0'),
        v.ListItem(children=[
            v.ListItemContent(children=[
                f"Scheme: {lb.select_case.v_model}"
            ],
            class_='px-4 py-0',
            )
        ],
        class_='mb-0'),
    ]

    return [
        v.Card(children=[
            v.CardTitle(children=['Information'], class_='pb-1'),
            v.List(children=items[0:min(tab_id, 3)],
            dense=True,
            class_='pa-0')
        ])
    ]
Esempio n. 6
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)
Esempio n. 7
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])
        ]
Esempio n. 8
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)
Esempio n. 9
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}
Esempio n. 10
0
    def __init__(self):
        self.label = v.TextField(label='label', v_model='')
        self.min_value = FloatField(label='minimum value')
        self.max_value = FloatField(label='maximum value')

        headers = [{
            'text': 'Name',
            'value': 'name'
        }, {
            'text': 'Color',
            'value': 'color'
        }]

        self.cmap = v.ListItemGroup(
            v_model=plt.colormaps().index('RdBu'),
            children=[
                v.ListItem(children=[
                    v.ListItemContent(children=[
                        v.ListItemTitle(children=[name]),
                        v.ListItemSubtitle(children=[
                            v.Img(src=f'pylbm_ui/widgets/cmap/{name}.png',
                                  height=30,
                                  width=400)
                        ])
                    ])
                ]) for name in plt.colormaps()
            ])

        self.widget = [
            self.label, self.min_value, self.max_value,
            v.ExpansionPanels(
                v_model=None,
                children=[
                    v.ExpansionPanel(children=[
                        v.ExpansionPanelHeader(children=['Colormaps']),
                        v.ExpansionPanelContent(children=[self.cmap])
                    ])
                ])
        ]
Esempio n. 11
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
Esempio n. 12
0
    def get_widgets(self, widget_width):
        """Creates and returns an address widget

        Args:
            widget_width (str): The width of all widgets to be created.

        Returns:
            Sequence[hdijupyterutils.ipywidgetfactory.IpyWidgetFactory]: list of widgets
        """
        self.project_widget = v.TextField(
            class_='ma-2',
            placeholder=constants.ENTER_PROJECT_MESSAGE,
            label='Project ID *',
            dense=True,
            v_model=self.
            project,  #will be none if no project can be determined from credentials
            color='primary',
            outlined=True,
        )

        self.account_widget = v.Select(
            class_='ma-2',
            placeholder='No accounts found',
            label='Account *',
            dense=True,
            color='primary',
            hide_selected=False,
            outlined=True,
            v_model=self.active_credentials,
            items=self.credentialed_accounts,
            auto_select_first=True,
            # v_slots allows help message to be displayed if no accounts are found.
            v_slots=[{
                'name':
                'no-data',
                'children':
                v.ListItem(children=[
                    v.ListItemContent(children=[
                        v.ListItemTitle(children=[
                            constants.NO_ACCOUNTS_FOUND_HELP_MESSAGE
                        ])
                    ])
                ])
            }],
        )

        self.region_widget = v.Combobox(
            class_='ma-2',
            placeholder=constants.SELECT_REGION_MESSAGE,
            label='Region *',
            dense=True,
            color='primary',
            hide_selected=True,
            outlined=True,
            items=get_regions(),
            v_model=None,
        )

        self.filter_widget = v.Combobox(
            class_='ma-2',
            placeholder=constants.NO_FILTERS_FOUND_MESSAGE,
            multiple=True,
            label='Filter by label',
            chips=True,
            dense=True,
            deletable_chips=True,
            color='primary',
            hide_selected=True,
            outlined=True,
            items=[],
            auto_select_first=True,
            v_model=None,
            v_slots=[{
                'name':
                'no-data',
                'children':
                v.ListItem(children=[
                    v.ListItemContent(children=[
                        v.ListItemTitle(
                            children=[constants.NO_FILTERS_FOUND_HELP_MESSAGE])
                    ])
                ])
            }],
        )

        self.cluster_widget = v.Combobox(
            class_='ma-2',
            placeholder=constants.NO_CLUSTERS_FOUND_MESSAGE,
            label='Cluster',
            dense=True,
            color='primary',
            hide_selected=True,
            outlined=True,
            items=[],
            auto_select_first=True,
            v_model=None,
            v_slots=[{
                'name':
                'no-data',
                'children':
                v.ListItem(children=[
                    v.ListItemContent(children=[
                        v.ListItemTitle(children=[
                            constants.NO_CLUSTERS_FOUND_HELP_MESSAGE
                        ])
                    ])
                ])
            }],
        )

        self.account_widget.on_event('change', self._update_active_credentials)
        self.project_widget.on_event('change', self._update_project)
        self.region_widget.on_event('change',
                                    self._update_cluster_list_on_region)
        self.filter_widget.on_event('change',
                                    self._update_cluster_list_on_filter)
        widgets = [
            self.account_widget, self.project_widget, self.region_widget,
            self.cluster_widget, self.filter_widget
        ]
        return widgets
Esempio n. 13
0
def select_or_create(items,
                     v_model=None,
                     multiple=False,
                     label=None,
                     hint='Select or create item(s)',
                     persistent_hint=True,
                     class_=None,
                     style_=None,
                     small_chips=True,
                     deletable_chips=True,
                     hide_selected=True,
                     **kwargs):
    """
    Select / Dropdown input

    Function to generate an ipyvuetify Combobox input widget.

    The value of the widget can be accessed or modified by the `v_model` property of the return value.

    See the vuetify documention for other arguments that can be passed as keyword arguments: https://vuetifyjs.com/en/components/combobox/

    Parameters:
    items : list
        Items to choose from in dropdown

    v_model : bool (optional, default None)
        Value of the time input, must be an element of choices

    multiple : bool
        Whether to allow multiple selected values

    hint : str
        Help text to display

    persistent_hint : bool
        Whether to always show hint text

    label : str (optional, default False)
        Default value of the checkbox input

    class_ : str (optional, default None)
        ipyvuetify HTML class string

    style_ : str (optional, default None)
        ipyvuetify HTML CSS string

    small_chips : bool (optional, default True)
        display selection as small chips

    deletable_chips : bool (optional, default True)
        display x on selection(s) to remove

    hide_selected : bool (default True)
        Hide selected elements from menu

    **kwargs
        Other arguments supported by ipyvuetify.TextField

    Returns:
    ipyvuetify.TextInput
        An ipyvuetify time input widget
    """

    if isinstance(items, dict):
        items = [{'text': i, 'value': items[i]} for i in items]

    if multiple and v_model is not None and not isinstance(v_model, list):
        v_model = [v_model]

    ret = ipyvuetify.Combobox(
        items=items,
        multiple=multiple,
        class_=class_,
        style_=style_,
        v_model=v_model,
        label=label,
        small_chips=small_chips,
        deletable_chips=deletable_chips,
        hide_selected=hide_selected,
        persistent_hint=persistent_hint,
        hint=hint,
        v_slots=[{
            'name':
            'no-data',
            'children':
            ipyvuetify.ListItem(children=[
                ipyvuetify.ListItemContent(children=[
                    ipyvuetify.ListItemTitle(children=[
                        'Your search returned no items. Press Enter to create a new one'
                    ])
                ])
            ])
        }])

    # Set other keyword arguments
    for arg in kwargs:
        setattr(ret, arg, kwargs[arg])

    # Return widget
    return ret