Beispiel #1
0
    def refresh_table(self):
        td_style = {'padding': '5px'}
        self.table.empty()
        date = self.date_picker.get_value()
        header = ('Класс', 'Урок', 'Предмет', 'Учитель', 'Удаление')
        tr = gui.TableRow()
        for col in header:
            tr.append(gui.TableTitle(col, style=td_style))
        self.table.append(tr)
        with self.app.db.from_query(
                "SELECT class_no, class_letter, lesson_no, lesson, teacher"
                " FROM lesson_replaces WHERE date = ?;", (date, )) as cursor:
            rows = cursor.fetchall()
            for row in rows:
                tr = gui.TableRow()
                tr.append(str(row[0]) + row[1])
                tr.append(str(row[2]))
                tr.append(row[3])
                tr.append(row[4])
                del_cell = gui.TableItem('[X] Удалить', style=td_style)

                def on_del_click(widget, to_drop):
                    self.app.db.do_query(
                        'DELETE FROM lesson_replaces WHERE '
                        ' date = ? AND class_no = ? AND class_letter = ? AND'
                        ' lesson_no = ? AND lesson = ? AND teacher = ?;',
                        to_drop)
                    self.refresh_table()

                tr.append(del_cell)
                del_cell.onclick.do(on_del_click, (date, ) + row)

                self.table.append(tr)
Beispiel #2
0
    def on_button_pressed(self):
        # Connect to the sqlite database using DB.py
        db = DB(filename="/home/pybokeh/Dropbox/data_sets/nba", dbtype="sqlite")

        sql = """
        select *

        from player_game_stats

        where
        team_name like '{{ name }}';"""

        # Get the text the user entered into the textinput widget
        token = self.txt.get_text()

        # To prevent sql injection attacks, parameterize the sql string
        parameter = '%' + token + '%'

        params = [
                  {"name": parameter}
                 ]

        # Execute the query and store the results into a pandas dataframe
        df = db.query(sql, data=params)

        # Get the column names of the query result and the query row_data
        column_names = df.columns
        row_data = df.values

        # Create the table widget with the specified dimensions
        self.table = gui.Table(1200, 800)
       
        # Generate the table row containing the table column names
        row = gui.TableRow()
        for column in column_names:
            item = gui.TableTitle()  # TableTitle refers to the column header/names
            item.append(str(id(item)), str(column))
            row.append(str(id(item)), item)

        # Now add the row to the table
        self.table.append(str(id(row)), row)

        # Generate rows that will contain the table data
        for _row in row_data:
            row = gui.TableRow()
            for row_item in _row:
                item = gui.TableItem() # TableItem refers to the table data
                item.append(str(id(item)), str(row_item))
                row.append(str(id(item)), item)

                self.table.append(str(id(row)), row)

        # Now render / add the bottom container to the master container
        self.masterContainer.append('2', self.bottomContainer)

        # Now add the table widget to the bottom container        
        self.bottomContainer.append('1', self.table)
Beispiel #3
0
 def test_init(self):
     widget = gui.TableTitle()
     assertValidHTML(widget.repr())
Beispiel #4
0
    def on_dropdown_change(self, widget, value):
        # If we had a previous client, disconnect it
        if self.dyn_rec_client is not None:
            self.dyn_rec_client.close()
        # Get new client
        self.dyn_rec_client = drc.Client(value, timeout=10.0)

        # Get a configuration which ensures we'll have the description too
        curr_conf = self.dyn_rec_client.get_configuration()
        self.gui_set_funcs_for_param = {}
        params_list = self.dyn_rec_client.group_description['parameters']
        if params_list is not None:
            table = gui.Table()
            row = gui.TableRow()
            item = gui.TableTitle()
            item.add_child(str(id(item)), 'Param name')
            row.add_child(str(id(item)), item)
            item = gui.TableTitle()
            item.add_child(str(id(item)), 'Min')
            row.add_child(str(id(item)), item)
            item = gui.TableTitle()
            item.add_child(str(id(item)), 'Edit')
            row.add_child(str(id(item)), item)
            item = gui.TableTitle()
            item.add_child(str(id(item)), 'Max')
            row.add_child(str(id(item)), item)
            item = gui.TableTitle()
            item.add_child(str(id(item)), 'Edit2')
            row.add_child(str(id(item)), item)
            table.add_child(str(id(row)), row)

            for idx, param in enumerate(params_list):
                if param['edit_method'] != '':
                    # Enum
                    param_name = param['name']
                    # WTF, really? the full enum dict is actually a string?
                    enum_dict_as_str = param['edit_method']
                    enum_dict = literal_eval(enum_dict_as_str)
                    description = enum_dict['enum_description']
                    current_value = curr_conf[param_name]
                    enums = enum_dict['enum']
                    # there must be at least one enum
                    enum_type = enums[0]['type']
                    # Create dynamically a method to be called
                    method_name, cb_method = self.add_cb_to_class_by_param_name_and_type(
                        param_name, 'enum', enum_type)
                    enum_wid, set_funcs = self.create_enum_row(
                        param_name, description, current_value, cb_method,
                        enums)
                    self.gui_set_funcs_for_param[param_name] = set_funcs
                    table.add_child(idx, enum_wid)
                elif param['type'] == 'int' or param['type'] == 'double':
                    param_name = param['name']
                    range_min = param['min']
                    range_max = param['max']
                    description = param['description']
                    current_value = curr_conf[param_name]
                    if param['type'] == 'int':
                        step = (range_max - range_min) / 100
                    elif param['type'] == 'double':
                        step = (range_max - range_min) / 100.0

                    # Create dynamically a method to be called
                    method_name, cb_method = self.add_cb_to_class_by_param_name_and_type(
                        param_name, 'digit')

                    num_wid, set_funcs = self.create_num_row(
                        param_name, description, range_min, range_max,
                        current_value, cb_method, step)
                    self.gui_set_funcs_for_param[param_name] = set_funcs
                    table.add_child(idx, num_wid)
                elif param['type'] == 'str':
                    param_name = param['name']
                    current_value = curr_conf[param_name]
                    description = param['description']
                    # Create dynamically a method to be called
                    method_name, cb_method = self.add_cb_to_class_by_param_name_and_type(
                        param_name, 'string')
                    str_wid, set_funcs = self.create_str_row(
                        param_name, description, current_value, cb_method)
                    self.gui_set_funcs_for_param[param_name] = set_funcs
                    table.add_child(idx, str_wid)
                elif param['type'] == 'bool':
                    param_name = param['name']
                    current_value = curr_conf[param_name]
                    description = param['description']
                    # Create dynamically a method to be called
                    method_name, cb_method = self.add_cb_to_class_by_param_name_and_type(
                        param_name, 'bool')
                    bool_wid, set_funcs = self.create_bool_row(
                        param_name, description, current_value, cb_method)
                    self.gui_set_funcs_for_param[param_name] = set_funcs
                    table.add_child(idx, bool_wid)

        self.wid.add_child(2, table)
        # This must be done later on! HACK! (append sets a margin)
        # This makes the table not stick left, but float in the middle
        table.style['margin'] = '10px auto'

        # Once the GUI is setup, setup the callback for new configs
        self.dyn_rec_client.set_config_callback(self.dyn_rec_conf_callback)
    def main(self):
        verticalContainer = gui.Widget(640, 680, gui.Widget.LAYOUT_VERTICAL,
                                       10)

        horizontalContainer = gui.Widget(620, 620,
                                         gui.Widget.LAYOUT_HORIZONTAL, 10)

        subContainerLeft = gui.Widget(340, 530, gui.Widget.LAYOUT_VERTICAL, 10)
        self.img = gui.Image(100, 100, './res/logo.png')

        self.table = gui.Table(300, 200)
        row = gui.TableRow()
        item = gui.TableTitle()
        item.append(str(id(item)), 'ID')
        row.append(str(id(item)), item)
        item = gui.TableTitle()
        item.append(str(id(item)), 'First Name')
        row.append(str(id(item)), item)
        item = gui.TableTitle()
        item.append(str(id(item)), 'Last Name')
        row.append(str(id(item)), item)
        self.table.append(str(id(row)), row)
        self.add_table_row(self.table, '101', 'Danny', 'Young')
        self.add_table_row(self.table, '102', 'Christine', 'Holand')
        self.add_table_row(self.table, '103', 'Lars', 'Gordon')
        self.add_table_row(self.table, '104', 'Roberto', 'Robitaille')
        self.add_table_row(self.table, '105', 'Maria', 'Papadopoulos')

        # the arguments are	width - height - layoutOrientationOrizontal
        subContainerRight = gui.Widget(240, 560, gui.Widget.LAYOUT_VERTICAL,
                                       10)

        self.lbl = gui.Label(200, 30, 'This is a LABEL!')

        self.bt = gui.Button(200, 30, 'Press me!')
        # setting the listener for the onclick event of the button
        self.bt.set_on_click_listener(self, 'on_button_pressed')

        self.txt = gui.TextInput(200, 30)
        self.txt.set_text('This is a TEXTAREA')
        self.txt.set_on_change_listener(self, 'on_text_area_change')

        self.spin = gui.SpinBox(200, 30, 100)
        self.spin.set_on_change_listener(self, 'on_spin_change')

        self.btInputDiag = gui.Button(200, 30, 'Open InputDialog')
        self.btInputDiag.set_on_click_listener(self, 'open_input_dialog')

        self.btFileDiag = gui.Button(200, 30, 'File Selection Dialog')
        self.btFileDiag.set_on_click_listener(self,
                                              'open_fileselection_dialog')

        self.btUploadFile = gui.FileUploader(200, 30, './')
        self.btUploadFile.set_on_success_listener(self,
                                                  'fileupload_on_success')
        self.btUploadFile.set_on_failed_listener(self, 'fileupload_on_failed')

        self.listView = gui.ListView(300, 120)
        self.listView.set_on_selection_listener(self, "list_view_on_selected")
        li0 = gui.ListItem(279, 20, 'Danny Young')
        li1 = gui.ListItem(279, 20, 'Christine Holand')
        li2 = gui.ListItem(279, 20, 'Lars Gordon')
        li3 = gui.ListItem(279, 20, 'Roberto Robitaille')
        self.listView.append('0', li0)
        self.listView.append('1', li1)
        self.listView.append('2', li2)
        self.listView.append('3', li3)

        self.dropDown = gui.DropDown(200, 20)
        c0 = gui.DropDownItem(200, 20, 'DropDownItem 0')
        c1 = gui.DropDownItem(200, 20, 'DropDownItem 1')
        self.dropDown.append('0', c0)
        self.dropDown.append('1', c1)
        self.dropDown.set_on_change_listener(self, 'drop_down_changed')
        self.dropDown.set_value('DropDownItem 0')

        self.slider = gui.Slider(200, 20, 10, 0, 100, 5)
        self.slider.set_on_change_listener(self, 'slider_changed')

        self.colorPicker = gui.ColorPicker(200, 20, '#ffbb00')
        self.colorPicker.set_on_change_listener(self, 'color_picker_changed')

        self.date = gui.Date(200, 20, '2015-04-13')
        self.date.set_on_change_listener(self, 'date_changed')

        # appending a widget to another, the first argument is a string key
        subContainerRight.append('1', self.lbl)
        subContainerRight.append('2', self.bt)
        subContainerRight.append('3', self.txt)
        subContainerRight.append('4', self.spin)
        subContainerRight.append('5', self.btInputDiag)
        subContainerRight.append('5_', self.btFileDiag)
        subContainerRight.append(
            '5__',
            gui.FileDownloader(200, 30, 'download test',
                               '../remi/res/logo.png'))
        subContainerRight.append('5___', self.btUploadFile)
        subContainerRight.append('6', self.dropDown)
        subContainerRight.append('7', self.slider)
        subContainerRight.append('8', self.colorPicker)
        subContainerRight.append('9', self.date)
        self.subContainerRight = subContainerRight

        subContainerLeft.append('0', self.img)
        subContainerLeft.append('1', self.table)
        subContainerLeft.append('2', self.listView)

        horizontalContainer.append('0', subContainerLeft)
        horizontalContainer.append('1', subContainerRight)

        menu = gui.Menu(620, 30)
        m1 = gui.MenuItem(100, 30, 'File')
        m2 = gui.MenuItem(100, 30, 'View')
        m2.set_on_click_listener(self, 'menu_view_clicked')
        m11 = gui.MenuItem(100, 30, 'Save')
        m12 = gui.MenuItem(100, 30, 'Open')
        m12.set_on_click_listener(self, 'menu_open_clicked')
        m111 = gui.MenuItem(100, 30, 'Save')
        m111.set_on_click_listener(self, 'menu_save_clicked')
        m112 = gui.MenuItem(100, 30, 'Save as')
        m112.set_on_click_listener(self, 'menu_saveas_clicked')

        menu.append('1', m1)
        menu.append('2', m2)
        m1.append('11', m11)
        m1.append('12', m12)
        m11.append('111', m111)
        m11.append('112', m112)

        verticalContainer.append('0', menu)
        verticalContainer.append('1', horizontalContainer)

        # returning the root widget
        return verticalContainer