def __init__(self): gui.Container.__init__(self) label = gui.Label("Text: ", color=fontcolor) self.textArea = gui.TextArea(value="", width=512 - label.style.width - 32, height=64, size=16) self.add(label, 0, (self.textArea.style.height - label.style.height) / 2) self.add(self.textArea, label.style.width, 0) self.engine = None
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, align=-1) c.tr() t = gui.TextArea(width=self.get("text_area_width"), height=self.get("text_area_height")) c.td(t, align=-1) c.tr() e = gui.Button(self.get("accept_text")) e.connect(gui.CLICK, self.app.quit, None) c.td(e, align=-1, height=32, valign=1) # Keep running the app until a response has been received while True: self.app.run(c) if t.value.strip() != "" or self.get("allow_empty") == "yes": break # Set the response and response time self.experiment.set( "response", self.experiment.usanitize(unicode(QtCore.QString( t.value.strip())))) self.experiment.set("response_time", self.time() - self.sri) # Return success return True
c.td(gui.Tool(g, gui.Label('B'), value='b')) c.td(gui.Tool(g, gui.Label('C'), value='c')) c.tr() c.td(gui.Label("Input")) def cb(): print("Input received") w = gui.Input(value='Cuzco', size=8) w.connect("activate", cb) c.td(w, colspan=3) c.tr() c.td(gui.Label("Slider")) c.td(gui.HSlider(value=23, min=0, max=100, size=20, width=120), colspan=3) c.tr() c.td(gui.Label("Keysym")) c.td(gui.Keysym(), colspan=3) c.tr() c.td(gui.Label("Text Area"), colspan=4, align=-1) c.tr() c.td(gui.TextArea(value="Cuzco the Goat", width=150, height=70), colspan=4) app.run(c)
def Create_input(): #Opens screen to handle text input from the user global Window, input_initialized, can_execute, Frame, input_from_user input_initialized = True #App over toolbar app = gui.App(screen=Window, area=Frame) app.connect(gui.QUIT, app.quit, None) my_container1 = gui.Container(width=670, height=500) #Label to write code Label_code = gui.Label("Escribe/modifica tu código:") #Label to buttons Label_buttons = gui.Label("Cambios realizados:") #Cancel button cancel_btn = gui.Button("Cancelar") cancel_btn.connect(gui.CLICK, app.quit, None) #To save current input on the display def cb(): global input_from_user, can_execute input_from_user = textarea_code.value can_execute = False app.quit() #Save button save_btn = gui.Button("Guardar") save_btn.connect(gui.CLICK, cb) #Checks for previous program if input_from_user == "": previous_text = "miPrograma Uno;\n{\ncrearPersonaje Nombre;\nvar Mi numero = 3;\nMi = 5;\nNombre.abajo(1);\n}" else: previous_text = input_from_user textarea_code = gui.TextArea(value=previous_text, width=235, height=360) 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() #Help button help_btn = gui.Button("Instrucciones") help_btn.connect(gui.CLICK, help) 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() #file treatment file_btn = gui.Button("Archivo") file_btn.connect(gui.CLICK, file_treat) # Display the background when playing as beginner def hint(): global numero_hint, Window #Window.fill(const.green) if numero_hint < 5: numero_hint = numero_hint + 1 else: numero_hint = 1 #Hint images for level 1 if dificulty_level == 1: if numero_hint == 1: img = images[0] elif numero_hint == 2: img = images[1] elif numero_hint == 3: img = images[2] elif numero_hint == 4: img = images[3] elif numero_hint == 5: img = images[4] img.set_colorkey(RLEACCEL) rect = Rect((-8, 35), (0, 0)) #Window.fill(const.green) Window.blit(img, rect) #Update_display() pygame.display.flip() #Next tip button hint_btn = gui.Button("Siguiente tip") hint_btn.connect(gui.CLICK, hint) #Add items to container my_container1.add(Label_buttons, 462, 30) my_container1.add(cancel_btn, 450, 50) my_container1.add(save_btn, 550, 50) my_container1.add(file_btn, 500, 5) my_container1.add(Label_code, 419, 75) my_container1.add(textarea_code, 419, 95) my_container1.add(help_btn, 480, 470) if dificulty_level == 1: my_container1.add(hint_btn, 145, 415) app.run(my_container1)
def build(self): panel.Panel.build(self) fileButtonsTable = gui.Table(width=120, height=geom['panel'].height) buttons = [(_("Quit"), "file-button-quit", self.quit), (_("New"), "file-button-new", self.openNewDialog), (_("Open"), "file-button-load", self.openLoadDialog), (_("Save"), "file-button-save", self.openSaveDialog), (_("Save As"), "file-button-saveAs", self.openSaveAsDialog), (_("Export"), "file-button-export", self.checkIfScriptNamed) ] for aButton in buttons: properName, internalName, function = aButton aButton = gui.Button(properName, name=internalName, style={ 'width': 90, 'height': 30 }) aButton.connect(gui.CLICK, function) fileButtonsTable.tr() fileButtonsTable.td(aButton, align=0) if properName == _("Save"): self.saveButton = aButton self.add(fileButtonsTable, 0, 0) self.owningWidgets.append(fileButtonsTable) logoImage = gui.Image(images['main-logo']) logoImage.connect(gui.CLICK, self.openCreditsDialog) self.add(logoImage, 160, 70) self.owningWidgets.append(logoImage) #creditsButton= gui.Button(_("Credits"), name= 'file-button-credits', style={'width': 80, 'height': 40}); #creditsButton.connect(gui.CLICK, self.openCreditsDialog); #self.add(creditsButton, 255, 175); #self.owningWidgets.append(creditsButton); fileDocument = gui.Document(width=geom['panel'].width // 2, align=-1) fileDocument.add(gui.Label(_("Title: ")), align=-1) titleInput = gui.Input(name='file-input-title', value=self.script.metadata.title, size=30) titleInput.connect(gui.CHANGE, self.modifyScriptMetadata, 'title') fileDocument.add(titleInput, align=1) fileDocument.space((10, 40)) fileDocument.br(1) fileDocument.add(gui.Label(_("Author(s): ")), align=-1) authorInput = gui.Input(name='file-input-author', value=self.script.metadata.author, size=30) authorInput.connect(gui.CHANGE, self.modifyScriptMetadata, 'author') fileDocument.add(authorInput, align=1) fileDocument.space((10, 40)) fileDocument.br(1) fileDocument.add(gui.Label(_("Description: ")), align=-1) fileDocument.br(1) descriptionArea = gui.TextArea(name='file-textArea-description', value=self.script.metadata.description, width=geom['panel'].width // 2 - 11, height=geom['panel'].height // 3) descriptionArea.connect(gui.CHANGE, self.modifyScriptMetadata, 'description') fileDocument.add(descriptionArea, align=-1) fileDocument.space((10, 10)) self.add(fileDocument, 500, 30) self.owningWidgets.append(fileDocument) # languageSelector= gui.Select(name='file-button-language', value=language, cols=2); ## languageSelector.connect(gui.SELECT, self.changePose); # for aLanguage in languages: # prettyLanguage= aLanguage.replace('_',' '); # languageSelector.add(prettyLanguage, aLanguage); # languageSelector.connect(gui.SELECT, self.changeLanguage) #self.add(languageSelector, 730, 170); #self.owningWidgets.append(languageSelector); self.script.controls[ "file-button-save"].disabled = not self.script.unsaved
class SkeletonControl(gui.Table): run_capture = False mydatetime = "0-0-0-0-0-0-0" status = "When there is a skeleton picture, click 'start' to record" textarea = gui.TextArea(value=status, width=500, height=20) name = gui.Input(value='', size=8) kl_result = gui.Input(value='', size=8) save_pic = False def __init__(self, **params): gui.Table.__init__(self, **params) fg = (255, 255, 255) # self.timesup_dialog = TimesUpDialog() self.tr() self.td(gui.Label("Skeleton GUI", color=fg), colspan=2) self.tr() self.td(gui.Label("Name: ", color=fg), align=1) self.td(self.name, colspan=3) self.tr() self.td(gui.Label("KL_Result: ", color=fg), align=1) self.td(self.kl_result, colspan=3) self.tr() self.td(gui.Label("Sex: ", color=fg), align=1) self.sex = gui.Input(value='', size=8) self.td(self.sex, colspan=3) self.tr() self.td(gui.Label("Age: ", color=fg), align=1) self.age = gui.Input(value='', size=8) self.td(self.age, colspan=3) self.tr() self.td(gui.Label("Height(m): ", color=fg), align=1) self.height = gui.Input(value='', size=8) self.td(self.height, colspan=3) self.tr() self.td(gui.Label("Weight(kg): ", color=fg), align=1) self.weight = gui.Input(value='', size=8) self.td(self.weight, colspan=3) # self.run_capture = False # self.mydatetime = "default" def click_start_btn(): if SkeletonControl.run_capture: self.textarea.value = "Recording Already Running" return else: msg = "startrecording" + "-" + self.name.value + '-' + self.kl_result.value for i in range(10): self.lan_broadcast_msg(msg) def get_datetime_string(): string = str(datetime.now()) mydate, mytime = string.split(" ") hour, minute, second = mytime.split(":") second = float(second) millisecond = str(int((second - int(second)) * 1000)) second = str(int(second)) return mydate + "-" + hour + '-' + minute + '-' + second + '-' + millisecond # self.mydatetime = get_datetime_string() # self.textarea.value = "recording" def times_up(): # self.run_capture = False msg = 'timesup' for i in range(10): self.lan_broadcast_msg(msg) self.textarea.value = "times up, recording stopped" # self.timesup_dialog.open() s = sched.scheduler(time.time, time.sleep) s.enter(10, 1, times_up, ()) t = threading.Thread(target=s.run) t.start() start_btn = gui.Button("Start") start_btn.connect(gui.CLICK, click_start_btn) self.tr() self.td(start_btn, colspan=3) def click_stop_btn(): if SkeletonControl.run_capture: SkeletonControl.run_capture = False self.textarea.value = "recording stopped" else: self.textarea.value = "You hava to start recording first!!!" # self.timesup_dialog.open() stop_btn = gui.Button("Stop") stop_btn.connect(gui.CLICK, click_stop_btn) self.tr() self.td(stop_btn, colspan=3) def click_save_pic_btn(): SkeletonControl.save_pic = True # print 'test' # print self.save_pic save_pic_btn = gui.Button("Save Pic") save_pic_btn.connect(gui.CLICK, click_save_pic_btn) self.tr() self.td(save_pic_btn, colspan=3) self.tr() self.td(gui.Label("MassageBox: ", color=fg), align=1) self.td(SkeletonControl.textarea, colspan=4) def lan_broadcast_msg(self, msg): host = "<broadcast>" # broadcast port = 6666 addr = (host, port) UDPSock = socket(AF_INET, SOCK_DGRAM) UDPSock.bind(("", 0)) UDPSock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) # buffer = msg.encode('utf-8') # UDPSock.sendto(buffer, addr) UDPSock.sendto(msg, addr) UDPSock.close()
app.connect(gui.QUIT, app.quit, None) c = gui.Table(width=200, height=120) def cb(): print(size.value, text.value, select.value) app.quit() def updateSize(): print((str(size.value))) text = gui.TextArea(value="", width=150, height=70) btn = gui.Button("Quit") btn.connect(gui.CLICK, cb) size = gui.HSlider(value=23, min=0, max=100, size=20, height=16, width=120) size.connect(gui.CHANGE, updateSize) c.tr() c.td(gui.Label("Select")) select = gui.Select() for i in range(1, 5): select.add(str(i), i) select.connect(gui.CHANGE, cb)