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
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
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)
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)
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') ]) ]
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)
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)
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]) ]) ]) ]
def __init__(self): # create the extra widget self.state = sw.StateBar(done=True) self.color = v.ListItemGroup(v_model = None, children=[v.ListItem(children= [c], value=c) for c in cp.planet_colors[:4]]) self.palette = v.Menu( value=False, v_slots=[{ 'name': 'activator', 'variable': 'menu', 'children': v.Btn(v_model = False, v_on='menu.on', color='primary', icon = True, children=[v.Icon(children=['mdi-palette'])]) }], children = [v.List(dense=True, outlined=True, rounded=True, children=[self.color])] ) # create the map super().__init__(gee=False) # add the widget to the map (as to left and right items) self.add_control(WidgetControl(widget=self.state, position='topleft')) self.add_control(WidgetControl(widget=self.palette, position='topleft')) # create jslinks jslink((self, 'combo'), (self.color, 'v_model'))
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)
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
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
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
def __init__(self, flip_func): f = open('app/config.json') self.cfg = json.load(f) self.output = Output() # Colorspace Seletor self.colorspace_sel = select( items=['RGB', 'HSV', 'LAB', 'GRAY'], v_model='RGB', ) # Image Selector self.img_selector = select( items=self.cfg['images']['images_files'], v_model='img_1.jpeg', style_='height: 15px', ) # Upload button self.upload_btn = button( class_='ma-4', style_='width:35px; height: 35px', size='small', fab=True, color='primary', icon='mdi-upload', outlined=True, ) self.f_input = v.FileInput(show_progress=True) # Turn Histogram Up Switch self.flip_hist_btn = button( class_='ma-4', style_='width:35px; height: 35px', color='primary', size='small', fab=True, icon='mdi-chart-histogram', outlined=True, on_click=flip_func, ) self.save_op_btn = button( class_='ma-4', style_='width:35px; height: 35px', color='primary', size='small', fab=True, icon='mdi-content-save', outlined=True, #on_click=flip_func, ) self.github_btn = button( class_='ma-4', style_='width:35px; height: 35px', size='small', fab=True, color='primary', icon='mdi-source-repository', outlined=True, href='https://github.com/Mateus-M-Reis/grancv', target='_blank', ) self.save_chart_btn = button( class_='ma-4', style_='width:35px; height: 35px', size='small', fab=True, color='secondary', icon='mdi-chart-histogram', #outlined=True, ) self.save_img_btn = button( class_='ma-4', style_='width:35px; height: 35px', size='small', fab=True, color='secondary', icon='mdi-image-plus', #outlined=True, ) self.show_console_btn = button( class_='ma-4', style_='width:35px; height: 35px', size='small', fab=True, color='secondary', icon='mdi-console-line', ##outlined=True, ) # Operations Selector self.op_selector = select_or_create( items=list(self.cfg['operations'].values()), v_model='neural-style-transfer', multiple=True, ) self.op_selector.on_event('change', self.update_expansion_panel) # Operations Panel self.op_panel = v.ExpansionPanels(children=[ smooth_expp, morpho_expp, threshold_expp, nst_expp, watershed_expp ], ) # Sidebar Layout self.drawer = v.Card( children=[ v.NavigationDrawer( width='325px', dark=True, color='#FF000000', #expand_on_hover=True, mini_variant_width='75px', fixed=True, # * floating=True, #permanent=True, #mini_variant=True, #app=True, #disable_route_watcher=True, #disable_resize_watcher=True, #v_model='drawer', #hide_overlay=True, #clipped=True, #absolute=True, #touchless=True, children=[ v.List( children=[ v.ListItem(children=[ self.upload_btn, self.img_selector ], class_='d-flex align-stretch mb-6', style_='height: 40px;'), v.ListItem(children=[ self.flip_hist_btn, self.colorspace_sel ], class_='d-flex align-stretch mb-6', style_='height: 40px;'), #v.ListItem( # children=[ # self.save_op_btn, # self.save_img_btn, # self.save_chart_btn, # self.show_console_btn, # ], # class_='d-flex align-stretch mb-6', # style_='\ # height: 40px; \ # ' # ), v.ListItem(children=[ self.github_btn, self.op_selector, ], class_='d-flex align-stretch mb-6', style_='\ height: 100%; \ '), ], style_='background-color: #000000BF'), v.Divider(), v.List(children=[ v.ListItem(children=[ self.op_panel, ], class_='d-flex align-stretch mb-6', style_='\ width: 100%; \ height: 100%; \ '), ]) ]) ], class_='d-flex flex-column mb-12', )
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=[{