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)
def initStats(self, robot): statsBox = self.sectionBox() motorDataBox = sea.vBoxWith(gui.Label("Motor Data")) self.motorDataTable = gui.Table() motorNumRow = gui.TableRow(gui.TableItem("Motor Number:")) motorAmpRow = gui.TableRow(gui.TableItem("Amp Draw:")) motorTempRow = gui.TableRow(gui.TableItem("Temp:")) motorMaxAmpRow = gui.TableRow(gui.TableItem("Max Amp Draw:")) motorMaxTempRow = gui.TableRow(gui.TableItem("Max Temp:")) self.motorDataTable.append(motorNumRow) self.motorDataDict["ampRow"] = self.motorDataTable.append(motorAmpRow) self.motorDataDict["tempRow"] = self.motorDataTable.append( motorTempRow) self.motorDataDict["maxAmpRow"] = self.motorDataTable.append( motorMaxAmpRow) self.motorDataDict["maxTempRow"] = self.motorDataTable.append( motorMaxTempRow) for motorNum in range(6): motorNumRow.append(gui.TableItem(str(motorNum + 1))) self.motorDataDict["amp"].append( motorAmpRow.append(gui.TableItem(""))) self.motorDataDict["temp"].append( motorTempRow.append(gui.TableItem(""))) self.motorDataDict["maxAmp"].append( motorMaxAmpRow.append(gui.TableItem(""))) self.motorDataDict["maxTemp"].append( motorMaxTempRow.append(gui.TableItem(""))) motorDataBox.append(self.motorDataTable) statsBox.append(motorDataBox) return statsBox
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)
def create_num_row(self, param_name, description, range_min, range_max, current_value, callback_cb, step): row = gui.TableRow() param_name = gui.Label(param_name, width=NAME_L_SIZE, height=FIELD_HEIGHT) param_name.attributes['title'] = description min_val = gui.Label(str(range_min), width=MIN_L_SIZE, height=FIELD_HEIGHT) range_slider = gui.Slider(width=SLIDER_SIZE, height=FIELD_HEIGHT, defaultValue=current_value, min=range_min, max=range_max, step=step) range_slider.set_on_change_listener(callback_cb) max_val = gui.Label(str(range_max), width=MAX_L_SIZE, height=FIELD_HEIGHT) spin_val = gui.SpinBox(width=EDIT2_SIZE, height=FIELD_HEIGHT, defaultValue=current_value, min=range_min, max=range_max, step=step) # https://github.com/dddomodossola/remi/issues/49 # Added 46 as it's dot so we allow floating point values spin_val.attributes[ spin_val. EVENT_ONKEYPRESS] = 'return event.charCode >= 48 && event.charCode <= 57 || event.charCode == 46 || event.charCode == 13' spin_val.set_on_change_listener(callback_cb) item = gui.TableItem() item.add_child(0, param_name) row.add_child(0, item) item = gui.TableItem() item.add_child(1, min_val) row.add_child(1, item) min_val.style['float'] = 'none' min_val.style['text-align'] = 'center' item = gui.TableItem() item.add_child(2, range_slider) row.add_child(2, item) item = gui.TableItem() item.add_child(3, max_val) row.add_child(3, item) max_val.style['float'] = 'none' max_val.style['text-align'] = 'center' item = gui.TableItem() item.add_child(4, spin_val) row.add_child(4, item) spin_val.style['display'] = 'block' spin_val.style['margin'] = '10px auto' spin_val.style['float'] = 'none' return row, [range_slider.set_value, spin_val.set_value]
def create_enum_row(self, param_name, description, current_value, callback_cb, enums): row = gui.TableRow() param_name = gui.Label(param_name, width=NAME_L_SIZE, height=FIELD_HEIGHT) param_name.attributes['title'] = description dropdown = gui.DropDown(width=SLIDER_SIZE, height=FIELD_HEIGHT) # Fill dropdown for idx, enum in enumerate(enums): description_enum = enum['description'] value = enum['value'] name = enum['name'] type_enum = enum['type'] ddi_text = name + " (" + str(value) + ")" ddi = gui.DropDownItem(ddi_text, width=EDIT1_SIZE, height=FIELD_HEIGHT) ddi.attributes['title'] = description_enum dropdown.add_child(value, ddi) if value == current_value: dropdown.select_by_key(value) item = gui.TableItem() item.add_child(0, param_name) row.add_child(0, item) # Dummy item item = gui.TableItem() item.add_child(1, "") row.add_child(1, item) item = gui.TableItem() item.add_child(2, dropdown) row.add_child(2, item) dropdown.style['display'] = 'block' dropdown.style['margin'] = '0px auto' dropdown.style['float'] = 'none' # Dummy item item = gui.TableItem() item.add_child(3, "") row.add_child(3, item) # Dummy item item = gui.TableItem() item.add_child(4, "") row.add_child(4, item) dropdown.set_on_change_listener(callback_cb) # return the row itself and the setter func list return row, [dropdown.select_by_key]
def add_table_row(self, table, field1, field2, field3): row = gui.TableRow() item = gui.TableItem() item.append(str(id(item)), field1) row.append(str(id(item)), item) item = gui.TableItem() item.append(str(id(item)), field2) row.append(str(id(item)), item) item = gui.TableItem() item.append(str(id(item)), field3) row.append(str(id(item)), item) table.append(str(id(row)), row)
async def build_pagination(self): row = G.TableRow(width="100%") min_page = await self.get_min_page() max_page = await self.get_max_page() cur_page = self.page buttons = self.make_pagination_controls(cur_page, min_page, max_page) td = TableExtendedItem(G.HBox([buttons], width="100%")) td.attributes['colspan'] = str(len(self.fields) + 1) row.append(td) self.append(row, "pagination_0")
async def build_title(self): row = G.TableRow(width="100%") checkbox_all = G.CheckBox(checked=False) row.append(TableExtendedItem(checkbox_all, width="20px"), str(0)) for index, field_name in enumerate(self.fields): style_args = dict() width = getattr(self, f"WIDTH_{field_name}", None) if width: style_args['width'] = width row.append(TableExtendedItem(G.Label(field_name), **style_args), str(index + 1)) self.append(row, "title_{0}")
def Define_TreeTable(self, heads, heads2=None): ''' Define a TreeTable with a heading row and optionally a second heading row. ''' display_heads = [] display_heads.append(tuple(heads[2:])) self.tree_table = TreeTable() self.tree_table.append_from_list(display_heads, fill_title=True) if heads2 is not None: heads2_color = heads2[1] row_widget = gui.TableRow() for index, field in enumerate(heads2[2:]): row_item = gui.TableItem( text=field, style={'background-color': heads2_color}) row_widget.append(row_item, field) self.tree_table.append(row_widget, heads2[0]) self.wid.append(self.tree_table)
def new_game(self, widget): self.time_count = 0 self.mine_table = gui.Table(margin='0px auto') # 900, 450 self.mine_matrix = self.build_mine_matrix(8, 8, 5) self.mine_table.empty() for x in range(0, len(self.mine_matrix[0])): row = gui.TableRow() for y in range(0, len(self.mine_matrix)): row.append(self.mine_matrix[y][x]) self.mine_matrix[y][x].onclick.do(self.mine_matrix[y][x].check_mine) self.mine_table.append(row) # self.mine_table.append_from_list(self.mine_matrix, False) self.main_container.append(self.mine_table, key="mine_table") self.check_if_win() self.set_root_widget(self.main_container)
def explosion(self, cell): print("explosion") self.mine_table = gui.Table(margin='0px auto') self.main_container.append(self.mine_table, key="mine_table") for x in range(0, len(self.mine_matrix[0])): for y in range(0, len(self.mine_matrix)): self.mine_matrix[y][x].style['background-color'] = 'red' self.mine_matrix[y][x].check_mine(None, False) self.mine_table.empty() # self.mine_table.append_from_list(self.mine_matrix, False) for x in range(0, len(self.mine_matrix[0])): row = gui.TableRow() for y in range(0, len(self.mine_matrix)): row.append(self.mine_matrix[y][x]) self.mine_matrix[y][x].onclick.do(self.mine_matrix[y][x].check_mine) self.mine_table.append(row)
def create_str_row(self, param_name, description, current_value, callback_cb): row = gui.TableRow() param_name = gui.Label(param_name, width=NAME_L_SIZE, height=FIELD_HEIGHT) param_name.attributes['title'] = description text_input = gui.TextInput(width=SLIDER_SIZE, height=FIELD_HEIGHT, single_line=True) text_input.set_text(current_value) text_input.set_on_enter_listener(callback_cb) # set_button = gui.Button(80, DEFAULT_HEIGHT, text="Set") # set_button.set_on_click_listener(self, callback_cb_name) item = gui.TableItem() item.add_child(0, param_name) row.add_child(0, item) # Dummy item item = gui.TableItem() item.add_child(1, "") row.add_child(1, item) item = gui.TableItem() item.add_child(2, text_input) row.add_child(2, item) text_input.style['display'] = 'block' text_input.style['margin'] = '10px auto' text_input.style['float'] = 'none' # Dummy item item = gui.TableItem() item.add_child(3, "") row.add_child(3, item) item = gui.TableItem() #item.add_child(4, set_button) item.add_child(4, "") row.add_child(4, item) return row, [text_input.set_text]
def append_row(self, value, key=''): modified_row = gui.TableRow(style={'display': 'table-row'}) fold_items = [''] * (self.fold_level + 1) for i in range(0, len(fold_items)): ti = gui.TableItem(fold_items[i]) ti.style['min-width'] = '10px' modified_row.append(ti, "fold_cell_%s" % i) for k in value._render_children_list: modified_row.append(value.children[k], k) modified_row.children[modified_row._render_children_list[self.fold_level + 1]]. \ attributes['colspan'] = str(self.max_fold_levels - self.fold_level) modified_row.on_row_item_click.connect(self.on_table_row_click) if self.fold_level > 0: self.current_fold_button[str(self.fold_level)].add_nested_row(modified_row) self.current_row = modified_row return super(gui.Table, self).append(modified_row, key)
async def get_element(self, element): self.logger.debug(f"E add_element {element}") row_id = element[self.model_instance.PK] row = G.TableRow(width="100%") self.logger.debug("drawing row ....") checkbox = self.make_selection_checkbox(row_id) row.append(TableExtendedItem(checkbox), str(0)) for col_index, field_name in enumerate(self.fields): col_element = await self.render_field(field_name, element) self.logger.debug(f"index = {row_id}{col_index} :{col_element}") try: row.append(TableExtendedItem(col_element), str(col_index + 1)) self.logger.debug("APPENDED") except ValueError as e: self.logger.debug( f"{e} ERR: trying to add as TableExtendedItem") row.append(TableExtendedItem(col_element), str(col_index + 1)) self.logger.debug(f"L add_element") self.append(row, row_id)
def create_bool_row(self, param_name, description, current_value, callback_cb): row = gui.TableRow() param_name = gui.Label(param_name, width=NAME_L_SIZE, height=FIELD_HEIGHT) param_name.attributes['title'] = description checkbox = gui.CheckBox(width=SLIDER_SIZE, height=FIELD_HEIGHT, checked=current_value) checkbox.set_on_change_listener(callback_cb) item = gui.TableItem() item.add_child(0, param_name) row.add_child(0, item) # Dummy item item = gui.TableItem() item.add_child(1, "") row.add_child(1, item) item = gui.TableItem() item.add_child(2, checkbox) row.add_child(2, item) # To center the checkbox checkbox.style['float'] = 'none' checkbox.style['margin'] = '0px auto' checkbox.style['display'] = 'block' # Dummy item item = gui.TableItem() item.add_child(3, "") row.add_child(3, item) # Dummy item item = gui.TableItem() item.add_child(4, "") row.add_child(4, item) return row, [checkbox.set_value]
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 Display_TreeTable(self, table): ''' Display a table in which the values in first column form one or more trees. The table has row with fields that are strings of identifiers/names. First convert each row into a row_widget and item_widgets that are displayed in a TableTree. Each input row shall start with a parent field (field[0]) that determines the tree hierarchy but that is not displayed on that row. The parent widget becomes an attribute of the first child widget. Field[1] is the row color, field[2:] contains the row values. Top child(s) shall have a parent field value that is blank (''). The input table rows shall be in the correct sequence. ''' parent_names = [] hierarchy = {} indent_level = 0 widget_dict = {} # key, value = name, widget for row in table: parent_name = row[0] row_color = row[1] child_name = row[2] row_widget = gui.TableRow(style={'background-color': row_color}) # Determine whether hierarchy of sub_sub concepts shall be open or not openness = 'true' row_widget.attributes['treeopen'] = openness # widget_dict[child_name] = row_widget for index, field in enumerate(row[2:]): # Determine field color field_color = '#ffff99' row_item = gui.TableItem(text=field, style={ 'text-align': 'left', 'background-color': field_color }) row_widget.append(row_item, field) if index == 0: row_item.parent = parent_name child_id = row_item # The root of each tree has a parent that is blank (''). # Each row with childs has as attribute openness, which by default is 'true'. # The fields can be given other attributes, such as color. # Verify whether the parent_name (child.parent) # is present or is in the list of parent_names. print('parent-child:', parent_name, child_name) if parent_name == '': hierarchy[child_name] = 0 parent_names.append(child_name) target_level = 0 elif parent_name in parent_names: hierarchy[child_name] = hierarchy[parent_name] + 1 target_level = hierarchy[child_name] else: # Parent not in parent_names print('Error: Parent name "{}" does not appear in network'. format(parent_name)) return print('indent, target-pre:', indent_level, target_level, parent_name, child_name) # Indentation if target_level > indent_level: self.tree_table.begin_fold() indent_level += 1 if target_level < indent_level: while target_level < indent_level: indent_level += -1 self.tree_table.end_fold() print('indent, target-post:', indent_level, target_level, parent_name, child_name) if child_name not in parent_names: parent_names.append(child_name) self.tree_table.append(row_widget, child_name)
def main(self): self.shmem_read(5) self.KegLines = list() self.settings_up = False # root object self.container = gui.Table(width=480) self.container.style['margin'] = 'auto' self.container.style['text-align'] = 'center' self.container.style['padding'] = '2em' # first row first_row = gui.TableRow(height=60) # temperature t = self.h.as_degF(self.ShData['data'].get('temp', 0)) co2 = self.ShData['data'].get('co2', '???') self.temp = gui.Label("%s<br />CO2:%s%%" % (t, co2)) self.temp.style['padding-bottom'] = '1em' table_item = gui.TableItem() table_item.append(self.temp) first_row.append(table_item) # title self.title = gui.Label("HOPLITE") self.title.style['font-size'] = '2em' self.title.style['padding-bottom'] = '0.5em' table_item = gui.TableItem() table_item.append(self.title) first_row.append(table_item) # settings button self.settings_button = gui.Image('/res/settings_16.png', width=16) self.settings_button.set_on_click_listener(self.show_settings_menu) self.settings_button.style['padding-bottom'] = '1.6em' table_item = gui.TableItem() table_item.append(self.settings_button) first_row.append(table_item) self.container.append(first_row) w_mode = self.ShData['config'].get('weight_mode', 'as_kg_gross') # iterate through HX sensors for index, hx_conf in enumerate(self.ShData['config']['hx']): hx_weight = self.ShData['data']['weight'][index] self.KegLines.insert(index, list()) self.KegLines[index].insert(0, None) self.KegLines[index].insert(1, None) # keg information for subindex, channel in enumerate(['A', 'B']): try: keg_name = hx_conf['channels'][channel].get('name', None) except KeyError: keg_name = None if keg_name != None: keg_label = gui.Label(keg_name, width=100, height=30) keg_bar = gui.Svg(240, 30) keg_w = hx_weight[subindex] keg_cap = hx_conf['channels'][channel]['size'][0] keg_tare = hx_conf['channels'][channel]['size'][1] keg_fill_pct = self.get_keg_fill_percent( keg_w, keg_cap, keg_tare) keg_bar_rect = gui.SvgRectangle(0, 0, 240 * keg_fill_pct, 30) keg_bar_rect.style['fill'] = self.h.fill_bar_color( keg_fill_pct) keg_bar_outline = gui.SvgRectangle(0, 0, 240, 30) keg_bar_outline.style['fill'] = 'rgb(0,0,0)' keg_bar_outline.style['fill-opacity'] = '0' keg_bar.append(keg_bar_rect) keg_bar.append(keg_bar_outline) keg_weight = gui.Label(self.h.format_weight( keg_w, (keg_tare * 1000), mode=w_mode, cap=(keg_cap * 1000)), width=100, height=30) try: self.KegLines[index].insert( subindex, [keg_label, keg_bar_rect, keg_weight]) except KeyError: self.KegLines.insert( index, [keg_label, keg_bar_rect, keg_weight]) table_row = gui.TableRow(height=30) for item in [keg_label, keg_bar, keg_weight]: table_item = gui.TableItem() table_item.append(item) table_row.append(table_item) self.container.append(table_row) # return of the root widget return self.container
def Draw_a_drawing_of_one_sheet(self, nrOfOccs, occs, parent_id): ''' - parent_id: the ID of the whole occurrence(box) of which the occNames(occurrences) are parts. ''' outputUID = '640019' # output role inputUID = '640016' # input role actorUID = '5036' # actor role (supertype of mechanism) subOutputs, subOutputUIDs = self.gel_net.Determine_subtype_list( outputUID) subInputs, subInputUIDs = self.gel_net.Determine_subtype_list(inputUID) subActors, subActorUIDs = self.gel_net.Determine_subtype_list(actorUID) thickness = 2 centerX = [] # X-Center of box[i] on canvas centerY = [] # Y-Center of box[i] on canvas midPts = [] boxes_on_sheet = [] lines_on_sheet = [] box_width = 120 # pixels box_height = 80 # pixels self.boxW2 = box_width / 2 # 1/2Width of boxes self.boxH2 = box_height / 2 # 1/2Height of boxes deltaX = self.screen_width / (nrOfOccs + 1) deltaY = self.screen_height / (nrOfOccs + 1) dxC = 8 # corner rounding dyC = 8 # dx = 8 # shifted start point for line on box dy = 8 # Initialize inputs, outputs, controls and mechanisms according to IDEF0. # occCon, occMech, occConUp and 0ccMechUp not yet used, but later exprected occIn = [] occOut = [] # occCon = [] # occMech = [] occInUp = [] occOutUp = [] # occConUp = [] # occMechUp = [] # Draw boxes (occurrences), return midpts[i] = N(x,y), S(x,y), E(x,y), W(x,y) for boxNr in range(0, nrOfOccs): centerX.append(deltaX + boxNr * deltaX) # X of center of box[i] on canvas centerY.append(deltaY + boxNr * deltaY) # Y of center of box[i] on canvas self.boxID = str(parent_id) + '.' + str(boxNr + 1) midPts.append( self.box_type_1(centerX[boxNr], centerY[boxNr], occs[boxNr].name)) # Debug print('NSEWPts:',boxNr,midPts[boxNr]) self.boxes.append(boxes_on_sheet) # Initialize number of I/O/C/M down and upwards for each occurrence on sheet occIn = [0 for i in range(0, nrOfOccs) ] # input stream nr of deltas downward occOut = [0 for i in range(0, nrOfOccs)] # occCon = [0 for i in range(0, nrOfOccs)] # control stream nr of deltas right # occMech = [0 for i in range(0, nrOfOccs)] occInUp = [0 for i in range(0, nrOfOccs) ] # input stream nr of deltas upward occOutUp = [0 for i in range(0, nrOfOccs)] # occConUp = [0 for i in range(0, nrOfOccs)] # control stream nr of deltas left # occMechUp = [0 for i in range(0, nrOfOccs)] # Draw lines (streams) strNr = 0 hor_size = 15 # horizontal half size of the rhombus polygon vert_size = 25 # vertical half size of the rhombus polygon left = True # indicator for left or right streamTree. border = 5 # Search for lines that have no begin/source occurrence (box), # but only a destination occurrence. for occur, involved, inv_role_kind, inv_kind_name in self.involv_table: # Debug print('ioRow[0]:', occur.uid, occur.name, involved.name, inv_role_kind.name) occUIDFrom = '0' # If inputStream to occurrence on this sheet, then if occur in occs and inv_role_kind.uid in subInputUIDs: # IndexTo is the nr of the occ that has stream as input. indexTo = occs.index(occur) # Verify whether found stream is an output of any box on sheet, # then set out = True origin = 'external' for occur_2, involved_2, inv_role_kind_2, inv_kind_name_2 in self.involv_table: if involved == involved_2 and occur_2 in occs \ and inv_role_kind_2.uid in subOutputUIDs: origin = 'box' break if origin == 'external': # Input comes from outside the sheet streamUID = involved.uid streamName = involved.name streamKind = inv_kind_name occIn[indexTo] += 1 occInUp[indexTo] += 1 strNr = strNr + 1 strID = str(strNr) endPt = midPts[indexTo][3] beginPt = [border, midPts[indexTo][3][1]] # Draw rhombus at x,y and determine its end points x = (beginPt[0] + endPt[0]) / 2 y = beginPt[1] rhombus = self.RhombusPolygon(x, y, strID, hor_size, vert_size) # Draw two straight lines from the left hand side to the rhombus # and from the rhombus to the box lConnPt = rhombus[3] rConnPt = rhombus[2] line1Pts = [beginPt, lConnPt] line2Pts = [rConnPt, endPt] line1 = gui.SvgLine(line1Pts[0][0], line1Pts[0][1], line1Pts[1][0], line1Pts[1][1]) line1.set_stroke(width=thickness, color='black') self.sheets[self.sheet_nr].append(line1) line2 = gui.SvgLine(line2Pts[0][0], line2Pts[0][1], line2Pts[1][0], line2Pts[1][1]) line2.set_stroke(width=thickness, color='black') self.sheets[self.sheet_nr].append(line2) lines_on_sheet.append(line1) lines_on_sheet.append(line2) # Add an arrow head to line2 head = SvgPolygon(4) arrow_height = 20 arrow_width = arrow_height / 3 recess = arrow_height / 5 head.add_arrow_coord(line2, arrow_height, arrow_width, recess) head.set_stroke(width=thickness, color='black') head.set_fill(color='blue') self.sheets[self.sheet_nr].append(head) # lines_on_sheet.append(head) # Record stream in left or right stream table values = [strID, streamName, streamUID, streamKind] table_row = gui.TableRow(style={'text-align': 'left'}) for field in values: item = gui.TableItem(text=field, style={ 'text-align': 'left', 'background-color': self.occ_color }) table_row.append(item) if left is True: # Debug print('Sheet nr:', self.sheet_nr) self.left_str_tables[self.sheet_nr].append(table_row) left = False else: self.right_str_tables[self.sheet_nr].append(table_row) left = True # Find streams per occurrence (box) on this sheet in involv_table # involv_table: occur_obj, involved_obj, role_obj (of invObj), invKindName. # Debug print('subI/O-UIDs:',occs[0].name, subInputUIDs, subOutputUIDs) for occ, involved, inv_role_kind, inv_kind_name in self.involv_table: # Debug print(' ioRow2:', occs[0].name, occ.name, involved.name, inv_role_kind.uid) occUIDTo = '0' # If outputStream from occurrence on this sheet, then if occ in occs and inv_role_kind.uid in subOutputUIDs: # Debug print('**outputStream:', involved.name, inv_role_kind.name) strNr = strNr + 1 strID = str(strNr) occUIDFrom = occ.uid streamUID = involved.uid streamName = involved.name streamKind = inv_kind_name # Verify if found streamUID is input in box on sheet. # If yes, then occUIDTo is known. for occ_2, involved_2, inv_role_kind_2, inv_kind_name_2 in self.involv_table: if streamUID == involved_2.uid and occ_2 in occs \ and inv_role_kind_2.uid in subInputUIDs: # Debug print('** inputStream:', occ_2.name, # inv_role_kind_2.name, inv_role_kind_2.name) occUIDTo = occ_2.uid # else occUIDTo remains '0' break # Determine index (in list of occs) of boxFrom and boxTo indexFrom = -1 indexTo = -1 for index in range(0, len(occs)): if occUIDFrom == occs[index].uid: indexFrom = index if occUIDTo == occs[index].uid: indexTo = index # Determine the sequenceNr of the input and output of the occurrence box # and adjust Yin and Yout accordingly. # Draw the stream line from box occUIDFrom to occUIDTo or to edge of sheet. if indexTo == -1: # No destination box, thus endPt is on rh side of the sheet. ddyFrom = (occOut[indexFrom]) * dy ddyTo = (occIn[indexTo]) * dy if occOut[indexFrom] == 0: # if not yet started downward, then middle becomes occupied. occOutUp[indexFrom] += 1 occOut[indexFrom] += 1 # occOut[indexTo] += 1 # indexTo == -1 # midPts(occNr, East, x / y) beginPt = [ midPts[indexFrom][2][0], midPts[indexFrom][2][1] + ddyFrom ] endPt = [self.screen_width - border, beginPt[1]] x = (beginPt[0] + endPt[0]) / 2 y = beginPt[1] # Rhombus on vertical line rhombus = self.RhombusPolygon(x, y, strID, hor_size, vert_size) lConnPt = rhombus[3] rConnPt = rhombus[2] line1Pts = [beginPt, lConnPt] line2Pts = [rConnPt, endPt] elif indexFrom + 1 < indexTo: # Destination box is behind next box. ddyFrom = (occOut[indexFrom]) * dy ddyTo = (occIn[indexTo]) * dy occOut[indexFrom] += 1 occOut[indexTo] += 1 beginPt = [ midPts[indexFrom][2][0], midPts[indexFrom][2][1] + ddyFrom ] endPt = [ midPts[indexTo][3][0], midPts[indexTo][3][1] + ddyTo ] mid1Pt = [ (beginPt[0] + midPts[indexFrom + 1][3][0]) / 2 - dxC, beginPt[1] ] mid2Pt = [(beginPt[0] + midPts[indexFrom + 1][3][0]) / 2, beginPt[1] + dyC] mid3Pt = [(beginPt[0] + midPts[indexFrom + 1][3][0]) / 2, endPt[1] - dyC] mid4Pt = [ (beginPt[0] + midPts[indexFrom + 1][3][0]) / 2 + dxC, endPt[1] ] x = mid2Pt[0] y = (mid2Pt[1] + mid3Pt[1]) / 2 rhombus = self.RhombusPolygon(x, y, strID, hor_size, vert_size) uConnPt = rhombus[0] lConnPt = rhombus[1] line1Pts = [beginPt, mid1Pt, mid2Pt, uConnPt] line2Pts = [lConnPt, mid3Pt, mid4Pt, endPt] elif indexFrom + 1 > indexTo: # Destination box id before source box (or the box itself). ddyUpFrom = (occOutUp[indexFrom]) * dy ddyUpTo = (occInUp[indexTo]) * dy occOutUp[indexFrom] += 1 occOutUp[indexTo] += 1 beginPt = [ midPts[indexFrom][2][0], midPts[indexFrom][2][1] - ddyUpFrom ] endPt = [ midPts[indexTo][3][0], midPts[indexTo][3][1] - ddyUpTo ] mid1Pt = [ (beginPt[0] + midPts[indexFrom + 1][3][0]) / 2 - dxC, beginPt[1] ] mid2Pt = [(beginPt[0] + midPts[indexFrom + 1][3][0]) / 2, beginPt[1] - dyC] mid3Pt = [(beginPt[0] + midPts[indexFrom + 1][3][0]) / 2, endPt[1] - box_height + dyC] mid4Pt = [ (beginPt[0] + midPts[indexFrom + 1][3][0]) / 2 - dxC, endPt[1] - box_height ] mid5Pt = [(endPt[0] - box_width / 2) + dxC, endPt[1] - box_height] mid6Pt = [(endPt[0] - box_width / 2), endPt[1] - box_height + dyC] mid7Pt = [(endPt[0] - box_width / 2), endPt[1] - dyC] mid8Pt = [(endPt[0] - box_width / 2) + dxC, endPt[1]] x = mid2Pt[0] y = (mid2Pt[1] + mid3Pt[1]) / 2 rhombus = self.RhombusPolygon(x, y, strID, hor_size, vert_size) uConnPt = rhombus[0] lConnPt = rhombus[1] line1Pts = [beginPt, mid1Pt, mid2Pt, lConnPt] line2Pts = [ uConnPt, mid3Pt, mid4Pt, mid5Pt, mid6Pt, mid7Pt, mid8Pt, endPt ] ## if mid5Pt[1] < 0: ## self.sheets[self.sheet_nr].yview_scroll(int(-mid5Pt[1]) + 20, 'units') else: # Destination box is next box ddyFrom = (occOut[indexFrom]) * dy ddyUpTo = (occIn[indexTo]) * dy occOut[indexFrom] += 1 occOutUp[indexTo] += 1 beginPt = [ midPts[indexFrom][2][0], midPts[indexFrom][2][1] + ddyFrom ] endPt = [ midPts[indexTo][3][0], midPts[indexTo][3][1] - ddyUpTo ] mid1Pt = [(beginPt[0] + endPt[0]) / 2 - dxC, beginPt[1]] mid2Pt = [(beginPt[0] + endPt[0]) / 2, beginPt[1] + dyC] mid3Pt = [(beginPt[0] + endPt[0]) / 2, endPt[1] - dyC] mid4Pt = [(beginPt[0] + endPt[0]) / 2 + dxC, endPt[1]] x = mid2Pt[0] y = (mid2Pt[1] + mid3Pt[1]) / 2 rhombus = self.RhombusPolygon(x, y, strID, hor_size, vert_size) uConnPt = rhombus[0] lConnPt = rhombus[1] line1Pts = [beginPt, mid1Pt, mid2Pt, uConnPt] line2Pts = [lConnPt, mid3Pt, mid4Pt, endPt] # Draw polyline 1 from box to rhombus and polyline 2 from rhombus to box # Debug print(' Stream:', indexFrom, indexTo, line1Pts) line1 = gui.SvgPolyline(_maxlen=4) for pt in line1Pts: line1.add_coord(pt[0], pt[1]) line1.set_stroke(width=thickness, color='black') self.sheets[self.sheet_nr].append(line1) line2 = gui.SvgPolyline(_maxlen=8) for pt in line2Pts: line2.add_coord(pt[0], pt[1]) line2.set_stroke(width=thickness, color='black') self.sheets[self.sheet_nr].append(line2) lines_on_sheet.append(line1) lines_on_sheet.append(line2) # Add an arrow head to line2 head2 = SvgPolygon(4) arrow_height = 20 arrow_width = arrow_height / 3 recess = arrow_height / 5 head2.add_arrow_coord(line2, arrow_height, arrow_width, recess) head2.set_stroke(width=thickness, color='black') head2.set_fill(color='blue') self.sheets[self.sheet_nr].append(head2) # Record stream in self.left_str_tables # or in self.right_str_tables[self.sheet_nr](s) values = [strID, streamName, streamUID, streamKind] table_row = gui.TableRow(style={'text-align': 'left'}) for field in values: item = gui.TableItem(text=field, style={ 'text-align': 'left', 'background-color': self.occ_color }) table_row.append(item) if left is True: self.left_str_tables[self.sheet_nr].append(table_row) left = False else: self.right_str_tables[self.sheet_nr].append(table_row) left = True self.lines.append(lines_on_sheet)
def build_keg_table(self): utils.debug_msg(self, "start") new_table = gui.Table(width=480) new_table.style['margin'] = 'auto' new_table.style['text-align'] = 'center' new_table.style['padding'] = '2em' w_mode = self.api_data.get('weight_mode', 'as_kg_gross') # iterate through HX sensors for index, hx_conf in enumerate(self.api_data['hx_list']): # keg information for channel in ['A', 'B']: try: keg_name = hx_conf['channels'][channel].get('name', None) except KeyError: keg_name = None try: if hx_conf['channels'][channel]['co2'] == True: local_w = hx_conf['channels'][channel]['weight'] local_max = hx_conf['channels'][channel][ 'volume'] * 1000 local_tare = hx_conf['channels'][channel]['tare'] * 1000 local_net_w = max((local_w - local_tare), 0) local_pct = local_net_w / float(local_max) self.co2_list.append(int(local_pct * 100)) continue except KeyError: pass if keg_name != None: utils.debug_msg(self, hx_conf['channels'][channel]) keg_label = gui.Label(keg_name, width=100, height=30) keg_bar = gui.Svg(width=240, height=30) keg_w = hx_conf['channels'][channel]['weight'] keg_cap = hx_conf['channels'][channel]['volume'] keg_tare = hx_conf['channels'][channel]['tare'] keg_fill_pct = utils.get_keg_fill_percent( keg_w, keg_cap, keg_tare) keg_bar_rect = gui.SvgRectangle(0, 0, 240 * keg_fill_pct, 30) keg_bar_rect.style['fill'] = utils.fill_bar_color( keg_fill_pct) keg_bar_outline = gui.SvgRectangle(0, 0, 240, 30) keg_bar_outline.style['fill'] = 'rgb(0,0,0)' keg_bar_outline.style['fill-opacity'] = '0' keg_bar.append(keg_bar_rect) keg_bar.append(keg_bar_outline) keg_weight = gui.Label(utils.format_weight( keg_w, w_mode, tare=(keg_tare * 1000), cap=(keg_cap * 1000)), width=100, height=30) table_row = gui.TableRow(height=30) for item in [keg_label, keg_bar, keg_weight]: table_item = gui.TableItem() table_item.append(item) table_row.append(table_item) new_table.append(table_row) utils.debug_msg(self, "end") return new_table
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
async def build_status(self): row = G.TableRow(width="100%") td = TableExtendedItem(G.Label(f"{self.model_instance.TABLE_NAME}")) td.attributes['colspan'] = str(len(self.fields) + 1) row.append(td) self.append(row, "status_0")
def test_init(self): widget = gui.TableRow() assertValidHTML(widget.repr())
def main(self, args): self.debug = args["debug"] utils.debug_msg(self, "start main") self.api_url = "http://127.0.0.1:5000/v1/" self.api_data = {} self.api_last_updated = 1 self.api_update_interval = 5 self.api_read() self.settings_up = False self.edit_keg_up = False self.delete_keg_up = False self.co2_list = [] # root object self.container = gui.VBox(width=480) self.container.style['margin'] = 'auto' self.container.style['text-align'] = 'center' # header self.header = gui.Table(width=480) self.header.style['margin'] = 'auto' self.header.style['text-align'] = 'center' self.header.style['padding'] = '2em' # keg table self.keg_table = gui.Table(width=480) self.keg_table.style['margin'] = 'auto' self.keg_table.style['text-align'] = 'center' self.keg_table.style['padding'] = '2em' # first row first_row = gui.TableRow(height=60) # temperature t = utils.as_degF(self.api_data.get('temp', 0)) self.temp = gui.Label("%s<br />CO2:%s%%" % (t, '???')) self.temp.style['padding-bottom'] = '1em' self.temp.style['white-space'] = 'pre' table_item = gui.TableItem(width=100, height=30) table_item.append(self.temp) first_row.append(table_item) # title self.title = gui.Label("HOPLITE") self.title.style['font-size'] = '2em' self.title.style['padding-bottom'] = '0.5em' table_item = gui.TableItem(width=240, height=30) table_item.append(self.title) first_row.append(table_item) # settings button self.settings_button = gui.Image('/static:settings_16.png', width=16) self.settings_button.set_on_click_listener(self.show_settings) self.settings_button.style['padding-bottom'] = '1.6em' table_item = gui.TableItem(width=100, height=30) table_item.append(self.settings_button) first_row.append(table_item) self.header.append(first_row) self.container.append(self.header) self.keg_table = self.build_keg_table() self.container.append(self.keg_table, 'keg_table') try: co2 = self.co2_list[0] #TODO: Handle multiple CO2 sources except IndexError: co2 = "???" self.temp.set_text("%s\nCO2:%s%%" % (t, co2)) utils.debug_msg(self, "end main") # return of the root widget return self.container