def create_spawn_panel(self): ''' create the panel for spawning the actors. Here, only spawn vehicle for function demo ''' self.uniquename_text = sgc.InputBox(label="name: ", pos=(60, 100), label_side="left") self.spawn_x_text = sgc.InputBox(label="x: ", pos=(60, 200), label_side="left") self.spawn_y_text = sgc.InputBox(label="y: ", pos=(60, 300), label_side="left") self.spawn_label = None # create a label that's going to show the place the user have clicked on the map self.spawn_button = sgc.Button(label="spawn", pos=(int(self.left_width / 2) - 50, self.left_height - 100)) self.spawn_button.config(on_click=self.spawn_in_intersection) self.interactive_mouse_button = sgc.Button(label=" Mouse", pos=(260, 200)) self.interactive_mouse_button.on_click = self.interactive_mouse_callback
def __init__(self,screen,font, player, trader): self.active = False self.player = player self.trader = trader self.screen = screen self.font = font self.playerTitle = sgc.Label(text="Player Inventory", font=self.font) self.playerTitle.rect.center = (self.screen.rect.centerx-100, 40) self.traderTitle = sgc.Label(text="Trader Inventory", font=self.font) self.traderTitle.rect.center = (self.screen.rect.centerx+100, 40) self.sell_button = sgc.Button(label="Sell\nItem", pos=(self.screen.rect.centerx-160,300)) self.buy_button = sgc.Button(label="Buy\nItem", pos=(self.screen.rect.centerx,300)) self.money_label = sgc.Label(text="Money: " + str(player.player_model.money), font=self.font) self.money_label.rect.center = (self.screen.rect.centerx-30, 275) self.stats = sgc.Label(text="", font=pg.font.SysFont("Arial", 15)) self.stats.rect.center = (self.screen.rect.centerx-160, 375) self.stats.config(text="") self.stats.add() self.player_radio_box = None self.player_radios = [] self.trader_radio_box = None self.trader_radios = []
def __init__(self, screen, font, player): self.active = False self.player = player self.screen = screen self.font = font self.radio_box = None self.radios = [] self.title = sgc.Label(text="Inventory", font=self.font) self.title.rect.center = (self.screen.rect.centerx, 40) self.drop_button = sgc.Button(label="Drop\nItem", pos=(self.screen.rect.centerx-160,300)) self.quit_button = sgc.Button(label="Quit", pos=(self.screen.rect.centerx,300)) self.stats = sgc.Label(text="", font=pg.font.SysFont("Arial", 15)) self.stats.rect.center = (self.screen.rect.centerx-160, 375) self.stats.config(text="")
def create_vehicle_panel(self): self.vehicle_name_text = sgc.Label(pos=(int(self.left_width / 2), 100)) self.vehicle_position_x_text = sgc.InputBox(label="x: ", pos=(50, 200), label_side="left") self.vehicle_position_y_text = sgc.InputBox(label="y: ", pos=(50, 300), label_side="left") self.vehicle_to_intersection_button = sgc.Button(label="Back", pos=(0, 0)) self.vehicle_to_intersection_button.on_click = self.vehicle_to_intersection_callback
def __init__(self, screen, font, player, enemy): self.active = False self.player = player self.enemy = enemy self.screen = screen self.font = font self.title = sgc.Label(text="Battle", font=self.font) self.title.rect.center = (self.screen.rect.centerx, 40) player_image_zoomed = pg.transform.rotozoom(player.image, 0, 3) self.player_img = sgc.Simple(surf=player_image_zoomed, pos=(self.screen.rect.centerx-160,75)) enemy_image_zoomed = pg.transform.rotozoom(enemy.image, 0, 3) self.enemy_img = sgc.Simple(surf=enemy_image_zoomed, pos=(self.screen.rect.centerx+120,75)) self.player_hp_label = sgc.Label(text="HP: " + str(self.player.player_model.current_health) + " / " + str(self.player.player_model.health_capacity), font=pg.font.SysFont("Arial", 15), pos=(35,130)) self.enemy_hp_label = sgc.Label(text="HP: " + str(self.enemy.enemy_model.current_health) + " / " + str(self.enemy.enemy_model.health_capacity), font=pg.font.SysFont("Arial", 15), pos=(300,130)) self.attack_option = sgc.Button(label="Attack") self.item_option = sgc.Button(label="Item") self.retreat_option = sgc.Button(label="Retreat") self.attack_options_box = sgc.VBox(widgets =[self.attack_option, self.item_option, self.retreat_option], pos=(10, 180))
def __init__(self, intersection_id, uniquename, img_x, img_y, map_x, map_y, yaw): btn_surface = pygame.Surface((32, 32)) pygame.draw.polygon(btn_surface, bright_green, [(1, 1), (1, 31), (21, 31), (31, 16), (21, 1)]) self.button = sgc.Button( surf=btn_surface, label=uniquename, pos=(img_x - int(btn_surface.get_width() / 2), img_y - int(btn_surface.get_height() / 2))) self.map_x = map_x self.map_y = map_y self.yaw = yaw self.uniquename = uniquename self.intersection_id = intersection_id self.button.on_click = self.vehicle_button_callback
names.append("img" + item.replace(".png", "").replace("h", ".")) images.append(pygame.image.load(item)) current_image = 0 # --- pygame.init() display_surface = sgc.surface.Screen((400, 400)) #display_surface = pygame.display.set_mode((400, 400)) display_rect = display_surface.get_rect() font = pygame.font.Font('freesansbold.ttf', 32) btn = sgc.Button(label="Clicky", pos=(10, 10)) #, label_font=font) btn.add(0) btn.on_click = on_click_button # --- clock = pygame.time.Clock() current_time = pygame.time.get_ticks() end_time = current_time + MAXDURATION * 1000 end_slide = current_time running = True while running and ((current_time < end_time) or (current_image < MAXNOTE)): ticks = clock.tick(30)
def create_intersection_panel(self): self.spawn_actor_button = sgc.Button(label="spawn actor", pos=(100, 300)) self.spawn_actor_button.config(on_click=self.go_to_spawn_callback)
background = pygame.image.load(background_image_filename[0]).convert() yardBackground = pygame.image.load(background_image_filename[1]).convert_alpha() welcome = pygame.image.load(welcome_image_filename).convert_alpha() font = pygame.font.Font("other/simsun.ttc",16) gameOverFont = pygame.font.Font("other/simsun.ttc",60) text_userName = font.render(u"游客", True, WHITE) #循环播放背景音乐 pygame.mixer.music.play(-1) loseSound = pygame.mixer.Sound(music_filenames[1]) evillaughSound = pygame.mixer.Sound(music_filenames[2]) # 以下是自定义对话框中label和button设置 label = sgc.Label(text="unlock!",pos=(160,120),col=WHITE,font=font) def print_pass(): dialogs[-1].remove() btn_ok = sgc.Button("images/interface/LongButton.png",label="ok", pos=(80,210)) btn_ok.on_click = print_pass dialog_container = sgc.Container(widgets=(label,btn_ok), border=10) dialogs = [] #开始标志 startflag = False #添加对话框 startGameButton = sgc.Button(startGame_image_filename,label="", pos=(startGameX,startGameY)) startGameButton.add() smallGameDialog = BtnDialog(smallGame_image_filename,label="", pos=(smallGameX,smallGameY)) smallGameDialog.modal = True smallGameDialog.add()
###################################################### #screen size, creating clock screen = sgc.surface.Screen((1280, 720)) clock = pygame.time.Clock() #elements # Title title = sgc.Label(text="Sistema Restaurante ", font=sgc.Font["title"], col=sgc.Font.col) title.rect.center = (screen.rect.centerx, 40) title.add() #buttons button = sgc.Button(label="Video", pos=(360, 100)) button.add(order=1) button2 = sgc.Button(label="Cliente", pos=(40, 100)) button2.add(order=1) button3 = sgc.Button(label="Admin", pos=(200, 100)) button3.add(order=1) #main while True: time = clock.tick(30) for event in pygame.event.get(): sgc.event(event)
import sys sys.path.insert(0, "..") import sgc from sgc.locals import * import pygame from pygame.locals import * pygame.display.init() pygame.font.init() screen = sgc.surface.Screen((640, 480)) clock = pygame.time.Clock() btn = sgc.Button(label="Clicky", pos=(100, 100)) btn.add(0) while True: time = clock.tick(30) for event in pygame.event.get(): sgc.event(event) if event.type == QUIT: exit() screen.fill((0, 0, 0)) sgc.update(time) pygame.display.flip()
def __init__(self, window): self.window = window width = 35 # TODO add a repeat switch self.runButton = sgc.Button(label="Run", pos=(self.window.width / 2, self.window.height - 60)) self.sizeScale = sgc.Scale(label="Size of the world grid", min=10, max=100, min_step=1, max_step=5, pos=(25, 25)) self.killRangeSlider = sgc.Scale(label="Predator kill range slider", min=1, max=30, min_step=1, max_step=1, pos=(25, 25 + width * 6)) self.initprey = sgc.Scale(label="Initial prey population", min=1, max=10**2, min_step=1, max_step=10, pos=(25, 25 + width * 7)) self.initpred = sgc.Scale(label="Initial predator population", min=1, max=10**2, min_step=1, max_step=10, pos=(25, 25 + width * 8)) self.alpha = sgc.InputBox(label="Alpha", pos=(25, 75)) self.beta = sgc.InputBox(label="Beta", pos=(25, 100)) self.gamma = sgc.InputBox(label="Gamma", pos=(25, 125)) self.delta = sgc.InputBox(label="Delta", pos=(25, 150)) self.run_lv_button = sgc.Button(label="Run LV", pos=(self.runButton.pos[0] + 200, self.runButton.pos[1])) self.lv_timelimit = sgc.Scale(label="Time limiter", min=1, max=50, min_step=1, max_step=5, pos=(400, 25)) self.lv_scale = sgc.Scale(label="LV SCALE", min=1, max=50, min_step=1, max_step=5, pos=(400, 75)) self.repeats = sgc.Scale(label="Monte-Carlo Repeats", min=1, max=200, min_step=1, max_step=5, pos=(400, 150)) self.repeatButtons = sgc.Button(label="Run Fast", pos=(self.run_lv_button.pos[0] + 200, self.runButton.pos[1])) self.runButton.add(0) self.sizeScale.add(1) self.alpha.add(2) self.beta.add(3) self.gamma.add(4) self.delta.add(5) self.initprey.add(6) self.initpred.add(7) self.run_lv_button.add(8) self.killRangeSlider.add(9) self.lv_timelimit.add(10) self.lv_scale.add(11) self.repeats.add(12) self.repeatButtons.add(13)
sgc.Font.col = (150, 150, 150) # TODO Button font colour # Title title = sgc.Label(text="Simple Game Code " + ver_no, font=sgc.Font["title"], col=sgc.Font.col) title.rect.center = (screen.rect.centerx, 40) title.add() # Create input_box input_box = sgc.InputBox(label="Input Box", default="default text...") input_box.config(pos=(30, 120)) input_box.add() # Change colour button, on_click event caught in event loop button = sgc.Button(label="Change\ncolour", pos=(40, 200)) # Create FPS counter fps = sgc.FPSCounter(clock=clock) fps.rect.midbottom = (screen.rect.w / 2, screen.rect.h) fps.add() # Pass config file as argument, to have Menu parse file with open("menu") as menu_file: menu = MainMenu(menu=menu_file) # Display menu on button click, on_click replaced through assignment btn_menu = sgc.Button(label="Menu", pos=(250, 200)) btn_menu.on_click = menu.add # Input_box for dialog window password_box = sgc.InputBox(label="Password", default="Enter password...") password_box.pos = (0, 10)
map_selection = "Castle" return (map_selection) windowSurface = sgc.surface.Screen((480, 320)) clock = pygame.time.Clock() font = pygame.font.Font("fonts/animeace2_reg.ttf", 24) font2 = pygame.font.Font("fonts/ASTONISH.TTF", 36) font3 = pygame.font.Font("fonts/animeace2_reg.ttf", 12) ### btn = sgc.Button(pos=(340, 250), label="Next", label_font=font2, label_col=(255, 255, 0)) btn.on_click = next btn2 = Save(pos=(10, 250), label="Save", label_font=font) ### combo Box weapons = ["pistol", "shotgun", "machinegun"] combo = sgc.Combo(pos=(10, 10), label="weapons", values=weapons, label_side="bottom", selection=0, label_font=font3, label_col=(0, 255, 255))
def __init__(self): # initialisation dans le run self.env = None # Initialize sliders (and actual starting values) here self.current_mass_value = param.STARTING_MASS_VALUE self.current_charge_value = param.STARTING_CHARGE_VALUE self.current_dipole_moment = param.STARTING_DIPOLE_MOMENT self.current_polarizability = param.STARTING_POLARIZABILITY self.current_stiffness = param.STARTING_STIFFNESS self.current_friction = param.STARTING_FRICTION self.sim_running = param.STARTING_SIM_RUNNING self.nb_sequences = -1 pygame.init() pygame.display.init() self.info = pygame.display.Info() self.dw = int(self.info.current_w / 3) self.dh = int(self.info.current_h / 3) self.screen = sgc.surface.Screen((2 * self.dw, 2 * self.dh)) self.fgColor = (0, 0, 0) self.bgColor = (255, 255, 255) btn = sgc.Button(label="Run/Pause", pos=(10, 440)) btn.on_click = self.change_sim_state btn.add(5) # Particle mass scale self.mass_scale = sgc.Scale(label="Particle mass", label_side="top", label_col=self.fgColor, pos=(10, 20), min=1, max=100, min_step=1, max_step=99) self.mass_scale.add(0) # Particle charge scale self.charge_scale = sgc.Scale(label="Particle charge", label_side="top", label_col=self.fgColor, pos=(10, 90), min=0, max=100, min_step=1, max_step=100) self.charge_scale.add(1) self.dipole_moment_scale = sgc.Scale(label="Particle dipole moment", label_side="top", label_col=self.fgColor, pos=(10, 160), min=0, max=100, min_step=1, max_step=100) self.dipole_moment_scale.add(2) self.polarizability_scale = sgc.Scale(label="Particle polarizability", label_side="top", label_col=self.fgColor, pos=(10, 230), min=0, max=100000, min_step=1, max_step=99999) self.polarizability_scale.add(3) self.stiffness_scale = sgc.Scale(label="Stiffness", label_side="top", label_col=self.fgColor, pos=(10, 300), min=0, max=100, min_step=1, max_step=100) self.stiffness_scale.add(4) self.friction_scale = sgc.Scale(label="Friction", label_side="top", label_col=self.fgColor, pos=(10, 370), min=0, max=100, min_step=1, max_step=100) self.friction_scale.add(5) self.mass_scale.value = self.current_mass_value self.charge_scale.value = self.current_charge_value self.dipole_moment_scale.value = self.current_dipole_moment self.polarizability_scale.value = self.current_polarizability self.stiffness_scale.value = self.current_stiffness self.friction_scale.value = self.current_friction self.clock = pygame.time.Clock()
def main(): # Global variables & constants global ZMQ_TIMEOUT ZMQ_TIMEOUT = 2.4 # Start information provider global pageInfo pageInfo = pageInfoProvider() pageInfo.daemon = True pageInfo.start() # Start MABx message receiver # mabxMsg = carserver.carInfo('MABx Messages', 1, 99999,['Code'],['']) # mabxMsg.daemon = True # mabxMsg.start() # Pygame surfaces global screen screen = sgc.surface.Screen((LCDW, LCDH)) clock = pygame.time.Clock() # Fill background global background background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((20, 25, 25)) # Start threads that depend on Pygame # Homebrew notification manager global notify notify = notificationMgr() notify.daemon = True # Air conditioning manager global hvac hvac = carserver.hvacMgr('hvac', 5556) hvac.daemon = True hvac.start() # Text data is handled by the page thing infoFont = pygame.font.Font(os.path.join('res', 'Ticketing.otf'), 42) # Put on the button row btnFont = pygame.font.Font(os.path.join('res', 'OSP-DIN.ttf'), 28) acbtnFont = pygame.font.Font(os.path.join('res', 'OSP-DIN.ttf'), 22) btnLabel = ['ESS', 'HVAC', 'MABx', 'TM4', 'Top Bar test', 'Override Msg'] btnPos = [25, LCDH - 80] # Painstakingly defining each button i = 0 btn0 = sgc.Button(label=btnLabel[i], pos=(btnPos[0], btnPos[1]), col=(225, 128, 0), label_font=(btnFont)) btn0.on_click = test_btn0 i += 1 btnPos[0] += 120 btn1 = sgc.Button(label=btnLabel[i], pos=(btnPos[0], btnPos[1]), col=(107, 28, 214), label_font=(btnFont)) btn1.on_click = test_btn1 i += 1 btnPos[0] += 120 btn2 = sgc.Button(label=btnLabel[i], pos=(btnPos[0], btnPos[1]), col=(0, 180, 0), label_font=(btnFont)) btn2.on_click = test_btn2 i += 1 btnPos[0] += 120 btn3 = sgc.Button(label=btnLabel[i], pos=(btnPos[0], btnPos[1]), col=(0, 180, 0), label_font=(btnFont)) btn3.on_click = test_btn3 i += 1 btnPos[0] += 120 btn4 = sgc.Button(label=btnLabel[i], pos=(btnPos[0], btnPos[1]), col=(0, 180, 0), label_font=(btnFont)) btn4.on_click = test_btn4 i += 1 btnPos[0] += 120 btn5 = sgc.Button(label=btnLabel[i], pos=(btnPos[0], btnPos[1]), col=(0, 180, 0), label_font=(btnFont)) btn5.on_click = test_btn5 btnDismiss = sgc.Button(label="Dismiss", pos=(25, 405), col=(1, 1, 1), label_font=(btnFont)) btnDismiss.on_click = dismiss_overlay acbtnPos = [25, 100] global acbtnOn acbtnOn = sgc.Switch(label="AC", pos=(acbtnPos[0], acbtnPos[1]), label_font=(acbtnFont), label_side="top") acbtnPos[0] += 140 global acbtnTemp acbtnTemp = sgc.Scale(label="Temperature", pos=(acbtnPos[0], acbtnPos[1]), label_font=(acbtnFont), label_side="top", min=hvac.MIN_TEMP, max=hvac.MAX_TEMP) acbtnPos[0] += 260 global acbtnFanSpd acbtnFanSpd = sgc.Scale(label="Fan Speed", pos=(acbtnPos[0], acbtnPos[1]), label_font=(acbtnFont), label_side="top") acbtnPos = [25, 180] global acbtnRecirc acbtnRecirc = sgc.Switch(label="Recirc", pos=(acbtnPos[0], acbtnPos[1]), label_font=(acbtnFont), label_side="top") notify.start() # Display the welcome message and start notification mgr showMenuButton = True showACButton = False pageInfo.setPage(0) notify.send(-1, 'MalibuTake2 main Pygame loop started') while True: sgctime = clock.tick(30) for event in pygame.event.get(): sgc.event(event) if event.type == GUI: print(event) if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): exit() if event.type == MOUSEBUTTONDOWN: if event.button == 1: if event.pos[1] <= 60: # If click is in the top 60 pixels, go to message centre pageInfo.setPage(9) # Button handlers if showMenuButton: btnDismiss.remove(1) btn0.add(0) btn1.add(0) btn2.add(0) btn3.add(0) btn4.add(0) btn5.add(0) elif not showMenuButton: btn0.remove(0) btn1.remove(0) btn2.remove(0) btn3.remove(0) btn4.remove(0) btn5.remove(0) if showACButton: hvac.pauseThread = False acbtnOn.add(0) acbtnTemp.add(0) acbtnFanSpd.add(0) acbtnRecirc.add(0) else: hvac.pauseThread = True acbtnOn.remove(0) acbtnTemp.remove(0) acbtnFanSpd.remove(0) acbtnRecirc.remove(0) # if pageInfo.activePage == 1: # afsd.add(0) # else: # asdf.remove(0) # Notifications are ran independently. Let's check on them: if notify.overlayActive: # Overlay notification page showACButton = False showMenuButton = False btn0.remove dispScreen = pygame.display.set_mode([LCDW, LCDH]) pygame.draw.rect(dispScreen, (200, 200, 200), (0, 0, LCDW, LCDH), 0) pygame.draw.rect(dispScreen, (200, 10, 10), (0, 0, LCDW, LCDH), 24) warnFont = pygame.font.Font(os.path.join('res', 'OSP-DIN.ttf'), 56) warnTxtPos = background.get_rect() warnTxtPos.left = 50 warnTxtPos.centery = 320 dispScreen.blit(warnFont.render(notify.OverlayText, 1, (180, 0, 0)), warnTxtPos) btnDismiss.add(0) elif pageInfo.activePage == 1: # HVAC Page showACButton = True showMenuButton = True screen.blit(background, (0, 60)) # redraws background to cover everything up. 60 pixels top bar. hvac.update([acbtnOn.state, acbtnTemp.value, acbtnFanSpd.value, acbtnRecirc.state]) # dispScreen = pygame.display.set_mode([LCDW,LCDH]) elif pageInfo.activePage == 9: # Message Centre showACButton = False showMenuButton = True screen.blit(background, (0, 60)) # redraws background to cover everything up. 60 pixels top bar. thisLinePos = screen.get_rect() thisLinePos.top = 80 thisLineColour = (190, 190, 190) thisLineKind = '?' msgListFont = pygame.font.Font(os.path.join('res', 'SourceSansPro-Regular.otf'), 24) listStart = len(notify.msgQueue) - 30 if(listStart < 1): listStart = 1 # Anything above 0, because that's the logo for i in xrange(listStart, len(notify.msgQueue)): kind = notify.msgQueue[i][1] if kind == -1: thisLineColour = (190, 190, 190) thisLineKind = 'LOG' elif kind == 1: thisLineColour = (90, 90, 190) thisLineKind = 'INFO' elif kind == 2: thisLineColour = (255, 230, 82) thisLineKind = 'CAUT' elif kind == 3: thisLineColour = (200, 0, 0) thisLineKind = 'WARN' thisLinePos.left = 25 screen.blit(msgListFont.render(str(i), 1, thisLineColour), thisLinePos) thisLinePos.left += 30 screen.blit(msgListFont.render(datetime.datetime.fromtimestamp(notify.msgQueue[i][0]).strftime('%H:%M:%S'), 1, thisLineColour), thisLinePos) thisLinePos.left += 90 screen.blit(msgListFont.render(thisLineKind, 1, thisLineColour), thisLinePos) thisLinePos.left += 70 screen.blit(msgListFont.render(notify.msgQueue[i][2], 1, thisLineColour), thisLinePos) thisLinePos.centery += 25 else: # Normal information page showACButton = False showMenuButton = True screen.blit(background, (0, 60)) # redraws background to cover everything up. 60 pixels top bar. thisLinePos = screen.get_rect() thisLinePos.top = 80 # print mabxMsg.data # print pageInfo.zmq_receiver.data for i in xrange(0, pageInfo.getDataLen()): thisLinePos.left = 25 screen.blit(infoFont.render(str(pageInfo.zmq_receiver.data[0][i]), 1, (0, 144, 0)), thisLinePos) thisLinePos.left += LCDW * 0.3 screen.blit(infoFont.render(str(pageInfo.zmq_receiver.data[1][i]), 1, (0, 222, 0)), thisLinePos) thisLinePos.left += LCDW * 0.4 screen.blit(infoFont.render(str(pageInfo.zmq_receiver.data[2][i]), 1, (155, 155, 155)), thisLinePos) thisLinePos.centery += 50 sgc.update(sgctime) pygame.display.flip()