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)
scroll_box.rect.center = screen.rect.center scroll_box.add(order=1) # Radio Buttons radio1 = sgc.Radio(group="group1", label="Option 1", active=True) radio2 = sgc.Radio(group="group1", label="Option 2") radio3 = sgc.Radio(group="group1", label="Option 3") radio_box = sgc.VBox(widgets=(radio1, radio2, radio3), pos=(40, 320)) radio_box.add(order=2) # Toggle Button switch = sgc.Switch(label="Switch", pos=(200, 320)) switch.add(order=3) # Scale widget scale = sgc.Scale(pos=(50, 400), show_value=4) scale.add(order=4) # Combo box combo = sgc.Combo(pos=(400, 400), values=("Option 1", "Option 2", "Another")) combo.add(order=5) # Selectable Label label = sgc.Label(text="This is a selectable label", selectable=True) label.rect.midtop = title.rect.midbottom label.add() # ds9=pygame.image.load(r"..\extentions\stock\civs\bajor\teroknorinorbit.jpg") while True: time = clock.tick()
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()
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()
radio_2 = sgc.Radio(label = "Shotgun", group = "weapon") radio_3 = sgc.Radio(label = "Sniper", group = "weapon") radio_box = sgc.VBox(widgets = (radio_1, radio_2, radio_3), pos = (50, 50)) ### switch switch = sgc.Switch(label = "Limit Bullets", pos = (300, 200), label_side = "top") ## slider slider = sgc.Scale(label = "Number of Monsters", pos = (10, 200), label_side = "top", label_col = (255, 255, 0)) label = sgc.Label(text = "This is a zombie shooter game \n" + "in which you journey through eight \n" + "levels to save a girl from \n" + "monsters. Good Luck!", pos = (10, 10), font = bloody, col = (255, 0, 0)) btn.add(0) btn2.add(1) combo.add(2) radio_box.add(3) switch.add(4) slider.add(5)