Example #1
0
 def make_window(self, document):
     win = Window(size = (400, 400), document = document)
     view = AppView(model = document, extent = (1000, 1000), scrolling = 'hv', #menu_width = 50
         #cursor = self.app_cursor
         )
     win.place(view, left = 0, top = 0, right = 0, bottom = 0, sticky = 'nsew')
     win.show()
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 test():
    cursor = StdCursors.empty_cursor()
    win = Window(title = "No Cursor", width = 500, height = 400)
    view = TestDrawing(position = (20, 20), size = (300, 200),
        cursor = cursor)
    win.add(view)
    win.show()
Example #4
0
def test():
    view = TestView(size=(300, 200))
    win = Window(title="Coloured Text")
    win.add(view)
    win.shrink_wrap()
    win.show()
    run()
def test():
    view = TestView(size = (300, 200))
    win = Window(title = "Coloured Text")
    win.add(view)
    win.shrink_wrap()
    win.show()
    run()
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()
Example #7
0
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()
Example #8
0
def main():
    win = Window()
    view = PolyView(width=120, height=120)
    win.add(view)
    win.shrink_wrap()
    win.show()
    application().run()
Example #9
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()
Example #10
0
    def make_window(self, document):

        window_width = 800
        window_height = 600

        #create a Window object and associate it with our document
        #so when the window is closed the doc can ask the user if
        #he wants to save
        app_window = Window(size=(window_width, window_height),
                            document=document)

        #make a view for the window
        app_view = LineView(model=document,
                            extent=(window_width, window_height),
                            printable=False,
                            cursor=self.line_cursor)

        #place the view in the window, make it resizeable
        app_window.place(app_view,
                         left=0,
                         top=0,
                         right=0,
                         bottom=0,
                         sticky='nsew')

        #display the window when we are done initializing
        app_window.show()
def test():
    win = Window(title = "Exceptions", size = (200, 100))
    but1 = Button("ApplicationError", action = raise_application_error)
    but2 = Button("Exception", action = raise_exception)
    win.place_column([but1, but2], left = 20, top = 20)
    win.shrink_wrap(padding = (20, 20))
    win.show()
    application().run()
def test():
    view = GearsView(size = (300, 300))
    win = Window(title = "Gears")
    win.place(view, sticky = "nsew")
    view.become_target()
    win.shrink_wrap()
    win.show()
    application().run()
Example #13
0
def test():
    win = Window(title="Exceptions", size=(200, 100))
    but1 = Button("ApplicationError", action=raise_application_error)
    but2 = Button("Exception", action=raise_exception)
    win.place_column([but1, but2], left=20, top=20)
    win.shrink_wrap(padding=(20, 20))
    win.show()
    application().run()
Example #14
0
def test():
    view = GearsView(size=(300, 300))
    win = Window(title="Gears")
    win.place(view, sticky="nsew")
    view.become_target()
    win.shrink_wrap()
    win.show()
    application().run()
Example #15
0
def test():
    starter = Button("Start", action=start_task)
    stopper = Button("Stop", action=stop_task)
    win = Window(title="Tasks")
    win.place_column([starter, stopper], left=20, top=20, spacing=20)
    win.shrink_wrap(padding=(20, 20))
    win.show()
    application().run()
Example #16
0
def test():
    win = Window(title="Targeting", size=(180, 100))
    patch1 = TestPatch("Red patch", red, position=(20, 20))
    patch2 = TestPatch("Green patch", green, position=(100, 20))
    win.add(patch1)
    win.add(patch2)
    win.show()
    application().run()
Example #17
0
 def make_window(self, document):
     win = Window(size=(400, 400), document=document)
     view = BlobView(model=document,
                     extent=(1000, 1000),
                     scrolling='hv',
                     cursor=self.blob_cursor)
     win.place(view, left=0, top=0, right=0, bottom=0, sticky='nsew')
     win.show()
def test():
    win = Window(title = "Targeting", size = (180, 100))
    patch1 = TestPatch("Red patch", red, position = (20, 20))
    patch2 = TestPatch("Green patch", green, position = (100, 20))
    win.add(patch1)
    win.add(patch2)
    win.show()
    application().run()
Example #19
0
def test():
    starter = Button("Start", action = start_task)
    stopper = Button("Stop", action = stop_task)
    win = Window(title = "Tasks")
    win.place_column([starter, stopper], left = 20, top = 20, spacing = 20)
    win.shrink_wrap(padding = (20, 20))
    win.show()
    application().run()
Example #20
0
def test():
    win = Window(title="Frame")
    frm = Frame()
    frm.place_column([Label("This is"), Label("A frame")], left=0, top=0)
    frm.shrink_wrap()
    win.place(frm, left=30, top=30)
    win.shrink_wrap(padding=(30, 30))
    win.show()
Example #21
0
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()
Example #22
0
def test():
    doc = TestDoc(title="Document")
    view = TestDocView(model=doc, size=(200, 200))
    win = Window(resizable=0, size=(200, 200))
    win.add(view)
    win.document = doc
    #say(view.x, view.y, view.width, view.height)
    win.show()
    application().run()
def test():
    doc = TestDoc(title = "Document")
    view = TestDocView(model = doc, size = (200, 200))
    win = Window(resizable = 0, size = (200, 200))
    win.add(view)
    win.document = doc
    #say(view.x, view.y, view.width, view.height)
    win.show()
    application().run()
Example #24
0
def main():
    view = CTV(size=(200, 300))
    win = Window(title="Canvas")
    win.add(view)
    win.shrink_wrap()
    view.become_target()
    win.show()
    app = application()
    app.menus = basic_menus() + [test_menu]
    app.run()
Example #25
0
def main():
    view = CTV(size=(200, 300))
    win = Window(title="Canvas")
    win.add(view)
    win.shrink_wrap()
    view.become_target()
    win.show()
    app = application()
    app.menus = basic_menus() + [test_menu]
    app.run()
Example #26
0
def test():
    cursor = StdCursors.finger
    win = Window(title = "Cursor", width = 500, height = 400)
    view1 = TestDrawing(position = (20, 20), size = (100, 70), cursor = cursor)
    view2 = TestScrollableView(position = (140, 20), size = (200, 200),
        scrolling = 'hv')
    view2.cursor = cursor
    win.add(view1)
    win.place(view2, sticky = 'nsew')
    win.shrink_wrap((20, 20))
    win.show()
def test():
    app = application()
    pixmap = GLPixmap(50, 50, double_buffer = False, alpha = False)
    pixmap.with_context(draw_triangle, flush = True)
    #pixmap.with_canvas(draw_circle)
    view = PixmapTestView(pixmap, size = (180, 200))
    win = Window(title = "GLPixmap", resizable = False)
    win.add(view)
    win.shrink_wrap()
    win.show()
    app.run()
Example #28
0
def test():
    win = Window(title = "Frame")
    frm = Frame()
    frm.place_column([
        Label("This is"),
        Label("A frame")],
        left = 0, top = 0)
    frm.shrink_wrap()
    win.place(frm, left = 30, top = 30)
    win.shrink_wrap(padding = (30, 30))
    win.show()
Example #29
0
def test():
    app = application()
    pixmap = GLPixmap(50, 50, double_buffer=False, alpha=False)
    pixmap.with_context(draw_triangle, flush=True)
    #pixmap.with_canvas(draw_circle)
    view = PixmapTestView(pixmap, size=(180, 200))
    win = Window(title="GLPixmap", resizable=False)
    win.add(view)
    win.shrink_wrap()
    win.show()
    app.run()
Example #30
0
def test():
    cursor = StdCursors.finger
    win = Window(title="Cursor", width=500, height=400)
    view1 = TestDrawing(position=(20, 20), size=(100, 70), cursor=cursor)
    view2 = TestScrollableView(position=(140, 20),
                               size=(200, 200),
                               scrolling='hv')
    view2.cursor = cursor
    win.add(view1)
    win.place(view2, sticky='nsew')
    win.shrink_wrap((20, 20))
    win.show()
Example #31
0
def make_view(db, options):
    pf = GLConfig(double_buffer=db)
    pf.alpha = "a" in options
    pf.depth_buffer = "d" in options
    pf.stencil_buffer = "s" in options
    pf.aux_buffers = "x" in options
    pf.accum_buffer = "A" in options
    view = TriangleView(pf, size=(200, 200))
    win = Window(title="%s Buffered GLView" % ["Single", "Double"][db],
                 size=(240, 240))
    win.place(view, left=20, top=20, sticky="nsew")
    view.become_target()
    win.show()
def test():
    file = "grail_masked.tiff"
    # file = "spam_masked.tiff"
    image = Image(os.path.join(sys.path[0], file))
    cursor = Cursor(image)
    win = Window(title="Image Cursor", width=500, height=400)
    view1 = TestDrawing(position=(20, 20), size=(100, 70), cursor=cursor)
    view2 = TestScrollableView(position=(140, 20), size=(200, 200), scrolling="hv")
    view2.cursor = cursor
    win.add(view1)
    win.place(view2, sticky="nsew")
    win.shrink_wrap((20, 20))
    win.show()
Example #33
0
def make_view(db, options):
    pf = GLConfig(double_buffer = db)
    pf.alpha = "a" in options
    pf.depth_buffer = "d" in options
    pf.stencil_buffer = "s" in options
    pf.aux_buffers = "x" in options
    pf.accum_buffer = "A" in options
    view = TriangleView(pf, size = (200, 200))
    win = Window(
        title = "%s Buffered GLView" % ["Single", "Double"][db],
        size = (240, 240))
    win.place(view, left = 20, top = 20, sticky = "nsew")
    view.become_target()
    win.show()
Example #34
0
def test():
	file = "grail_masked.tiff"
	#file = "spam_masked.tiff"
	image = Image(os.path.join(sys.path[0], file))
	cursor = Cursor(image)
	win = Window(title = "Image Cursor", width = 500, height = 400)
	view1 = TestDrawing(position = (20, 20), size = (100, 70), cursor = cursor)
	view2 = TestScrollableView(position = (140, 20), size = (200, 200),
		scrolling = 'hv')
	view2.cursor = cursor
	win.add(view1)
	win.place(view2, sticky = 'nsew')
	win.shrink_wrap((20, 20))
	win.show()
Example #35
0
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()
Example #36
0
    def make_window(self, document):
        self.tabview = view = TabView()

        win = Window(size=(600, 400), document=document)

        self.view1 = Button(title='Item 1', action=self.item1Action)
        view.add_item(self.view1, title='asdfe')

        self.view2 = Button(title='Item 2', action=self.item2Action)
        view.add_item(self.view2, title="Two")

        win.place(view, left=0, top=0, right=0, bottom=0, sticky='nsew')

        win.show()
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()
Example #38
0
def test():
    def select():
        i = group.value
        name = cursor_names[i]
        say("Selecting cursor no. %d (%s)" % (i, name))
        cursor = getattr(StdCursors, name)
        say("...", cursor)
        view.cursor = cursor
    win = Window(title = "Std Cursors")
    view = TestArea(size = (100, 100))
    win.place(view, left = 20, top = 20)
    group = RadioGroup(action = select)
    for i, name in enumerate(cursor_names):
        group.add_item(RadioButton(title = name, value = i))
    win.place_column(group, left = view + 20, top = 20, spacing = 0)
    win.shrink_wrap((20, 20))
    win.show()
    application().run()
Example #39
0
 def make_window(self, document):
     
     window_width = 800
     window_height = 600
     
     #create a Window object and associate it with our document 
     #so when the window is closed the doc can ask the user if
     #he wants to save
     app_window = Window(size = (window_width, window_height), document = document)
     
     #make a view for the window
     app_view = LineView(model = document, extent = (window_width, window_height), printable = False, cursor = self.line_cursor)
     
     #place the view in the window, make it resizeable
     app_window.place(app_view, left = 0, top = 0, right = 0, bottom = 0, sticky = 'nsew')
     
     #display the window when we are done initializing
     app_window.show()
Example #40
0
def test(orient, pos, pad):
	win = Window(title = "%s Sliders" % orient.upper(), position = pos,
		auto_position = False)
	sliders = []
	if 1:
		#say("Creating slider 1")
		sl1 = sl2 = sl3 = None
		sl1 = Slider(orient = orient, max_value = 100)
		sl1.action = slid(sl1, orient, 1)
		sliders.append(sl1)
	if 1:
		#say("Creating slider 2")
		sl2 = Slider(orient = orient, max_value = 100, ticks = 6, live = False)
		sl2.value = 50
		sl2.action = slid(sl2, orient, 2)
		sliders.append(sl2)
	if 1:
		#say("Creating slider 3")
		sl3 = Slider(orient = orient, max_value = 100, ticks = 6, discrete = True)
		sl3.value = 100
		sl3.action = slid(sl3, orient, 3)
		sliders.append(sl3)
	#say("Created sliders")
	if orient == 'h':
		win.place_column(sliders, left = 20, top = 20, spacing = 20, sticky = 'ew')
		if sl2:
			sl2.vstretch = True
		if sl3:
			sl3.vmove = True
	else:
		win.place_row(sliders, left = 20, top = 20, spacing = 20, sticky = 'ns')
		if sl2:
			sl2.hstretch = True
		if sl3:
			sl3.hmove = True
	#say("Placed sliders")
	win.shrink_wrap()
	win.show()
Example #41
0
def test(orient, pos, pad):
    win = Window(title = "%s Sliders" % orient.upper(), position = pos,
        auto_position = False)
    sliders = []
    if 1:
        #say("Creating slider 1")
        sl1 = sl2 = sl3 = None
        sl1 = Slider(orient = orient, max_value = 100)
        sl1.action = slid(sl1, orient, 1)
        sliders.append(sl1)
    if 1:
        #say("Creating slider 2")
        sl2 = Slider(orient = orient, max_value = 100, ticks = 6, live = False)
        sl2.value = 50
        sl2.action = slid(sl2, orient, 2)
        sliders.append(sl2)
    if 1:
        #say("Creating slider 3")
        sl3 = Slider(orient = orient, max_value = 100, ticks = 6, discrete = True)
        sl3.value = 100
        sl3.action = slid(sl3, orient, 3)
        sliders.append(sl3)
    #say("Created sliders")
    if orient == 'h':
        win.place_column(sliders, left = 20, top = 20, spacing = 20, sticky = 'ew')
        if sl2:
            sl2.vstretch = True
        if sl3:
            sl3.vmove = True
    else:
        win.place_row(sliders, left = 20, top = 20, spacing = 20, sticky = 'ns')
        if sl2:
            sl2.hstretch = True
        if sl3:
            sl3.hmove = True
    #say("Placed sliders")
    win.shrink_wrap()
    win.show()
Example #42
0
    def open_soldier_chooser(self, blob, defender, x, y):
        win = Window(size=(220, 100), style='nonmodal_dialog')
        button = Button('Attack')
        text_field = TextField()
        button.style = 'normal'
        slider = Slider('h')

        def set_textfield():
            text_field.set_text(str(int(slider.get_value())))

        def start_conquering():
            winner = war(blob, defender, int(slider.get_value()))
            looser = blob if winner != blob else defender
            soldiers_left = int(slider.get_value() - (slider.max_value+1 - blob.get_soldiers()))
            conquer_territory(winner, looser, soldiers_left)
            self.model.set_blob_position(blob, x, y)
            print "Winner is: " + winner.territory.get_owner() + "!"
            win.destroy()

        if blob.get_soldiers() - 1 != 1:
            slider.max_value = blob.get_soldiers() - 1
            slider.min_value = 1
            slider.ticks = blob.get_soldiers() - 1
            slider.discrete = True
            slider.action = set_textfield
            button.action = start_conquering
            win.place(slider, left=0, top=10, right=220, bottom=50)
            win.place(button, left=15, top=50, right=55, bottom=90)
            win.place(text_field, left=170, top=50, right=210, bottom=70)
            win.show()
        else:
            winner = war(blob, defender, 1)
            looser = blob if winner != blob else defender
            soldiers_left = int(slider.get_value()) - (int(slider.max_value) - blob.get_soldiers())
            conquer_territory(winner, looser, soldiers_left)
            self.model.set_blob_position(blob, x, y)
            print "Winner is: " + winner.territory.get_owner() + "!"
from GUI import Window, ListButton, application
from testing import say

def report():
    print "Value =", but.value

but = ListButton(position = (20, 20),
    titles = ["Item %d" % i for i in xrange(30)],
    action = report)
but.value = 42
win = Window(title = "List Button")
win.add(but)
but.become_target()
win.show()

instructions = """
There should be a list button containing 30 items.
   
Selecting an item should cause its value to be reported. On Windows,
it should be possible to make a selection by typing the first letter
of the title.
"""

say(instructions)
application().run()
Example #44
0
def main():
    win = Window(size=(500, 400))
    view1 = View1(position=(10, 10), size=(200, 100))
    win.add(view1)
    win.show()
    application().run()
Example #45
0
                if button == Mouse.Right:
                    self.xxmin, self.xxmax = self.gwidget.zoomout(
                        self.xxmin, self.xxmax, self._xmin, self._xmax)
                    self.yymin, self.yymax = self.gwidget.zoomout(
                        self.yymin, self.yymax, self._ymin, self._ymax)
                else:
                    self.xxmin, self.xxmax, self.yymin, self.yymax = self._xmin, self._xmax, self._ymin, self._ymax
                self.gwidget.zoom(self.xxmin, self.xxmax, self.yymin,
                                  self.yymax)

                self.gwidget.make_data_list()
                self.gwidget.updateGL()
            self.px, self.py = None, None


##############################################################################
view = GLGraphWidget(size=(300, 300))
win = Window(title="Gears")
win.place(view, sticky="nsew")
view.become_target()
win.shrink_wrap()
win.show()

application().run()

#    app=QApplication(sys.argv)
#    g = glGraph()
#    app.setMainWidget(g.win)
#    g.win.show()
#    app.exec_loop()
Example #46
0
def test():
    cursor = StdCursors.empty_cursor()
    win = Window(title="No Cursor", width=500, height=400)
    view = TestDrawing(position=(20, 20), size=(300, 200), cursor=cursor)
    win.add(view)
    win.show()
Example #47
0
from PyQt4 import QtCore, QtGui
from GUI import Window
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:

    def _fromUtf8(s):
        return s


try:
    _encoding = QtGui.QApplication.UnicodeUTF8

    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)

except AttributeError:

    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)


if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)

    window = Window()
    window.show()
    sys.exit(app.exec_())
Example #48
0
def open_edit_menu(window_x, window_y, db_dict, attr_dict=None, attr_list=None, settings=None):

    list_players = PlayerDB.PlayerDB()
    list_formations = FormationDB.FormationDB()
    list_teams = TeamDB.TeamDB()

    if settings['edit_subject'] == 'players':
        list_players.load(settings['file_name'], 'list')
    elif settings['edit_subject'] == 'formations':
        list_formations.load(settings['file_name'], 'list')
    elif settings['edit_subject'] == 'teams':
        list_teams.load(settings['file_name'])

    if attr_dict is None:
        attr_dict = {}

    if attr_list is None:
        attr_list = []

    if settings is None:
        settings = {
            'window': 'edit',
            'edit_type': 'add',
            'edit_mode': 'simple',
            'edit_subject': 'players',
            'sort_order': True,
            'messages': {
                'search': [],
                'sort': [],
                'results': []
            }
        }
    else:
        if 'window' not in settings:
            settings['window'] = 'edit'
        if 'edit_type' not in settings:
            settings['edit_type'] = 'add'
        if 'edit_mode' not in settings:
            settings['edit_mode'] = 'simple'
        if 'edit_subject' not in settings:
            settings['edit_subject'] = 'players'
        if 'sort_order' not in settings:
            settings['sort_order'] = True
        if 'messages' not in settings:
            settings['messages'] = {'search': [], 'sort': [], 'results': []}

    num_results = 20
    general_display = []
    simple_display = []
    advanced_display = []

    # ========== Window ==========
    win_edit = Window()
    win_edit.title = edit_win_title
    win_edit.auto_position = False
    win_edit.position = (window_x, window_y)
    win_edit.size = (win_width, win_height)
    win_edit.resizable = 0
    win_edit.name = edit_title + " Window"

    # ========== Window Image View ==========
    class FormationsWindowImageView(View):
        def draw(self, c, r):
            c.backcolor = view_backcolor
            c.erase_rect(r)

    view = FormationsWindowImageView(size=win_edit.size)

    # ========== Title ==========
    title = Label(text=edit_title + ' File: ' + settings['file_name'])
    title.font = title_font
    title.width = title_width
    title.height = title_height
    title.x = (win_width - title_width) / 2
    title.y = top_border
    title.color = title_color
    title.just = 'center'
    general_display.append(title)

    # ========== Action Button Declarations ==========
    start_btn = Button("Start")
    back_btn = Button("Back")

    # ========== Mode Button Declarations ==========
    simple_btn = Button("Simple")
    advanced_btn = Button("Advanced")

    # ========== Tool Button Declarations ==========
    attribute_btn = Button("Add Search Attribute")
    sort_btn = Button("Add Sort Attribute")
    reset_btn = Button("Reset Results")

    # ========== Simple Field Declarations ==========
    rating_label = Label("Rating: ")
    rating_tf = TextField()
    name_label = Label("Name: ")
    name_tf = TextField()

    # ========== Action Button Functions ==========
    def start_btn_func():
        # Search for players based on attributes
        if settings['edit_subject'] == 'players':

            # Get the attributes to search with based on what mode is in use
            if simple_btn.enabled == 0:
                if len(name_tf.value) > 0:
                    search_dict = {'name_custom': (name_tf.value, 'exact')}
                else:
                    search_dict = {}
                if rating_tf.value.isdigit():
                    search_dict['rating'] = (int(rating_tf.value), 'exact')
            else:
                search_dict = attr_dict

            # Get players from database to add and search
            if settings['edit_type'] == 'add':

                db_players = db_dict['player_db'][1]

                if len(search_dict) == 0:
                    search_results = db_players
                else:
                    search_results = db_players.search(search_dict)
                    search_results = PlayerDB.PlayerDB(search_results)

            # Get players from list to edit or delete and search
            else:
                if len(search_dict) == 0:
                    search_results = list_players
                else:
                    search_results = list_players.search(search_dict)
                    search_results = PlayerDB.PlayerDB(search_results)

            # Sort players - if no attribute selected, use rating
            if len(attr_list) == 0:
                search_results.sort(['rating'], sort_order_radio_group.value)
            else:
                search_results.sort(attr_list, sort_order_radio_group.value)

            # Get attributes list and avoid duplicates
            attributes_list = []

            for attr in attr_list:
                if attributes_list.count(attr) == 0:
                    attributes_list.append(attr)

            for attr_key in attr_dict.iterkeys():
                if attributes_list.count(attr_key) == 0:
                    attributes_list.append(attr_key)

            display_players(search_results, attributes_list, (0, num_results))

        # Start button corresponds to formations
        elif settings['edit_subject'] == 'formations':

            # Get the attributes to search with based on what mode is in use
            if simple_btn.enabled == 0:
                if len(name_tf.value) > 0:
                    search_dict = {'name': (name_tf.value, 'exact')}
                else:
                    search_dict = {}
            else:
                search_dict = attr_dict

            # Get formations from database to add and search
            if settings['edit_type'] == 'add':

                db_formations = db_dict['formation_db'][1]

                if len(search_dict) == 0:
                    search_results = db_formations
                else:
                    search_results = db_formations.search(search_dict)
                    search_results = FormationDB.FormationDB(search_results)

            # Get formations from list to edit or delete and search
            else:
                if len(search_dict) == 0:
                    search_results = list_formations
                else:
                    search_results = list_formations.search(search_dict)
                    search_results = FormationDB.FormationDB(search_results)

            # Sort formations - if no attribute selected, use name
            if len(attr_list) == 0:
                search_results.sort(['name'], sort_order_radio_group.value)
            else:
                search_results.sort(attr_list, sort_order_radio_group.value)

            # Get attributes list and avoid duplicates
            attributes_list = []

            for attr in attr_list:
                if attributes_list.count(attr) == 0:
                    attributes_list.append(attr)

            for attr_key in attr_dict.iterkeys():
                if attributes_list.count(attr_key) == 0:
                    attributes_list.append(attr_key)

            display_formations(search_results, attributes_list, (0, num_results))

        # Start button corresponds to teams
        elif settings['edit_subject'] == 'teams':
            stuff = 0

        win_edit.become_target()

    def back_btn_func():
        # Clean up
        reset_btn_func()

        win_edit.hide()
        PickFile.open_pick_file_window(win_edit.x, win_edit.y, db_dict, settings)

    # ========== Search Type Button Functions ==========
    def simple_btn_func():
        simple_btn.enabled = 0
        advanced_btn.enabled = 1
        settings['edit_mode'] = 'simple'

        for display_item in advanced_display:
            view.remove(display_item)

        clean_results()

        for display_item in simple_display:
            view.add(display_item)

        name_tf.become_target()

    def advanced_btn_func():
        advanced_btn.enabled = 0
        simple_btn.enabled = 1
        settings['edit_mode'] = 'advanced'

        for display_item in simple_display:
            view.remove(display_item)

        clean_results()
        display_attributes()

        for display_item in advanced_display:
            view.add(display_item)

        win_edit.become_target()

    # ========== Tool Button Functions ==========
    def attribute_btn_func():
        # Delete results
        del settings['messages']['results'][:]

        attr_type = ''
        if settings['edit_subject'] == 'players':
            attr_type = 'player_search'
        elif settings['edit_subject'] == 'formations':
            attr_type = 'formation_search'
        elif settings['team_subject'] == 'teams':
            attr_type = 'player_search'
        else:
            print "Invalid edit_subject settings."

        # Open new window and close current window
        win_edit.hide()
        AddAttribute.open_attribute_window(win_edit.x, win_edit.y,
                                           db_dict, attr_dict, attr_list, attr_type, settings)

    def sort_btn_func():
        # Delete results
        del settings['messages']['results'][:]

        attr_type = ''
        if settings['edit_subject'] == 'players':
            attr_type = 'player_sort'
        elif settings['edit_subject'] == 'formations':
            attr_type = 'formation_sort'
        elif settings['team_subject'] == 'teams':
            attr_type = 'player_sort'
        else:
            print "Invalid edit_subject settings."

        # Open new window and close current window
        win_edit.hide()
        AddAttribute.open_attribute_window(win_edit.x, win_edit.y, db_dict,
                                           attr_dict, attr_list, attr_type, settings)

    def display_attributes():
        for search_item in settings['messages']['search']:
            view.add(search_item)
        for sort_item in settings['messages']['sort']:
            view.add(sort_item)

    def clean_results():
        # Remove messages off page
        for message in settings['messages']['search']:
            view.remove(message)
        for message in settings['messages']['sort']:
            view.remove(message)
        for message in settings['messages']['results']:
            view.remove(message)

        del settings['messages']['results'][:]

        win_edit.become_target()

    def reset_btn_func():
        # Remove messages off page
        for message in settings['messages']['search']:
            view.remove(message)
        for message in settings['messages']['sort']:
            view.remove(message)
        for message in settings['messages']['results']:
            view.remove(message)

        # Delete the attribute parameters for search and sort
        attr_dict.clear()
        del attr_list[:]
        del settings['messages']['results'][:]

        win_edit.become_target()

    def player_bio_btn_func(player):
        win_edit.become_target()
        PlayerBio.open_player_bio_window(win_edit.x, win_edit.y, player, win_edit,
                                         file_name=settings['file_name'], current_list=list_players)
        win_edit.hide()

    def formation_bio_btn_func(formation):
        win_edit.become_target()
        FormationBio.open_formation_bio_window(
                win_edit.x, win_edit.y, formation, win_edit, settings['file_name'], list_formations)
        win_edit.hide()

    def add_btn_func(list_item, btn):
        if settings['edit_subject'] == 'players':
            # Check if player is already on selected players list
            # Remove player from list
            player_data = list_players.search({'id': (list_item['id'], 'exact')})
            if len(player_data) > 0:
                # Remove
                list_players.db.remove(player_data[0])
                # Save
                list_players.sort(['rating'])
                list_players.save(settings['file_name'], 'list', True)

                # Switch button title
                btn.title = "+"

            # Add player to the list
            else:
                # Add
                list_players.db.append(list_item)
                # Save
                list_players.sort(['rating'])
                list_players.save(settings['file_name'], 'list', True)

                # Switch button title
                btn.title = "-"

        elif settings['edit_subject'] == 'formations':
            # Check if formation is already on selected formations list
            # Remove formation from list
            if list_item in list_formations.db:
                # Remove
                list_formations.db.remove(list_item)
                # Save
                list_formations.sort(['name'])
                list_formations.save(settings['file_name'], 'list', True)

                # Switch button title
                btn.title = "+"

            # Add formation to the list
            else:
                # Add
                list_formations.db.append(list_item)
                # Save
                list_formations.sort(['name'])
                list_formations.save(settings['file_name'], 'list', True)

                # Switch button title
                btn.title = "-"

        win_edit.become_target()

    def pos_btn_func(player, btn):
        # Open window to get position
        win_edit.hide()
        PickPosition.open_pick_position_window(win_edit.x, win_edit.y, player, list_players, settings, btn, win_edit)
        win_edit.become_target()

    # ========== Action Buttons ==========
    start_btn.x = (win_width - 2*small_button_width - small_button_spacing) / 2
    start_btn.y = title.bottom + small_button_top_spacing
    start_btn.height = small_button_height
    start_btn.width = small_button_width
    start_btn.font = small_button_font
    start_btn.action = start_btn_func
    start_btn.style = 'default'
    start_btn.color = small_button_color
    start_btn.just = 'right'
    general_display.append(start_btn)

    back_btn.x = start_btn.right + small_button_spacing
    back_btn.y = start_btn.top
    back_btn.height = small_button_height
    back_btn.width = small_button_width
    back_btn.font = small_button_font
    back_btn.action = back_btn_func
    back_btn.style = 'default'
    back_btn.color = small_button_color
    back_btn.just = 'right'
    general_display.append(back_btn)

    # ========== Edit Type Radio Buttons ==========
    def get_edit_type_rg():
        settings['edit_type'] = edit_type_radio_group.value
        win_edit.become_target()

    edit_type_radio_group = RadioGroup(action=get_edit_type_rg)

    radio_btn_width = 125
    radio_btn_space = 5

    # Edit Type
    type_add_radio_btn = RadioButton()
    if settings['edit_subject'] == 'players':
        type_add_radio_btn.title = 'Add Players'
    elif settings['edit_subject'] == 'formations':
        type_add_radio_btn.title = 'Add Formations'
    elif settings['edit_subject'] == 'teams':
        type_add_radio_btn.title = 'Add Teams'
    type_add_radio_btn.width = radio_btn_width
    type_add_radio_btn.x = (win_edit.width - 2*radio_btn_width - radio_btn_space) / 2
    type_add_radio_btn.y = start_btn.bottom + small_button_top_spacing
    type_add_radio_btn.group = edit_type_radio_group
    type_add_radio_btn.value = 'add'
    general_display.append(type_add_radio_btn)

    type_edit_radio_btn = RadioButton()
    if settings['edit_subject'] == 'players':
        type_edit_radio_btn.title = 'Edit/Delete Players'
    elif settings['edit_subject'] == 'formations':
        type_edit_radio_btn.title = 'Edit/Delete Forms'
    elif settings['edit_subject'] == 'teams':
        type_edit_radio_btn.title = 'Edit/Delete Teams'
    type_edit_radio_btn.width = radio_btn_width
    type_edit_radio_btn.x = type_add_radio_btn.right + radio_btn_space
    type_edit_radio_btn.y = type_add_radio_btn.top
    type_edit_radio_btn.group = edit_type_radio_group
    type_edit_radio_btn.value = 'edit'
    general_display.append(type_edit_radio_btn)

    edit_type_radio_group.value = settings['edit_type']

    # ========== Mode Buttons ==========
    simple_btn.x = (win_width - 2*small_button_width - small_button_spacing) / 2
    simple_btn.y = type_add_radio_btn.bottom + small_button_top_spacing
    simple_btn.height = small_button_height
    simple_btn.width = small_button_width
    simple_btn.font = small_button_font
    simple_btn.action = simple_btn_func
    simple_btn.style = 'default'
    simple_btn.color = small_button_color
    simple_btn.just = 'right'
    if settings['edit_mode'] == 'simple':
        simple_btn.enabled = 0
    general_display.append(simple_btn)

    advanced_btn.x = simple_btn.right + small_button_spacing
    advanced_btn.y = simple_btn.top
    advanced_btn.height = small_button_height
    advanced_btn.width = small_button_width
    advanced_btn.font = small_button_font
    advanced_btn.action = advanced_btn_func
    advanced_btn.style = 'default'
    advanced_btn.color = small_button_color
    advanced_btn.just = 'right'
    if settings['edit_mode'] == 'advanced':
        advanced_btn.enabled = 0
    general_display.append(advanced_btn)

    # ========== Sort Order Radio Buttons ==========
    def get_attribute_sort_order_rg():
        settings['sort_order'] = sort_order_radio_group.value
        win_edit.become_target()

    sort_order_radio_group = RadioGroup(action=get_attribute_sort_order_rg)

    asc_desc_radio_btn_width = 75
    asc_msg_width = 80
    radio_btn_space = 5

    asc_desc_rg_msg = Label(text="Sort Order:", font=std_tf_font, width=asc_msg_width, height=std_tf_height,
                            color=title_color)
    asc_desc_rg_msg.x = (win_edit.width - 2*asc_desc_radio_btn_width - radio_btn_space - asc_msg_width) / 2
    asc_desc_rg_msg.y = simple_btn.bottom + radio_btn_space
    general_display.append(asc_desc_rg_msg)

    descend_radio_btn = RadioButton("Descending")
    descend_radio_btn.width = asc_desc_radio_btn_width
    descend_radio_btn.x = asc_desc_rg_msg.right
    descend_radio_btn.y = asc_desc_rg_msg.top
    descend_radio_btn.group = sort_order_radio_group
    descend_radio_btn.value = True
    general_display.append(descend_radio_btn)

    ascend_radio_btn = RadioButton("Ascending")
    ascend_radio_btn.width = asc_desc_radio_btn_width
    ascend_radio_btn.x = descend_radio_btn.right + radio_btn_space
    ascend_radio_btn.y = descend_radio_btn.top
    ascend_radio_btn.group = sort_order_radio_group
    ascend_radio_btn.value = False
    general_display.append(ascend_radio_btn)

    sort_order_radio_group.value = settings['sort_order']

    # ========== Tool Buttons ==========
    attribute_btn.x = (win_width - 3*small_button_width - 2*small_button_spacing) / 2
    attribute_btn.y = asc_desc_rg_msg.bottom + 5
    attribute_btn.height = small_button_height
    attribute_btn.width = small_button_width
    attribute_btn.font = small_button_font
    attribute_btn.action = attribute_btn_func
    attribute_btn.style = 'default'
    attribute_btn.color = small_button_color
    attribute_btn.just = 'right'
    advanced_display.append(attribute_btn)

    sort_btn.x = attribute_btn.right + small_button_spacing
    sort_btn.y = attribute_btn.top
    sort_btn.height = small_button_height
    sort_btn.width = small_button_width
    sort_btn.font = small_button_font
    sort_btn.action = sort_btn_func
    sort_btn.style = 'default'
    sort_btn.color = small_button_color
    sort_btn.just = 'right'
    advanced_display.append(sort_btn)

    reset_btn.x = sort_btn.right + small_button_spacing
    reset_btn.y = attribute_btn.top
    reset_btn.height = small_button_height
    reset_btn.width = small_button_width
    reset_btn.font = small_button_font
    reset_btn.action = reset_btn_func
    reset_btn.style = 'default'
    reset_btn.color = small_button_color
    reset_btn.just = 'right'
    advanced_display.append(reset_btn)

    # ========== Simple Fields ==========
    label_width = 50
    rating_tf_width = 30
    field_spacing = 20

    rating_label.font = std_tf_font
    rating_label.width = label_width
    rating_label.height = std_tf_height
    rating_label.x = (win_edit.width - 2*label_width - std_tf_width - rating_tf_width - field_spacing) / 2
    rating_label.y = asc_desc_rg_msg.bottom + 5
    rating_label.color = title_color
    if settings['edit_subject'] != 'formations':
        simple_display.append(rating_label)

    rating_tf.font = std_tf_font
    rating_tf.width = rating_tf_width
    rating_tf.height = 25
    rating_tf.x = rating_label.right
    rating_tf.y = rating_label.top
    if settings['edit_subject'] != 'formations':
        simple_display.append(rating_tf)

    name_label.font = std_tf_font
    name_label.width = label_width
    name_label.height = std_tf_height
    if settings['edit_subject'] != 'formations':
        name_label.x = rating_tf.right + field_spacing
    else:
        name_label.x = (win_edit.width - label_width - std_tf_width) / 2
    name_label.y = rating_label.top
    name_label.color = title_color
    simple_display.append(name_label)

    name_tf.font = std_tf_font
    name_tf.width = std_tf_width
    name_tf.height = 25
    name_tf.x = name_label.right
    name_tf.y = rating_label.top
    simple_display.append(name_tf)

    # ========== Messages ==========
    lowest_msg_l = start_btn.top
    lowest_msg_r = start_btn.top

    attr_msg_offset = 25

    # Attribute Messages
    del settings['messages']['search'][:]
    del settings['messages']['sort'][:]

    if len(attr_dict) > 0:
        settings['messages']['search'].append(Label(text="Search Attributes:", font=title_tf_font, width=std_tf_width,
                                                    height=std_tf_height, x=attr_msg_offset, y=lowest_msg_l,
                                                    color=title_color))
        lowest_msg_l += std_tf_height

        for key, value in attr_dict.iteritems():
            msg_text = format_attr_name(key) + ": "
            if key in ['id', 'baseId', 'nationId', 'leagueId', 'clubId']:
                msg_text += str(value[0])
            elif type(value[0]) is int:
                msg_text += value[1].capitalize() + ' ' + str(value[0])
            elif value[1] == 'not':
                msg_text += value[1].capitalize() + ' "' + str(value[0]) + '"'
            else:
                msg_text += '"' + str(value[0]) + '"'

            attr_label = Label(text=msg_text, font=std_tf_font, width=std_tf_width,
                               height=std_tf_height, x=attr_msg_offset, y=lowest_msg_l, color=title_color)
            lowest_msg_l += std_tf_height
            settings['messages']['search'].append(attr_label)

    if len(attr_list) > 0:
        settings['messages']['sort'].append(Label(text="Sort Attributes:", font=title_tf_font, width=std_tf_width,
                                                  height=std_tf_height, x=advanced_btn.right + 3*attr_msg_offset,
                                                  y=lowest_msg_r, color=title_color))
        lowest_msg_r += std_tf_height

        for value in attr_list:
            attr_label = Label(text=(format_attr_name(value)), font=std_tf_font, width=std_tf_width,
                               height=std_tf_height, x=advanced_btn.right + 3*attr_msg_offset, y=lowest_msg_r,
                               color=title_color)
            lowest_msg_r += std_tf_height
            settings['messages']['sort'].append(attr_label)

    # ========== Previous, Add to List, Next Buttons ==========
    previous_btn = Button("<<< Previous %d" % num_results)
    add_to_list_btn = Button()
    next_btn = Button("Next %d >>>" % num_results)
    total_num_results_label = Label()
    pages_label = Label()

    def add_to_list_btn_func(input_list, func_type):
        item_list = copy.deepcopy(input_list)

        if settings['edit_subject'] == 'players':
            if func_type == 'add all':
                added_players = []
                # Add current results to player list
                for player in item_list:
                    if list_players.db.count(player) == 0:
                        list_players.db.append(player)
                        added_players.append(player)

                # Sort
                list_players.sort(['rating'])
                # Save
                list_players.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Players"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'remove select')

                # Keep track of just added players
                settings['messages']['players_changed'] = added_players

            elif func_type == 'remove all':
                removed_players = []
                # Remove current results from player list
                for player in item_list:
                    if list_players.db.count(player) > 0:
                        list_players.db.remove(player)
                        removed_players.append(player)

                # Sort
                list_players.sort(['rating'])
                # Save
                list_players.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Players"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'add select')

                # Keep track of just removed players
                settings['messages']['players_changed'] = removed_players

            elif func_type == 'add select':
                # Add select players back to player list
                for player in settings['messages']['players_changed']:
                    if list_players.db.count(player) == 0:
                        list_players.db.append(player)

                # Sort
                list_players.sort(['rating'])
                # Save
                list_players.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Players"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'remove select')

            elif func_type == 'remove select':
                # Remove select players from player list
                for player in settings['messages']['players_changed']:
                    if list_players.db.count(player) > 0:
                        list_players.db.remove(player)

                # Sort
                list_players.sort(['rating'])
                # Save
                list_players.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Players"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'add select')

        elif settings['edit_subject'] == 'formations':
            if func_type == 'add all':
                added_formations = []
                # Add current results to formation list
                for formation in item_list:
                    if list_formations.db.count(formation) == 0:
                        list_formations.db.append(formation)
                        added_formations.append(formation)

                # Sort
                list_formations.sort(['name'])
                # Save
                list_formations.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Forms"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'remove select')

                # Keep track of just added formations
                settings['messages']['formations_changed'] = added_formations

            elif func_type == 'remove all':
                removed_formations = []
                # Remove current results from formation list
                for formation in item_list:
                    if formation in list_formations.db:
                        list_formations.db.remove(formation)
                        removed_formations.append(formation)

                # Sort
                list_formations.sort(['name'])
                # Save
                list_formations.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Forms"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'add select')

                # Keep track of just removed formations
                settings['messages']['formations_changed'] = removed_formations

            elif func_type == 'add select':
                # Add select formations back to formation list
                for formation in settings['messages']['formations_changed']:
                    if list_formations.db.count(formation) == 0:
                        list_formations.db.append(formation)

                # Sort
                list_formations.sort(['name'])
                # Save
                list_formations.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Forms"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'remove select')

            elif func_type == 'remove select':
                # Remove select formations from formation list
                for formation in settings['messages']['formations_changed']:
                    if list_formations.db.count(formation) > 0:
                        list_formations.db.remove(formation)

                # Sort
                list_formations.sort(['name'])
                # Save
                list_formations.save(settings['file_name'], 'list', True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Forms"
                add_to_list_btn.action = (add_to_list_btn_func, item_list, 'add select')

        del item_list
        win_edit.become_target()

    def previous_btn_func(display_db=None, attributes=None, index_range=None):
        if display_db is not None:
            # display previous results
            if settings['edit_subject'] == 'players':
                display_players(display_db, attributes, index_range)
            elif settings['edit_subject'] == 'formations':
                display_formations(display_db, attributes, index_range)
            #elif settings['edit_subject'] == 'teams':
                #display_teams(display_db, attributes, index_range)
        win_edit.become_target()

    def next_btn_func(display_db=None, attributes=None, index_range=None):
        if display_db is not None:
            # display next results
            if settings['edit_subject'] == 'players':
                display_players(display_db, attributes, index_range)
            elif settings['edit_subject'] == 'formations':
                display_formations(display_db, attributes, index_range)
            # elif settings['edit_subject'] == 'teams':
                # display_teams(display_db, attributes, index_range)
        win_edit.become_target()

    add_to_list_btn.x = attribute_btn.right + small_button_spacing
    add_to_list_btn.y = attribute_btn.bottom + 5
    add_to_list_btn.height = tiny_button_height
    add_to_list_btn.width = small_button_width
    add_to_list_btn.font = small_button_font
    add_to_list_btn.style = 'default'
    add_to_list_btn.color = small_button_color
    add_to_list_btn.just = 'right'

    previous_btn.height = tiny_button_height
    previous_btn.width = small_button_width
    previous_btn.x = add_to_list_btn.left - previous_btn.width - small_button_spacing
    previous_btn.y = add_to_list_btn.top
    previous_btn.font = small_button_font
    previous_btn.action = previous_btn_func
    previous_btn.style = 'default'
    previous_btn.color = small_button_color
    previous_btn.just = 'right'

    next_btn.height = tiny_button_height
    next_btn.width = small_button_width
    next_btn.x = add_to_list_btn.right + small_button_spacing
    next_btn.y = add_to_list_btn.top
    next_btn.font = small_button_font
    next_btn.action = next_btn_func
    next_btn.style = 'default'
    next_btn.color = small_button_color
    next_btn.just = 'right'

    total_num_results_label.font = std_tf_font
    total_num_results_label.width = 100
    total_num_results_label.height = std_tf_height
    total_num_results_label.x = previous_btn.left + - 100 - 10
    total_num_results_label.y = add_to_list_btn.top
    total_num_results_label.color = title_color
    total_num_results_label.just = 'right'

    pages_label.font = std_tf_font
    pages_label.width = 125
    pages_label.height = std_tf_height
    pages_label.x = next_btn.right + 10
    pages_label.y = add_to_list_btn.top
    pages_label.color = title_color
    pages_label.just = 'left'

    # ========== Display players from search ==========
    def display_players(display_db, attributes, index_range):
        # Remove old messages off page
        for message in settings['messages']['results']:
            view.remove(message)
        del settings['messages']['results'][:]

        # Add navigation buttons to page
        if settings['edit_type'] == 'add':
            add_to_list_btn.title = 'Add All Players'
            add_to_list_btn.action = (add_to_list_btn_func, display_db.db, 'add all')
        elif settings['edit_type'] == 'edit':
            add_to_list_btn.title = 'Remove All Players'
            add_to_list_btn.action = (add_to_list_btn_func, display_db.db, 'remove all')
        else:
            print "Invalid edit type."

        previous_range = (index_range[0]-num_results, index_range[0])
        previous_btn.action = (previous_btn_func, display_db, attributes, previous_range)

        next_range = (index_range[1], index_range[1]+num_results)
        next_btn.action = (next_btn_func, display_db, attributes, next_range)

        total_num_results_label.text = str(len(display_db.db)) + " Players"
        pages_label.text = "Page %d of %d" % (int(index_range[1]/num_results),
                                              math.ceil(len(display_db.db) / float(num_results)))

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(display_db.db) - 1:
            next_btn.enabled = 1
        else:
            next_btn.enabled = 0

        settings['messages']['results'].append(add_to_list_btn)
        settings['messages']['results'].append(previous_btn)
        settings['messages']['results'].append(next_btn)
        settings['messages']['results'].append(total_num_results_label)
        settings['messages']['results'].append(pages_label)

        # Print out labels
        labels = player_info_labels(attributes)
        stat_index = 1
        spacing_list = [25, 125, 40, 40, 65, 115, 115, 115, 40]
        left_border = (win_width - sum(spacing_list[:-1]) - (len(labels) - len(spacing_list) + 2) * spacing_list[-1])/2
        msg_x = left_border + spacing_list[0]
        msg_y = add_to_list_btn.bottom + 5

        for info_label in labels:
            player_label = Label(text=info_label, font=std_tf_font_bold, width=spacing_list[stat_index]-5,
                                 height=std_tf_height, x=msg_x, y=msg_y, color=title_color)
            settings['messages']['results'].append(player_label)
            msg_x += spacing_list[stat_index]

            if stat_index < len(spacing_list)-1:
                stat_index += 1

        msg_y += std_tf_height + 5

        # Print out players
        for idx, player in enumerate(display_db.db[index_range[0]:index_range[1]]):
            msg_x = left_border
            player_stats = player_info(player, attributes)
            stat_index = 0

            player_data = list_players.search({'id': (player['id'], 'exact')})
            if len(player_data) > 0:
                add_btn_text = '-'
                temp_player = player_data[0]
            else:
                add_btn_text = '+'
                temp_player = player
            add_btn = Button(title=add_btn_text, width=spacing_list[stat_index]-5, height=15, x=msg_x, y=msg_y)
            add_btn.action = (add_btn_func, temp_player, add_btn)
            settings['messages']['results'].append(add_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            # Check for names that are too long
            name = player_stats[0]
            if len(name) > 20:
                name = player['lastName']

            bio_btn = Button(title=name, width=spacing_list[stat_index]-5, height=15, x=msg_x, y=msg_y,
                             action=(player_bio_btn_func, temp_player))
            settings['messages']['results'].append(bio_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for player_stat in player_stats[1:]:
                player_label = Label(text=player_stat, font=small_button_font, width=spacing_list[stat_index]-5,
                                     height=std_tf_height, x=msg_x, y=msg_y, color=title_color)
                settings['messages']['results'].append(player_label)

                # Save values for position edit button
                if stat_index == 3:
                    edit_x = msg_x
                    edit_y = msg_y

                msg_x += spacing_list[stat_index]
                if stat_index < len(spacing_list) - 1:
                    stat_index += 1

            if settings['edit_type'] == 'edit':
                pos_btn = Button(title=player_stats[2], width=28, height=15, x=edit_x, y=edit_y)
                pos_btn.action = (pos_btn_func, player, pos_btn)
                settings['messages']['results'].append(pos_btn)

            msg_y += std_tf_height

        for results_msg in settings['messages']['results']:
            view.add(results_msg)

    # ========== Display formations from search ==========
    def display_formations(display_db, attributes, index_range):
        # Remove old messages off page
        for message in settings['messages']['results']:
            view.remove(message)
        del settings['messages']['results'][:]

        # Add navigation buttons to page
        if settings['edit_type'] == 'add':
            add_to_list_btn.title = 'Add All Formations'
            add_to_list_btn.action = (add_to_list_btn_func, display_db.db, 'add all')
        elif settings['edit_type'] == 'edit':
            add_to_list_btn.title = 'Remove All Formations'
            add_to_list_btn.action = (add_to_list_btn_func, display_db.db, 'remove all')
        else:
            print "Invalid edit type."

        previous_range = (index_range[0]-num_results, index_range[0])
        previous_btn.action = (previous_btn_func, display_db, attributes, previous_range)

        next_range = (index_range[1], index_range[1]+num_results)
        next_btn.action = (next_btn_func, display_db, attributes, next_range)

        total_num_results_label.text = str(len(display_db.db)) + " Formations"
        pages_label.text = "Page %d of %d" % (int(index_range[1]/num_results),
                                              math.ceil(len(display_db.db)/float(num_results)))

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(display_db.db) - 1:
            next_btn.enabled = 1
        else:
            next_btn.enabled = 0

        settings['messages']['results'].append(add_to_list_btn)
        settings['messages']['results'].append(previous_btn)
        settings['messages']['results'].append(next_btn)
        settings['messages']['results'].append(total_num_results_label)
        settings['messages']['results'].append(pages_label)

        # Print out labels
        labels = formation_info_labels()
        stat_index = 1
        spacing_list = [25, 100, 100, 55, 55, 55, 55, 140, 160]
        left_border = (win_edit.width - sum(spacing_list))/2
        msg_x = left_border + spacing_list[0]
        msg_y = add_to_list_btn.bottom + 5

        for info_label in labels:
            formation_label = Label(text=info_label, font=std_tf_font_bold, width=spacing_list[stat_index]-5,
                                    height=std_tf_height, x=msg_x, y=msg_y, color=title_color)
            settings['messages']['results'].append(formation_label)
            msg_x += spacing_list[stat_index]

            if stat_index < len(spacing_list)-1:
                stat_index += 1

        msg_y += std_tf_height + 5

        # Print out formations
        for idx, formation in enumerate(display_db.db[index_range[0]:index_range[1]]):
            msg_x = left_border
            formation_stats = formation_info(formation)
            stat_index = 0

            if formation in list_formations.db:
                add_btn_text = '-'
            else:
                add_btn_text = '+'

            add_btn = Button(title=add_btn_text, width=spacing_list[stat_index]-5, height=15, x=msg_x, y=msg_y)
            add_btn.action = (add_btn_func, formation, add_btn)
            settings['messages']['results'].append(add_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            bio_btn = Button(title=formation['name'], width=spacing_list[stat_index]-5, height=15, x=msg_x, y=msg_y,
                             action=(formation_bio_btn_func, formation))
            settings['messages']['results'].append(bio_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for formation_stat in formation_stats[1:]:
                formation_label = Label(text=formation_stat, font=small_button_font, width=spacing_list[stat_index]-5,
                                        height=std_tf_height, x=msg_x, y=msg_y, color=title_color)
                settings['messages']['results'].append(formation_label)

                msg_x += spacing_list[stat_index]
                if stat_index < len(spacing_list) - 1:
                    stat_index += 1

            msg_y += std_tf_height

        for results_msg in settings['messages']['results']:
            view.add(results_msg)

    # ========== Add components to view and add view to window ==========
    for item in general_display:
        view.add(item)

    if settings['edit_mode'] == 'simple':
        for item in simple_display:
            view.add(item)
    elif settings['edit_mode'] == 'advanced':
        for item in advanced_display:
            view.add(item)
        display_attributes()

    for msg in settings['messages']['results']:
        view.add(msg)

    win_edit.add(view)
    view.become_target()
    win_edit.show()
Example #49
0
def open_create_list_window(window_x, window_y, db_dict, settings):

    message_text = 'Select list type.'
    create_list_settings = dict()
    create_list_settings['results'] = []
    create_list_settings['process_step'] = 'list type'
    num_results = 5

    # ========== Window ==========
    win_create_list = Window()
    win_create_list.title = create_list_win_title
    win_create_list.auto_position = False
    win_create_list.position = (window_x+100, window_y+100)
    win_create_list.size = (win_width-100, win_height-200)
    win_create_list.resizable = 0
    win_create_list.name = create_list_title + " Window"
    win_create_list.show()

    # ========== Window Image View ==========
    class StartWindowImageView(View):
        def draw(self, c, r):
            c.backcolor = view_backcolor
            c.erase_rect(r)

    view = StartWindowImageView(size=win_create_list.size)

    # ========== Title ==========
    title = Label(text=create_list_title)
    title.font = title_font
    title.width = title_width
    title.height = title_height
    title.x = (win_create_list.width - title_width) / 2
    title.y = top_border
    title.color = title_color
    title.just = 'center'

    # ========== Message Label ==========
    message = Label(font=title_font_3, width=win_create_list.width - 50, height=title_height,
                    x=25, y=title.bottom + top_border, color=title_color, just='center')
    message.text = message_text

    # ========== Button Declarations ==========
    enter_btn = Button("Enter")
    undo_btn = Button("Undo Add")
    back_btn = Button("Back")

    player_list_btn = Button("Player")
    formation_list_btn = Button("Formation")
    team_list_btn = Button("Team")

    # ========== Results Navigation Item Declarations ==========
    previous_btn = Button("<<< Previous %d" % num_results)
    next_btn = Button("Next %d >>>" % num_results)
    total_num_results_label = Label()
    pages_label = Label()

    # ========== Button Functions ==========
    def enter_btn_func():
        # Get file name and save
        if create_list_settings['process_step'] == 'file name':

            # Get file name and file prefix
            file_name = value_tf.value
            file_prefix = get_file_prefix('current_' + create_list_settings['list_type'] + '_list')

            if len(file_name) > 0:

                if not isfile('JSONs/' + file_prefix + file_name + '.json'):

                    # Create list object, set message, and set process step
                    if create_list_settings['list_type'] == 'player':
                        new_list = PlayerDB()
                        message.text = "Enter player rating/name or just name."
                        create_list_settings['process_step'] = 'get player'

                    elif create_list_settings['list_type'] == 'formation':
                        new_list = FormationDB()
                        message.text = "Enter part or full formation name, or nothing for full list."
                        create_list_settings['process_step'] = 'get formation'

                    elif create_list_settings['list_type'] == 'team':
                        new_list = TeamDB()
                        message.text = "Blank team list created. Add teams from Search menu."
                        create_list_settings['process_step'] = 'get team'
                        back_btn.title = "Done"
                        enter_btn.enabled = 0

                    else:
                        new_list = PlayerDB()
                        print "Invalid list type."

                    # Assign file name and file object
                    create_list_settings['list'] = new_list
                    create_list_settings['file_name'] = file_name

                    # Clear box content
                    value_tf.value = ''

                else:
                    message.text = "A file with that name already exists."

            else:
                message.text = "File name must be at least 1 character."

        # Get player to add to list
        elif create_list_settings['process_step'] == 'get player':
            # Get input
            player_input = value_tf.value

            # Remove result messages off page
            for result_message in create_list_settings['results']:
                view.remove(result_message)

            if len(player_input) > 0:
                search_dict = {}

                # Check for rating
                if player_input.split(' ')[0].isdigit():
                    # Check if there is a name and rating
                    if len(player_input.split(' ')) > 1:
                        search_dict['rating'] = (int(player_input.split(' ')[0]), 'exact')

                        # Get name
                        search_dict['name_custom'] = (player_input.split(' ', 1)[1], 'exact')

                    else:
                        message.text = "Invalid. Ex: '99 Superman'  or 'Superman'."

                # No rating, just name (or invalid)
                else:
                    search_dict['name_custom'] = (player_input, 'exact')

                # Valid input
                if len(search_dict) > 0:
                    # Search for players
                    results = PlayerDB(db_dict['player_db'][1].search(search_dict))
                    results.sort(['rating'])

                    # No matching players found
                    if len(results.db) == 0:
                        message.text = "Unable to find player. Try again."

                    # If only one player in results, add player.
                    elif len(results.db) == 1:
                        add_player_btn_func(results.db[0])

                    else:
                        message.text = "Multiple players found. Pick correct one."
                        display_players(results, [], (0, num_results))

            else:
                message.text = "Invalid. Ex: '99 Superman' or 'Superman'."

        # Get formation to add to list
        elif create_list_settings['process_step'] == 'get formation':
            # Get input
            formation_input = value_tf.value

            # Remove result messages off page
            for result_message in create_list_settings['results']:
                view.remove(result_message)

            search_dict = {'name': (formation_input, 'exact')}

            # Search for formations
            results = FormationDB(db_dict['formation_db'][1].search(search_dict))
            # Remove formations already on list
            for formation in create_list_settings['list'].db:
                if formation in results.db:
                    results.db.remove(formation)
            results.sort(['name'])

            # No matching formations found
            if len(results.db) == 0:
                message.text = "Unable to find formation. Try again."

            # If only one formation in results, add formation.
            elif len(results.db) == 1:
                add_formation_btn_func(results.db[0])

            else:
                message.text = "Multiple formations found. Pick correct one."
                display_formations(results, [], (0, num_results))

        # Get team to add to list
        elif create_list_settings['process_step'] == 'get team':
            stuff = 0

        # Invalid process step
        else:
            print "Create file process step is invalid."

        value_tf.become_target()

    def undo_btn_func():
        # Remove last player added and save
        if create_list_settings['process_step'] == 'get player':
            if len(create_list_settings['list'].db) > 0:
                player = create_list_settings['list'].db.pop(-1)
                create_list_settings['list'].save(create_list_settings['file_name'], 'list', True)

                common_name = ascii_text(player['commonName'])
                player_name = ascii_text(player['firstName']) + ' ' + ascii_text(player['lastName'])
                if len(common_name) > 0:
                    player_name = common_name + " (" + player_name + ")"

                message.text = "Removed %s!" % player_name

        # Remove last formation added and save
        elif create_list_settings['process_step'] == 'get formation':
            if len(create_list_settings['list'].db) > 0:
                formation = create_list_settings['list'].db.pop(-1)
                create_list_settings['list'].save(create_list_settings['file_name'], 'list', True)

                message.text = "Removed %s!" % formation['name']

        # Disable undo if no items left
        if len(create_list_settings['list'].db) == 0:
            undo_btn.enabled = 0

    def back_btn_func():
        # Sort and save player list before exiting
        if create_list_settings['process_step'] == 'get player':
            create_list_settings['list'].sort(['rating'])
            create_list_settings['list'].save(create_list_settings['file_name'], 'list', True)

        # Sort and save formation list before exiting
        elif create_list_settings['process_step'] == 'get formation':
            create_list_settings['list'].sort(['name'])
            create_list_settings['list'].save(create_list_settings['file_name'], 'list', True)

        elif create_list_settings['process_step'] == 'get team':
            create_list_settings['list'].sort(['rating'])
            create_list_settings['list'].save(create_list_settings['file_name'], True)

        FilesMenu.open_files_menu(window_x, window_y, db_dict, settings)
        win_create_list.hide()

    def list_type_func(list_type):
        # Remove list type buttons
        view.remove(player_list_btn)
        view.remove(formation_list_btn)
        view.remove(team_list_btn)

        # Add textfield, enabled enter button, and change message
        view.add(value_tf)
        enter_btn.enabled = 1
        message.text = "Enter file name."
        create_list_settings['list_type'] = list_type

        # Set list type
        create_list_settings['process_step'] = 'file name'
        value_tf.become_target()

    # ========== Action Buttons ==========
    enter_btn.x = (win_create_list.width - 3*button_width - 2*button_spacing) / 2
    enter_btn.y = win_create_list.height - button_height - 40
    enter_btn.height = button_height
    enter_btn.width = button_width
    enter_btn.font = button_font
    enter_btn.action = enter_btn_func
    enter_btn.style = 'default'
    enter_btn.color = button_color
    enter_btn.just = 'right'
    enter_btn.enabled = 0

    undo_btn.x = enter_btn.right + button_spacing
    undo_btn.y = enter_btn.top
    undo_btn.height = button_height
    undo_btn.width = button_width
    undo_btn.font = button_font
    undo_btn.action = undo_btn_func
    undo_btn.style = 'default'
    undo_btn.color = button_color
    undo_btn.just = 'right'
    undo_btn.enabled = 0

    back_btn.x = undo_btn.right + button_spacing
    back_btn.y = enter_btn.top
    back_btn.height = button_height
    back_btn.width = button_width
    back_btn.font = button_font
    back_btn.action = back_btn_func
    back_btn.style = 'default'
    back_btn.color = button_color
    back_btn.just = 'right'

    # ========== List Type Buttons ==========
    player_list_btn.x = (win_create_list.width - 3*button_width - 2*button_spacing) / 2
    player_list_btn.y = message.bottom + top_border
    player_list_btn.height = button_height
    player_list_btn.width = button_width
    player_list_btn.font = button_font
    player_list_btn.action = (list_type_func, 'player')
    player_list_btn.style = 'default'
    player_list_btn.color = button_color
    player_list_btn.just = 'right'

    formation_list_btn.x = player_list_btn.right + button_spacing
    formation_list_btn.y = player_list_btn.top
    formation_list_btn.height = button_height
    formation_list_btn.width = button_width
    formation_list_btn.font = button_font
    formation_list_btn.action = (list_type_func, 'formation')
    formation_list_btn.style = 'default'
    formation_list_btn.color = button_color
    formation_list_btn.just = 'right'

    team_list_btn.x = formation_list_btn.right + button_spacing
    team_list_btn.y = player_list_btn.top
    team_list_btn.height = button_height
    team_list_btn.width = button_width
    team_list_btn.font = button_font
    team_list_btn.action = (list_type_func, 'team')
    team_list_btn.style = 'default'
    team_list_btn.color = button_color
    team_list_btn.just = 'right'

    # ========== Value Textfield ==========
    value_tf = TextField()
    value_tf.width = 200
    value_tf.x = (win_create_list.width - value_tf.width) / 2
    value_tf.y = message.bottom + top_border
    value_tf.height = 25
    value_tf.font = std_tf_font

    # ========== Players navigation functions ==========
    def previous_btn_func(display_db=None, attributes=None, index_range=None):
        if display_db is not None:
            # display previous results
            if create_list_settings['process_step'] == 'get player':
                display_players(display_db, attributes, index_range)
            elif create_list_settings['process_step'] == 'get formation':
                display_formations(display_db, attributes, index_range)
        win_create_list.become_target()

    def next_btn_func(display_db=None, attributes=None, index_range=None):
        if display_db is not None:
            # display next results
            if create_list_settings['process_step'] == 'get player':
                display_players(display_db, attributes, index_range)
            elif create_list_settings['process_step'] == 'get formation':
                display_formations(display_db, attributes, index_range)
        win_create_list.become_target()

    def add_player_btn_func(player):
        # Check for duplicates
        if create_list_settings['list'].db.count(player) == 0:
            # Add player and save
            create_list_settings['list'].db.append(player)
            create_list_settings['list'].save(create_list_settings['file_name'], 'list', True)

            # Remove result messages off page
            for result_message in create_list_settings['results']:
                view.remove(result_message)

            common_name = ascii_text(player['commonName'])
            player_name = ascii_text(player['firstName']) + ' ' + ascii_text(player['lastName'])
            if len(common_name) > 0:
                player_name = common_name + " (" + player_name + ")"

            # Reset page
            value_tf.value = ''
            message.text = "Added %s!" % player_name
            back_btn.title = "Done"
            undo_btn.enabled = 1
            value_tf.become_target()

        # Duplicate player, don't add
        else:
            message.text = "Player already on list."
            win_create_list.become_target()

    def add_formation_btn_func(formation):
        # Check for duplicates
        if create_list_settings['list'].db.count(formation) == 0:
            # Add formation and save
            create_list_settings['list'].db.append(formation)
            create_list_settings['list'].save(create_list_settings['file_name'], 'list', True)

            # Remove result messages off page
            for result_message in create_list_settings['results']:
                view.remove(result_message)

            # Reset page
            value_tf.value = ''
            message.text = "Added %s!" % formation['name']
            back_btn.title = "Done"
            undo_btn.enabled = 1
            value_tf.become_target()

        # Duplicate formation, don't add
        else:
            message.text = "Formation already on list."
            win_create_list.become_target()

    # ========== Display Players Buttons ==========
    previous_btn.height = tiny_button_height
    previous_btn.width = small_button_width
    previous_btn.x = (win_create_list.width - 2*small_button_width - small_button_spacing) / 2
    previous_btn.y = value_tf.bottom + top_border
    previous_btn.font = small_button_font
    previous_btn.action = previous_btn_func
    previous_btn.style = 'default'
    previous_btn.color = small_button_color
    previous_btn.just = 'right'

    next_btn.height = tiny_button_height
    next_btn.width = small_button_width
    next_btn.x = previous_btn.right + small_button_spacing
    next_btn.y = previous_btn.top
    next_btn.font = small_button_font
    next_btn.action = next_btn_func
    next_btn.style = 'default'
    next_btn.color = small_button_color
    next_btn.just = 'right'

    total_num_results_label.font = std_tf_font
    total_num_results_label.width = 100
    total_num_results_label.height = std_tf_height
    total_num_results_label.x = previous_btn.left + - 100 - 10
    total_num_results_label.y = previous_btn.top
    total_num_results_label.color = title_color
    total_num_results_label.just = 'right'

    pages_label.font = std_tf_font
    pages_label.width = 125
    pages_label.height = std_tf_height
    pages_label.x = next_btn.right + 10
    pages_label.y = previous_btn.top
    pages_label.color = title_color
    pages_label.just = 'left'

    # ========== Display info from search ==========
    def display_players(results_list, attributes, index_range):
        # Remove old messages off page
        for result_message in create_list_settings['results']:
            view.remove(result_message)
        del create_list_settings['results'][:]

        # Add navigation buttons to page
        previous_range = (index_range[0]-num_results, index_range[0])
        previous_btn.action = (previous_btn_func, results_list, attributes, previous_range)

        next_range = (index_range[1], index_range[1]+num_results)
        next_btn.action = (next_btn_func, results_list, attributes, next_range)

        total_num_results_label.text = str(len(results_list.db)) + " Players"
        pages_label.text = "Page %d of %d" % (int(index_range[1]/num_results),
                                              math.ceil(len(results_list.db)/float(num_results)))

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(results_list.db) - 1:
            next_btn.enabled = 1
        else:
            next_btn.enabled = 0

        create_list_settings['results'].append(previous_btn)
        create_list_settings['results'].append(next_btn)
        create_list_settings['results'].append(total_num_results_label)
        create_list_settings['results'].append(pages_label)

        # Print out labels
        labels = [''] + player_info_labels(attributes)
        stat_index = 0
        add_btn_width = 30
        add_btn_space = add_btn_width + 10
        spacing_list = [add_btn_space, 125, 40, 40, 65, 115, 115, 115]
        left_border = (win_create_list.width - sum(spacing_list)) / 2
        msg_x = left_border
        msg_y = previous_btn.bottom + 5

        for info_label in labels:
            player_label = Label(text=info_label, font=std_tf_font_bold, width=spacing_list[stat_index]-5,
                                 height=std_tf_height, x=msg_x, y=msg_y, color=title_color)
            create_list_settings['results'].append(player_label)
            msg_x += spacing_list[stat_index]
            stat_index += 1

        msg_y += std_tf_height + 5

        # Print out players
        for idx, player in enumerate(results_list.db[index_range[0]:index_range[1]]):
            msg_x = left_border
            player_stats = player_info(player, attributes)
            stat_index = 0

            add_btn = Button("Add", width=add_btn_width, height=15, x=msg_x, y=msg_y,
                             action=(add_player_btn_func, player))
            create_list_settings['results'].append(add_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for player_stat in player_stats:
                player_label = Label(text=player_stat, font=small_button_font, width=win_width-(2*left_border),
                                     height=std_tf_height, x=msg_x, y=msg_y, color=title_color)

                create_list_settings['results'].append(player_label)
                msg_x += spacing_list[stat_index]
                stat_index += 1

            msg_y += std_tf_height

        for results_msg in create_list_settings['results']:
            view.add(results_msg)

    def display_formations(results_list, attributes, index_range):
        # Remove old messages off page
        for result_message in create_list_settings['results']:
            view.remove(result_message)
        del create_list_settings['results'][:]

        # Add navigation buttons to page
        previous_range = (index_range[0]-num_results, index_range[0])
        previous_btn.action = (previous_btn_func, results_list, attributes, previous_range)

        next_range = (index_range[1], index_range[1]+num_results)
        next_btn.action = (next_btn_func, results_list, attributes, next_range)

        total_num_results_label.text = str(len(results_list.db)) + " Formations"
        pages_label.text = "Page %d of %d" % (int(index_range[1]/num_results),
                                              math.ceil(len(results_list.db)/float(num_results)))

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(results_list.db) - 1:
            next_btn.enabled = 1
        else:
            next_btn.enabled = 0

        create_list_settings['results'].append(previous_btn)
        create_list_settings['results'].append(next_btn)
        create_list_settings['results'].append(total_num_results_label)
        create_list_settings['results'].append(pages_label)

        # Print out labels
        labels = [''] + formation_info_labels()[:-2]
        stat_index = 0
        add_btn_width = 30
        add_btn_space = add_btn_width + 10
        spacing_list = [add_btn_space, 100, 100, 55, 55, 55, 55]
        left_border = (win_create_list.width - sum(spacing_list)) / 2
        msg_x = left_border
        msg_y = previous_btn.bottom + 5

        for info_label in labels:
            player_label = Label(text=info_label, font=std_tf_font_bold, width=win_width-(2*left_border),
                                 height=std_tf_height, x=msg_x, y=msg_y, color=title_color)
            create_list_settings['results'].append(player_label)
            msg_x += spacing_list[stat_index]
            stat_index += 1

        msg_y += std_tf_height + 5

        # Print out formations
        for idx, formation in enumerate(results_list.db[index_range[0]:index_range[1]]):
            msg_x = left_border
            formation_stats = formation_info(formation)[:-2]
            stat_index = 0

            add_btn = Button("Add", width=add_btn_width, height=15, x=msg_x, y=msg_y,
                             action=(add_formation_btn_func, formation))
            create_list_settings['results'].append(add_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for formation_stat in formation_stats:
                formation_label = Label(text=formation_stat, font=small_button_font, width=win_width-(2*left_border),
                                        height=std_tf_height, x=msg_x, y=msg_y, color=title_color)

                create_list_settings['results'].append(formation_label)
                msg_x += spacing_list[stat_index]
                stat_index += 1

            msg_y += std_tf_height

        for results_msg in create_list_settings['results']:
            view.add(results_msg)

    # ========== Add items to window ==========
    view.add(title)
    view.add(message)
    view.add(enter_btn)
    view.add(undo_btn)
    view.add(back_btn)
    view.add(player_list_btn)
    view.add(formation_list_btn)
    view.add(team_list_btn)

    win_create_list.add(view)
    view.become_target()
    win_create_list.show()
Example #50
0
def open_pick_formation_window(window_x, window_y, db_dict, win_previous):

    general_display = []

    # ========== Window ==========
    win_pick_formation = Window()
    win_pick_formation.title = pick_formation_win_title
    win_pick_formation.auto_position = False
    win_pick_formation.position = (window_x, window_y)
    win_pick_formation.size = (win_width, win_height)
    win_pick_formation.resizable = 0
    win_pick_formation.name = enter_text_title + " Window"
    win_pick_formation.show()

    # ========== Window Image View ==========
    class StartWindowImageView(View):
        def draw(self, c, r):
            c.backcolor = view_backcolor
            c.erase_rect(r)

    view = StartWindowImageView(size=win_pick_formation.size)

    # ========== Title ==========
    title = Label(text=pick_formation_title)
    title.font = title_font
    title.width = title_width
    title.height = title_height
    title.x = (win_pick_formation.width - title_width) / 2
    title.y = top_border
    title.color = title_color
    title.just = 'center'
    general_display.append(title)

    # ========== Button Functions ==========
    def formation_btn_func(formation):
        win_pick_formation.become_target()
        AssignPlayers.open_assign_players_window(win_pick_formation.x, win_pick_formation.y,
                                                 db_dict, formation, win_pick_formation)
        win_pick_formation.hide()

    def formation_list_btn_func():
        generic_formation = {"style": "Generic",
                             "name": "Generic",
                             "description": "Generic formation for picking players to be used with list of formations.",
                             "num_links": 17,
                             "num_defenders": 4,
                             "num_midfielders": 4,
                             "num_attackers": 2,
                             "positions": {
                                 "11": {"index": 0, "symbol": "11", "name": "Spot 11", "links": []},
                                 "10": {"index": 1, "symbol": "10", "name": "Spot 10", "links": []},
                                 "9": {"index": 2, "symbol": "9", "name": "Spot 9", "links": []},
                                 "8": {"index": 3, "symbol": "8", "name": "Spot 8", "links": []},
                                 "7": {"index": 4, "symbol": "7", "name": "Spot 7", "links": []},
                                 "6": {"index": 5, "symbol": "6", "name": "Spot 6", "links": []},
                                 "5": {"index": 6, "symbol": "5", "name": "Spot 5", "links": []},
                                 "4": {"index": 7, "symbol": "4", "name": "Spot 4", "links": []},
                                 "3": {"index": 8, "symbol": "3", "name": "Spot 3", "links": []},
                                 "2": {"index": 9, "symbol": "2", "name": "Spot 2", "links": []},
                                 "1": {"index": 10, "symbol": "1", "name": "Spot 1", "links": []}}}
        win_pick_formation.become_target()
        AssignPlayers.open_assign_players_window(win_pick_formation.x, win_pick_formation.y,
                                                 db_dict, generic_formation, win_pick_formation)
        win_pick_formation.hide()

    def back_btn_func():
        win_pick_formation.become_target()
        win_previous.show()
        win_pick_formation.hide()

    # ========== Formation Button Declarations ==========
    formation_button_width = 200
    msg_y = title.bottom

    # Sort DB so it is consistent
    db_dict['formation_db'][1].sort(['name'])

    for formation in db_dict['formation_db'][1].db:
        formation_btn = Button(title=formation['name'],
                                  font=std_tf_font,
                                  width=formation_button_width, height=std_tf_height,
                                  x=(win_pick_formation.width - formation_button_width)/2, y=msg_y,
                                  action=(formation_btn_func, formation))
        general_display.append(formation_btn)

        msg_y += std_tf_height + 1

    msg_y += 9

    formation_list_btn = Button(title='Use Formation List',
                                font=std_tf_font,
                                width=formation_button_width, height=std_tf_height,
                                x=(win_pick_formation.width - formation_button_width)/2, y=msg_y,
                                action=formation_list_btn_func)
    general_display.append(formation_list_btn)

    msg_y += std_tf_height + 10

    back_btn = Button('Back',
                      font=std_tf_font_bold,
                      width=button_width, height=button_height,
                      x=(win_pick_formation.width - button_width)/2, y=msg_y,
                      action=back_btn_func)
    general_display.append(back_btn)

    # ========== Add buttons to window ==========
    for item in general_display:
        view.add(item)

    win_pick_formation.add(view)
    view.become_target()
    win_pick_formation.show()
Example #51
0
def open_search_menu(window_x, window_y, db_dict, attr_dict=None, attr_list=None, settings=None):

    num_results = 20
    general_display = []

    if attr_dict is None:
        attr_dict = {}

    if attr_list is None:
        attr_list = []

    if settings is None:
        settings = {
            "window": "search",
            "mode": "players",
            "p_db_rg": "player_db",
            "f_db_rg": "formation_db",
            "order_rg": True,
            "messages": {"search": [], "sort": [], "results": []},
        }

    # ========== Window ==========
    win_search = Window()
    win_search.title = search_win_title
    win_search.auto_position = False
    win_search.position = (window_x, window_y)
    win_search.size = (win_width, win_height)
    win_search.resizable = 0
    win_search.name = search_title + " Window"

    # ========== Window Image View ==========
    class FormationsWindowImageView(View):
        def draw(self, c, r):
            c.backcolor = view_backcolor
            c.erase_rect(r)

    view = FormationsWindowImageView(size=win_search.size)

    # ========== Title ==========
    title = Label(text=search_title)
    title.font = title_font
    title.width = title_width
    title.height = title_height
    title.x = (win_width - title_width) / 2
    title.y = top_border
    title.color = title_color
    title.just = "center"
    general_display.append(title)

    # ========== Action Button Declarations ==========
    start_btn = Button("Start")
    back_btn = Button("Back")

    # ========== Search Type Button Declarations ==========
    players_btn = Button("Players")
    formations_btn = Button("Formations")
    teams_btn = Button("Teams")

    search_type_button_list = [players_btn, formations_btn, teams_btn]

    # ========== Tool Button Declarations ==========
    attribute_btn = Button("Add Search Attribute")
    sort_btn = Button("Add Sort Attribute")
    reset_btn = Button("Reset Results")

    # ========== Action Button Functions ==========
    def start_btn_func():
        # Start button corresponds to players
        if settings["mode"] == "players":
            # Search - if no attribute selected, return all
            if len(attr_dict) == 0:
                search_results = db_dict[p_db_radio_group.value][1]
            else:
                search_results = db_dict[p_db_radio_group.value][1].search(attr_dict)
                search_results = PlayerDB.PlayerDB(search_results)

            # Sort - if no attribute selected, use rating
            if len(attr_list) == 0:
                search_results.sort(["rating"], sort_order_radio_group.value)
            else:
                search_results.sort(attr_list, sort_order_radio_group.value)

            # Get attributes list and avoid duplicates
            attributes_list = []

            for attr in attr_list:
                if attributes_list.count(attr) == 0:
                    attributes_list.append(attr)

            for attr_key in attr_dict.iterkeys():
                if attributes_list.count(attr_key) == 0:
                    attributes_list.append(attr_key)

            display_players(search_results, attributes_list, (0, num_results))

        # Start button corresponds to formations
        elif settings["mode"] == "formations":
            # Search - if no attribute selected, return all
            if len(attr_dict) == 0:
                search_results = db_dict[f_db_radio_group.value][1]
            else:
                search_results = db_dict[f_db_radio_group.value][1].search(attr_dict)
                search_results = FormationDB.FormationDB(search_results)

            # Sort - if no attribute selected, use name
            if len(attr_list) == 0:
                search_results.sort(["name"], sort_order_radio_group.value)
            else:
                search_results.sort(attr_list, sort_order_radio_group.value)

            # Get attributes list and avoid duplicates
            attributes_list = []

            for attr in attr_list:
                if attributes_list.count(attr) == 0:
                    attributes_list.append(attr)

            for attr_key in attr_dict.iterkeys():
                if attributes_list.count(attr_key) == 0:
                    attributes_list.append(attr_key)

            display_formations(search_results, attributes_list, (0, num_results))

        # Start button corresponds to teams
        elif settings["mode"] == "teams":
            # Search - if no attribute selected, return all
            if len(attr_dict) == 0:
                search_results = db_dict["team_list"][1]
            else:
                search_results = db_dict["team_list"][1].search(attr_dict)
                search_results = TeamDB.TeamDB(search_results)

            # Sort - if no attribute selected, use rating
            if len(attr_list) == 0:
                search_results.sort(["rating"], sort_order_radio_group.value)
            else:
                search_results.sort(attr_list, sort_order_radio_group.value)

            # Get attributes list and avoid duplicates
            attributes_list = []

            for attr in attr_list:
                if attributes_list.count(attr) == 0:
                    attributes_list.append(attr)

            for attr_key in attr_dict.iterkeys():
                if attributes_list.count(attr_key) == 0:
                    attributes_list.append(attr_key)

            display_teams(search_results, attributes_list, (0, num_results))

        win_search.become_target()

    def back_btn_func():
        win_search.hide()
        StartMenu.open_start_menu(win_search.x, win_search.y, db_dict)

    # ========== Search Type Button Functions ==========
    def players_btn_func():
        for btn in search_type_button_list:
            btn.enabled = 1
        players_btn.enabled = 0
        settings["mode"] = "players"

        # Reset screen
        reset_btn_func()

        view.remove(formation_db_radio_btn)
        view.remove(f_db_file_btn)
        view.remove(formation_list_radio_btn)
        view.remove(f_list_file_btn)
        view.remove(team_list_button)

        view.add(player_db_radio_btn)
        view.add(p_db_file_btn)
        view.add(player_list_radio_btn)
        view.add(p_list_file_btn)

        win_search.become_target()

    def formations_btn_func():
        for btn in search_type_button_list:
            btn.enabled = 1
        formations_btn.enabled = 0
        settings["mode"] = "formations"

        # Reset screen
        reset_btn_func()

        view.remove(player_db_radio_btn)
        view.remove(p_db_file_btn)
        view.remove(player_list_radio_btn)
        view.remove(p_list_file_btn)
        view.remove(team_list_button)

        view.add(formation_db_radio_btn)
        view.add(f_db_file_btn)
        view.add(formation_list_radio_btn)
        view.add(f_list_file_btn)

        win_search.become_target()

    def teams_btn_func():
        for btn in search_type_button_list:
            btn.enabled = 1
        teams_btn.enabled = 0
        settings["mode"] = "teams"

        # Reset screen
        reset_btn_func()

        view.remove(player_db_radio_btn)
        view.remove(p_db_file_btn)
        view.remove(player_list_radio_btn)
        view.remove(p_list_file_btn)
        view.remove(formation_db_radio_btn)
        view.remove(f_db_file_btn)
        view.remove(formation_list_radio_btn)
        view.remove(f_list_file_btn)

        view.add(team_list_button)

        win_search.become_target()

    # ========== Tool Button Functions ==========
    def attribute_btn_func():
        # Delete results
        del settings["messages"]["results"][:]

        # Set type argument
        attr_type = ""
        if settings["mode"] == "players":
            attr_type = "player_search"
        elif settings["mode"] == "formations":
            attr_type = "formation_search"
        elif settings["mode"] == "teams":
            attr_type = "team_search"
        else:
            print "Invalid mode."

        # Open new window and close current window
        win_search.hide()
        AddAttribute.open_attribute_window(
            win_search.x, win_search.y, db_dict, attr_dict, attr_list, attr_type, settings
        )

    def sort_btn_func():
        # Delete results
        del settings["messages"]["results"][:]

        # Set type argument
        attr_type = ""
        if settings["mode"] == "players":
            attr_type = "player_sort"
        elif settings["mode"] == "formations":
            attr_type = "formation_sort"
        elif settings["mode"] == "teams":
            attr_type = "team_sort"
        else:
            print "Invalid mode."

        # Open new window and close current window
        win_search.hide()
        AddAttribute.open_attribute_window(
            win_search.x, win_search.y, db_dict, attr_dict, attr_list, attr_type, settings
        )

    def reset_btn_func():
        # Remove messages off page
        for message in settings["messages"]["search"]:
            view.remove(message)
        for message in settings["messages"]["sort"]:
            view.remove(message)
        for message in settings["messages"]["results"]:
            view.remove(message)

        # Delete the attribute parameters for search and sort
        attr_dict.clear()
        del attr_list[:]
        del settings["messages"]["results"][:]

        win_search.become_target()

    def player_bio_btn_func(player):
        win_search.hide()
        PlayerBio.open_player_bio_window(
            win_search.x,
            win_search.y,
            player,
            win_search,
            db_dict,
            db_dict["player_list"][0],
            db_dict["player_list"][1],
        )
        win_search.become_target()

    def formation_bio_btn_func(formation):
        win_search.hide()
        FormationBio.open_formation_bio_window(
            win_search.x,
            win_search.y,
            formation,
            win_search,
            db_dict["formation_list"][0],
            db_dict["formation_list"][1],
        )
        win_search.become_target()

    def team_bio_btn_func(team):
        win_search.hide()
        TeamBio.open_team_bio_window(
            win_search.x, win_search.y, team, win_search, db_dict["team_list"][0], db_dict["team_list"][1]
        )
        win_search.become_target()

    # ========== Pick DB/List Button Functions ==========
    def pick_file():
        # Remove old messages off page
        for message in settings["messages"]["results"]:
            view.remove(message)
        del settings["messages"]["results"][:]

        settings["file_changes"] = False
        settings["prev_window"] = "search"
        settings["attr_dict"] = attr_dict
        settings["attr_list"] = attr_list
        PickFile.open_pick_file_window(win_search.x, win_search.y, db_dict, settings)
        win_search.hide()

    def pick_p_db_func():
        settings["file_type"] = "current_player_db"
        pick_file()

    def pick_p_list_func():
        settings["file_type"] = "current_player_list"
        pick_file()

    def pick_f_db_func():
        settings["file_type"] = "current_formation_db"
        pick_file()

    def pick_f_list_func():
        settings["file_type"] = "current_formation_list"
        pick_file()

    def pick_t_list_func():
        settings["file_type"] = "current_team_list"
        pick_file()

    # ========== Action Buttons ==========
    start_btn.x = (win_width - 2 * small_button_width - small_button_spacing) / 2
    start_btn.y = title.bottom + small_button_top_spacing
    start_btn.height = small_button_height
    start_btn.width = small_button_width
    start_btn.font = small_button_font
    start_btn.action = start_btn_func
    start_btn.style = "default"
    start_btn.color = small_button_color
    start_btn.just = "right"
    general_display.append(start_btn)

    back_btn.x = start_btn.right + small_button_spacing
    back_btn.y = start_btn.top
    back_btn.height = small_button_height
    back_btn.width = small_button_width
    back_btn.font = small_button_font
    back_btn.action = back_btn_func
    back_btn.style = "default"
    back_btn.color = small_button_color
    back_btn.just = "right"
    general_display.append(back_btn)

    # ========== Search Type Buttons ==========
    players_btn.x = (win_width - 3 * small_button_width - 2 * small_button_spacing) / 2
    players_btn.y = start_btn.bottom + small_button_top_spacing
    players_btn.height = small_button_height
    players_btn.width = small_button_width
    players_btn.font = small_button_font
    players_btn.action = players_btn_func
    players_btn.style = "default"
    players_btn.color = small_button_color
    players_btn.just = "right"
    if settings["mode"] == "players":
        players_btn.enabled = 0
    general_display.append(players_btn)

    formations_btn.x = players_btn.right + small_button_spacing
    formations_btn.y = players_btn.top
    formations_btn.height = small_button_height
    formations_btn.width = small_button_width
    formations_btn.font = small_button_font
    formations_btn.action = formations_btn_func
    formations_btn.style = "default"
    formations_btn.color = small_button_color
    formations_btn.just = "right"
    if settings["mode"] == "formations":
        formations_btn.enabled = 0
    general_display.append(formations_btn)

    teams_btn.x = formations_btn.right + small_button_spacing
    teams_btn.y = players_btn.top
    teams_btn.height = small_button_height
    teams_btn.width = small_button_width
    teams_btn.font = small_button_font
    teams_btn.action = teams_btn_func
    teams_btn.style = "default"
    teams_btn.color = small_button_color
    teams_btn.just = "right"
    if settings["mode"] == "teams":
        teams_btn.enabled = 0
    general_display.append(teams_btn)

    # ========== Tool Buttons ==========
    attribute_btn.x = (win_width - 3 * small_button_width - 2 * small_button_spacing) / 2
    attribute_btn.y = players_btn.bottom + 5
    attribute_btn.height = small_button_height
    attribute_btn.width = small_button_width
    attribute_btn.font = small_button_font
    attribute_btn.action = attribute_btn_func
    attribute_btn.style = "default"
    attribute_btn.color = small_button_color
    attribute_btn.just = "right"
    general_display.append(attribute_btn)

    sort_btn.x = attribute_btn.right + small_button_spacing
    sort_btn.y = attribute_btn.top
    sort_btn.height = small_button_height
    sort_btn.width = small_button_width
    sort_btn.font = small_button_font
    sort_btn.action = sort_btn_func
    sort_btn.style = "default"
    sort_btn.color = small_button_color
    sort_btn.just = "right"
    general_display.append(sort_btn)

    reset_btn.x = sort_btn.right + small_button_spacing
    reset_btn.y = attribute_btn.top
    reset_btn.height = small_button_height
    reset_btn.width = small_button_width
    reset_btn.font = small_button_font
    reset_btn.action = reset_btn_func
    reset_btn.style = "default"
    reset_btn.color = small_button_color
    reset_btn.just = "right"
    general_display.append(reset_btn)

    # ========== DB Radio Buttons ==========
    def get_attribute_p_db_rg():
        settings["p_db_rg"] = p_db_radio_group.value
        win_search.become_target()

    def get_attribute_f_db_rg():
        settings["f_db_rg"] = f_db_radio_group.value
        win_search.become_target()

    p_db_radio_group = RadioGroup(action=get_attribute_p_db_rg)
    f_db_radio_group = RadioGroup(action=get_attribute_f_db_rg)

    db_msg_width = 35
    db_radio_btn_width = 150
    db_file_btn_width = 40
    db_radio_btn_space = 5
    db_file_btn_space = 2

    file_label = Label(text="File:", font=std_tf_font, width=db_msg_width, height=std_tf_height, color=title_color)
    file_label.x = (
        win_search.width
        - 2 * db_radio_btn_width
        - 2 * db_file_btn_width
        - db_radio_btn_space
        - 2 * db_file_btn_space
        - db_msg_width
    ) / 2
    file_label.y = reset_btn.bottom + db_radio_btn_space
    view.add(file_label)

    # Players DB RG
    player_db_radio_btn = RadioButton(db_dict["player_db"][0])
    player_db_radio_btn.width = db_radio_btn_width
    player_db_radio_btn.x = file_label.right
    player_db_radio_btn.y = file_label.top
    player_db_radio_btn.group = p_db_radio_group
    player_db_radio_btn.value = "player_db"

    p_db_file_btn = Button("Pick")
    p_db_file_btn.x = player_db_radio_btn.right + db_file_btn_space
    p_db_file_btn.y = file_label.top
    p_db_file_btn.height = std_tf_height
    p_db_file_btn.width = db_file_btn_width
    p_db_file_btn.font = small_button_font
    p_db_file_btn.action = pick_p_db_func
    p_db_file_btn.style = "default"
    p_db_file_btn.color = small_button_color
    p_db_file_btn.just = "right"

    player_list_radio_btn = RadioButton(db_dict["player_list"][0])
    player_list_radio_btn.width = db_radio_btn_width
    player_list_radio_btn.x = p_db_file_btn.right + db_radio_btn_space
    player_list_radio_btn.y = file_label.top
    player_list_radio_btn.group = p_db_radio_group
    player_list_radio_btn.value = "player_list"

    p_list_file_btn = Button("Pick")
    p_list_file_btn.x = player_list_radio_btn.right + db_file_btn_space
    p_list_file_btn.y = file_label.top
    p_list_file_btn.height = std_tf_height
    p_list_file_btn.width = db_file_btn_width
    p_list_file_btn.font = small_button_font
    p_list_file_btn.action = pick_p_list_func
    p_list_file_btn.style = "default"
    p_list_file_btn.color = small_button_color
    p_list_file_btn.just = "right"

    p_db_radio_group.value = settings["p_db_rg"]

    # Formations DB RG
    formation_db_radio_btn = RadioButton(db_dict["formation_db"][0])
    formation_db_radio_btn.width = db_radio_btn_width
    formation_db_radio_btn.x = file_label.right
    formation_db_radio_btn.y = file_label.top
    formation_db_radio_btn.group = f_db_radio_group
    formation_db_radio_btn.value = "formation_db"

    f_db_file_btn = Button("Pick")
    f_db_file_btn.x = formation_db_radio_btn.right + db_file_btn_space
    f_db_file_btn.y = file_label.top
    f_db_file_btn.height = std_tf_height
    f_db_file_btn.width = db_file_btn_width
    f_db_file_btn.font = small_button_font
    f_db_file_btn.action = pick_f_db_func
    f_db_file_btn.style = "default"
    f_db_file_btn.color = small_button_color
    f_db_file_btn.just = "right"

    formation_list_radio_btn = RadioButton(db_dict["formation_list"][0])
    formation_list_radio_btn.width = db_radio_btn_width
    formation_list_radio_btn.x = f_db_file_btn.right + db_radio_btn_space
    formation_list_radio_btn.y = file_label.top
    formation_list_radio_btn.group = f_db_radio_group
    formation_list_radio_btn.value = "formation_list"

    f_list_file_btn = Button("Pick")
    f_list_file_btn.x = formation_list_radio_btn.right + db_file_btn_space
    f_list_file_btn.y = file_label.top
    f_list_file_btn.height = std_tf_height
    f_list_file_btn.width = db_file_btn_width
    f_list_file_btn.font = small_button_font
    f_list_file_btn.action = pick_f_list_func
    f_list_file_btn.style = "default"
    f_list_file_btn.color = small_button_color
    f_list_file_btn.just = "right"

    f_db_radio_group.value = settings["f_db_rg"]

    # Teams DB Button
    teams_db_msg_width = 2 * db_radio_btn_width + 2 * db_file_btn_width + db_radio_btn_space + 2 * db_file_btn_space

    team_list_button = Button(
        title=db_dict["team_list"][0],
        font=std_tf_font,
        just="left",
        width=teams_db_msg_width,
        height=std_tf_height,
        color=title_color,
    )
    team_list_button.x = file_label.right
    team_list_button.y = reset_btn.bottom + db_radio_btn_space
    team_list_button.action = pick_t_list_func

    if settings["mode"] == "players":
        view.add(player_db_radio_btn)
        view.add(p_db_file_btn)
        view.add(player_list_radio_btn)
        view.add(p_list_file_btn)
    elif settings["mode"] == "formations":
        view.add(formation_db_radio_btn)
        view.add(f_db_file_btn)
        view.add(formation_list_radio_btn)
        view.add(f_list_file_btn)
    elif settings["mode"] == "teams":
        view.add(team_list_button)
    else:
        print "Error: Invalid mode."

    # ========== Sort Order Radio Buttons ==========
    def get_attribute_sort_order_rg():
        settings["order_rg"] = sort_order_radio_group.value
        win_search.become_target()

    sort_order_radio_group = RadioGroup(action=get_attribute_sort_order_rg)

    asc_desc_radio_btn_width = 75
    asc_msg_width = 80
    radio_btn_space = 5

    asc_desc_rg_msg = Label(
        text="Sort Order:", font=std_tf_font, width=asc_msg_width, height=std_tf_height, color=title_color
    )
    asc_desc_rg_msg.x = (win_search.width - 2 * asc_desc_radio_btn_width - radio_btn_space - asc_msg_width) / 2
    asc_desc_rg_msg.y = formation_db_radio_btn.bottom + radio_btn_space
    general_display.append(asc_desc_rg_msg)

    descend_radio_btn = RadioButton("Descending")
    descend_radio_btn.width = asc_desc_radio_btn_width
    descend_radio_btn.x = asc_desc_rg_msg.right
    descend_radio_btn.y = asc_desc_rg_msg.top
    descend_radio_btn.group = sort_order_radio_group
    descend_radio_btn.value = True
    general_display.append(descend_radio_btn)

    ascend_radio_btn = RadioButton("Ascending")
    ascend_radio_btn.width = asc_desc_radio_btn_width
    ascend_radio_btn.x = descend_radio_btn.right + radio_btn_space
    ascend_radio_btn.y = descend_radio_btn.top
    ascend_radio_btn.group = sort_order_radio_group
    ascend_radio_btn.value = False
    general_display.append(ascend_radio_btn)

    sort_order_radio_group.value = settings["order_rg"]

    # ========== Messages ==========
    lowest_msg_l = start_btn.top
    lowest_msg_r = start_btn.top

    attr_msg_offset = 25

    # Attribute Messages
    del settings["messages"]["search"][:]
    del settings["messages"]["sort"][:]

    if len(attr_dict) > 0:
        settings["messages"]["search"].append(
            Label(
                text="Search Attributes:",
                font=title_tf_font,
                width=std_tf_width,
                height=std_tf_height,
                x=attr_msg_offset,
                y=lowest_msg_l,
                color=title_color,
            )
        )
        lowest_msg_l += std_tf_height

        for key, value in attr_dict.iteritems():
            msg_text = format_attr_name(key) + ": "
            if key in ["id", "baseId", "nationId", "leagueId", "clubId"]:
                msg_text += str(value[0])
            elif type(value[0]) is int:
                msg_text += value[1].capitalize() + " " + str(value[0])
            elif value[1] == "not":
                msg_text += value[1].capitalize() + ' "' + str(value[0]) + '"'
            else:
                msg_text += '"' + str(value[0]) + '"'

            attr_label = Label(
                text=msg_text,
                font=std_tf_font,
                width=std_tf_width,
                height=std_tf_height,
                x=attr_msg_offset,
                y=lowest_msg_l,
                color=title_color,
            )
            lowest_msg_l += std_tf_height
            settings["messages"]["search"].append(attr_label)

    if len(attr_list) > 0:
        settings["messages"]["sort"].append(
            Label(
                text="Sort Attributes:",
                font=title_tf_font,
                width=std_tf_width,
                height=std_tf_height,
                x=teams_btn.right + 3 * attr_msg_offset,
                y=lowest_msg_r,
                color=title_color,
            )
        )
        lowest_msg_r += std_tf_height

        for value in attr_list:
            attr_label = Label(
                text=(format_attr_name(value)),
                font=std_tf_font,
                width=std_tf_width,
                height=std_tf_height,
                x=teams_btn.right + 3 * attr_msg_offset,
                y=lowest_msg_r,
                color=title_color,
            )
            lowest_msg_r += std_tf_height
            settings["messages"]["sort"].append(attr_label)

    # ========== Previous, Add to List, Next Buttons ==========
    previous_btn = Button("<<< Previous %d" % num_results)
    add_to_list_btn = Button()
    next_btn = Button("Next %d >>>" % num_results)
    total_num_results_label = Label()
    pages_label = Label()

    def add_to_list_btn_func(input_list, func_type):
        results_list = copy.deepcopy(input_list)
        if func_type == "add all":
            if settings["mode"] == "players":
                added_players = []
                # Add current results to player list
                for player in results_list:
                    if db_dict["player_list"][1].db.count(player) == 0:
                        db_dict["player_list"][1].db.append(player)
                        added_players.append(player)

                # Sort
                db_dict["player_list"][1].sort(["rating"])
                # Save
                db_dict["player_list"][1].save(db_dict["player_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Players"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "remove select")

                # Keep track of just added players
                settings["messages"]["players_changed"] = added_players

            elif settings["mode"] == "formations":
                added_formations = []
                # Add current results to formation list
                for formation in results_list:
                    if db_dict["formation_list"][1].db.count(formation) == 0:
                        db_dict["formation_list"][1].db.append(formation)
                        added_formations.append(formation)

                # Sort
                db_dict["formation_list"][1].sort(["name"])
                # Save
                db_dict["formation_list"][1].save(db_dict["formation_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Forms"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "remove select")

                # Keep track of just added formations
                settings["messages"]["formations_changed"] = added_formations

        elif func_type == "remove all":
            if settings["mode"] == "players":
                removed_players = []
                # Remove current results from player list
                for player in results_list:
                    if db_dict["player_list"][1].db.count(player) > 0:
                        db_dict["player_list"][1].db.remove(player)
                        removed_players.append(player)

                # Sort
                db_dict["player_list"][1].sort(["rating"])
                # Save
                db_dict["player_list"][1].save(db_dict["player_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Players"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "add select")

                # Keep track of just removed players
                settings["messages"]["players_changed"] = removed_players

            elif settings["mode"] == "formations":
                removed_formations = []
                # Remove current results from formation list
                for formation in results_list:
                    if db_dict["formation_list"][1].db.count(formation) > 0:
                        db_dict["formation_list"][1].db.remove(formation)
                        removed_formations.append(formation)

                # Sort
                db_dict["formation_list"][1].sort(["name"])
                # Save
                db_dict["formation_list"][1].save(db_dict["formation_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Forms"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "add select")

                # Keep track of just removed players
                settings["messages"]["formations_changed"] = removed_formations

        elif func_type == "add select":
            if settings["mode"] == "players":
                # Add select players back to player list
                for player in settings["messages"]["players_changed"]:
                    if db_dict["player_list"][1].db.count(player) == 0:
                        db_dict["player_list"][1].db.append(player)

                # Sort
                db_dict["player_list"][1].sort(["rating"])
                # Save
                db_dict["player_list"][1].save(db_dict["player_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Players"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "remove select")

            elif settings["mode"] == "formations":
                # Add select formations back to formation list
                for formation in settings["messages"]["formations_changed"]:
                    if db_dict["formation_list"][1].db.count(formation) == 0:
                        db_dict["formation_list"][1].db.append(formation)

                # Sort
                db_dict["formation_list"][1].sort(["name"])
                # Save
                db_dict["formation_list"][1].save(db_dict["formation_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Remove Added Forms"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "remove select")

        elif func_type == "remove select":
            if settings["mode"] == "players":
                # Remove select players from player list
                for player in settings["messages"]["players_changed"]:
                    if db_dict["player_list"][1].db.count(player) > 0:
                        db_dict["player_list"][1].db.remove(player)

                # Sort
                db_dict["player_list"][1].sort(["rating"])
                # Save
                db_dict["player_list"][1].save(db_dict["player_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Players"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "add select")

            elif settings["mode"] == "formations":
                # Remove select formations from formation list
                for formation in settings["messages"]["formations_changed"]:
                    if db_dict["formation_list"][1].db.count(formation) > 0:
                        db_dict["formation_list"][1].db.remove(formation)

                # Sort
                db_dict["formation_list"][1].sort(["name"])
                # Save
                db_dict["formation_list"][1].save(db_dict["formation_list"][0], "list", True)

                # Change button title and action
                add_to_list_btn.title = "Add Removed Forms"
                add_to_list_btn.action = (add_to_list_btn_func, results_list, "add select")

        win_search.become_target()

    def previous_btn_func(results_list, attributes, index_range):
        # display previous results
        if settings["mode"] == "players":
            display_players(results_list, attributes, index_range)
        elif settings["mode"] == "formations":
            display_formations(results_list, attributes, index_range)
        elif settings["mode"] == "teams":
            display_teams(results_list, attributes, index_range)
        win_search.become_target()

    def next_btn_func(results_list, attributes, index_range):
        # display next results
        if settings["mode"] == "players":
            display_players(results_list, attributes, index_range)
        elif settings["mode"] == "formations":
            display_formations(results_list, attributes, index_range)
        elif settings["mode"] == "teams":
            display_teams(results_list, attributes, index_range)
        win_search.become_target()

    add_to_list_btn.x = attribute_btn.right + small_button_spacing
    add_to_list_btn.y = descend_radio_btn.bottom + 5
    add_to_list_btn.height = tiny_button_height
    add_to_list_btn.width = small_button_width
    add_to_list_btn.font = small_button_font
    add_to_list_btn.style = "default"
    add_to_list_btn.color = small_button_color
    add_to_list_btn.just = "right"

    previous_btn.height = tiny_button_height
    previous_btn.width = small_button_width
    previous_btn.x = add_to_list_btn.left - previous_btn.width - small_button_spacing
    previous_btn.y = add_to_list_btn.top
    previous_btn.font = small_button_font
    previous_btn.style = "default"
    previous_btn.color = small_button_color
    previous_btn.just = "right"

    next_btn.height = tiny_button_height
    next_btn.width = small_button_width
    next_btn.x = add_to_list_btn.right + small_button_spacing
    next_btn.y = add_to_list_btn.top
    next_btn.font = small_button_font
    next_btn.style = "default"
    next_btn.color = small_button_color
    next_btn.just = "right"

    total_num_results_label.font = std_tf_font
    total_num_results_label.width = 100
    total_num_results_label.height = std_tf_height
    total_num_results_label.x = previous_btn.left + -100 - 10
    total_num_results_label.y = add_to_list_btn.top
    total_num_results_label.color = title_color
    total_num_results_label.just = "right"

    pages_label.font = std_tf_font
    pages_label.width = 125
    pages_label.height = std_tf_height
    pages_label.x = next_btn.right + 10
    pages_label.y = add_to_list_btn.top
    pages_label.color = title_color
    pages_label.just = "left"

    # ========== Display players from search ==========
    def display_players(results_list, attributes, index_range):
        # Remove old messages off page
        for message in settings["messages"]["results"]:
            view.remove(message)
        del settings["messages"]["results"][:]

        # Add navigation buttons to page
        if settings["p_db_rg"] == "player_db":
            add_to_list_btn.title = "Add All Players"
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, "add all")
        elif settings["p_db_rg"] == "player_list":
            add_to_list_btn.title = "Remove All Players"
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, "remove all")
        else:
            print "Invalid edit type."

        previous_range = (index_range[0] - num_results, index_range[0])
        previous_btn.action = (previous_btn_func, results_list, attributes, previous_range)

        next_range = (index_range[1], index_range[1] + num_results)
        next_btn.action = (next_btn_func, results_list, attributes, next_range)

        total_num_results_label.text = str(len(results_list.db)) + " Players"
        pages_label.text = "Page %d of %d" % (
            int(index_range[1] / num_results),
            math.ceil(len(results_list.db) / float(num_results)),
        )

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(results_list.db) - 1:
            next_btn.enabled = 1
        else:
            next_btn.enabled = 0

        settings["messages"]["results"].append(add_to_list_btn)
        settings["messages"]["results"].append(previous_btn)
        settings["messages"]["results"].append(next_btn)
        settings["messages"]["results"].append(total_num_results_label)
        settings["messages"]["results"].append(pages_label)

        # Print out labels
        labels = player_info_labels(attributes)
        stat_index = 0
        # Spacing values for each of the stats
        spacing_list = [125, 40, 40, 65, 115, 115, 115, 40]
        # Calculate the maximum number of stat fields that will fit on screen
        max_player_fields = len(spacing_list[:-1]) + (win_search.width - sum(spacing_list[:-1])) / spacing_list[-1]
        # Calculate the left border of the stats based on the number and width of the stats
        left_border = (
            win_width
            - sum(spacing_list[:-1])
            - (len(labels[:max_player_fields]) - len(spacing_list) + 1) * spacing_list[-1]
        ) / 2
        msg_x = left_border
        msg_y = add_to_list_btn.bottom + 5

        for info_label in labels[:max_player_fields]:
            player_label = Label(
                text=info_label,
                font=std_tf_font_bold,
                width=spacing_list[stat_index] - 5,
                height=std_tf_height,
                x=msg_x,
                y=msg_y,
                color=title_color,
            )
            settings["messages"]["results"].append(player_label)
            msg_x += spacing_list[stat_index]

            if stat_index < len(spacing_list) - 1:
                stat_index += 1

        msg_y += std_tf_height + 5

        # Print out players
        for idx, player in enumerate(results_list.db[index_range[0] : index_range[1]]):
            msg_x = left_border
            player_stats = player_info(player, attributes)
            stat_index = 0

            # Check for names that are too long
            name = player_stats[0]
            if len(name) > 20:
                name = player["lastName"]

            bio_btn = Button(
                title=name,
                width=spacing_list[stat_index] - 5,
                height=15,
                x=msg_x,
                y=msg_y,
                action=(player_bio_btn_func, player),
            )
            settings["messages"]["results"].append(bio_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for player_stat in player_stats[1:max_player_fields]:
                player_label = Label(
                    text=player_stat,
                    font=small_button_font,
                    width=spacing_list[stat_index] - 5,
                    height=std_tf_height,
                    x=msg_x,
                    y=msg_y,
                    color=title_color,
                )

                settings["messages"]["results"].append(player_label)
                msg_x += spacing_list[stat_index]
                if stat_index < len(spacing_list) - 1:
                    stat_index += 1

            msg_y += std_tf_height

        for results_msg in settings["messages"]["results"]:
            view.add(results_msg)

    # ========== Display formations from search ==========
    def display_formations(results_list, attributes, index_range):
        # Remove old messages off page
        for message in settings["messages"]["results"]:
            view.remove(message)
        del settings["messages"]["results"][:]

        # Add navigation buttons to page
        if settings["f_db_rg"] == "formation_db":
            add_to_list_btn.title = "Add All Formations"
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, "add all")
        elif settings["f_db_rg"] == "formation_list":
            add_to_list_btn.title = "Remove All Formations"
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, "remove all")
        else:
            print "Invalid edit type."

        previous_range = (index_range[0] - num_results, index_range[0])
        previous_btn.action = (previous_btn_func, results_list, attributes, previous_range)

        next_range = (index_range[1], index_range[1] + num_results)
        next_btn.action = (next_btn_func, results_list, attributes, next_range)

        total_num_results_label.text = str(len(results_list.db)) + " Formations"
        pages_label.text = "Page %d of %d" % (
            int(index_range[1] / num_results),
            math.ceil(len(results_list.db) / float(num_results)),
        )

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(results_list.db) - 1:
            next_btn.enabled = 1
        else:
            next_btn.enabled = 0

        settings["messages"]["results"].append(add_to_list_btn)
        settings["messages"]["results"].append(previous_btn)
        settings["messages"]["results"].append(next_btn)
        settings["messages"]["results"].append(total_num_results_label)
        settings["messages"]["results"].append(pages_label)

        # Print out labels
        labels = formation_info_labels()
        stat_index = 0
        # Spacing values for each of the stats
        spacing_list = [100, 100, 55, 55, 55, 55, 140, 160]
        # Calculate the left border of the stats based on the number and width of the stats
        left_border = (win_search.width - sum(spacing_list)) / 2
        msg_x = left_border
        msg_y = add_to_list_btn.bottom + 5

        for info_label in labels:
            formation_label = Label(
                text=info_label,
                font=std_tf_font_bold,
                width=spacing_list[stat_index] - 5,
                height=std_tf_height,
                x=msg_x,
                y=msg_y,
                color=title_color,
            )
            settings["messages"]["results"].append(formation_label)
            msg_x += spacing_list[stat_index]

            if stat_index < len(spacing_list) - 1:
                stat_index += 1

        msg_y += std_tf_height + 5

        # Print out formations
        for formation in results_list.db[index_range[0] : index_range[1]]:
            msg_x = left_border
            formation_stats = formation_info(formation)
            stat_index = 0

            bio_btn = Button(
                title=formation_stats[0],
                width=spacing_list[stat_index] - 5,
                height=15,
                x=msg_x,
                y=msg_y,
                action=(formation_bio_btn_func, formation),
            )
            settings["messages"]["results"].append(bio_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for formation_stat in formation_stats[1:]:
                formation_label = Label(
                    text=formation_stat,
                    font=small_button_font,
                    width=spacing_list[stat_index] - 5,
                    height=std_tf_height,
                    x=msg_x,
                    y=msg_y,
                    color=title_color,
                )

                settings["messages"]["results"].append(formation_label)
                msg_x += spacing_list[stat_index]
                if stat_index < len(spacing_list) - 1:
                    stat_index += 1

            msg_y += std_tf_height

        for results_msg in settings["messages"]["results"]:
            view.add(results_msg)

    # ========== Display teams from search ==========
    def display_teams(results_list, attributes, index_range):
        # Remove old messages off page
        for message in settings["messages"]["results"]:
            view.remove(message)
        del settings["messages"]["results"][:]

        # Add navigation buttons to page
        '''if settings['f_db_rg'] == 'formation_db':
            add_to_list_btn.title = 'Add All Formations'
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, 'add all')
        elif settings['f_db_rg'] == 'formation_list':
            add_to_list_btn.title = 'Remove All Formations'
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, 'remove all')
        else:
            print "Invalid edit type."'''
        add_to_list_btn.title = ""
        add_to_list_btn.action = ()

        previous_range = (index_range[0] - num_results, index_range[0])
        previous_btn.action = (previous_btn_func, results_list, attributes, previous_range)

        next_range = (index_range[1], index_range[1] + num_results)
        next_btn.action = (next_btn_func, results_list, attributes, next_range)

        total_num_results_label.text = str(len(results_list.db)) + " Teams"
        pages_label.text = "Page %d of %d" % (
            int(index_range[1] / num_results),
            math.ceil(len(results_list.db) / float(num_results)),
        )

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(results_list.db) - 1:
            next_btn.enabled = 1
        else:
            next_btn.enabled = 0

        settings["messages"]["results"].append(add_to_list_btn)
        settings["messages"]["results"].append(previous_btn)
        settings["messages"]["results"].append(next_btn)
        settings["messages"]["results"].append(total_num_results_label)
        settings["messages"]["results"].append(pages_label)

        # Print out labels
        labels = team_info_labels(attributes)
        stat_index = 0
        # Spacing values for each of the stats
        spacing_list = [60, 40, 55, 90, 100, 115, 115, 40]
        # Calculate the maximum number of stat fields that will fit on screen
        max_team_fields = len(spacing_list[:-1]) + (win_search.width - sum(spacing_list[:-1])) / spacing_list[-1]
        # Calculate the left border of the stats based on the number and width of the stats
        left_border = (
            win_width
            - sum(spacing_list[:-1])
            - (len(labels[:max_team_fields]) - len(spacing_list) + 1) * spacing_list[-1]
        ) / 2
        msg_x = left_border
        msg_y = add_to_list_btn.bottom + 5

        for info_label in labels[:max_team_fields]:
            team_label = Label(
                text=info_label,
                font=std_tf_font_bold,
                width=spacing_list[stat_index] - 5,
                height=std_tf_height,
                x=msg_x,
                y=msg_y,
                color=title_color,
            )
            settings["messages"]["results"].append(team_label)
            msg_x += spacing_list[stat_index]

            if stat_index < len(spacing_list) - 1:
                stat_index += 1

        msg_y += std_tf_height + 5

        # Print out teams
        for team in results_list.db[index_range[0] : index_range[1]]:
            msg_x = left_border
            team_stats = team_info(team, attributes)
            stat_index = 0

            bio_btn = Button(
                title=team_stats[0],
                width=spacing_list[stat_index] - 5,
                height=15,
                x=msg_x,
                y=msg_y,
                action=(team_bio_btn_func, team),
            )
            settings["messages"]["results"].append(bio_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for team_stat in team_stats[1:max_team_fields]:
                team_label = Label(
                    text=team_stat,
                    font=small_button_font,
                    width=spacing_list[stat_index] - 5,
                    height=std_tf_height,
                    x=msg_x,
                    y=msg_y,
                    color=title_color,
                )

                settings["messages"]["results"].append(team_label)
                msg_x += spacing_list[stat_index]
                if stat_index < len(spacing_list) - 1:
                    stat_index += 1

            msg_y += std_tf_height

        for results_msg in settings["messages"]["results"]:
            view.add(results_msg)

    # ========== Add components to view and add view to window ==========
    for msg in general_display:
        view.add(msg)
    for msg in settings["messages"]["search"]:
        view.add(msg)
    for msg in settings["messages"]["sort"]:
        view.add(msg)
    for msg in settings["messages"]["results"]:
        view.add(msg)

    win_search.add(view)
    view.become_target()
    win_search.show()
Example #52
0
def open_start_menu(window_x, window_y, db_dict):

    view_item_list = []

    # Load console type
    settings = {'console_type': ''}
    with open(config_filename, 'r') as f:
        settings["console_type"] = json.load(f)['console_type']
        f.close()

    # ========== Window ==========
    win_start = Window()
    win_start.title = start_win_title
    win_start.auto_position = False
    win_start.position = (window_x, window_y)
    win_start.size = (win_width, win_height)
    win_start.resizable = 0
    win_start.name = start_title + " Window"

    # ========== Window Image View ==========
    class StartWindowImageView(View):
        def draw(self, c, r):
            c.backcolor = view_backcolor
            c.erase_rect(r)
            image_pos = ((win_start.width - start_window_image.width)/2, search_btn.bottom + title_border)
            src_rect = start_window_image.bounds
            dst_rect = Geometry.offset_rect(src_rect, image_pos)
            start_window_image.draw(c, src_rect, dst_rect)

    view = StartWindowImageView(size=win_start.size)

    # ========== Start Window Image ==========
    start_window_image = Image(file='Images/start_menu_image.jpg')

    # ========== Title ==========
    title = Label(text=start_title)
    title.font = title_font
    title.width = title_width
    title.height = title_height
    title.x = (win_width - title_width) / 2
    title.y = top_border
    title.color = title_color
    title.just = 'center'
    view_item_list.append(title)

    # ========== Sort Order Radio Buttons ==========
    def save_console_type():
        """
        Save the console type
        """

        # Load configurations
        from AppConfig import config_filename
        with open(config_filename, 'r') as config_file:
            configurations = json.load(config_file)
            config_file.close()

        # Edit configurations
        configurations['console_type'] = settings["console_type"]

        # Save the settings
        with open(config_filename, 'w') as config_file:
            json.dump(configurations, config_file)
            config_file.close()

    def get_attribute_console_rg():
        settings["console_type"] = console_radio_group.value
        win_start.become_target()
        save_console_type()

    console_radio_group = RadioGroup(action=get_attribute_console_rg)

    console_radio_btn_width = 75
    console_label_width = 80
    radio_btn_space = 5

    console_rg_label = Label(text="Sort Order:", font=std_tf_font, width=console_label_width, height=std_tf_height,
                            color=title_color)
    console_rg_label.x = (win_start.width - 2 * console_radio_btn_width - radio_btn_space - console_label_width) / 2
    console_rg_label.y = title.bottom + radio_btn_space
    view_item_list.append(console_rg_label)

    playstation_radio_btn = RadioButton("PlayStation")
    playstation_radio_btn.width = console_radio_btn_width
    playstation_radio_btn.x = console_rg_label.right
    playstation_radio_btn.y = console_rg_label.top
    playstation_radio_btn.group = console_radio_group
    playstation_radio_btn.value = 'PLAYSTATION'
    view_item_list.append(playstation_radio_btn)

    xbox_radio_btn = RadioButton("Xbox")
    xbox_radio_btn.width = console_radio_btn_width
    xbox_radio_btn.x = playstation_radio_btn.right + radio_btn_space
    xbox_radio_btn.y = playstation_radio_btn.top
    xbox_radio_btn.group = console_radio_group
    xbox_radio_btn.value = 'XBOX'
    view_item_list.append(xbox_radio_btn)

    if settings["console_type"] in ['PLAYSTATION', 'XBOX']:
        console_radio_group.value = settings["console_type"]
    else:
        print "Invalid console type."

    # ========== Button Declarations ==========
    search_btn = Button("Search")
    teams_btn = Button("Teams")
    files_btn = Button("Files")

    button_list = [search_btn,
                   teams_btn,
                   files_btn]

    # ========== Button Functions ==========
    def search_btn_func():
        win_start.hide()
        SearchMenu.open_search_menu(win_start.x, win_start.y, db_dict)

    def teams_btn_func():
        win_start.hide()
        TeamsMenu.open_teams_menu(win_start.x, win_start.y, db_dict)

    def files_btn_func():
        win_start.hide()
        FilesMenu.open_files_menu(win_start.x, win_start.y, db_dict)

    # ========== Buttons ==========
    search_btn.x = (win_width - len(button_list)*button_width - (len(button_list)-1)*button_spacing) / 2
    search_btn.y = console_rg_label.bottom + title_border
    search_btn.height = button_height
    search_btn.width = button_width
    search_btn.font = button_font
    search_btn.action = search_btn_func
    search_btn.style = 'default'
    search_btn.color = button_color
    search_btn.just = 'right'
    view_item_list.append(search_btn)

    teams_btn.x = button_spacing + search_btn.right
    teams_btn.y = search_btn.top
    teams_btn.height = button_height
    teams_btn.width = button_width
    teams_btn.font = button_font
    teams_btn.action = teams_btn_func
    teams_btn.style = 'default'
    teams_btn.color = button_color
    teams_btn.just = 'right'
    view_item_list.append(teams_btn)

    files_btn.x = button_spacing + teams_btn.right
    files_btn.y = search_btn.top
    files_btn.height = button_height
    files_btn.width = button_width
    files_btn.font = button_font
    files_btn.action = files_btn_func
    files_btn.style = 'default'
    files_btn.color = button_color
    files_btn.just = 'right'
    view_item_list.append(files_btn)

    # ========== Add components to view and add view to window ==========
    for item in view_item_list:
        view.add(item)

    win_start.add(view)
    view.become_target()
    win_start.show()
Example #53
0
 def make_window(self, document):
     win = Window(size = (400, 400), document = document)
     view = BlobView(model = document, extent = (1000, 1000), scrolling = 'hv')
     win.place(view, left = 0, top = 0, right = 0, bottom = 0, sticky = 'nsew')
     win.show()
Example #54
0
import sys
from PyQt5.QtWidgets import QApplication

from GUI import Window

if __name__ == '__main__':

    app = QApplication(sys.argv)

    window = Window()
    window.show()  #transfer the window in the GUI

    sys.exit(app.exec_())
Example #55
0
 def make_window(self):
     win = Window(size=(400, 400))
     tex = CodeEditor()
     win.place(tex, left=0, top=0, right=0, bottom=0, sticky='nesw')
     win.show()
Example #56
0
def open_enter_text_window(window_x, window_y, db_dict, settings, box_type, fill_text='', file_prefix=''):

    general_display = []

    if box_type == 'rename':
        title = 'Rename File'
        old_file_name = fill_text
        message_text = 'Enter new file name.'
    elif box_type == 'duplicate':
        title = 'Duplicate File'
        old_file_name = fill_text
        message_text = 'Enter new file name.'
    elif box_type == 'download':
        title = 'Download Player Database'
        message_text = 'Enter player database name.'
        download_settings = {'overwrite_counter': 0, 'last_entered_text': ''}
    else:
        title = 'Enter Text'
        message_text = 'Enter text.'

    # ========== Window ==========
    win_enter_text = Window()
    win_enter_text.title = title
    win_enter_text.auto_position = False
    win_enter_text.position = (window_x+100, window_y+100)
    win_enter_text.size = (win_width-200, win_height-400)
    win_enter_text.resizable = 0
    win_enter_text.name = enter_text_title + " Window"
    win_enter_text.show()

    # ========== Window Image View ==========
    class StartWindowImageView(View):
        def draw(self, c, r):
            c.backcolor = view_backcolor
            c.erase_rect(r)

    view = StartWindowImageView(size=win_enter_text.size)

    # ========== Title ==========
    title = Label(text=title)
    title.font = title_font
    title.width = title_width
    title.height = title_height
    title.x = (win_enter_text.width - title_width) / 2
    title.y = top_border
    title.color = title_color
    title.just = 'center'
    general_display.append(title)

    # ========== Message Label ==========
    message = Label(font=title_font_2, width=win_enter_text.width - 50, height=title_height,
                    x=25, y=title.bottom + top_border, color=title_color, just='center')
    message.text = message_text
    general_display.append(message)

    # ========== Button Declarations ==========
    enter_btn = Button("Enter")
    back_btn = Button("Back")

    # ========== Button Functions ==========
    def enter_btn_func():
        # Rename file
        if box_type == 'rename':

            # Get new name
            new_file_name = value_tf.value

            if len(new_file_name) > 0:

                if not isfile('JSONs/' + file_prefix + new_file_name + '.json'):
                    # Rename file
                    rename('JSONs/' + file_prefix + old_file_name + '.json',
                           'JSONs/' + file_prefix + new_file_name + '.json')

                    # Disable pick file back button in case the selected file has changed
                    settings['file_changes'] = True

                    PickFile.open_pick_file_window(window_x, window_y, db_dict, settings)
                    win_enter_text.hide()

                else:
                    message.text = "A file with that name already exists."

            else:
                message.text = "File name must be at least 1 character."

        # Duplicate file
        elif box_type == 'duplicate':

            # Get new name
            duplicate_file_name = value_tf.value

            if len(duplicate_file_name) > 0:

                if not isfile('JSONs/' + file_prefix + duplicate_file_name + '.json'):
                    # Create duplicate file
                    copyfile('JSONs/' + file_prefix + old_file_name + '.json',
                             'JSONs/' + file_prefix + duplicate_file_name + '.json')

                    PickFile.open_pick_file_window(window_x, window_y, db_dict, settings)
                    win_enter_text.hide()

                else:
                    message.text = "A file with that name already exists."

            else:
                message.text = "File name must be at least 1 character."

        elif box_type == 'download':
            valid_name = False

            # Get new player database name
            new_player_db_name = value_tf.value

            if new_player_db_name != download_settings['last_entered_text']:
                download_settings['overwrite_counter'] = 0
                message.text = message_text

            if len(new_player_db_name) > 0:

                if not isfile('JSONs/play_db_' + new_player_db_name + '.json'):
                    valid_name = True

                else:
                    download_settings['last_entered_text'] = new_player_db_name

                    if download_settings['overwrite_counter'] == 0:
                        download_settings['overwrite_counter'] += 1
                        message.text = "File already exists. Overwrite?"
                    elif download_settings['overwrite_counter'] == 1:
                        download_settings['overwrite_counter'] += 1
                        message.text = "Are you sure you want to overwrite?"
                    elif download_settings['overwrite_counter'] == 2:
                        download_settings['overwrite_counter'] += 1
                        message.text = "Really, really, really sure?"
                    elif download_settings['overwrite_counter'] >= 3:
                        valid_name = True

                if valid_name:
                    # Open status window to start download of players
                    StatusWindow.open_status_window(win_enter_text.x, win_enter_text.y, db_dict,
                                                    get_prices=sort_order_radio_group.value,
                                                    file_name=new_player_db_name, settings=settings,
                                                    win_previous=win_enter_text, win_next='FilesMenu')
                    win_enter_text.hide()

            else:
                message.text = "File name must be at least 1 character."

    def back_btn_func():
        if box_type == 'download':
            FilesMenu.open_files_menu(window_x, window_y, db_dict, settings)
        else:
            PickFile.open_pick_file_window(window_x, window_y, db_dict, settings)
        win_enter_text.hide()

    # ========== Buttons ==========
    enter_btn.x = (win_enter_text.width - 2*button_width - button_spacing) / 2
    enter_btn.y = win_enter_text.height - 70
    enter_btn.height = button_height
    enter_btn.width = button_width
    enter_btn.font = button_font
    enter_btn.action = enter_btn_func
    enter_btn.style = 'default'
    enter_btn.color = button_color
    enter_btn.just = 'right'
    general_display.append(enter_btn)

    back_btn.x = enter_btn.right + button_spacing
    back_btn.y = enter_btn.top
    back_btn.height = button_height
    back_btn.width = button_width
    back_btn.font = button_font
    back_btn.action = back_btn_func
    back_btn.style = 'default'
    back_btn.color = button_color
    back_btn.just = 'right'
    general_display.append(back_btn)

    # ========== Value Textfield ==========
    value_tf = TextField()
    value_tf.width = 200
    value_tf.x = (win_enter_text.width - value_tf.width) / 2
    value_tf.y = enter_btn.top - 65
    value_tf.height = 25
    value_tf.font = std_tf_font
    value_tf.value = fill_text
    general_display.append(value_tf)

    def get_attribute_sort_order_rg():
        settings['order_rg'] = sort_order_radio_group.value
        win_enter_text.become_target()

    sort_order_radio_group = RadioGroup(action=get_attribute_sort_order_rg)

    prices_label_width = 85
    prices_button_width = 50
    prices_label = Label(text="Get Prices?:", font=std_tf_font, width=prices_label_width, height=std_tf_height,
                         color=title_color)
    prices_label.x = (win_enter_text.width - 2*prices_button_width - 10 - prices_label_width) / 2
    prices_label.y = enter_btn.top - 38
    prices_label.just = 'center'

    prices_yes = RadioButton("Yes")
    prices_yes.width = prices_button_width
    prices_yes.x = prices_label.right + 5
    prices_yes.y = prices_label.top
    prices_yes.group = sort_order_radio_group
    prices_yes.value = True

    prices_no = RadioButton("No")
    prices_no.width = prices_button_width
    prices_no.x = prices_yes.right + 5
    prices_no.y = prices_label.top
    prices_no.group = sort_order_radio_group
    prices_no.value = False

    sort_order_radio_group.value = True

    if box_type == 'download':
        value_tf.y = enter_btn.top - 75

        general_display.append(prices_label)
        general_display.append(prices_yes)
        general_display.append(prices_no)

    # ========== Add buttons to window ==========
    for item in general_display:
        view.add(item)

    win_enter_text.add(view)
    view.become_target()
    win_enter_text.show()