Example #1
0
    def test_siblings(self):
        app = App()
        for page in Page(app), Page(app, width=200, height=200):
            text1 = Label(page, "hi")
            text2 = Label(page, "hello")
            self.assertEqual(text1.getSiblings(), [text2])
            self.assertEqual(text2.getSiblings(), [text1])
            self.assertEqual(text1.getSiblings(ignore=text1), [text2])
            self.assertEqual(text1.getSiblings(ignore=text2), [])
            self.assertEqual(text1.getSiblings(ignore=(text1, text2)), [])
            self.assertFalse(text1.isShown())
            self.assertFalse(text2.isShown())

            text1.showSiblings(mainloop=False)
            self.assertTrue(text2.isShown())
            self.assertTrue(text1.isShown())

            text1.hideSiblings(ignore=text2)
            self.assertTrue(text1.isShown())
            self.assertTrue(text2.isShown())

            text1.hideSiblings()
            self.assertTrue(text1.isShown())
            self.assertFalse(text2.isShown())

            text2.removeSiblings()
            self.assertRaises(tk.TclError, text1.isShown)
            self.assertFalse(text2.isShown())

            text1.parentPage.showChildren(mainloop=False)
            self.assertTrue(text2.isShown())
Example #2
0
    def test_labelCheckbutton(self):
        labelCheckbutton = LabelCheckbutton(Page(App()), "hello")
        self.assertEqual("hello", labelCheckbutton.label.getValue())
        self.assertIs(False, labelCheckbutton.checkbutton.getValue())

        labelCheckbutton = LabelCheckbutton(Page(App()), "hello", True)
        self.assertEqual("hello", labelCheckbutton.label.getValue())
        self.assertIs(True, labelCheckbutton.checkbutton.getValue())
Example #3
0
    def test_getElementByValue(self):
        app = App()

        labelEntry = LabelEntry(Page(app), value="value here")
        self.assertEqual(labelEntry.label, app.getElementByValue("value here"))

        button = Button(Page(Page(Page(app))), value="test val")
        self.assertEqual(button, app.getElementByValue("test val"))
    def test_getVisibleFraction(self):
        app = App()
        page = Page(app, width=100, height=100, scrollable=True)
        page2 = Page(page, width=196, height=196)

        with self.assertRaises(AttributeError):
            app.getVisibleFraction(page.canvas)

        page2.show(mainloop=False)
        self.assertEqual(Vec2(0.5), app.getVisibleFraction(page.canvas))
Example #5
0
    def test_toggleShow(self):
        app = App()
        page = Page(app)

        self.assertEqual(False, page.isPacked())
        page.toggleShow(mainloop=False)
        self.assertEqual(True, page.isPacked())
        page.toggleShow(mainloop=False)
        self.assertEqual(False, page.isPacked())
Example #6
0
    def test_init(self):
        page = Page(App())
        label = Label(page, "Text")

        bind = label.createBind("<Button-1>", lambda: 5)
        self.assertEqual([5], label.callBind("<Button-1>"))

        bind.remove()
        self.assertEqual([], label.callBind("<Button-1>"))

        label.createBind("<Button-1>", lambda: 5)
        page.createBind("<Button-1>", lambda: 2)
        self.assertEqual([5, 2], label.callBind("<Button-1>"))

        label.setBindPropagation("<Button-1>", False)
        self.assertEqual([5], label.callBind("<Button-1>"))

        label.setBindPropagation("<Button-1>", True)
        self.assertEqual([5, 2], label.callBind("<Button-1>"))

        label.setBindPropagation("<Button-1>", False)
        label.createBind("<Button-1>", lambda: 5)
        label.createBind("<Button-1>", lambda: 2)
        self.assertEqual([5, 5, 2], label.callBind("<Button-1>"))

        label.createBind("<Button-1>", lambda: 3, add=False)
        self.assertEqual([3], label.callBind("<Button-1>"))

        label.createBind("<Button-1>", lambda: 5, name="hello")
        self.assertEqual([3, 5], label.callBind("<Button-1>"))

        label.createBind("<Button-1>", lambda: 5, name="hello")
        self.assertEqual([3, 5], label.callBind("<Button-1>"))

        label.createBind("<Button-1>", lambda: 5, name="hello", add=False)
        self.assertEqual([5], label.callBind("<Button-1>"))

        label.onClick(lambda: 5, add=False)
        label.onClick(lambda: 2)
        self.assertEqual([5, 2], label.click(animate=False))
        self.assertEqual([5, 2], label.click(animate=True))

        label.onRightClick(lambda: 5, add=False)
        label.onRightClick(lambda: 2)
        self.assertEqual([5, 2], label.rightClick(animate=False))
        self.assertEqual([5, 2], label.rightClick(animate=True))

        label.remove()
        self.assertEqual([], label.callBind("<Button-1>"))
Example #7
0
    def test_button(self):
        app = App()
        for page in Page(app), Page(app, width=200, height=200):
            button = Button(page, "hello", lambda: 5)
            self.assertEqual(button.parentPage, page)
            self.assertIs(button.widget.element, button)
            self.assertFalse(button.isShown())

            button.show(mainloop=False)
            self.assertTrue(button.isShown())

            self.assertEqual([5], button.click())

            page.remove()
            self.assertRaises(tk.TclError, button.isShown)
Example #8
0
    def test_getValue_and_setValue(self):
        entry = Entry(Page(App()), "default")
        self.assertEqual("default", entry.getValue())

        entry.setValue("hello there")
        self.assertEqual("hello there", entry.getValue())

        entry.setValue("")
        self.assertEqual("default", entry.getValue())

        entry.setValue(None)
        self.assertEqual("default", entry.getValue())

        entry.setValue(True)
        self.assertIs(True, entry.getValue())

        entry.setValue(5.2)
        self.assertEqual(5.2, entry.getValue())

        entry.setValue(5)
        self.assertEqual(5, entry.getValue())

        entry.setValue("5")
        self.assertEqual(5, entry.getValue())

        entry.setValue("none")
        self.assertEqual(None, entry.getValue())

        entry.app.remove()
Example #9
0
    def test_label(self):
        app = App()
        for page in Page(app), Page(app, width=200, height=200):
            label = Label(page)
            self.assertEqual("", label.getValue())

            label = Label(page, "hello")
            self.assertEqual(label.parentPage, page)
            self.assertIs(label.widget.element, label)
            self.assertFalse(label.isShown())

            label.show(mainloop=False)
            self.assertTrue(label.isShown())

            page.remove()
            self.assertRaises(tk.TclError, label.isShown)
Example #10
0
    def test_default(self):
        entry = Entry(Page(App()), "default")
        entry.clearIfDefault()
        self.assertEqual("", entry.getValue())

        entry.setDefault("test")
        self.assertEqual("", entry.getValue())

        entry.callBind("<FocusOut>")
        self.assertEqual("test", entry.getValue())

        entry.clearIfDefault()
        self.assertEqual("", entry.getValue())

        entry.setValue("hello")
        self.assertEqual("hello", entry.getValue())

        entry.clearIfDefault()
        self.assertEqual("hello", entry.getValue())

        entry.setValue("not default")
        entry.callBind("<FocusOut>")
        self.assertEqual("not default", entry.getValue())

        entry.setDefault("not default")
        entry.clearIfDefault()
        self.assertEqual("", entry.getValue())

        entry.callBind("<FocusOut>")
        self.assertEqual("not default", entry.getValue())

        entry.setDefault(True)
        self.assertEqual(True, entry.getValue())

        entry.app.remove()
Example #11
0
    def test__removeWord(self):
        entry = Entry(Page(App()))
        entry.setValue("hello there")
        entry._removeWord()
        self.assertEqual("hello x", entry.getValue())

        entry.setValue("hello there")
        entry.setMarker(5)
        entry._removeWord()
        self.assertEqual("x there", entry.getValue())

        entry.setValue("hello there")
        entry.setMarker(6)
        entry._removeWord()
        self.assertEqual("helloxthere", entry.getValue())

        entry.setValue("hello there")
        entry.setMarker(6)
        entry._removeWord(delete=True)
        self.assertEqual("hello x", entry.getValue())

        entry.setValue("hello there")
        entry.setMarker(5)
        entry._removeWord(delete=True)
        self.assertEqual("helloxthere", entry.getValue())

        entry.app.remove()
    def test_packPart(self):
        elementList = ElementList(Page(App()), maxFirstSteps=5)
        for i in range(6):
            Label(elementList, "hello")
        self.assertEqual([
            Vec2(0, 0),
            Vec2(0, 1),
            Vec2(0, 2),
            Vec2(0, 3),
            Vec2(0, 4),
            Vec2(1, 0)
        ], [elementList.getGridPos(ele) for ele in elementList.getChildren()])

        elementList.removeChildren()
        elementList.maxFirstSteps = 2
        for i in range(6):
            LabelEntry(elementList, "hello")
        self.assertEqual([
            Vec2(0, 0),
            Vec2(0, 1),
            Vec2(1, 0),
            Vec2(1, 1),
            Vec2(2, 0),
            Vec2(2, 1)
        ], [elementList.getGridPos(ele) for ele in elementList.getChildren()])
Example #13
0
    def test_place(self):
        app = App()
        label = Label(Page(app, width=500, height=500), "testing", pack=False)

        label.place(Vec2(100, 100))
        label.show(mainloop=False)

        self.assertEqual(Vec2(100, 100), label.getTopLeftPos())
Example #14
0
    def test_getParents(self):
        app = App()
        LabelEntry(Page(app))

        self.assertEqual([], app.getParents())
        self.assertEqual([app], app.getParents(includeSelf=True))
        self.assertEqual([app], app.getParents(includeApp=True))
        self.assertEqual([app],
                         app.getParents(includeSelf=True, includeApp=True))
Example #15
0
    def test_getFirstParentByClass(self):
        app = App()
        LabelEntry(Page(app))

        self.assertEqual(None, app.getFirstParentByClass("App"))
        self.assertEqual(app, app.getFirstParentByClass("App",
                                                        includeSelf=True))
        self.assertEqual(
            None, app.getFirstParentByClass("LabelEntry", includeSelf=True))
Example #16
0
    def test_getBaseTopElementWidget(self):
        app = App()
        LabelEntry(Page(app))

        self.assertEqual(app, app.getBaseElement())
        self.assertEqual(app.widget, app.getBaseWidget())

        self.assertEqual(app, app.getTopElement())
        self.assertEqual(app.widget, app.getTopWidget())
Example #17
0
    def test_toggleShow(self):
        app = App()
        label = Label(Page(app), "testing")

        self.assertEqual(True, label.isPacked())
        label.toggleShow(mainloop=False)
        self.assertEqual(False, label.isPacked())
        label.toggleShow(mainloop=False)
        self.assertEqual(True, label.isPacked())
Example #18
0
 def test_nextSibling(self):
     page = Page(App())
     button = Button(page, "button")
     label = Label(page, "label")
     checkbutton = Checkbutton(page)
     self.assertEqual(button.nextSibling(), label)
     self.assertEqual(label.nextSibling(), checkbutton)
     self.assertEqual(checkbutton.nextSibling(), button)
     self.assertEqual(checkbutton.previousSibling(), label)
     self.assertEqual(button.previousSibling(), checkbutton)
Example #19
0
    def test_init(self):
        page = Page(App())
        label = Label(page, "random")
        page.show(mainloop=False)

        red = label.createStyle("color red", bg="red", priority=3)
        blue = label.createStyle("color blue", bg="blue", priority=2)

        self.assertEqual(False, red.isEnabled())

        blue.enable()
        self.assertEqual("blue", label.getWidgetConfig("bg"))

        blue.disable()
        red.enable()
        self.assertEqual(True, red.isEnabled())
        self.assertEqual("red", label.getWidgetConfig("bg"))

        blue.enable()
        self.assertEqual("red", label.getWidgetConfig("bg"))

        red.disable()
        self.assertEqual(False, red.isEnabled())
        self.assertEqual("blue", label.getWidgetConfig("bg"))

        blue.delete()
        self.assertEqual(False, blue.isEnabled())
        self.assertEqual(red.styleHandler.originalStyle["bg"],
                         label.getWidgetConfig("bg"))

        self.assertRaises(AttributeError, blue.enable)
        self.assertEqual(False, blue.isEnabled())

        self.assertEqual(2, len(label.styleHandler.allStyles))
        self.assertEqual(1, len(label.styleHandler.styles.objects))
        red.enable()
        self.assertEqual(2, len(label.styleHandler.allStyles))
        self.assertEqual(2, len(label.styleHandler.styles.objects))
        red.enable()
        self.assertEqual(2, len(label.styleHandler.allStyles))
        self.assertEqual(2, len(label.styleHandler.styles.objects))

        page.app.remove()
    def test_removeInput(self):
        inputList = InputList(Page(App()))

        inputList.setValues({"test": True})
        self.assertEqual({"test": True}, inputList.getValues())

        self.assertTrue(inputList.removeInput("test"))
        self.assertEqual({}, inputList.getValues())

        self.assertFalse(inputList.removeInput("test"))
    def test_removeChildren(self):
        inputList = InputList(Page(App()))

        inputList.setValues({"test": True, "entry": "text"})
        self.assertEqual({"test": True, "entry": "text"}, inputList.getValues())

        inputList.removeChildren()
        self.assertEqual({}, inputList.getValues())

        with self.assertRaises(NotImplementedError):
            inputList.removeChildren(ignore=["foobar"])
Example #22
0
 def test_textOnClick(self):
     text = Label(Page(App()), "hello")
     text.onClick(lambda: 1, add=False)
     self.assertEqual([1], text.click())
     text.onClick(lambda: 2, add=False)
     self.assertEqual([2], text.click())
     text.onClick(lambda: 3, add=True)
     self.assertEqual([2, 3], text.click())
     text.onClick(lambda: 4)
     self.assertEqual([2, 3, 4], text.click())
     text.onClick(lambda: 5, add=False)
     self.assertEqual([5], text.click())
Example #23
0
 def test_buttonOnRightClick(self):
     button = Button(Page(App()), "hello")
     button.onRightClick(lambda: 1, add=False)
     self.assertEqual([1], button.rightClick())
     button.onRightClick(lambda: 2, add=False)
     self.assertEqual([2], button.rightClick())
     button.onRightClick(lambda: 3, add=True)
     self.assertEqual([2, 3], button.rightClick())
     button.onRightClick(lambda: 4)
     self.assertEqual([2, 3, 4], button.rightClick())
     button.onRightClick(lambda: 5, add=False)
     self.assertEqual([5], button.rightClick())
Example #24
0
    def test_config(self):
        app = App()
        label = Label(Page(app), "testing")

        self.assertEqual(True, "bg" in label.getAllWidgetConfigs())
        self.assertEqual("SystemButtonFace", label.getWidgetConfig("bg"))

        label.widgetConfig(bg="red")
        self.assertEqual("red", label.getWidgetConfig("bg"))

        with self.assertRaises(tk.TclError):
            label.getWidgetConfig("doesntexist")
Example #25
0
    def test__clickNextButton(self):
        page = Page(App())
        entry = Entry(page, "hello")
        Label(page, "random")
        Button(page, "Change default", lambda: 5)
        self.assertEqual([5], entry._clickNextButton())

        entry2 = Entry(page, "hello")
        Button(page, "Change default", lambda: 3)
        self.assertEqual([3], entry2._clickNextButton())

        page.app.remove()
Example #26
0
    def test_pos(self):
        app = App()
        self.assertEqual(Vec2(), app.getWindowPos())
        self.assertEqual(Vec2(1), app.getSize())
        app.show(mainloop=False)
        self.assertEqual(True, app.getWindowPos().inrange(1, 500))

        self.assertEqual(Vec2(), app.getTopLeftPos())
        self.assertEqual(Vec2(200), app.getBottomRightPos())
        self.assertEqual(Vec2(200), app.getSize())

        app.setSize(Vec2(250, 300))
        app.widget.update()
        self.assertEqual(Vec2(250, 300), app.getSize())

        app.setSize(145)
        app.widget.update()
        self.assertEqual(Vec2(145), app.getSize())

        page = Page(app, width=300, height=250)
        page.show(mainloop=False)
        self.assertEqual(Vec2(300, 250), app.getBottomRightPos())
        self.assertEqual(Vec2(300, 250), app.getSize())

        self.assertEqual(True, app.getMouse().inrange(-100000, 100000))

        self.assertEqual(page.frame, app.getElementByPos(10))

        page.remove()
        self.assertEqual(app, app.getElementByPos(10))

        self.assertEqual(None, app.getElementByPos(-10))
        self.assertEqual(None, app.getElementByPos(400))
Example #27
0
    def test_pos(self):
        app = App()
        label = Button(Page(app), "testing", pack=False)
        self.assertEqual(Vec2(), label.getTopLeftPos())
        self.assertEqual(Vec2(1), label.getSize())

        label.show(mainloop=False)
        self.assertEqual(True, label.getWindowPos().inrange(1, 500))
        self.assertEqual(True, label.getSize().inrange(10, 100))

        self.assertEqual(True, label.getTopLeftPos().inrange(0, 100))
        self.assertLess(label.getTopLeftPos(), label.getBottomRightPos())
        self.assertEqual(True, label.getSize().inrange(10, 100))
Example #28
0
    def test_place(self):
        app = App()
        Page(app, width=200, height=200).show(mainloop=False)
        page = Page(app, width=10, height=10, bg="green")
        app.showChildren(mainloop=False)

        page.place(Vec2(100, 100))
        self.assertEqual(Vec2(100, 100), page.getTopLeftPos())
Example #29
0
    def test_value(self):
        label = Label(Page(App()), "hello")

        label.setValue("test")
        self.assertEqual("test", label.getValue())

        label.setValue(None)
        self.assertEqual("", label.getValue())

        label.setValue("")
        self.assertEqual("", label.getValue())

        label.setValue(True)
        self.assertEqual(True, label.getValue())
Example #30
0
    def test_value(self):
        button = Button(Page(App()), "start")
        self.assertEqual("start", button.getValue())

        button.setValue("changed")
        self.assertEqual("changed", button.getValue())

        button.setValue("")
        self.assertEqual("", button.getValue())

        button.setValue(True)
        self.assertIs(True, button.getValue())

        button.setValue(None)
        self.assertIs("", button.getValue())