Exemplo 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
Exemplo 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
Exemplo n.º 3
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)
Exemplo n.º 4
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}
Exemplo n.º 5
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)
Exemplo n.º 6
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])
                    ])
                ])
        ]
Exemplo n.º 7
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)
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
0
import ipyvuetify as v

lorum_ipsum = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et 
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'''

items = [
    v.ListItem(children=[v.ListItemTitle(children=[f'Click me {i}'])])
    for i in range(1, 5)
]

menu = v.Menu(offset_y=True,
              v_slots=[{
                  'name':
                  'activator',
                  'variable':
                  'menuData',
                  'children':
                  v.Btn(v_on='menuData.on',
                        color='primary',
                        children=[
                            'menu',
                            v.Icon(right=True, children=['mdi-menu-down'])
                        ]),
              }],
              children=[v.List(children=items)])

dialog = v.Dialog(
    width='500',
    v_slots=[{