Exemplo n.º 1
0
 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)
class TopqueryLabel(Label):
    
    VALUES_HEADER = ['count |    values', '-' * 90]

    def __init__(self, query, values, **kwargs):
        Label.__init__(self, **kwargs)
        self.query = query
        self.values = values
        self.expanded = False
        self.text = query
        self.font = Font("Courier", 13)
        self.resize()

    def resize(self):
        self.size = (self.font.width(self.text),
                     self.font.line_height * (self.text.count("\n") + 1))

    def mouse_down(self, event):
        self.expanded = not self.expanded
        if self.expanded and self.values:
            self.text = '\n\t'.join([self.query] +
                                    TopqueryLabel.VALUES_HEADER +
                                    self.values)
        else:
            self.text = self.query
        self.resize()
Exemplo n.º 3
0
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 __init__(self, query, values, **kwargs):
     Label.__init__(self, **kwargs)
     self.query = query
     self.values = values
     self.expanded = False
     self.text = query
     self.font = Font("Courier", 13)
     self.resize()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 def get_font(self):
     font = self._font
     if not font:
         font = Font._from_pango_description(
             self._gtk_inner_widget.style.font_desc)
     return font
Exemplo n.º 8
0
              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:
Exemplo n.º 9
0
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
Exemplo n.º 10
0
 def get_font(self):
     return Font._from_ns_font(self._ns_cell().font())
Exemplo n.º 11
0
#
#		Python GUI - Standard Fonts - PyObjC
#

from AppKit import NSFont
from GUI import Font

system_font = Font._from_ns_font(NSFont.systemFontOfSize_(0))
application_font = Font._from_ns_font(NSFont.userFontOfSize_(0))
Exemplo n.º 12
0
def _win_stock_font(id):
    h = gui.GetStockObject(id)
    lf = gui.GetObject(h)
    return Font._from_win_logfont(lf)
Exemplo n.º 13
0
 def get_header_font(self):
     return Font._from_ns_font(self._ns_column.headerCell().font())
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
class CodeEditor(ScrollableView):
    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 container_resized(self, event):
        self.extent = (self.width, self.height)
        ScrollableView.container_resized(self, event)

    def draw(self, cr, update_rect):
        cr.fillcolor = Colors.rgb(1, 1, 1)
        cr.fill_rect(update_rect)
        d = self.font.descent
        h = self.font.height
        w = self.font.width(' ')
        cr.font = self.font
        if '\n' in self.text[:self.scursorpos]:
            scw = self.font.width(
                self.text[self.text.rindex('\n', 0, self.scursorpos):self.
                          scursorpos])
        else:
            scw = self.font.width(self.text[:self.scursorpos])
        if '\n' in self.text[:self.cursorpos]:
            cw = self.font.width(
                self.text[self.text.rindex('\n', 0, self.cursorpos):self.
                          cursorpos])
        else:
            cw = self.font.width(self.text[:self.cursorpos])
        selines = self.text[:self.scursorpos].count('\n') + 1
        elines = self.text[:self.cursorpos].count('\n') + 1
        if self.selecting:
            cr.fillcolor = Colors.rgb(0.5, 0.75, 1)
            cr.moveto(scw, d + h * selines)
            cr.lineto(scw, -h + h * selines)
            if selines != elines:
                cr.lineto(self.extent[0], -h + h * selines)
                cr.lineto(self.extent[0], -h + h * elines)
            cr.lineto(cw, -h + h * elines)
            cr.lineto(cw, d + h * elines)
            if selines != elines:
                cr.lineto(0, d + h * elines)
                cr.lineto(0, d + h * selines)
            cr.fill()
            # cr.fill_rect([scw,d+h*elines,cw,-h+h*elines])
            cr.newpath()
        cr.moveto(0, self.font.height)
        self.formatter.cr = cr
        self.formatter.height = self.font.height
        self.formatter.tabwidth = self.font.width('\t')
        highlight(self.text, self.lexer, self.formatter)
        cr.newpath()
        cr.moveto(cw, d + h * elines)
        cr.lineto(cw, -h + h * elines)
        cr.stroke()
        # cr.show_text(self.text)
        # cr.stroke()
    def mouse_down(self, event):
        self.become_target()
        x, y = event.position
        self.selecting = False
        # self.cursorpos = self.text.replace('\n',' ',int(y/self.font.height)-1).find('\n')
        # if self.cursorpos==-1:
        # 	self.cursorpos = len(self.text)-1
        # self.cursorpos+=1
        # self.cursorpos = min(self.cursorpos+int(x/self.font.width(' ')), max(self.text.find('\n',self.cursorpos+1),0) or len(self.text))
        lns = self.text.splitlines()
        self.cursorpos = sum([len(i) for i in lns[:int(y / self.font.height)]])
        try:
            self.cursorpos += min(
                int(x / self.font.width(' ')) + 1,
                lns[int(y / self.font.height)])
        except:
            pass
        self.scursorpos = self.cursorpos
        self.selection = (self.cursorpos, self.cursorpos)
        if int(y / self.font.height):
            self.cursorpos += 1
        self.invalidate_rect([0, 0, self.extent[0], self.extent[1]])

    def mouse_drag(self, event):
        x, y = event.position
        self.selecting = True
        lns = self.text.splitlines()
        self.cursorpos = sum([len(i) for i in lns[:int(y / self.font.height)]])
        try:
            self.cursorpos += min(
                int(x / self.font.width(' ')) + 1,
                lns[int(y / self.font.height)])
        except:
            pass
        if int(y / self.font.height):
            self.cursorpos += 1
        self.selection = (min(self.cursorpos, self.scursorpos),
                          max(self.cursorpos, self.scursorpos))
        self.invalidate_rect([0, 0, self.extent[0], self.extent[1]])

    def key_down(self, event):
        keydict = {
            127: "backspace",
            63272: "delete",
            63232: "up_arrow",
            63233: "down_arrow",
            63235: "right_arrow",
            63234: "left_arrow",
            13: "enter",
            9: "tab",
            63236: "F1",
            63237: "F2",
            63238: "F3",
            63239: "F4",
            63240: "F5",
            63241: "F6",
            63242: "F7",
            63243: "F8",
            27: "escape"
        }
        if not event.unichars == '':
            if ord(event.unichars) in keydict:
                key = keydict[ord(event.unichars)]
            else:
                key = event.unichars
                print 'uni', key
        else:
            key = event.key  #.upper()
            print key
        if key == "\b":
            if self.cursorpos > 0:
                self.text = self.text[:self.cursorpos -
                                      1] + self.text[self.cursorpos:]
        elif key == "enter":
            self.text = self.text[:self.cursorpos] + "\n" + self.text[
                self.cursorpos:]
            self.height = self.font.height * (self.text.count('\n') + 1)
            self.cursorpos += 1
        elif key == "backspace":
            if self.cursorpos > 0:
                self.text = self.text[:self.cursorpos -
                                      1] + self.text[self.cursorpos:]
                self.cursorpos -= 1
        elif key == "delete":
            if self.cursorpos < len(self.text):
                self.text = self.text[:self.
                                      cursorpos] + self.text[self.cursorpos +
                                                             1:]
        elif key == "left_arrow":
            if self.cursorpos > 0:
                self.cursorpos -= 1
        elif key == "right_arrow":
            if self.cursorpos < len(self.text):
                self.cursorpos += 1
        elif key == "up_arrow":
            if '\n' in self.text[:self.cursorpos]:
                lpos = self.text[:self.cursorpos].rindex(
                    '\n', 0, self.cursorpos)
                if '\n' in self.text[:lpos]:
                    llpos = self.text[:lpos].rindex('\n', 0, lpos)
                else:
                    llpos = -1  # to account for no \n preceding it
                self.cursorpos = min(self.cursorpos - lpos + llpos, lpos)
        elif key == "down_arrow":
            if '\n' in self.text[self.cursorpos:]:
                if '\n' in self.text[:self.cursorpos]:
                    lpos = self.text[:self.cursorpos].rindex(
                        '\n', 0, self.cursorpos)
                else:
                    lpos = -1
                npos = self.text[self.cursorpos:].index('\n')
                if '\n' in self.text[self.cursorpos + npos + 1:]:
                    nnpos = self.text[self.cursorpos + npos + 1:].index('\n')
                else:
                    nnpos = len(self.text[self.cursorpos:])
                self.cursorpos = min(
                    self.cursorpos + npos + self.cursorpos - lpos,
                    self.cursorpos + npos + nnpos + 1)
        else:
            self.text = self.text[:self.cursorpos] + str(
                key) + self.text[self.cursorpos:]
            self.cursorpos += 1
        self.scursorpos = self.cursorpos
        self.selection = (self.cursorpos, self.cursorpos)
        self.invalidate_rect([0, 0, self.extent[0], self.extent[1]])
Exemplo n.º 16
0
#
#		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")
Exemplo n.º 17
0
    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()
Exemplo n.º 18
0
    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()
Exemplo n.º 19
0
    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()
Exemplo n.º 20
0
def _win_stock_font(id):
    h = gui.GetStockObject(id)
    lf = gui.GetObject(h)
    return Font._from_win_logfont(lf)
Exemplo n.º 21
0
 def get_font(self):
     return Font._from_ns_font(self._ns_cell().font())
Exemplo n.º 22
0
from GUI import View, Button, FileDialogs, Label, Font
Exemplo n.º 23
0
#
#		Python GUI - Standard Fonts - Gtk
#

import gtk
from GUI import Font

system_font = Font._from_pango_description(gtk.Label().style.font_desc)
application_font = Font._from_pango_description(gtk.Entry().style.font_desc)
Exemplo n.º 24
0
 def get_font(self):
     return Font._from_ns_font(self._ns_column.dataCell().font())
Exemplo n.º 25
0
 def get_font(self):
     font = self._font
     if not font:
         font = Font._from_pango_description(self._gtk_inner_widget.style.font_desc)
     return font
Exemplo n.º 26
0
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):
Exemplo n.º 27
0
class CodeEditor(ScrollableView):
    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 container_resized(self, event):
        self.extent = (self.width, self.height)
        ScrollableView.container_resized(self, event)

    def draw(self, cr, update_rect):
        cr.fillcolor = Colors.rgb(1, 1, 1)
        cr.fill_rect(update_rect)
        d = self.font.descent
        h = self.font.height
        w = self.font.width(" ")
        cr.font = self.font
        if "\n" in self.text[: self.scursorpos]:
            scw = self.font.width(self.text[self.text.rindex("\n", 0, self.scursorpos) : self.scursorpos])
        else:
            scw = self.font.width(self.text[: self.scursorpos])
        if "\n" in self.text[: self.cursorpos]:
            cw = self.font.width(self.text[self.text.rindex("\n", 0, self.cursorpos) : self.cursorpos])
        else:
            cw = self.font.width(self.text[: self.cursorpos])
        selines = self.text[: self.scursorpos].count("\n") + 1
        elines = self.text[: self.cursorpos].count("\n") + 1
        if self.selecting:
            cr.fillcolor = Colors.rgb(0.5, 0.75, 1)
            cr.moveto(scw, d + h * selines)
            cr.lineto(scw, -h + h * selines)
            if selines != elines:
                cr.lineto(self.extent[0], -h + h * selines)
                cr.lineto(self.extent[0], -h + h * elines)
            cr.lineto(cw, -h + h * elines)
            cr.lineto(cw, d + h * elines)
            if selines != elines:
                cr.lineto(0, d + h * elines)
                cr.lineto(0, d + h * selines)
            cr.fill()
            # cr.fill_rect([scw,d+h*elines,cw,-h+h*elines])
            cr.newpath()
        cr.moveto(0, self.font.height)
        self.formatter.cr = cr
        self.formatter.height = self.font.height
        self.formatter.tabwidth = self.font.width("\t")
        highlight(self.text, self.lexer, self.formatter)
        cr.newpath()
        cr.moveto(cw, d + h * elines)
        cr.lineto(cw, -h + h * elines)
        cr.stroke()
        # cr.show_text(self.text)
        # cr.stroke()

    def mouse_down(self, event):
        self.become_target()
        x, y = event.position
        self.selecting = False
        # self.cursorpos = self.text.replace('\n',' ',int(y/self.font.height)-1).find('\n')
        # if self.cursorpos==-1:
        # 	self.cursorpos = len(self.text)-1
        # self.cursorpos+=1
        # self.cursorpos = min(self.cursorpos+int(x/self.font.width(' ')), max(self.text.find('\n',self.cursorpos+1),0) or len(self.text))
        lns = self.text.splitlines()
        self.cursorpos = sum([len(i) for i in lns[: int(y / self.font.height)]])
        try:
            self.cursorpos += min(int(x / self.font.width(" ")) + 1, lns[int(y / self.font.height)])
        except:
            pass
        self.scursorpos = self.cursorpos
        self.selection = (self.cursorpos, self.cursorpos)
        if int(y / self.font.height):
            self.cursorpos += 1
        self.invalidate_rect([0, 0, self.extent[0], self.extent[1]])

    def mouse_drag(self, event):
        x, y = event.position
        self.selecting = True
        lns = self.text.splitlines()
        self.cursorpos = sum([len(i) for i in lns[: int(y / self.font.height)]])
        try:
            self.cursorpos += min(int(x / self.font.width(" ")) + 1, lns[int(y / self.font.height)])
        except:
            pass
        if int(y / self.font.height):
            self.cursorpos += 1
        self.selection = (min(self.cursorpos, self.scursorpos), max(self.cursorpos, self.scursorpos))
        self.invalidate_rect([0, 0, self.extent[0], self.extent[1]])

    def key_down(self, event):
        keydict = {
            127: "backspace",
            63272: "delete",
            63232: "up_arrow",
            63233: "down_arrow",
            63235: "right_arrow",
            63234: "left_arrow",
            13: "enter",
            9: "tab",
            63236: "F1",
            63237: "F2",
            63238: "F3",
            63239: "F4",
            63240: "F5",
            63241: "F6",
            63242: "F7",
            63243: "F8",
            27: "escape",
        }
        if not event.unichars == "":
            if ord(event.unichars) in keydict:
                key = keydict[ord(event.unichars)]
            else:
                key = event.unichars
                print "uni", key
        else:
            key = event.key  # .upper()
            print key
        if key == "\b":
            if self.cursorpos > 0:
                self.text = self.text[: self.cursorpos - 1] + self.text[self.cursorpos :]
        elif key == "enter":
            self.text = self.text[: self.cursorpos] + "\n" + self.text[self.cursorpos :]
            self.height = self.font.height * (self.text.count("\n") + 1)
            self.cursorpos += 1
        elif key == "backspace":
            if self.cursorpos > 0:
                self.text = self.text[: self.cursorpos - 1] + self.text[self.cursorpos :]
                self.cursorpos -= 1
        elif key == "delete":
            if self.cursorpos < len(self.text):
                self.text = self.text[: self.cursorpos] + self.text[self.cursorpos + 1 :]
        elif key == "left_arrow":
            if self.cursorpos > 0:
                self.cursorpos -= 1
        elif key == "right_arrow":
            if self.cursorpos < len(self.text):
                self.cursorpos += 1
        elif key == "up_arrow":
            if "\n" in self.text[: self.cursorpos]:
                lpos = self.text[: self.cursorpos].rindex("\n", 0, self.cursorpos)
                if "\n" in self.text[:lpos]:
                    llpos = self.text[:lpos].rindex("\n", 0, lpos)
                else:
                    llpos = -1  # to account for no \n preceding it
                self.cursorpos = min(self.cursorpos - lpos + llpos, lpos)
        elif key == "down_arrow":
            if "\n" in self.text[self.cursorpos :]:
                if "\n" in self.text[: self.cursorpos]:
                    lpos = self.text[: self.cursorpos].rindex("\n", 0, self.cursorpos)
                else:
                    lpos = -1
                npos = self.text[self.cursorpos :].index("\n")
                if "\n" in self.text[self.cursorpos + npos + 1 :]:
                    nnpos = self.text[self.cursorpos + npos + 1 :].index("\n")
                else:
                    nnpos = len(self.text[self.cursorpos :])
                self.cursorpos = min(self.cursorpos + npos + self.cursorpos - lpos, self.cursorpos + npos + nnpos + 1)
        else:
            self.text = self.text[: self.cursorpos] + str(key) + self.text[self.cursorpos :]
            self.cursorpos += 1
        self.scursorpos = self.cursorpos
        self.selection = (self.cursorpos, self.cursorpos)
        self.invalidate_rect([0, 0, self.extent[0], self.extent[1]])