def make_window(): global win_num win_num += 1 win = TestWindow(size=(260, 200), title="Text fields %d" % (win_num)) win.tf1 = TextField(position=(20, 20), width=200) #say("Field 1 Height =", win.tf1.height) ### win.tf2 = TextField(position=(20, win.tf1.bottom + 10), width=200, text="Spam\nGlorious Spam", multiline=True, lines=2) #say("Field 2 Height =", win.tf2.height) ### win.tf3 = TextField(position=(20, win.tf2.bottom + 10), width=200, font=fancy) show_but = Button("Show", position=(20, win.tf3.bottom + 20), action=(show_text, win)) sel_but = Button("Select", position=(show_but.right + 5, win.tf3.bottom + 20), action=(select_text, win)) new_but = Button("New", position=(sel_but.right + 5, win.tf3.bottom + 20), action=make_window) win.add(win.tf1) win.add(win.tf2) win.add(win.tf3) win.add(show_but) win.add(sel_but) win.add(new_but) win.height = show_but.bottom + 20 win.tf1.become_target() win.show() return win
def setupComponents(self, parent): separation = 5 bottom = self.height - 50 inventoryHeight = ((INVENTORYSLOTS - 1) / 8 + 1) * (30 + separation) descriptionHeight = 110 #EquipmentTopLeft = (10, 10) #InventoryTopLeft = (10, bottom - inventoryHeight) #InvDescriptionTopLeft = (10, bottom - inventoryHeight - descriptionHeight) #EquipDescriptionTopLeft = (10, bottom - inventoryHeight - descriptionHeight * 2) InventoryTopLeft = (10, 10) InvDescriptionTopLeft = (10, 10 + inventoryHeight) EquipmentTopLeft = (10, 10 + inventoryHeight + 10 + descriptionHeight + 20) EquipDescriptionTopLeft = (10, 10 + inventoryHeight + 10 + descriptionHeight + 20 + 2 * (30 + separation)) self.equipmentSlots = [] for i in range(EQUIPMENTSLOTS): on = len(self.equipmentSlots) esl = InventorySlot( position=(EquipmentTopLeft[0] + (30 + separation) * (on % 7), EquipmentTopLeft[1] + (30 + separation) * (on / 7))) self.equipmentSlots += [esl] esl.setupComponents(self, [EQUIPMENTSLOT, on]) self.add(esl) self.inventorySlots = [] for i in range(INVENTORYSLOTS): on = len(self.inventorySlots) isl = InventorySlot( position=(InventoryTopLeft[0] + (30 + separation) * (on % 8), InventoryTopLeft[1] + (30 + separation) * (on / 8))) self.inventorySlots += [isl] isl.setupComponents(self, [INVENTORYSLOT, on]) self.add(isl) self.inventoryDescriptionField = TextField( multiline=True, size=(self.width - InvDescriptionTopLeft[0] * 2, 100), position=InvDescriptionTopLeft, enabled=False) self.add(self.inventoryDescriptionField) self.equippedDescriptionField = TextField( multiline=True, size=(self.width - EquipDescriptionTopLeft[0] * 2, 100), position=EquipDescriptionTopLeft, enabled=False) self.add(self.equippedDescriptionField) ViewWithBackButton.setupComponents(self, parent)
def make_window(): win = Window(size=(240, 100), title="Password") tf = TextField(position=(20, 20), width=200, password=True) ok = Button("OK", position=(20, 60), action=(show, tf)) win.add(tf) win.add(ok) win.show()
def __init__(self, action, **kwargs): title = 'Password' self._action = action lbl_text = action.get_pass_desc() ModalDialog.__init__(self, title=title) label = Label(lbl_text) self.txt_passwd = TextField(multiline=False, password=True) self.ok_button = Button("Connect", action="ok", enabled=True, style='default') self.cancel_button = Button("Cancel", enabled=True, style='cancel', action='cancel') self.place(label, left=padding, top=padding) self.place(self.txt_passwd, left=padding, top=label + padding, right=label.right if label.right > 260 else 260) self.place(self.cancel_button, top=self.txt_passwd + padding, right=self.txt_passwd.right) self.place(self.ok_button, top=self.txt_passwd + padding, right=self.cancel_button - padding) self.shrink_wrap(padding=(padding, padding))
def main(): f = None args = sys.argv[1:] if args: fontsize = int(args[0]) sf = StdFonts.system_font f = Font(sf.family, fontsize, sf.style) #showfont("Using font", f) win = Window(title="Heights") if f: kwds = {'font': f} else: kwds = {} controls = [ Label(text="Label", **kwds), TextField(text="Text", **kwds), CheckBox(title="Check", **kwds), RadioButton(title="Radio", **kwds), Slider(orient='h', width=50), #Button(title = "Button", **kwds), ] #for ctl in controls: # say("Height of %r is %s" % (ctl, ctl.height)) win.place_row(controls, left=10, top=10) win.shrink_wrap(padding=(10, 10)) win.show() run()
def main(): global cb1, cb2, rg win = Window(title="Place Me By Your Side", width=720, height=500) view1 = TestDrawing(width=320, height=200) cb1 = CheckBox(title="Check Me!", action=checked_it) cb2 = CheckBox(title="Check Me Too!", action=checked_it) rbs = [] for i in range(1, 4): rb = RadioButton(title="Hoopy Option %d" % i, value=i) rbs.append(rb) rg = RadioGroup(rbs, action=option_chosen) pb = Button(title="Push Me!", action=pushed_it) view2 = TestScrollableDrawing(width=300, height=300) label = Label(text="Flavour:") entry = TextField(width=200) win.place(view1, left=10, top=10, border=1) win.place_row([cb1, cb2], left=10, top=(view1, 20), spacing=20) win.place_column(rbs, left=view1 + 20, top=10) win.place(pb, right=-20, bottom=-10, anchor='rb') win.place(view2, left=rbs[0] + 20, top=10, right=-20, bottom=pb - 10, scrolling='hv', anchor='ltrb', border=1) win.place(label, left=10, top=(cb1, 20)) win.place( entry, left=10, top=(label, 10), #border = 1 ) entry.become_target() win.show() import GUI GUI.run()
def make_row(align): return Row([ CheckBox("One"), Label("Two"), TextField(text="Three", size=(100, 50)), Button("Four"), ], expand=2, align=align)
def test(): def bing(): say("Bing!") #fld._win_dump_flags() win = Window(title = "Shrink Wrap", resizable = 0) but = Button("Bing!", action = bing) cbx = CheckBox("Spam") fld = TextField(width = 100) win.place(but, left = 20, top = 20) win.place(cbx, left = but + 20, top = 20) win.place(fld, left = 20, top = but + 20) win.shrink_wrap() win.show() application().run()
def modal_dialog(): #global dlog ### dlog = ModalDialog(title="Spanish Inquisition", size=(200, 140)) dlog.place(Label(text="Surprise!!!"), left=20, top=20) field = TextField() dlog.place(field, left=20, top=60, right=-20) field.become_target() dlog.default_button = DefaultButton() dlog.cancel_button = CancelButton() dlog.place(dlog.default_button, right=-20, bottom=-20) dlog.place(dlog.cancel_button, left=20, bottom=-20) dlog.center() result = dlog.present() say("Result =", result) dlog.destroy()
def setupComponents(self, parent): self.learnedAbilities = [] separation = 5 bottom = self.height - 50 inventoryHeight = ( (ABILITYDISPLAYSLOTS - 1) / 8 + 1) * (40 + separation) descriptionHeight = 110 EquipmentTopLeft = (self.width / 2, 10) InventoryTopLeft = (10, 10 + (40 + separation) + descriptionHeight + 10 * 2) EquipDescriptionTopLeft = (10, 10 + (40 + separation) + 10 * 1) self.abilitySlots = [] for i in range(ABILITYSLOTS): on = len(self.abilitySlots) abilSlot = AbilitySlot( position=(EquipmentTopLeft[0] + (40 + separation) * on - (40 + separation) * ABILITYSLOTS / 2, EquipmentTopLeft[1])) self.abilitySlots += [abilSlot] abilSlot.setupComponents(self, [EQUIPPEDSLOT, on]) self.add(abilSlot) self.learnedSlots = [] for i in range(ABILITYDISPLAYSLOTS): on = len(self.learnedSlots) isl = AbilitySlot( position=(InventoryTopLeft[0] + (40 + separation) * (on % 6), InventoryTopLeft[1] + (40 + separation) * (on / 6))) self.learnedSlots += [isl] isl.setupComponents(self, [LEARNEDSLOT, on]) self.add(isl) self.equippedDescriptionField = TextField( multiline=True, size=(self.width - EquipDescriptionTopLeft[0] * 2, 100), position=EquipDescriptionTopLeft, enabled=False) self.add(self.equippedDescriptionField) ViewWithBackButton.setupComponents(self, parent)
def __init__(self, session, transport, **kwargs): title = 'Login' self._session = session self._transport = transport if 'title' in kwargs: title = kwargs['title'] ModalDialog.__init__(self, title=title) label = Label('Key File:') btn_rsa = RadioButton(title='RSA', value='RSA') btn_dss = RadioButton(title='DSS', value='DSS') self.key_file_group = key_file_group = RadioGroup( items=[btn_rsa, btn_dss]) key_file_group.value = 'RSA' self.txt_key_file = txt_key_file = TextField(multiline=False, password=False) btn_browse_file = Button('Browse', action='choose_key_file', enabled=True) lbl_login = Label('Login') self.txt_login = TextField(multiline=False, password=False) if 'username' in kwargs: self.txt_login.text = kwargs['username'] lbl_passwd = Label('Password') self.txt_passwd = TextField(multiline=False, password=True) self.ok_button = Button("Connect", action="ok", enabled=True, style='default') self.cancel_button = Button("Cancel", enabled=True, style='cancel', action='cancel') self.place(label, left=padding, top=padding) self.place(btn_rsa, left=label + padding, top=padding) self.place(btn_dss, left=btn_rsa + padding, top=padding) self.place(txt_key_file, left=padding, top=btn_rsa + padding, right=240) self.place(btn_browse_file, left=txt_key_file, top=txt_key_file.top) self.place(lbl_login, left=padding, top=txt_key_file + padding) self.place(self.txt_login, left=padding, top=lbl_login + padding, right=btn_browse_file.right) self.place(lbl_passwd, left=padding, top=self.txt_login + padding) self.place(self.txt_passwd, left=padding, top=lbl_passwd + padding, right=btn_browse_file.right) self.place(self.cancel_button, top=self.txt_passwd + padding, right=btn_browse_file.right) self.place(self.ok_button, top=self.txt_passwd + padding, right=self.cancel_button - padding) self.shrink_wrap(padding=(padding, padding))
from GUI import Window, CheckBox, Label, TextField, Grid, application from testing import say items = [ [Label("Name"), TextField(width=100)], [Label("Age"), TextField(width=50)], [Label("Language"), CheckBox("Python")], ] grid = Grid(items) win = Window(title="Grid") grid.position = (10, 10) win.add(grid) win.shrink_wrap() win.show() instructions = """ There should be six components laid out in a grid of three rows and two columns. Each component should be centre-left aligned within its cell. """ say(instructions) application().run()
def _get_default_editor(self): editor = self._default_editor if not editor: editor = TextField() self._default_editor = editor return editor
from GUI import Window, Frame from GUI import Button, Label, ListButton, Slider, TextField, CheckBox from GUI import application from GriddedWindow import GriddedWindow w = GriddedWindow(size=(401, 301), style='modal_dialog', title='DemoGui') theme_list_button = ListButton(width=150, titles=['Standard', 'Dark']) theme_list_button = ListButton(width=150, titles=['Standard', 'Dark']) text_label_slider = Slider(orient='h', width=150) volume_text_field = TextField(text='70', width=150) fps_list_button = ListButton(width=150, titles=['29.97', '60.0']) sound_checkbox = CheckBox(title='Sound') save_button = Button('Save', width=80) cancel_button = Button('Cancel', width=80) w.set_inner_sep(10) w.set_col_seps([80]) w.set_row_seps([10, 10, 10, 10, 30]) w.place_item(Label('Theme:'), 0, 0) w.place_item(Label('TextLabel'), 1, 0) w.place_item(Label('Volume:'), 2, 0) w.place_item(Label('FPS:'), 3, 0) w.place_item(theme_list_button, 0, 1) w.place_item(text_label_slider, 1, 1) w.place_item(volume_text_field, 2, 1) w.place_item(fps_list_button, 3, 1) w.place_item(sound_checkbox, 4, 1) w.place_item(save_button, 5, 0) w.place_item(cancel_button, 5, 1)