def build_slots(self): slots_group = gui.Group(value=self.inp['slot']) slots = gui.Table() for slot in [1, 2, 3]: slots.tr() if slot in self.slots: slots.td(gui.Tool(slots_group, gui.Image(p('icons/slot%d.png' % (slot))), value=slot)) # if this slot is already selected make it visible elif slot == self.inp['slot']: slots.td(gui.Tool(slots_group, gui.Image(p('icons/slot%d.png' % (slot))), value=slot, pcls='down')) else: slots.td(gui.Image(p('icons/slot%d.png' % (slot)))) slots.tr() slots.td(gui.Tool(slots_group, gui.Label('None'), value=0)) slots_group.connect(gui.CHANGE, self.slot_change, slots_group) return slots
def build_sensors(self): sensors_group = gui.Group(value='') sensors = gui.Table() sensors.tr() sensors.td( gui.Tool(sensors_group, gui.Image(p('icons/light.png')), value='light')) sensors.tr() sensors.td( gui.Tool(sensors_group, gui.Image(p('icons/sonic.png')), value='sonic')) sensors.tr() sensors.td( gui.Tool(sensors_group, gui.Image(p('icons/touch.png')), value='touch')) sensors.tr() sensors.td( gui.Tool(sensors_group, gui.Image(p('icons/compass.png')), value='compass')) sensors.tr() sensors.td(gui.Tool(sensors_group, gui.Label('None'), value='')) sensors_group.connect(gui.CHANGE, self.sensor_change, sensors_group) return sensors
def __init__(self, ship=None, system=None): self.ship = ship self.system = system self.position = 1500, 705 self.container = pgui.Container(width=300, height=100) # any fixed value works self.minimap_icon = pgui.Image(texture["minimap"]) self.container.add(self.minimap_icon, 0 ,0) self.targets = [] self.button = pgui.Image(texture["minimap_button"]) def button_code(value): print("pressed! minimap button") self.button.connect(pgui.CLICK, button_code, None) self.container.add(self.button, 285,232) self.last_velocity=-1 blank_velocity_surface = pygame.Surface((90,263)) self.velocity_shader = pgui.Image(blank_velocity_surface) self.container.add(self.velocity_shader, 7, 37) self.mode = self.GLOBAL self. map_surface = pgui.Image(pygame.Surface((320,320),pygame.SRCALPHA,32)) self.container.add(self.map_surface, 44,7) self.update()
def icon(self, iconName, size=16, color="black", scale="auto"): """ get a gui.Image from the icon font @iconName the css name of the icon Note: homeAssistant uses a mdi: prefix & is converted to our prefix @size the icon size in px (w=h), default 16 @color the color of the icon you want, default black @scale the scaling to use, default auto """ if iconName.startswith("mdi:"): iconName = iconName.replace('mdi:', 'mdi-', 1) file = "{}-x{}-c{}-s{}-HUD.png".format(iconName, str(size), color, str(scale)) # if we find a file in the tmp folder, use that if os.path.isfile("{}/{}".format("/tmp", iconName)): return gui.Image("{}/{}".format("/tmp", iconName)) self.icons.export_icon(iconName, size, filename=file, export_dir="/tmp", color=color, scale=scale) return gui.Image("{}/{}".format("/tmp", file))
def __init__(self, instance = None, ship = None): class Fake_It_Till_You_Make_It: day = 0 scrap = 0 influence = 0 fuel = 160 max_fuel = 200 if instance is None: instance = Fake_It_Till_You_Make_It() if ship is None: ship = Fake_It_Till_You_Make_It() self.last_fuel=-1 self.ship = ship self.instance = instance self.container = pgui.Container(width=300, height=100) self.position = 1920-720, 0 self.container.add(pgui.Image(texture["stat_block_background"]), 0,0) self.label_date = pgui.Label("") blank_fuel_surface = pygame.Surface((256,74)) self.label_fuel = pgui.Image(blank_fuel_surface) self.label_influence = pgui.Label("") self.label_scrap = pgui.Label("") self.label_date.set_font(font["ui_font_2"]) self.label_influence.set_font(font["ui_font_2"]) self.label_scrap.set_font(font["ui_font_2"]) self.container.add(self.label_date, 360, 16) self.container.add(self.label_fuel, 375, 75) self.container.add(self.label_influence, 590, 16) self.container.add(self.label_scrap, 190, 16) self.update()
def __init__(self, **params): title = gui.Label("Settings") self.value = gui.Form() self.container = gui.Container() table = gui.Table() table.tr() self.sensors_img = gui.Image(p('icons/sensors.jpg')) table.td(self.sensors_img, cellspan=3) spacer = gui.Image(p('icons/choose_port.png')) self.box = gui.ScrollArea(spacer) table.tr() table.td(self.box, style={'border': 1}) table.tr() table.td(self.build_background_select(), style={ 'padding_top': 10, 'padding_bottom': 10 }) save = gui.Button('Save') save.connect(gui.CLICK, self.send, gui.CHANGE) table.tr() table.td(save, align=1) self.container.add(table, 0, 0) self.init_ports() gui.Dialog.__init__(self, title, self.container)
def handle_data(self,txt): if self.type == 'table': return elif self.type in ('pre','code'): txt = txt.replace("\t"," ") ss = txt.split("\n") if ss[-1] == "": del ss[-1] for sentence in ss: img = self.font.render(sentence,1,self.color) w = gui.Image(img) self.item.add(w) self.item.block(-1) return txt = re.compile("^[\t\r\n]+").sub("",txt) txt = re.compile("[\t\r\n]+$").sub("",txt) tst = re.compile("[\t\r\n]+").sub("",txt) if tst == "": return txt = re.compile("\s+").sub(" ",txt) if txt == "": return if txt == " ": self.item.space(self.font.size(" ")) return for word in txt.split(" "): word = word.replace(chr(160)," ") # #print self.item.cls w = gui.Image(self.font.render(word,1,self.color)) self.item.add(w) self.item.space(self.font.size(" "))
def openSaveAsDialog(self): dialog = None special_button = None if hacks['xo']: t = gui.Table() t.tr() if self.script.journal: t.td(gui.Image("games/broadway/images/dialog-folders.png")) t.tr() t.td(gui.Label(_("Folders"))) else: t.td(gui.Image("games/broadway/images/dialog-journal.png")) t.tr() t.td(gui.Label(_("Journal"))) special_button = gui.Button(t) def closeAndSaveAs(): dialog.close() self.script.refreshTheater() self.script.filepath = None self.script.journal = not self.script.journal self.openSaveAsDialog() special_button.connect(gui.CLICK, closeAndSaveAs) if self.script.journal: if self.script.filepath: saveName = self.script.filepath.metadata['title'] elif self.script.metadata.title: saveName = self.script.metadata.title else: saveName = "" dialog = gui.JournalDialog(_("Save a script"), saveName, True, special_button=special_button) dialog.loadJournalItems( datastore.find({"mime_type": "application/broadway"})[0]) else: if self.script.filepath: saveName = os.path.basename(self.script.filepath) else: saveName = filenameStrip( self.script.metadata.title) + information['filetype'] dialog = gui.FileDialog(_("Save a script"), _("Okay"), path=directories['export-folder'], filter=[information['filetype']], default=saveName, favorites=defaults['favorites'], special_button=special_button) dialog.open() dialog.connect(gui.CLOSE, self.script.refreshTheater) dialog.connect(gui.CHANGE, self.saveFile)
def __init__(self,**params): fga = (255,25,0) title = gui.Label(u"游戏设置",font=psubfts) self.dfstr=[u'普 通',u'高 级',u'专 家',u'大 师'] self.value=gui.Form() tab=gui.Table() tab.tr() tab.td(gui.Spacer(width=8,height=16)) tab.tr() tab.td(gui.Label(u"难 度:",font=psubfts), align=1,valign=1) tt=gui.Table(width=200) sld=gui.HSlider(0,0,3,size=32,width=180,height=25,name='dif') dflb=gui.Label(self.dfstr[sld.value],width=180,font=psubfts,color=fga) sld.connect(gui.CHANGE, self.ajust,(sld,dflb)) tt.tr() tt.td(dflb) tt.tr() tt.td(sld,align=0,width=240) tab.td(tt) tab.tr() tab.td(gui.Spacer(width=8,height=16)) g = gui.Group(name='gstyle',value='style 1') tab.tr() tab.td(gui.Label(u"样 式:",font=psubfts),align=1) tt=gui.Table(width=200) tt.tr() tt.td(gui.Radio(g,value="style 1"),align=1) tt.td(gui.Image('data/s1.gif',width=36,height=36),align=-1) #tt.td(gui.Label(u"一",font=psubfts),align=-1) tt.td(gui.Radio(g,value="style 2"),align=1) tt.td(gui.Image('data/s2.gif',width=36,height=36),align=-1) tt.td(gui.Radio(g,value="style 3"),align=1) tt.td(gui.Image('data/s3.png',width=36,height=36),align=-1) tab.td(tt) tab.tr() tab.td(gui.Spacer(width=8,height=16)) tab.tr() bv=gui.Label(u"确定",font=psubfts,color=fga) bt=gui.Button(bv) bt.connect(gui.CLICK, self.send, gui.CHANGE) tab.td(bt,width=120,align=1) bv=gui.Label(u"取消",font=psubfts,color=fga) bt=gui.Button(bv) bt.connect(gui.CLICK, self.close,None) tab.td(bt) tab.tr() tab.td(gui.Spacer(width=8,height=16)) gui.Dialog.__init__(self, title, tab)
def create_main_app(screen): """Create an app with a background widget.""" app = gui.App() background = pygame.Surface(screen.get_size()) widget = gui.Image(background) app.init(widget, screen) return app
def __init__(self,**params): title = gui.Label("About Cuzco's Paint") width = 900 height = 500 doc = gui.Document(width=width) space = title.style.font.size(" ") doc.block(align=0) for word in """Cuzco's Paint v1.0 by Phil Hassey""".split(" "): doc.add(gui.Label(word)) doc.space(space) doc.br(space[1]) doc.block(align=-1) doc.add(gui.Image("../../../img/gravitas_logo.png"),align=1) for word in """Cuzco's Paint is a revolutionary new paint program it has all the awesome features that you need to paint really great pictures.""".split(" "): doc.add(gui.Label(word)) doc.space(space) doc.br(space[1]) doc.block(align=-1) for word in """Cuzco's Paint will drive you wild! Cuzco's Paint was made as a demo of Phil's Pygame Gui. We hope you enjoy it!""".split(" "): doc.add(gui.Label(word)) doc.space(space) for i in range(0,10): doc.block(align=-1) for word in """This text has been added so we can show off our ScrollArea widget. It is a very nice widget built by Gal Koren!""".split(" "): doc.add(gui.Label(word)) doc.space(space) doc.br(space[1]) gui.Dialog.__init__(self,title,gui.ScrollArea(doc,width,height))
def __init__(self, bckg="None", port=None, **params): self.bckg = bckg self.port = port title = gui.Label("Setting sensor for port %d" % int(self.port)) self.value = gui.Form() self.container = gui.Container() table = gui.Table() table.tr() self.sensors_img = gui.Image(p('icons/sensors.jpg')) table.td(self.sensors_img, cellspan=3) spacer = gui.Spacer(200, 100) self.box = gui.ScrollArea(spacer) table.tr() table.td(self.box, style={'border': 1}) save = gui.Button('Save') save.connect(gui.CLICK, self.send, gui.CHANGE) table.tr() table.td(save, align=1) self.container.add(table, 0, 0) self.init_ports() self.change() gui.Dialog.__init__(self, title, self.container)
def file_treat(): global Window, Frame #TODO Agregar imagen a botones y estilo a fondo third_app = gui.Desktop(screen=Window, area=Frame) third_app.connect(gui.QUIT, third_app.quit, None) third_app.connect(gui.QUIT, app.quit, None) my_container3 = gui.Container(width=670, height=500) #Open button open_btn = gui.Button("Abrir") open_btn.connect(gui.CLICK, open_file_browser, True) #Save button save_btn = gui.Button("Guardar") save_btn.connect(gui.CLICK, open_file_browser, False) #Continue button / close file treatment ok_btn = gui.Button("Listo!") ok_btn.connect(gui.CLICK, third_app.quit, None) ok_btn.connect(gui.CLICK, app.quit, None) #Cancel button cancel_btn = gui.Button("Cancelar") cancel_btn.connect(gui.CLICK, third_app.quit, None) cancel_btn.connect(gui.CLICK, app.quit, None) #Add elements to container my_container3.add( gui.Image(const.imagespath + "Archivo_Background.png"), 0, 0) my_container3.add(open_btn, 155, 330) my_container3.add(save_btn, 455, 330) my_container3.add(ok_btn, 310, 375) my_container3.add(cancel_btn, 580, 10) third_app.run(my_container3) pygame.display.flip()
def _create_image_widget(self, fullpath): """Create an image showing the contents of a save game file.""" try: data, screenshot, level_name, timestamp = read_savegame(fullpath) except Exception: return gui.Label("Bad Save Game") tbl = gui.Table() tbl.tr() if screenshot is None: tbl.td(gui.Label("No screenshot")) else: tbl.td(gui.Image(screenshot)) tbl.tr() if level_name is None: tbl.td(gui.Label("Level: ???")) else: tbl.td(gui.Label("Level: %s" % (level_name, ))) if timestamp is not None: tbl.tr() tbl.td(gui.Label(timestamp.strftime(self.TIMESTAMP_DISPLAY))) return tbl
def update(self): health = self.ship.health empty_health = self.ship.max_health-self.ship.health self.container.widgets.clear() x = 0 for i in range(health): ico = pgui.Image(texture["full_health_point"]) self.container.add(ico, x ,0) x += self.spacing for i in range(empty_health): ico = pgui.Image(texture["empty_health_point"]) self.container.add(ico, x, 0) x += self.spacing
def init_ports(self): self.pt = {} self.pt['img'] = gui.Image(p('icons/w_port%d.png' % int(self.port))) self.inp = {'type': None, 'slot': 0} self.pt['sensors'] = self.build_sensors() self.container.add(self.pt['img'], 30+(60*self.port), 24)
def build(self): """ Virtual function that is called when the Panel is first given focus. Should be used to (re)build any components in the panel. """ self.add( gui.Image(images['main-panel'], name='panel-image-background'), 0, 0)
def handle_image(self,src,alt,ismap,align,width,height): try: w = gui.Image(self.loader.load_image(src)) if align != '': self.item.add(w,_amap[align]) else: self.item.add(w) except: print('handle_image: missing %s'%src)
def run(self): """Run the item""" # Initialize the item self.set_item_onset() self.sri = self.time() self.experiment.set("response", None) self.experiment.set("response_time", None) # Create the app self.app = gui.Desktop(item=self) self.app.connect(gui.QUIT, self.app.quit, None) pad = 0 # The maximum line length, used to pad the options # Create an HTML document for the content doc = html.HTML("") for l in self.experiment.unsanitize(self.get("question")).split("\n"): doc.add(gui.Label(l)) pad = max(pad, len(l)) doc.br(0) # Create a 2-column table, start with the HTML on the first row c = gui.Table() c.tr() c.td(doc, colspan=self.get("maximum_rating") + 1, align=-1) c.tr() surf = pygame.image.load( self.experiment.resource("rating_inactive.png")) self.img_list = [] for i in range(self.get("maximum_rating")): img = gui.Image(surf) img.connect(gui.CLICK, self.set_response, i) c.td(img, align=-1, width=64, height=64) self.img_list.append(img) c.tr() e = gui.Button(self.get("accept_text")) e.connect(gui.CLICK, self.app.quit, None) c.td(e, colspan=self.get("maximum_rating") + 1, align=-1, height=32, valign=1) # Keep running the app until a response has been received while True: self.app.run(c) if self.get("response") != "None": break # Return success return True
def init_ports(self): for x in range(1, 5): self.ports[x] = {} self.ports[x]['img'] = gui.Image(p('icons/port%d.png' % x)) self.ports[x]['img'].connect(gui.CLICK, self.change, x) self.ports[x]['sensors'] = self.build_sensors() self.container.add(self.ports[x]['img'], 30 + (60 * x), 24) self.inputs[x] = {'type': None, 'slot': ''}
def on_enter(self): """Create the Theater""" # The theater is the Sypral Group responsible for holding the # backdrop, actors, and subtitler. It is held by the Script. self.theater = spyral.sprite.Group(self.theaterCamera) bg = spyral.util.new_surface(geom['screen'].size) bg.fill(colors['bg']) self.screenCamera.set_background(bg) self.script = script.Script() self.script.setTheater(self.theater) self.script.setRecorder(self.recorder) self.script.default() self.gui = gui.App(theme=pgu['theme']) self.guiContainer = gui.Container(align=-1, valign=-1) if geom['frame'] != geom['screen']: images['main-background'] = spyral.util.load_image( images['main-background']) croppedFrame = spyral.util.new_surface(geom['screen'].size) croppedFrame.blit(images['main-background'], geom['frame'], area=geom['screen']) images['main-background'] = croppedFrame self.guiContainer.add(gui.Image(images['main-background']), *geom['screen'].topleft) self.guiContainer.add(gui.Image(images['main-tab']), *geom['tab'].topleft) # Tab is used to switch between the different panels self.tab = tab.Tab(self.script) # Add the tab and panel holder to the screen self.guiContainer.add(self.tab, *geom['tab'].topleft) self.guiContainer.add(self.tab.panelHolder, *geom['panel'].topleft) self.script.gui = self.gui self.gui.init(self.guiContainer)
def build_slots(self): slots_group = gui.Group(value=self.inputs[self.port]['slot']) slots = gui.Table() wslots = [self.inputs[self.port]['slot']] + self.slots for slot in [1, 2, 3]: slots.tr() if slot in wslots: slots.td( gui.Tool(slots_group, gui.Image(p('icons/slot%d.png' % (slot))), value=slot)) else: slots.td(gui.Image(p('icons/slot%d.png' % (slot)))) slots.tr() slots.td(gui.Tool(slots_group, gui.Label('None'), value='')) slots_group.connect(gui.CHANGE, self.slot_change, slots_group) return slots
def __init__(self,**params): title = gui.Label("Welcome") doc = gui.Document(width=400) space = title.style.font.size(" ") doc.block(align=-1) doc.add(gui.Image("../../../img/gravyboat_logo_text_alt.png"),align=1) for word in """Welcome to Cuzco's Paint. Cuzco's Paint is a demo of the features of Phil's Pygame GUI. Cuzco's Paint only supports saving in the .TGA format.""".split(" "): doc.add(gui.Label(word)) doc.space(space) gui.Dialog.__init__(self,title,doc)
def buildFocusSelecter(self, focus=None): if self.focusDocument is not None: self.groups = [] self.focusDocument.clear() self.remove(self.focusDocument) if self.focusDocument in self.owningWidgets: self.owningWidgets.remove(self.focusDocument) self.killEditableDocument() actors = self.script.actors if focus is not None: focusGroup = gui.Group('actor-group-focus', focus) else: focusGroup = gui.Group('actor-group-focus', actors[0]) focusGroup.connect(gui.CHANGE, self.changeFocus) self.groups.append(focusGroup) focusDocument = gui.Document() length = 20 - len(actors) i = 0 for anActor in actors: focusToolTable = gui.Table() focusToolTable.tr() focusToolTable.td(gui.Image(anActor.thumb)) focusToolTable.tr() focusToolTable.td(gui.Label(anActor.shortName(length))) focusTool = gui.Tool(focusGroup, focusToolTable, anActor, name='actor-tool-focus-' + str(i)) focusDocument.add(focusTool) focusDocument.add(gui.Spacer(4, 1)) i += 1 if len(actors) < limits['actors']: plusLabel = gui.Label(_("Add actor")) plusTool = gui.Tool(focusGroup, plusLabel, _("Add actor"), style={ 'margin': 10, 'padding': 5 }, name='actor-focus-plusTool') focusDocument.add(plusTool) self.add(focusDocument, 20, 20) self.focusDocument = focusDocument self.buildEditablesDocument() self.owningWidgets.append(focusDocument)
def change(self): # changing the image spacer = gui.Spacer(200, 100) table = gui.Table() table.tr() table.td(self.pt['sensors']) table.td(gui.Image(p('icons/arrow.png'))) slots = self.build_slots() table.td(slots) table.tr() self.box.widget = table
def BackgroundFromFile(self, tmpfile): size = imagesize.get(tmpfile) if size[0] > (self.width - 100): wpercent = ((self.width - 100) / float(size[0])) hsize = int(float(size[1]) * wpercent) else: hsize = size[1] self.picture = gui.Image(tmpfile, style={ "width": int(self.width - 100), "height": hsize }) self.widget.add(self.picture, 50, 0) self.widget.add(self.name, 10, hsize - (19 * 3)) self.widget.add(self.title, 10, hsize - (19 * 2)) self.widget.add(self.artist, 10, hsize - 19) self.widget.repaint()
def playScript(self): if self.playButton.activated: self.stopScript() self.script.director.stop() else: self.playButton.value = gui.Image(images['media-pause']) self.playButton.activated = True if self.script.director.isDone(): self.script.director.reset() self.progressSlider.value = 0 position = self.progressSlider.value self.script.director.startAt( position, callback=self.stopScript, continualCallback=self.updateProgressBar) self.script.disableControls(['write-button-test']) self.on = False
def __init__(self): super(Menu, self).__init__(theme=gui.Theme('data/themes/clean')) self.active = True self.veil = pygame.Surface((app.screen_width, app.screen_height), pygame.SRCALPHA) self.veil.fill((0, 0, 0, 128)) # Some basic elements label_title = gui.Label('Only fighters', cls='h1', color=(255, 255, 255)) keyboard = gui.Image('data/themes/keyboard.png', align=1) button_hi = gui.Button('Hi world') button_quit = gui.Button('Quit') # Making useful the 'Quit' button button_quit.connect(gui.CLICK, quit, None) # An usage example of a poping dialog t = gui.Table(width=50, height=50) t.tr() t.td(gui.Label('Game made by Álvaro González Redondo')) t.tr() t.td(gui.Label('*****@*****.**')) t.tr() e = gui.Button("Oh. Great.") t.td(e, colspan=2) dialog = gui.Dialog(gui.Label('Hello world'), t) e.connect(gui.CLICK, dialog.close, None) button_hi.connect(gui.CLICK, dialog.open, None) # Arranging the elements of the menu menu = gui.Table(width=500, height=500) menu.tr() menu.td(label_title) menu.tr() menu.td(keyboard) menu.tr() menu.td(button_hi) menu.tr() menu.td(button_quit) # Initializes the object self.init(widget=menu)
def change(self, port): # changing the image self.port_select(port, self.port) self.port = port spacer = gui.Spacer(200, 100) table = gui.Table() table.tr() table.td(self.ports[port]['sensors']) table.td(gui.Image(p('icons/arrow.png'))) slots = self.build_slots() table.td(slots) table.tr() self.box.widget = table
def help(): global Window, Frame, input_from_user #Saves changes on the input input_from_user = textarea_code.value #App over toolbar second_app = gui.Desktop(screen=Window, area=Frame) my_container2 = gui.Container(width=670, height=500) second_app.connect(gui.QUIT, second_app.quit, None) second_app.connect(gui.QUIT, app.quit, None) #Exit button cancel_btn = gui.Button("Regresar") cancel_btn.connect(gui.CLICK, second_app.quit, None) cancel_btn.connect(gui.CLICK, app.quit, None) #Add items to container my_container2.add( gui.Image(const.imagespath + "Instrucciones_Background.png"), 0, 0) my_container2.add(cancel_btn, 575, 10) second_app.run(my_container2) pygame.display.flip()