def main(self, game): self.game = game self.last_known_turn = self.game.turn width, height = 800, 600 # Set board width and height svg = gui.Svg(width=width, height=height) svg.style['background-color'] = 'yellow' r = 35 # Set radius of slots ys = np.round(np.linspace(2 * r, height - 2 * r, self.game.dim[0])).astype(int) xs = np.round(np.linspace(2 * r, width - 2 * r, self.game.dim[1])).astype(int) self.grid = np.empty(self.game.dim, dtype='object') for rowi, y in enumerate(ys): for coli, x in enumerate(xs): circ = gui.SvgCircle(x=x, y=y, radius=r) # Create slot circ.style['stroke'] = 'black' # Set color of slot outline circ.style['fill'] = 'white' # Set color of empty slot circ.onclick.do(self.on_click, pos=(rowi, coli)) svg.append(circ) # Add slot to GUI self.grid[rowi, coli] = circ self.text = gui.Label('') self.reset_button = gui.Button('Reset Game') self.reset_button.onclick.connect(self.reset) self.ended = False threading.Thread(target=self.update_thread).start() container = gui.VBox(width=width, height=height) container.append(svg) container.append(self.text) container.append(self.reset_button) return container
def initFieldMap(self, robot): fieldBox = self.sectionBox() robotBox = gui.HBox() fieldBox.append(robotBox) setPositionBtn = gui.Button("Set Robot to Cursor") setPositionBtn.onclick.connect(self.c_setRobotPosition) robotBox.append(setPositionBtn) def setRobotAngle(button, angle): pathFollower = self.robot.pathFollower pathFollower.setPosition(pathFollower.robotX, pathFollower.robotY, angle) leftBtn = gui.Button('<') leftBtn.onclick.connect(setRobotAngle, math.radians(90)) robotBox.append(leftBtn) rightBtn = gui.Button('>') rightBtn.onclick.connect(setRobotAngle, math.radians(-90)) robotBox.append(rightBtn) upBtn = gui.Button('^') upBtn.onclick.connect(setRobotAngle, 0) robotBox.append(upBtn) downBtn = gui.Button('v') downBtn.onclick.connect(setRobotAngle, math.radians(180)) robotBox.append(downBtn) self.fieldSvg = gui.Svg(CompetitionBotDashboard.FIELD_WIDTH, CompetitionBotDashboard.FIELD_HEIGHT) self.fieldSvg.set_on_mousedown_listener(self.mouse_down_listener) fieldBox.append(self.fieldSvg) self.image = gui.SvgShape(0, 0) self.image.type = 'image' self.image.attributes['width'] = CompetitionBotDashboard.FIELD_WIDTH self.image.attributes['height'] = CompetitionBotDashboard.FIELD_HEIGHT self.image.attributes['xlink:href'] = '/res:frcField.PNG' self.fieldSvg.append(self.image) self.targetPoints = coordinates.targetPoints for point in self.targetPoints: point = fieldToSvgCoordinates(point.x, point.y) wp_dot = gui.SvgCircle(point[0], point[1], 5) wp_dot.attributes['fill'] = 'blue' self.fieldSvg.append(wp_dot) self.cursorArrow = Arrow('red') self.fieldSvg.append(self.cursorArrow) self.robotArrow = Arrow('green') self.fieldSvg.append(self.robotArrow) self.robotPathLines = [] return fieldBox
def default_icon(name, view_w=2, view_h=0.6): """ A simple function to make a default svg icon for the widgets such icons can be replaced later with a good one """ icon = gui.Svg(width=100,height=30) icon.set_viewbox(-view_w/2,-view_h/2,view_w,view_h) text = gui.SvgText(0,0,name) text.style['font-size'] = "0.2px" text.style['text-anchor'] = "middle" stroke_width = 0.01 rect = gui.SvgRectangle(-view_w/2+stroke_width,-view_h/2+stroke_width,view_w-stroke_width*2,view_h-stroke_width*2) rect.set_fill("none") rect.set_stroke(0.01,'black') icon.append([rect, text]) return icon
def main(self): self.frame = gui.VBox(width='100%', height='80%', style={ 'overflow': 'auto', 'background-color': '#eeffdd' }) self.sheet = gui.Svg(width='100%', height='100%') self.screen_width = 1000 self.screen_height = 600 self.int_id = 0 self.sheet.set_viewbox(0, 0, self.screen_width, self.screen_height) self.frame.append(self.sheet) nr_of_boxes = 2 box_names = ['Activity-A', 'Activity-B'] self.Draw_a_drawing_of_one_sheet(nr_of_boxes, box_names) return self.frame
def initFieldMap(self, robot): fieldBox = self.sectionBox() robotBox = gui.HBox() fieldBox.append(robotBox) setPositionBtn = gui.Button("Set Robot to Cursor") setPositionBtn.set_on_click_listener(self.c_setRobotPosition) robotBox.append(setPositionBtn) setRotationBtn = gui.Button("Point Robot at Cursor") setRotationBtn.set_on_click_listener(self.c_pointAtCursor) robotBox.append(setRotationBtn) def setCursorAngle(button, angle): self.selectedCoord.angle = angle self.updateCursorPosition() leftBtn = gui.Button('<') leftBtn.set_on_click_listener(setCursorAngle, math.radians(90)) robotBox.append(leftBtn) rightBtn = gui.Button('>') rightBtn.set_on_click_listener(setCursorAngle, math.radians(-90)) robotBox.append(rightBtn) upBtn = gui.Button('^') upBtn.set_on_click_listener(setCursorAngle, 0) robotBox.append(upBtn) downBtn = gui.Button('v') downBtn.set_on_click_listener(setCursorAngle, math.radians(180)) robotBox.append(downBtn) self.fieldSvg = gui.Svg() self.makeField('/res:field.png', True) fieldBox.append(self.fieldSvg) self.robotPathLines = [] self.selectedCoord = coordinates.FieldCoordinate( "Center", 0, 0, math.radians(-90)) self.updateCursorPosition() return fieldBox
def main(self, robot, appCallback): self.robot = robot root = gui.VBox(width=600) self.fieldWidth = 500 self.fieldHeight = 450 self.fieldSvg = gui.Svg(self.fieldWidth, self.fieldHeight) root.append(self.fieldSvg) self.arrow = gui.SvgPolyline() self.fieldSvg.append(self.arrow) self.arrow.add_coord(0, 0) self.arrow.add_coord(30, 30) self.arrow.add_coord(-30, 30) self.arrow.style['fill'] = 'gray' self._c_resetPosition(None) resetButton = gui.Button("Reset") resetButton.set_on_click_listener(self._c_resetPosition) root.append(resetButton) appCallback(self) return root
def test_init(self): widget = gui.Svg(10, 10) assertValidHTML(widget.repr())
def Define_a_drawing_of_one_sheet(self, sheet_name): """ Create a Notebook page and draw one sheet on that page and draw boxes by calling box_type_1 and draw lines between them by calling CreateLine. """ # Occurrences drawing frame tab ## draw_text = ['Drawing of ', 'Tekening van '] ## drawing_name = draw_text[self.GUI_lang_index] + sheet_name ## self.drawing_frame = gui.VBox(width='100%', height='100%', ## style='background-color:#eeffdd') ## self.drawings.append(self.drawing_frame) ## self.user_interface.views_noteb.add_tab(self.drawing_frame, ## self.sheet_nr, ## self.tab_cb(drawing_name)) self.draw_button_row = gui.HBox(height=20, width='100%') draw_button_text = ['View', 'Toon'] self.draw_but = gui.Button(draw_button_text[self.GUI_lang_index], width='15%', height=20) self.draw_but.attributes['title'] = 'Press button to view selected box' self.draw_but.onclick.connect(self.RightMouseButton) self.draw_button_row.append(self.draw_but) self.close_sheet = gui.Button( self.close_button_text[self.GUI_lang_index], width='15%', height=20) self.close_sheet.attributes[ 'title'] = 'Press button when you want to remove this tag' self.close_sheet.onclick.connect(self.user_interface.Close_tag, self.user_interface.views_noteb, self.occ_name) self.draw_button_row.append(self.close_sheet) self.occ_frame.append(self.draw_button_row) # Define drawing space widget sheet = gui.Svg(width='100%', height='100%') sheet.set_viewbox(0, 0, self.screen_width, self.screen_height) self.occ_frame.append(sheet) self.sheets.append(sheet) # Add stream frames - left and right - to occ_frame str_frames = gui.HBox(width='100%', height=200, style='background-color:#eeffdd') self.left_str_frames.append( gui.VBox(width='50%', height='100%', style='background-color:#eeffdd')) self.right_str_frames.append( gui.VBox(width='50%', height='100%', style='background-color:#eeffdd')) str_frames.append(self.left_str_frames[self.sheet_nr]) str_frames.append(self.right_str_frames[self.sheet_nr]) self.occ_frame.append(str_frames) # Create left and right stream tables on the sheet self.left_str_tables.append( SingleRowSelectionTable(width='100%', style={ 'overflow': 'auto', 'background-color': '#eeffaa', 'border-width': '2px', 'border-style': 'solid', 'font-size': '12px', 'table-layout': 'auto', 'text-align': 'left' })) # Specify and create header row str_nr_text = ['Number', 'Nummer'] str_text = ['Stream Name', 'Stroomnaam'] uid_text = ['UID', 'UID'] kind_text = ['Kind', 'Soort'] columns = [ (str_nr_text[self.GUI_lang_index], str_text[self.GUI_lang_index], uid_text[self.GUI_lang_index], kind_text[self.GUI_lang_index]) ] self.left_str_tables[self.sheet_nr].append_from_list(columns, fill_title=True) self.left_str_frames[self.sheet_nr].append( self.left_str_tables[self.sheet_nr]) self.right_str_tables.append( SingleRowSelectionTable(width='100%', style={ 'overflow': 'auto', 'background-color': '#eeffaa', 'border-width': '2px', 'border-style': 'solid', 'font-size': '12px', 'table-layout': 'auto', 'text-align': 'left' })) self.right_str_tables[self.sheet_nr].append_from_list(columns, fill_title=True) self.right_str_frames[self.sheet_nr].append( self.right_str_tables[self.sheet_nr]) self.uom_color = '#ccf' self.occ_color = '#cfc'
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 test_init(self): widget = gui.Svg(width=10, height=10) assertValidHTML(widget.repr())
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