Esempio n. 1
0
class DialogController(AbstrController):
    __layout = v.Dialog(
        width="unset",
        v_model=False,
        children=[
            v.Card(children=[
                v.CardTitle(class_='headline gray lighten-2',
                            primary_title=True,
                            children=[]),
                v.CardText(children=[])
            ])
        ]
    )

    def __init__(self):
        super().__init__("dialog")

    def _get_layout(self):
        return self.__layout

    def show(self, card_title, card_text):
        card = self.__layout.children[0]
        card.children[0].children = [card_title]
        card.children[1].children = [card_text]

        self.__layout.v_model = True

    def hide(self):
        self.__layout.v_model = False
Esempio n. 2
0
    def __init__(self, table, **kwargs):
        self.table = table

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

        self.form_1d = FormProperties_1D()
        self.form_2d = FormProperties_2D()

        self.form = v.CardText(children=self.form_1d.widget)

        self.dialog = v.Dialog(
            width='500',
            v_model=False,
            children=[
                v.Card(children=[
                    v.CardTitle(class_='headline gray lighten-2',
                                primary_title=True,
                                children=['Plot properties']), self.form,
                    v.CardActions(children=[v.Spacer(), update, close])
                ]),
            ])

        def close_btn(widget, event, data):
            self.dialog.v_model = False

        update.on_event('click', self.update_btn)
        close.on_event('click', close_btn)

        super().__init__(**kwargs)
Esempio n. 3
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. 4
0
    def __init__(self, table, **kwargs):
        self.table = table

        update = v.Btn(children=['update'])
        close = v.Btn(children=['close'])

        self.form = [
            IntField(label='linewidth', v_model=plot_config['linewidth']),
            v.Select(label='Line style',
                     items=[{
                         'text': v,
                         'value': k
                     } for k, v in Line2D.lineStyles.items()],
                     v_model=plot_config['linestyle']),
            v.Select(label='Marker',
                     items=[{
                         'text': v,
                         'value': k
                     } for k, v in Line2D.markers.items()],
                     v_model=plot_config['marker']),
            IntField(label='Marker size', v_model=plot_config['markersize']),
            FloatField(label='alpha', v_model=plot_config['alpha']),
            v.ColorPicker(v_model=plot_config['colors'][0]),
        ]

        self.dialog = v.Dialog(
            width='500',
            v_model=False,
            children=[
                v.Card(children=[
                    v.CardTitle(class_='headline gray lighten-2',
                                primary_title=True,
                                children=['Plot properties']),
                    v.CardText(children=self.form),
                    v.CardActions(children=[v.Spacer(), update, close])
                ]),
            ])

        def close_btn(widget, event, data):
            self.dialog.v_model = False

        update.on_event('click', self.update_btn)
        close.on_event('click', close_btn)
        super().__init__(**kwargs)
Esempio n. 5
0
    def __init__(self, *args, **kwargs):
        with out:
            self.form = self.item_class.form_class(*args, **kwargs)

            create_add = v.Btn(children=['add'], color='success')
            create_close = v.Btn(children=['close'], color='error')

            create_dialog = v.Dialog(
                width='500',
                v_model=False,
                children=[
                    v.Card(children=[
                        v.CardTitle(class_='headline gray lighten-2',
                                    primary_title=True,
                                    children=[self.new_text]),
                        v.CardText(children=[self.form]),
                        v.CardActions(
                            children=[v.Spacer(), create_add, create_close])
                    ]),
                ])

            self.item_list = v.List(children=[])
            add_button = v.Btn(
                children=[v.Icon(children=['mdi-plus']), create_dialog],
                fab=True,
                color='primary',
                small=True,
                dark=True,
            )

            def close_click(widget, event, data):
                create_dialog.v_model = False

            def on_change(change):
                self.item_list.notify_change({
                    'name': 'children',
                    'type': 'change'
                })

            def add_click(widget, event, data):
                self.form.check_rules()

                if self.form.v_model:
                    new_item = self.create_item()
                    self.item_list.children.append(new_item)
                    create_dialog.v_model = False

                    def remove_item(widget, event, data):
                        self.item_list.children.remove(new_item)
                        self.item_list.notify_change({
                            'name': 'children',
                            'type': 'change'
                        })

                    new_item.btn.on_event('click', remove_item)
                    new_item.on_event('click', new_item.update_item)
                    new_item.observe(on_change, 'children')

                    self.item_list.notify_change({
                        'name': 'children',
                        'type': 'change'
                    })

            create_close.on_event('click', close_click)
            create_add.on_event('click', add_click)

            def on_add_click(widget, event, data):
                with out:
                    self.form.reset_form()
                    create_dialog.v_model = True

            add_button.on_event('click', on_add_click)

            self.add_button = add_button
            self.widget = v.Card(children=[
                v.CardText(children=[self.item_list]),
                v.CardActions(children=[v.Spacer(), add_button])
            ])
Esempio n. 6
0
def dialog_button(label='',
                  icon='mdi-help',
                  _class="icon ma-2",
                  _style="",
                  color="primary",
                  dark=False,
                  dialog_width=600,
                  dialog_title="Dialog Title",
                  dialog_content="Dialog Content",
                ):
    """
    Creates a button and activates a dialog on click

    Useful to display application documentation/help

    Parameters
    ----------
    icon : str (optional, default None)
        Icon to display on button
    label : str (optoinal, default None)
        Text to display on button
    dialog_width : int (optional, default 600)
        Width of the dialog in pixels
    dialog_title : str (optional, default 'Help Title')
        Dialog title
    dialog_content : str (optional, default '')
        Dialog content in markdown format
    color : str (optional, default 'primary')
        Color of button
    dark : bool
        Use dark style
    _class : str (optional, default 'icon ma-2')
        CSS classes of button
    _style: str
        CSS style of button
    """

    if icon is None:
        icon=''

    if label is None:
        label=''

    dialog_button = ipyvuetify.Btn(
        _class_="icon ma-2",
        _style='',
        color=color,
        depressed=True,
        dark=dark,
        children=[label, ipyvuetify.Icon(children=[icon])],
    )

    close_dialog_btn = ipyvuetify.Btn(children=["Close"])

    dialog_dialog = ipyvuetify.Dialog(
        v_model=False,
        scrollable=True,
        width=dialog_width,
        children=[
            ipyvuetify.Card(children=[
                ipyvuetify.CardTitle(class_="headline pa-4",
                                     children=[dialog_title]),
                ipyvuetify.Divider(),
                ipyvuetify.CardText(
                    class_="pa-4 text--primary",
                    primary_title=True,
                    children=[dialog_content],
                ),
                ipyvuetify.Divider(),
                close_dialog_btn,
            ])
        ],
    )

    def open_dialog_dialog(widget, event, data):
        dialog_dialog.v_model = True

    def close_dialog_dialog(widget, event, data):
        dialog_dialog.v_model = False

    display(ipyvuetify.Layout(children=[dialog_dialog]))
    close_dialog_btn.on_event("click", close_dialog_dialog)
    dialog_button.on_event("click", open_dialog_dialog)
    return dialog_button
Esempio n. 7
0
                        ]),
              }],
              children=[v.List(children=items)])

dialog = v.Dialog(
    width='500',
    v_slots=[{
        'name':
        'activator',
        'variable':
        'x',
        'children':
        v.Btn(v_on='x.on',
              color='success',
              dark=True,
              children=['Open dialog']),
    }],
    children=[
        v.Card(children=[
            v.CardTitle(class_='headline gray lighten-2',
                        primary_title=True,
                        children=["Lorem ipsum"]),
            v.CardText(children=[
                lorum_ipsum,
                v.TextField(label='Label', placeholder='Placeholder')
            ]),
        ])
    ])

dialog.on_event('keydown.stop', lambda *args: None)

v.Container(children=[
Esempio n. 8
0
    def __init__(self):

        self.select_dim = v.Select(label='Dimension', items=[1, 2], v_model=1)
        self.previous_dim = 1

        headers = [
            {
                'text': 'Id',
                'value': 'id'
            },
            {
                'text': 'Iteration',
                'value': 'iteration'
            },
            {
                'text': 'Time',
                'value': 'time'
            },
            {
                'text': 'Field',
                'value': 'field'
            },
            {
                'text': 'Model',
                'value': 'model'
            },
            {
                'text': 'Test case',
                'value': 'test case'
            },
            {
                'text': 'LB scheme',
                'value': 'lb scheme'
            },
            {
                'text': 'Filename',
                'value': 'file'
            },
            {
                'text': 'Directory',
                'value': 'directory'
            },
        ]

        headers_select = v.Select(label='Show columns',
                                  items=[{
                                      'text': v['text'],
                                      'value': i + 1
                                  } for i, v in enumerate(headers[1:])],
                                  v_model=list(range(1, 7)),
                                  multiple=True)

        search = v.TextField(
            v_model=None,
            append_icon="mdi-magnify",
            label="Search",
            single_line=True,
            hide_details=True,
        )

        self.table = v.DataTable(
            v_model=[],
            headers=[headers[i] for i in headers_select.v_model],
            items=[],
            item_key="id",
            single_select=False,
            show_select=True,
            search='',
        )

        self.selected_cache = [[]] * 3
        self.select_item_cache = [[]] * 3
        self.properties_cache = [[]] * 3
        self.select_table = SelectedDataTable(
            self.table,
            headers=[headers[i]
                     for i in headers_select.v_model] + [{
                         'text': 'Action',
                         'value': 'action'
                     }],
        )

        self.plot = Plot()

        def select(change):
            with out:
                for e in list(self.table.v_model):
                    self.select_table.items.append(e)
                    if e['dim'] == 1:
                        self.select_table.properties.append({
                            'label':
                            e['field'],
                            'color':
                            plot_config['colors'][0],
                            'alpha':
                            plot_config['alpha'],
                            'linewidth':
                            plot_config['linewidth'],
                            'linestyle':
                            plot_config['linestyle'],
                            'marker':
                            plot_config['marker'],
                            'markersize':
                            plot_config['markersize']
                        })
                    elif e['dim'] == 2:
                        h5 = os.path.join(e['directory'], e['file'])
                        h5_data = h5py.File(h5)
                        data = h5_data[e['field']][:]
                        self.select_table.properties.append({
                            'label':
                            e['field'],
                            'min_value':
                            np.nanmin(data),
                            'max_value':
                            np.nanmax(data),
                            'cmap':
                            plt.colormaps().index(plot_config['cmap'])
                        })
                    self.table.items.remove(e)
                self.table.v_model = []
                self.select_table.notify_change({
                    'name': 'items',
                    'type': 'change'
                })
                self.table.notify_change({'name': 'items', 'type': 'change'})

        def search_text(change):
            self.table.search = search.v_model

        # self.update(None)

        self.select_table.observe(self.plot_result, 'items')
        self.select_table.observe(self.plot_result, 'properties')
        self.select_table.observe(self.plot_result, 'selected')
        search.observe(search_text, 'v_model')
        self.table.observe(select, 'v_model')
        self.select_dim.observe(self.cache, 'v_model')

        def update_headers(change):
            with out:
                self.table.headers = [
                    headers[i] for i in headers_select.v_model
                ]
                self.select_table.headers = [
                    headers[i] for i in headers_select.v_model
                ] + [{
                    'text': 'Action',
                    'value': 'action'
                }]
                self.select_table.notify_change({
                    'name': 'items',
                    'type': 'change'
                })
                self.table.notify_change({'name': 'items', 'type': 'change'})

        headers_select.observe(update_headers, 'v_model')

        download_zip = v.Btn(children=['Download results'])

        def create_zip(widget, event, data):
            from zipfile import ZipFile

            zipfilename = os.path.join(voila_notebook, 'results.zip')
            with ZipFile(zipfilename, 'w') as zipObj:
                for folderName, subfolders, filenames in os.walk(default_path):
                    for filename in filenames:
                        #create complete filepath of file in directory
                        filePath = os.path.join(folderName, filename)

                        # Add file to zip
                        zipObj.write(filePath,
                                     filePath.replace(default_path, ''))

            dialog.children = [
                v.Card(children=[
                    v.CardTitle(children=[
                        widgets.HTML(
                            f'<a href="./results.zip" download="results.zip">Download the archive</a>'
                        )
                    ])
                ])
            ]
            dialog.v_model = True

        self.title = v.TextField(label='Plot title', v_model='')
        self.xlabel = v.TextField(label='x label', v_model='')
        self.ylabel = v.TextField(label='y label', v_model='')
        self.legend = v.Switch(label='Add legend', v_model=False)

        self.title.observe(self.set_plot_properties, 'v_model')
        self.xlabel.observe(self.set_plot_properties, 'v_model')
        self.ylabel.observe(self.set_plot_properties, 'v_model')
        self.legend.observe(self.set_plot_properties, 'v_model')

        dialog = v.Dialog()
        dialog.v_model = False
        dialog.width = '200'
        download_zip.on_event('click', create_zip)

        self.menu = [
            self.select_dim, headers_select, self.title, self.xlabel,
            self.ylabel, self.legend, download_zip, dialog
        ]
        self.main = [
            v.Card(
                children=[
                    v.CardTitle(
                        children=['Available results',
                                  v.Spacer(), search]),
                    self.table,
                ],
                class_='ma-2',
            ),
            v.Card(
                children=[
                    v.CardTitle(children=[
                        'Selected results',
                    ]),
                    self.select_table,
                    self.select_table.dialog,
                ],
                class_='ma-2',
            ),
            v.Row(children=[self.plot.fig.canvas], justify='center'),
        ]