def __init__(self): ScrollableView.__init__(self) self.text = "_root.onMouseDown = function () {\n\ttrace('Hi');\n};" self.font = Font('Courier', 16) self.selecting = False self.lexer = ActionScriptLexer() self.cursorpos = 0 self.scursorpos = 0 self.selection = (0, 0) self.formatter = PyGUIFormatter() # self.filter = NameHighlightFilter( self.filter = EverythingHighlightFilter( names=['trace'], tokentype=Token.Keyword, names2=['_root', '_global'], tokentype2=Token.Name.Builtin, names3=[ '_alpha', 'blendMode', 'cacheAsBitmap', '_currentframe', '_droptarget', 'enabled', 'filters', 'focusEnabled', '_focusRect', 'forceSmoothing', '_framesloaded', '_height', '_highquality', 'hitArea', '_lockroot', 'menu', 'opaqueBackground', '_parent', '_quality', '_rotation', 'scale9Grid', 'scrollRect', '_soundbuftime', 'tabChildren', 'tabEnabled', 'tabIndex', '_target', 'totalframes', 'trackAsMenu', 'transform', '_url', 'useHandCursor', '_visible', '_width', '_x', '_xmouse', '_xscale', '_y', '_ymouse', '_yscale' ], tokentype3=Token.Name.Variable.Class) self.extent = (self.width, self.height) # Not working - no idea why - disabled to add speed self.lexer.add_filter(self.filter)
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 gui(): screen = pygame.display.set_mode((400, 200)) normal_text = SimpleText("42, c'est moi !", (270, 20), GREEN, anchor=MIDTOP) math_text = LaText(r'$$\sqrt{2}^{7x+3}\times\sum_{k=0}^{\infty} 3A_kf(ke^{i\pi})= 0$$', (200, 100)) matrix = LaText(r""" \[ M= \begin{bmatrix} 1 & 2 & 3 & 4 & 5 \\ 3 & 4 & 5 & 6 & 7 \end{bmatrix} \] """, (300, 150), color=RED, font=Font(10)) pi = LaText(r'$$\pi$$', (84, 42), LIGHT_GREY, font=Font(24)) # Too big fonts doesn't works, max is 24 pi_size = 24 run = True while run: for e in pygame.event.get(): if e.type == pygame.QUIT: run = False if e.type == pygame.MOUSEBUTTONDOWN: if e.button == 4: pi_size = max(pi_size - 1, 1) elif e.button == 5: pi_size += 1 normal_text.set_font_size(px=pi_size) pi.font.font_size = pi_size pi.text = pi_size screen.fill((250, 250, 250)) math_text.render(screen) matrix.render(screen) pi.render(screen) normal_text.render(screen) pygame.display.flip()
from GUI import Font, Window, TextField, Button, application from testing import say fancy = Font("Times", 24, ['italic']) win_num = 0 class TestWindow(Window): def do_default_action(self): say("Default") def do_cancel_action(self): say("Cancel") def show_text(win): fields = [win.tf1, win.tf2, win.tf3] n = None t = application().target for i, f in enumerate(fields): say("Field %d:" % (i + 1), repr(f.text)) if f is t: n = i + 1 if n: say("Focus: Field %d: Selection = %r" % (n, t.selection)) else: say("No focus") def select_text(win):
# # User-defined views used by test programs # from GUI import View, Color, Font from GUI.StdFonts import system_font, application_font from GUI.StdColors import black, red, green, blue, yellow, white from testing import say fancy_font = Font("Times", 48, ['italic']) #fancy_font = Font("Courier New", 48) #fancy_font = Font("Courier", 48) class TestDrawing(View): def draw(self, c, r): c.backcolor = yellow c.erase_rect((0, 0, self.width, self.height)) self.draw_triangle(c, 10, 40, red) c.gsave() c.rectclip((100, 0, 120, 50)) self.draw_triangle(c, 100, 40, green) c.grestore() self.draw_triangle(c, 50, 100, blue) f1 = system_font f2 = application_font f3 = fancy_font self.draw_text(c, 150, 100, f1, "System Font") self.draw_text(c, 150, 120, f2, "Application Font") self.draw_text(c, 5, 180, f3, "Times Italic 48")
from GUI import View, Button, FileDialogs, Label, Font
def _get_win_ppi(): dc = win_none.GetDC() ppi = dc.GetDeviceCaps(wc.LOGPIXELSY) win_none.ReleaseDC(dc) return ppi _win_ppi = _get_win_ppi() def _win_pts_to_pixels(x): return int(round(x * _win_ppi / 72)) def _win_stock_font(id): h = gui.GetStockObject(id) lf = gui.GetObject(h) return Font._from_win_logfont(lf) #system_font = _win_stock_font(wc.SYSTEM_FONT) #system_font = _win_stock_font(17) # DEFAULT_GUI_FONT #system_font = Font._from_win(win_none) #system_font = Font("System", 13) #system_font = Font("Tahoma", 10) #system_font = Font("Tahoma", 11) system_font = Font("Tahoma", _win_pts_to_pixels(8)) #print "StdFonts: System font ascent =", system_font.ascent #print "StdFonts: System font descent =", system_font.descent application_font = system_font
action=stop_recording, style='default') btn5 = Button(position=(230, 30), title="Play", action=play_recording, style='default') """btn2 = Button(x = 30, y = btn1.bottom + 30, width = 200, title = "Goodbye", just = 'centre', action = say_goodbye, enabled = 0) btn2.font = Font("Times", 1.2 * system_font.size, [])""" btn3 = Button(x=30, y=btn1.bottom + 30, width=200, font=Font("Times", 1.2 * system_font.size, ['italic']), action=stop_recording, title="Wrong", style='cancel') btn3.color = red btn3.just = 'right' btn3.title = "Gidday Mate" win.add(btn1) """win.add(btn2)""" """win.add(btn3)""" win.add(btn5) win.show() instructions = """ There should be 3 buttons arranged vertically:
def loginScreen(self): MyFont = Font(20, file=dirPath + r"/WHOOPASS.TTF") IDTextBox = SimpleText( " I D ", (int(self.screenSize[0] / 2), int(self.screenSize[1] * 2 / 3)), color=WHITE, bg_color=NAVY, anchor=TOPRIGHT, font=MyFont) PasswordTextBox = SimpleText(" PASSWORD ", IDTextBox.bottomleft + Sep(0, 2), color=WHITE, bg_color=NAVY, anchor=TOPLEFT, font=MyFont) IDInputBox = InLineTextBox(IDTextBox.topright + Sep(2, 0), 100, BLACK, WHITE, anchor=TOPLEFT) PasswordInputBox = InLinePassBox(PasswordTextBox.topright + Sep(2, 0), 100, BLACK, WHITE, anchor=TOPLEFT) buttonSize = (20, 75) LoginButton = Button( self.login, (int(self.screenSize[0] / 2), int(self.screenSize[1] * 4 / 5)), (150, 30), "Login", color=BLACK, takeArg=True, flags=BaseButton.THREADED_CALL | BaseButton.CALL_ON_PRESS) QuitButton = Button(self.stopGame, LoginButton.topright + Sep(5, 0), (150, 30), "Quit", color=BLACK, anchor=TOPLEFT) RegisterButton = Button(self.registerScreen, LoginButton.topleft + Sep(5, 0), (150, 30), "Register", color=BLACK, anchor=TOPRIGHT) LoginFailBox = SimpleText("Login Failed", (10, 10), RED, WHITE, anchor=TOPLEFT) renderList = [ IDInputBox, IDTextBox, PasswordInputBox, PasswordTextBox, LoginButton, QuitButton, RegisterButton ] focus = FocusSelector(IDInputBox, PasswordInputBox) focus.select(0) running = True while running: self.clock.tick(self.fpsLimit) mouse = pyg.mouse.get_pos() LoginButton.set_arg((IDInputBox.text, PasswordInputBox.text)) for event in pyg.event.get(): focus.selected().update(event) LoginButton.update(event) QuitButton.update(event) RegisterButton.update(event) if event.type == QUIT: self.stopGame() elif event.type == KEYDOWN: if event.key == K_RETURN: if IDInputBox.text != "" and PasswordInputBox.text != "": self.login(IDInputBox.text, PasswordInputBox.text) elif event.key == K_TAB: if event.mod & KMOD_SHIFT: focus.prev() else: focus.next() elif event.type == MOUSEBUTTONDOWN: if mouse in IDInputBox: focus.select(IDInputBox) elif mouse in PasswordInputBox: focus.select(PasswordInputBox) elif event.type == LoginFailBoxEvent: renderList.remove(LoginFailBox) if event.type == LoginTimeoutEvent: self.handler.receiveStop() while not (self.handler.received.empty()): message = self.handler.received.get() print(message) if message == LoginSuccessful: self.handler.receiveStop() return if message == WrongUsernameOrPassword: self.handler.receiveStop() pyg.time.set_timer(LoginFailBoxEvent, LoginFailBoxShowTime) renderList.append(LoginFailBox) self.screen.fill(WHITE) for item in renderList: item.render(self.screen) pyg.display.update() pyg.display.flip()
def gameStartScreen(self): MyFont = Font(20, file=dirPath + r"/WHOOPASS.TTF") background = ImageBox((0, 0), self.screenSize, "resources/loginBackground.png", anchor=TOPLEFT) """ nicknameBox = SimpleText("Nickname : " + self.user.nickname, (20, 100),color=NAVY,bg_color=WHITE,font=MyFont,anchor=TOPLEFT) winRateBox = SimpleText("Win Rate : " + str(self.user.winRate), nicknameBox.bottomleft + Sep(0,3), color = NAVY, bg_color=WHITE,font=MyFont, anchor=TOPLEFT) winBox = SimpleText("Games Won : " + str(self.user.wins), winRateBox.bottomleft + Sep(0, 3), color = NAVY, bg_color=WHITE,font=MyFont,anchor=TOPLEFT) loseBox = SimpleText("Games Lost : " + str(self.user.loses), winBox.bottomleft + Sep(0,3), color = NAVY, bg_color=WHITE,font=MyFont,anchor=TOPLEFT) gamesPlayed = SimpleText("Games Played : " + str(self.user.gamesPlayed),loseBox.bottomleft +Sep(0,3), color = NAVY, bg_color=WHITE,font=MyFont,anchor=TOPLEFT) doraemonRateBox = SimpleText("Doraemon Win Rate : " + str(self.user.doraemonWinRate), gamesPlayed.bottomleft + Sep(0, 3), color=NAVY, bg_color=WHITE, font=MyFont, anchor=TOPLEFT) doraemonWinBox = SimpleText("Doraemons Won : " + str(self.user.doraemonWins),doraemonRateBox.bottomleft +Sep(0,3), color = NAVY, bg_color=WHITE,font=MyFont,anchor=TOPLEFT) doraemonLoseBox = SimpleText("Doraemons Lost : " + str(self.user.doraemonLoses), doraemonWinBox.bottomleft + Sep(0, 3), color=NAVY, bg_color=WHITE, font=MyFont, anchor=TOPLEFT) doraemonPlayedBox = SimpleText("Doraemons Played: " + str(self.user.doraemonPlayed), doraemonLoseBox.bottomleft + Sep(0, 3), color=NAVY, bg_color=WHITE, font=MyFont, anchor=TOPLEFT) """ gameReadyButton = Button( self.playerReady, (int(self.screenSize[0] / 2), int(self.screenSize[1] / 2)), (200, 40), "Game Ready", color=NAVY) cancelButton = Button(self.cancel, gameReadyButton.bottomleft + Sep(0, 3), (200, 30), "Cancel", takeArg=True, anchor=TOPLEFT, color=NAVY, flags=BaseButton.CALL_ON_PRESS) cancelButton.set_arg(StopReady) ReadyCanceledBox = SimpleText("Ready Canceled", cancelButton.bottomleft + Sep(0, 5), color=RED, font=MyFont, anchor=TOPLEFT) ReadyCanceledBox.hide = True renderList = [ background, gameReadyButton, cancelButton, ReadyCanceledBox ] running = True while running: self.clock.tick(self.fpsLimit) mouse = pyg.mouse.get_pos() for event in pyg.event.get(): gameReadyButton.update(event) cancelButton.update(event) if event.type == QUIT: self.stopGame() if event.type == StopReady: self.handler.receiveStop() data = ("READYSTOP") self.handler.client.send(data) while not self.handler.received.empty(): message = self.handler.received.get() if message == MatchingSuccessful: self.handler.receiveStop() return True for item in renderList: item.render(self.screen) pyg.display.flip() pyg.display.update()
def registerScreen(self): MyFont = Font(20, file=dirPath + r"/WHOOPASS.TTF") background = ImageBox((0, 0), self.screenSize, "resources/loginBackground.png", TOPLEFT) IDTextBox = SimpleText( "ID", (int(self.screenSize[0] * 1 / 4), int(self.screenSize[1] * 1 / 3)), color=WHITE, bg_color=NAVY, anchor=TOPRIGHT, font=MyFont) IDInputBox = InLineTextBox(IDTextBox.topright + Sep(2, 0), 300, BLACK, WHITE, anchor=TOPLEFT) IDWarningBox = SimpleText("ID must be at least 6 characters", IDInputBox.topleft + Sep(0, -1), color=RED, anchor=BOTTOMLEFT) PasswordWarningBox = SimpleText( "Password must be at least 8 characters", IDInputBox.bottomleft + Sep(0, 2), color=RED, anchor=TOPLEFT) PasswordInputBox = InLinePassBox(PasswordWarningBox.bottomleft + Sep(0, 1), 300, BLACK, WHITE, anchor=TOPLEFT) PasswordTextBox = SimpleText("PASSWORD", PasswordInputBox.topleft + Sep(-2, 0), color=WHITE, bg_color=NAVY, anchor=TOPRIGHT, font=MyFont) PasswordCheckWarningBox = SimpleText("Check password does not match", PasswordInputBox.bottomleft + Sep(0, 2), color=RED, anchor=TOPLEFT) PasswordCheckInputBox = InLinePassBox( PasswordCheckWarningBox.bottomleft + Sep(0, 1), 300, BLACK, WHITE, anchor=TOPLEFT) PasswordCheckTextBox = SimpleText("PASSWORD CHECK", PasswordCheckInputBox.topleft + Sep(-2, 0), color=WHITE, bg_color=NAVY, anchor=TOPRIGHT, font=MyFont) NickNameWarningBox = SimpleText( "Nickname must be at least 4 characters", PasswordCheckInputBox.bottomleft + Sep(0, 2), color=RED, anchor=TOPLEFT) NickNameInputBox = InLineTextBox(NickNameWarningBox.bottomleft + Sep(0, 1), 300, BLACK, WHITE, anchor=TOPLEFT) NickNameTextBox = SimpleText("NICK NAME", NickNameInputBox.topleft + Sep(-2, 0), color=WHITE, bg_color=NAVY, anchor=TOPRIGHT, font=MyFont) ConfirmButton = Button( self.register, (int(self.screenSize[0] / 2), int(self.screenSize[1] * 2 / 3)) + Sep(1, 0), (150, 30), "Register", color=BLACK, anchor=TOPRIGHT, takeArg=True, flags=BaseButton.THREADED_CALL | BaseButton.CALL_ON_PRESS) CancelButton = Button(self.cancel, ConfirmButton.topright + Sep(2, 0), (150, 30), "Cancel", color=BLACK, takeArg=True, anchor=TOPLEFT) CancelButton.arg = StopRunning RegisterFailBox = SimpleText("Register failed", (10, 10), RED, WHITE, anchor=TOPLEFT) RegisterFailBox.hide = True renderList = [ background, IDTextBox, PasswordTextBox, PasswordCheckTextBox, NickNameTextBox, IDInputBox, PasswordInputBox, PasswordCheckInputBox, NickNameInputBox, ConfirmButton, CancelButton, PasswordWarningBox, IDWarningBox, PasswordCheckWarningBox, NickNameWarningBox, RegisterFailBox ] feedEventList = [ConfirmButton, CancelButton] focus = FocusSelector(IDInputBox, PasswordInputBox, PasswordCheckInputBox, NickNameInputBox) focus.select(0) running = True while running: self.clock.tick(self.fpsLimit) mouse = pyg.mouse.get_pos() ConfirmButton.set_arg((IDInputBox.text, PasswordInputBox.text, NickNameInputBox.text)) if len(IDInputBox.text) >= 6: IDWarningBox.hide = True IDcorrect = True else: IDWarningBox.hide = False IDcorrect = False if len(PasswordInputBox.text) >= 8: PasswordWarningBox.hide = True PasswordCorrect = True else: PasswordWarningBox.hide = False PasswordCorrect = False if PasswordInputBox.text == PasswordCheckInputBox.text: PasswordCheckWarningBox.hide = True PasswordCheckCorrect = True else: PasswordCheckWarningBox.hide = False PasswordCheckCorrect = False if len(NickNameInputBox.text) >= 4: NickNameWarningBox.hide = True NicknameCorrect = True else: NickNameWarningBox.hide = False NicknameCorrect = False if IDcorrect and PasswordCheckCorrect and PasswordCorrect and NicknameCorrect: ConfirmButton.isEnabled = True else: ConfirmButton.isEnabled = False for event in pyg.event.get(): focus.selected().update(event) for item in feedEventList: item.update(event) if event.type == QUIT: self.stopGame() elif event.type == KEYDOWN: if event.key == K_RETURN: if IDcorrect and PasswordCorrect and PasswordCheckCorrect and NicknameCorrect: self.register(IDInputBox.text, PasswordInputBox.text, NickNameInputBox.text) elif event.key == K_TAB: if event.mod & KMOD_SHIFT: focus.prev() else: focus.next() elif event.type == MOUSEBUTTONDOWN: if mouse in IDInputBox: focus.select(IDInputBox) elif mouse in PasswordInputBox: focus.select(PasswordInputBox) elif mouse in PasswordCheckInputBox: focus.select(PasswordCheckInputBox) elif mouse in NickNameInputBox: focus.select(NickNameInputBox) elif event.type == RegisterFailBoxShowEvent: RegisterFailBox.hide = True elif event.type == StopRunning: running = False if event.type == RegisterTimeoutEvent: self.handler.receiveStop() while not self.handler.received.empty(): message = self.handler.received.get() if message == RegisterSuccessful: self.handler.receiveStop() return True if message == RegisterFailed: self.handler.receiveStop() return False for item in renderList: item.render(self.screen) pyg.display.flip() pyg.display.update()
from GUI import TextEditor, Window, Menu, Font, StdFonts, application from GUI.StdMenus import basic_menus font_size = StdFonts.application_font.size mono_font = Font("Courier", font_size) sans_font = Font("Helvetica", font_size) tab_text = \ """X----X----X A\tB\tC""" test_text = \ """This is just an example that shows how you could insert any text that you want in this editor at any time """ menus = [ Menu("Test", [ ("Set Text/4", 'set_text_cmd'), ("Monospaced Font/5", 'mono_cmd'), ("Sans-Serif Font/6", 'sans_cmd'), ]), ] class TestWindow(Window): def setup_menus(self, m): Window.setup_menus(self, m) m.show_selection_cmd.enabled = True m.set_selection_cmd.enabled = True