Ejemplo n.º 1
0
    def __init__(self, table, schema, *args, default=None, **kwargs):
        """
        
        Dialog to modify/create new elements from the ClassTable data table
        
        Args: 
            table (ClassTable, v.DataTable): Table linked with dialog
            schema (dict {'title':'type'}): Schema for table showing headers and type of data
            default (dict): Dictionary with default valules
        """

        self.table = table
        self.default = default
        self.title = "New element" if not self.default else "Modify element"
        self.schema = schema
        self.v_model = True
        self.max_width = 500
        self.overlay_opcity = 0.7

        # Action buttons
        self.save = v.Btn(children=['Save'])
        save_tool = sw.Tooltip(self.save, 'Create new element')

        self.cancel = v.Btn(children=['Cancel'])
        cancel_tool = sw.Tooltip(self.cancel, 'Ignore changes')

        self.modify = v.Btn(children=['Modify'])
        modify_tool = sw.Tooltip(self.modify, 'Update row')

        save = [save_tool, cancel_tool]
        modify = [modify_tool, cancel_tool]

        actions = v.CardActions(children=save if not default else modify)

        super().__init__(*args, **kwargs)

        self.children=[
            v.Card(
                class_='pa-4',
                children=[
                    v.CardTitle(children=[self.title])] + \
                    self._get_widgets() + \
                    [actions]
            )
        ]

        # Create events

        self.save.on_event('click', self._save)
        self.modify.on_event('click', self._modify)
        self.cancel.on_event('click', self._cancel)
Ejemplo n.º 2
0
    def __init__(self, table, out_path, *args, **kwargs):
        """

        Dialog to save as .csv file the content of a ClassTable data table

        Args:
            table (ClassTable, v.DataTable): Table linked with dialog
            out_path (str): Folder path to store table content
        """
        self.max_width = 500
        self.v_model = False
        self.out_path = out_path

        super().__init__(*args, **kwargs)

        self.table = table

        self.w_file_name = v.TextField(label="Insert output file name",
                                       type="string",
                                       v_model="new_table.csv")

        # Action buttons
        self.save = v.Btn(children=["Save"])
        save = sw.Tooltip(self.save, "Save table")

        self.cancel = v.Btn(children=["Cancel"])
        cancel = sw.Tooltip(self.cancel, "Cancel")

        info = (sw.Alert().add_msg("The table will be stored in {}".format(
            str(out_path))).show())

        self.children = [
            v.Card(
                class_="pa-4",
                children=[
                    v.CardTitle(children=["Save table"]),
                    self.w_file_name,
                    info,
                    save,
                    cancel,
                ],
            )
        ]

        # Create events
        self.save.on_event("click", self._save)
        self.cancel.on_event("click", self._cancel)
Ejemplo n.º 3
0
    def __init__(self, table, out_path, *args, **kwargs):
        """
        
        Dialog to save as .csv file the content of a ClassTable data table
        
        Args: 
            table (ClassTable, v.DataTable): Table linked with dialog
            out_path (str): Folder path to store table content
        """
        self.max_width = 500
        self.v_model = False
        self.out_path = out_path

        super().__init__(*args, **kwargs)

        self.table = table

        self.w_file_name = v.TextField(label='Insert output file name',
                                       type='string',
                                       v_model='new_table.csv')

        # Action buttons
        self.save = v.Btn(children=['Save'])
        save = sw.Tooltip(self.save, 'Save table')

        self.cancel = v.Btn(children=['Cancel'])
        cancel = sw.Tooltip(self.cancel, 'Cancel')

        info = sw.Alert().add_msg('The table will be stored in {}'.format(
            str(out_path))).show()

        self.children = [
            v.Card(class_='pa-4',
                   children=[
                       v.CardTitle(children=['Save table']), self.w_file_name,
                       info, save, cancel
                   ])
        ]

        # Create events
        self.save.on_event('click', self._save)
        self.cancel.on_event('click', self._cancel)
Ejemplo n.º 4
0
    def __init__(self, io, nb_class):

        # gather the io
        self.io = io

        # create the download layout
        self.down_test = sw.Btn(cm.bin.default.btn,
                                icon="mdi-cloud-download-outline",
                                small=True,
                                outlined=True,
                                class_="ma-5")
        tooltip = sw.Tooltip(widget=self.down_test,
                             tooltip=cm.bin.default.tooltip)

        # create the widgets

        self.file = sw.FileInput(['.tif', '.tiff'])
        self.classes = [
            v.Select(label=cp.convert[nb_class]['label'][i],
                     items=None,
                     v_model=None,
                     chips=True,
                     small_chips=True,
                     multiple=True,
                     dense=True,
                     deletable_chips=True)
            for i in range(len(cp.convert[nb_class]['label']))
        ]
        requirements = sw.Markdown(cm.requirement[nb_class])

        # bind it to the io
        self.output = sw.Alert().bind(self.file, self.io, 'file')
        for i in range(len(cp.convert[nb_class]['label'])):
            self.output.bind(self.classes[i], self.io,
                             cp.convert[nb_class]['io'][i])

        # create the btn
        btn = sw.Btn(cm.bin.btn)

        super().__init__(
            self.io.tile_id,
            cm.bin.title,
            inputs=[tooltip, v.Divider(), requirements, self.file] +
            self.classes,
            output=self.output,
            btn=btn)

        # bind js event
        btn.on_event('click', self._on_click)
        self.file.observe(self._on_change, 'v_model')
        self.down_test.on_event('click', self._on_download)
Ejemplo n.º 5
0
 def test_init(self):
     
     # minimal tooltip on a btn 
     btn = sw.Btn('click')
     tooltip = sw.Tooltip(widget=btn, tooltip='Click over the button')
     
     # assert that a slot cannot be modified 
     with self.assertRaises(Exception): 
         tooltip.bottom = False
     
     return 
     
     
     
Ejemplo n.º 6
0
    def __init__(self,
                 schema,
                 out_path=Path("~").expanduser() / "downloads",
                 *args,
                 **kwargs):
        """Custom data table to display classification .csv files with features to create,
        edit or remove rows.

        Args:
            schema (dict): schema (dict {'title':'type'}): Dictionary
                with column names (key) and type of data (value), representing the scheme
                of the table.

            out_path (str) (optional): output path where table will be saved, default to ~/downloads/
        """

        self.out_path = out_path
        self.schema = schema
        self.dialog = Output()

        self.edit_icon = v.Icon(children=["mdi-pencil"])
        edit_icon = sw.Tooltip(self.edit_icon, "Edit selelcted row")

        self.delete_icon = v.Icon(children=["mdi-delete"])
        delete_icon = sw.Tooltip(self.delete_icon,
                                 "Permanently delete the selected row")

        self.add_icon = v.Icon(children=["mdi-plus"])
        add_icon = sw.Tooltip(self.add_icon, "Create a new element")

        self.save_icon = v.Icon(children=["mdi-content-save"])
        save_icon = sw.Tooltip(self.save_icon,
                               "Write current table on SEPAL space")
        self.save_dialog = SaveDialog(table=self,
                                      out_path=self.out_path,
                                      transition=False)

        slot = v.Toolbar(
            class_="d-flex mb-6",
            flat=True,
            children=[
                self.dialog,
                v.ToolbarTitle(children=["Customization tools"]),
                v.Divider(class_="mx-4", inset=True, vertical=True),
                v.Flex(class_="ml-auto",
                       children=[edit_icon, delete_icon, add_icon]),
                v.Divider(class_="mx-4", inset=True, vertical=True),
                save_icon,
            ],
        )

        self.v_slots = [{"name": "top", "variable": "top", "children": [slot]}]

        self.v_model = []
        self.item_key = "id"
        self.show_select = True
        self.single_select = True
        self.hide_default_footer = True

        super().__init__(*args, **kwargs)

        self.edit_icon.on_event("click", self._edit_event)
        self.delete_icon.on_event("click", self._remove_event)
        self.add_icon.on_event("click", self._add_event)
        self.save_icon.on_event("click", self._save_event)
Ejemplo n.º 7
0
    def __init__(self,
                 schema,
                 out_path=Path('~').expanduser() / 'downloads',
                 *args,
                 **kwargs):
        """ Custom data table to display classification .csv files with features to create,
        edit or remove rows.
        
        Args: 
            schema (dict): schema (dict {'title':'type'}): Dictionary 
                with column names (key) and type of data (value), representing the scheme
                of the table.

            out_path (str) (optional): output path where table will be saved, default to ~/downloads/
        """

        self.out_path = out_path
        self.schema = schema
        self.dialog = Output()

        self.edit_icon = v.Icon(children=['mdi-pencil'])
        edit_icon = sw.Tooltip(self.edit_icon, 'Edit selelcted row')

        self.delete_icon = v.Icon(children=['mdi-delete'])
        delete_icon = sw.Tooltip(self.delete_icon,
                                 'Permanently delete the selected row')

        self.add_icon = v.Icon(children=['mdi-plus'])
        add_icon = sw.Tooltip(self.add_icon, 'Create a new element')

        self.save_icon = v.Icon(children=['mdi-content-save'])
        save_icon = sw.Tooltip(self.save_icon,
                               'Write current table on SEPAL space')
        self.save_dialog = SaveDialog(table=self,
                                      out_path=self.out_path,
                                      transition=False)

        slot = v.Toolbar(class_='d-flex mb-6',
                         flat=True,
                         children=[
                             self.dialog,
                             v.ToolbarTitle(children=['Customization tools']),
                             v.Divider(class_='mx-4',
                                       inset=True,
                                       vertical=True),
                             v.Flex(
                                 class_='ml-auto',
                                 children=[edit_icon, delete_icon, add_icon]),
                             v.Divider(class_='mx-4',
                                       inset=True,
                                       vertical=True), save_icon
                         ])

        self.v_slots = [{'name': 'top', 'variable': 'top', 'children': [slot]}]

        self.v_model = []
        self.item_key = 'id'
        self.show_select = True
        self.single_select = True
        self.hide_default_footer = True

        super().__init__(*args, **kwargs)

        self.edit_icon.on_event('click', self._edit_event)
        self.delete_icon.on_event('click', self._remove_event)
        self.add_icon.on_event('click', self._add_event)
        self.save_icon.on_event('click', self._save_event)