def show_main_menu(f1, f2, f3): global menu_title global menu_subti global menu_calls global menu_items global menu_titbg global menu_chars global menu_visib global menu_runan menu_runan = 0 menu_visib = True menu_titbg = shape.Shape(PATH_MENU_TIT_BG, "", "", 0, 235, 1, 1) menu_title = label.Label("TURTLE RACE", colors.get("title"), 0, 250, 48) menu_subti = label.Label("THE BEST BETTING GAME", colors.get("subti"), 150, 200, 18) menu_calls = [f1, f2, f3] menu_items = [ button.Button(" START ", 0, 30, callback1), button.Button(" SETTINGS ", 0, -30, callback2), button.Button(" ABOUT ", 0, -90, callback3), button.Button(" EXIT ", 0, -150, callback4) ] menu_chars = [ shape.Shape(PATH_MENU_CHAR1[0], "", "", 0, 350, 1, 1), shape.Shape(PATH_MENU_CHAR2[0], "", "", -400, 200, 1, 1), shape.Shape(PATH_MENU_CHAR3[0], "", "", 400, 0, 1, 1), shape.Shape(PATH_MENU_CHAR4[0], "", "", -300, -200, 1, 1), shape.Shape(PATH_MENU_CHAR5[0], "", "", 300, -200, 1, 1), ] menu_char_anim()
def get_label(self, v): if hasattr(v, "value"): l = label.Label(v.value, parent=self, container=self) l._cells["value"] = ComputedCell(lambda: str(v.value)) if type(v) == int: v = str(v) if type(v) == str or type(v) == unicode: l = label.Label(v, parent=self) return l
def __init_ui(self): """Sets an ui for a game. size = 800x600 position = 200, 200 background = backgroundPE.png music while setting field: setting_field1.wav music while playing: gameplay.wav """ self.setGeometry(200, 200, 800, 600) self.setWindowTitle("Battleships") self.setWindowIcon(QIcon("res/pictures/icon.png")) # Setting background background = QPalette() background.setBrush(QPalette.Background, QBrush(QPixmap("res/pictures/backgroundPE.png"))) self.setPalette(background) # Setting player's field self.playerFieldLabel = label.Label(self, "Player") self.playerFieldLabel.setGeometry(50, 50, 295, 295) # Set player's target field self.targetFieldLabel = label.Label(self, "Enemy") self.targetFieldLabel.setGeometry(455, 50, 295, 295) # Add a label which shows information to player self.informativeLabel = QLabel(self) self.informativeLabel.setFont(QFont("MutantAcademyBB", 30)) # 54 self.informativeLabel.setStyleSheet('color: white') self.informativeLabel.setText("Click on your field to place the ship") self.informativeLabel.setGeometry(20, 500, 800, 90) # Add a label which tells in-game informations self.inGameLabel = QLabel(self) self.inGameLabel.setFont(QFont("Capture It", 25)) self.inGameLabel.setStyleSheet('color: pink') self.inGameLabel.setText("Ships to be placed: 10") self.inGameLabel.setGeometry(37, 400, 600, 90) # Add 'ready' button - it starts the game with ToolTip self.readyButton = QPushButton("Ready", self) self.readyButton.setToolTip( "Click this button once you set up the ships") self.readyButton.resize(self.readyButton.sizeHint()) self.readyButton.move(360, 2) self.readyButton.clicked.connect(self.startGame) # Add which ship is being placed self.whichShipLabel = QLabel(self) self.whichShipLabel.setFont(QFont("Tahoma", 25)) self.whichShipLabel.setGeometry(520, 400, 300, 90) self.whichShipLabel.setStyleSheet('color: red') self.whichShipLabel.setText("%d-mast ship" % self.playerFieldLabel.hp)
def set_label(self, v): if hasattr(v, "value"): l = label.Label(v.value, parent=self) l._cells["value"] = ComputedCell(lambda: str(v.value)) if type(v) == int: v = str(v) if type(v) == str or type(v) == unicode: l = label.Label(v, parent=self) self.send(CHANGE) self._label = l self._label._cells["hovering"] = self._cells["hovering"] self._label._cells["focused"] = self._cells["focused"] self._label._cells["pressing"] = self._cells["pressing"]
def __init__(self, frame, text): view.View.__init__(self, frame) self.checked = False check_frame = pygame.Rect(0, 0, 1, 1) self.check_label = label.Label(check_frame, ' ') self.add_child(self.check_label) self.label = label.Label(pygame.Rect(0, 0, 1, 1), text) self.add_child(self.label) self.on_checked = callback.Signal() self.on_unchecked = callback.Signal()
def __init__(self, dataObj, **kwargs): self.dataObj = dataObj self.kwargs = kwargs self.bandCount = helpers.kwargExists("bandCount", kwargs) self.condense = helpers.setBoolKwarg("condense", kwargs, CONDENSE_VALUE) self.showColorCodes = helpers.setBoolKwarg("showColorCodes", kwargs, SHOW_COLOR_CODES) self.showTolerance = helpers.setBoolKwarg("showTolerance", kwargs, SHOW_TOLERANCE) self.voltage = helpers.kwargExists("voltage", kwargs) self.temperature = helpers.kwargExists("temperature", kwargs) ## With all other data set, try to guess which component it is. self.component = helpers.kwargExists("component", kwargs) or self.guessComponent() ## With the component set, set the tolerance and then apply the user's units or pick them based off of the component. self.tolerance = helpers.kwargExists("tolerance", kwargs) self.unitName = helpers.kwargExists("unitName", kwargs) or self.setUnits() self._labels = [] for value in self.dataObj.dataLines: text, colorCode = self.buildComponentLabel(value) self.labels.append(label.Label(text, colorCode))
def __init__(self, frame, items): """items: list of views; str(item) used for selection display""" assert len(items) > 0 view.View.__init__(self, pygame.Rect(frame.topleft, (1, 1))) self.on_selection_changed = callback.Signal() self.on_list_opened = callback.Signal() self.top_label = label.Label(pygame.Rect(0, 0, 1, 1), '') self.top_label.halign = label.LEFT self.top_label._enabled = True self.top_label.on_mouse_down.connect(self.show_list) self.add_child(self.top_label) self.list_view = listview.ListView(pygame.Rect(0, 0, 1, 1), items) self.list_view.on_selected.connect(self.item_selected) self.list_view.on_deselected.connect(self.item_deselected) self.scroll_view = scroll.ScrollView(pygame.Rect(0, 0, 1, 1), self.list_view) self.scroll_view.hidden = True self.add_child(self.scroll_view) self.disclosure = button.Button(pygame.Rect(0, 0, 1, 1), caption='') self.disclosure.on_clicked.connect(self._toggle_show_list) self.add_child(self.disclosure)
def create_labels(self): labels = [] for i, p in enumerate(self.points): l = label.Label(self.text_list[i]) l.set_x(p[0] + (self.cWidth - l.get_width()) * self.text_hAlign) l.set_y(p[1] + (self.cHeight - l.get_height()) * self.text_vAlign) labels.append(l) return labels
def show_about(): global about_title global about_text global about_btn about_title = label.Label("ABOUT", colors.get("subti"), 0, 150, 36) about_text = [] about_text.append( label.Label( "Turtle race is a betting game and designed for single player.", colors.get("fg"), 0, 100)) about_text.append( label.Label( "As long as posible, you can play this game for 1000 minutes, or 1000 years... ", colors.get("fg"), 0, about_text[0].get_y() - 30)) about_text.append( label.Label("The first, it was made for the mid-term project.", colors.get("fg"), 0, about_text[1].get_y() - 30)) about_text.append( label.Label( "You can download the source from github, don't worry about the license, it's FREE.", colors.get("fg"), 0, about_text[2].get_y() - 30)) about_text.append( label.Label( "Developer: Thai Chi Cuong, Tran Nguyen Quynh Anh, Dinh Le Trieu Duong, Phan Vo Minh Huy, Nguyen Hoang Huy.", colors.get("fg"), 0, about_text[3].get_y() - 30)) about_text.append( label.Label("Designer: Tran Nguyen Quynh Anh.", colors.get("fg"), 0, about_text[4].get_y() - 30)) about_btn = button.Button("BACK TO MAIN MENU", 0, -150, about_btn_callback) about_btn.use_enter()
def generate_label(self): l = label.Label(pygame.Rect((0, 0), (self.frame.width, 0))) l.size = 24 l.text_alignment = 'center' l.autofit_height() l.update_text(self.text) l.text_color = self.text_color l.background_color = (100, 1, 50) self.add_subview(l) return l
def test_empty_init(self): "Test the default Label creation" # 1. Create default Label object myobj = label.Label() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(len(myobj.ingredients), 0) self.assertEqual(len(myobj.allergens), 0)
def __init__(self, msg): frame = pygame.Rect(0, 0, window.rect.w // 3, window.rect.h // 2) dialog.DialogView.__init__(self, frame) self.message_label = label.Label(pygame.Rect((0, 0), frame.size), msg, wrap=label.WORD_WRAP) self.add_child(self.message_label) self.auto_close = True self.auto_close_after = 3 self.elapsed = 0
def __init__(self): # background self.background = dist.imagedist['screen_game'] self.rect = self.background.get_rect() self.rect.x = 0 self.rect.y = 0 # score self.scorePlayer = 0 self.scoreAI = 0 x = 15 y = 0.5 * dist.SCREEN_HEIGHT delta = dist.BTN_HEIGHT + dist.BTN_GAP_SPACE # button self.btnMenu = button.Button(dist.imagedist['btnMenu'], x, y) self.btnHuongDan = button.Button(dist.imagedist['btnHuongDan'], x, y + delta) self.btnThoat = button.Button(dist.imagedist['btnThoat'], x, y + 2 * delta) # label self.lblPlayer = label.Label('PLAYER', dist.FONTSIZE, 200, 330) self.lblScorePlayer = label.Label('SCORE', dist.FONTSIZE, 450, 400) self.lblValueScorePlayer = label.Label(str(self.scorePlayer), dist.FONTSIZE, 560, 400) self.lblAI = label.Label('COMPUTER', dist.FONTSIZE, 200, 120) self.lblScoreAI = label.Label('SCORE', dist.FONTSIZE, 450, 50) self.lblValueScoreAI = label.Label(str(self.scorePlayer), dist.FONTSIZE, 560, 50)
def show_settings(): global set_title global set_edname global set_edwid global set_edhei global set_savebtn set_title = label.Label("SETTINGS", colors.get("subti"), 0, 150, 36) set_edname = lineedit.LineEdit(0, 60, config.player_name) set_edwid = lineedit.LineEdit(0, 0, config.road_width, True) set_edhei = lineedit.LineEdit(0, -60, config.road_height, True) set_savebtn = button.Button("SAVE AND BACK", 0, -150, set_savebtn_callback) set_savebtn.use_enter()
def __init__(self): self.surface = Surface_Drawable((WIN_WIDTH, WIN_HEIGHT)) # loading screen design self.surface.fill(c.WHITE) l = label.Label("Loading: please wait") l.set_x((WIN_WIDTH - l.get_width()) / 2) l.set_y((WIN_HEIGHT - l.get_height()) / 2) l.draw(self.surface) # loading bar atributes self.bar_start = 200 self.bar_end = WIN_WIDTH - 200 self.bar_percent = 0 self.bar_y = WIN_HEIGHT//2 + 100 self.bar_h = 30
def __init__(self, y, cols, width): self.__labels = [] self.__icons = [] self.__width = width self.__cols = cols self.__perx = self.__width / (self.__cols - 1) self.__x = -((self.__width) / 2) self.__y = y for i in range(self.__cols): self.__labels.append( label.Label("", colors.get("lead_fg"), self.__x, self.__y)) self.__labels[i].align("center") self.__x += self.__perx
def __init__(self, title, message, buttons=0xFF): dialog.DialogView.__init__(self, pygame.Rect(0, 0, 1, 1)) self.title = title self.message = message self.buttons = buttons self.message_label = label.Label(pygame.Rect(0, 0, 1, 1), message, wrap=label.WORD_WRAP) self.message_label.valign = label.TOP self.add_child(self.message_label) self.title_label = label.Label(pygame.Rect(0, 0, 1, 1), title) self.add_child(self.title_label) self.ok = button.Button(pygame.Rect(0, 0, 0, 0), 'OK') self.ok.on_clicked.connect(self._dismiss) self.add_child(self.ok) self.cancel = button.Button(pygame.Rect(0, 0, 0, 0), 'Cancel') self.cancel.on_clicked.connect(self._dismiss) self.add_child(self.cancel)
def _draw_text(self): text_score = 'CURRENT SCORE: {score}'.format(score=self.scores) text_position = 'POSITION: {position}'.format( position=self.pacman._get_pacman_position()) # * Скорее лучше будет не повторять инциализацию, а добавить метод изменения текста score = label.Label(constants.TEXT_SCORE_POSITION, text_score, constants.MAIN_FONT, constants.MAIN_SIZE_FONT, constants.DEFAULT_TEXT_COLOUR) position = label.Label(constants.TEXT_PACMAN_POSITION, text_position, constants.MAIN_FONT, constants.MAIN_SIZE_FONT, constants.DEFAULT_TEXT_COLOUR) score.draw(self.screen) position.draw(self.screen) if self.pacman.is_helper_activated(): helper_time_text = 'TIME CHERRY: {time}'.format( time=self.pacman.helper_time) helper_time = label.Label( constants.TEXT_HELPER_TIME_POSITION, helper_time_text, constants.MAIN_FONT, constants.MAIN_SIZE_FONT, constants.DEFAULT_TEXT_COLOUR) helper_time.draw(self.screen)
def __init__(self, frame, text='', placeholder=''): view.View.__init__(self, frame) self.text = text or '' self.placeholder = placeholder self.label = label.Label(pygame.Rect((0, 0), frame.size), text or placeholder) self.label.halign = label.LEFT self.add_child(self.label) self.enabled = True self.max_len = None self.secure = False self.on_return = callback.Signal() self.on_text_change = callback.Signal()
def __init__(self, x, y, default_val, number_only = False): self.__selected = False self.__edited = False self.__default_val = default_val self.__string = str(self.__default_val) self.__entry = shape.Shape("square", colors.get("borders"), colors.get("borders"), x, y - 14, self.DEFAULT_WIDTH, 1, 0) self.__text = label.Label(self.__string, colors.get("fg"), x, y, self.DEFAULT_FONT_SIZE) self.__number_only = number_only self.__top_left = [ x - (self.DEFAULT_WIDTH / 2), y + (self.DEFAULT_HEIGHT / 2)] self.__bot_right = [ x + (self.DEFAULT_WIDTH / 2), y - (self.DEFAULT_HEIGHT / 2)] muievent.bind_click(self.__checkclick) muievent.bind_key(self.__checkkeypress)
def __init__(self, nquan, x, y): self.nquan = nquan self.frames = map(lambda i: dist.imagedist['%sq' % (i)], range(1, 8, 1)) if self.nquan == 0: self.image = dist.imagedist['N'] else: idx = self.nquan - 1 idx_frame = 6 if idx >= 7 else idx self.image = self.frames[idx_frame] self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y # label value self.label = label.Label(self.nquan, dist.FONTSIZE1, x + dist.SQUARE_WIDTH - 10, y + dist.SQUARE_HEIGHT - 10)
def updateOLED(self, sandbox): try: open(self._toDisplay, "rb") bmpinfo = bmpInfo(self._toDisplay) #bmpinfo.display() # make the color at 0 index transparent. bmpinfo.palette.make_transparent(0) # Create the sprite TileGrid sprite1 = displayio.TileGrid( bmpinfo.bitmap, pixel_shader=bmpinfo.palette, width=self._gridWidth, height=self._gridHeight, tile_width=self._tileWidth, tile_height=self._tileHeight, default_tile=0, ) try: sprite_group = displayio.Group() self._display.show(sprite_group) sprite_group.append(sprite1) except Exception as e: print(e) except OSError as e: print("File does not exist, resorting to text!") import terminalio try: import label except Exception as e: print( "You need to place the adafruit_displayio_text module in your lib folder" ) if self._toDisplay.upper() == "ACTIVE LAYER": print("Active Layer: %s" % sandbox.active_layers[0]) text = "Active Layer: %s" % sandbox.active_layers[0] splash = displayio.Group() self._display.show(splash) text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=28, y=15) splash.append(text_area)
def _update_text_objects(self): objects = [] texts = ['START', 'EXIT'] spaces_text = self.TOP_BUFFER for index, text in enumerate(texts): spaces_text += self.SPACES_TEXT if index == self.current_object: colour = constants.SELECTED_TEXT_COLOUR else: colour = constants.DEFAULT_TEXT_COLOUR text = label.Label(VEC_2(self.CENTER_OF_SCREEN, spaces_text), text, constants.MAIN_FONT, constants.MAIN_SIZE_FONT, colour) objects.append(text) self.objects = objects
def test_text_init(self): "Test the Label object creation from text" # 1. Create Label object from text myobj = label.Label(text=EXAMPLE_TEXT) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 47) self.assertEqual(len(myobj.ingredients), 4) self.assertEqual(len(myobj.allergens), 2) # 3. Check methods self.assertEqual(myobj.has_ingredient('mxmxvkd'), True) self.assertEqual(myobj.has_ingredient('kfcds'), True) self.assertEqual(myobj.has_ingredient('dairy'), False) self.assertEqual(myobj.has_allergen('dairy'), True) self.assertEqual(myobj.has_allergen('fish'), True) self.assertEqual(myobj.has_allergen('soy'), False) self.assertEqual(myobj.has_allergen('kfcds'), False)
def _process_text(self, text): "Create labels, ingredients, and allergens from input text" # 1. Process text to create list of labels for line in text: self.labels.append(label.Label(text=line, part2=self.part2)) # 2. Get list of ingredients for lab in self.labels: self.ingredients.update(lab.ingredients) # 3. Get list of allergens for lab in self.labels: self.allergens.update(lab.allergens) # 4. Map the allergens to (possible) ingredents for lab in self.labels: for allergen in lab.allergens: if allergen not in self.mapping: self.mapping[allergen] = set(lab.ingredients) else: self.mapping[allergen] &= set(lab.ingredients)
def __init__(self, charclass, color, name, x, y): self.__anim_stand = [0, 1] self.__anim_run = [2, 5] self.__anim_runback = [6, 9] self.__anim_win = [10, 11] self.__anim_lose = [12, 13] self.__anim_list = [] self.__anim_ind = 0 self.__anim_stick = 0 self.__anim_start = 0 self.__anim_end = 0 self.__anim_delay = 0 self.__load_animation("res/img/" + charclass + "/animation.txt", color) if (color is "Blue"): color = "#55aaff" elif (color is "Green"): color = "#00fcb9" elif (color is "Gray"): color = "#A0A0A0" self.__char_name = label.Label(name, color.lower(), x, y + 65) self.__char_shape = shape.Shape(self.__anim_list[0], "", "", x, y + 15, 64, 64) self.__max_speed = self.DICT_SPEED[config.player_class] self.__min_speed = self.DICT_MIN_SPEED[config.player_class] self.name = name self.color = color self.time = 0.0 self.win = 0 self.lose = 0 self.__pause = True self.__runback = False
def __init__(self, text, x, y, callback, fontsize = 16): h = fontsize + 10 w = len(text * fontsize) self.__autodest = False self.__use_enter = False self.__callback = callback self.__state = "btn_normal" self.__bgbtn = shape.Shape("res/img/Else/button.gif", "", "", x, y, 1, 1) self.__label = label.Label(text, "", x, y, fontsize) self.__color_by_state() self.__top_left = [ x - (w / 2), y + (h / 2)] self.__bot_right = [ x + (w / 2), y - (h / 2)] muievent.bind_click(self.__checkclick) muievent.bind_motion(self.__checkhover) muievent.bind_release(self.__checkrelease)
def __pressure_value(self): self.press_value = label.Label(60, 40, 30, 10, self.lcd)
def _draw_text_pause(self): text = label.Label(VEC_2(self.CENTER_OF_SCREEN, 200), 'PAUSE', constants.MAIN_FONT, constants.MAIN_SIZE_FONT, constants.PAUSE_TEXT_COLOUR) text.draw(self.screen)
med_bitmap = displayio.Bitmap(16, 16, 1) med_square = displayio.TileGrid(med_bitmap, pixel_shader=color_palette, x=71, y=15) splash.append(med_square) lrg_bitmap = displayio.Bitmap(32, 32, 1) lrg_square = displayio.TileGrid(lrg_bitmap, pixel_shader=color_palette, x=91, y=28) splash.append(lrg_square) # Draw some label text text1 = "0123456789ABCDEF123456789AB" # overly long to see where it clips text_area = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF, x=8, y=8) splash.append(text_area) text2 = "SH1107" text_area2 = label.Label(terminalio.FONT, text=text2, scale=2, color=0xFFFFFF, x=9, y=44) splash.append(text_area2) while True: pass