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())
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())
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())
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_nextSibling(self): page = Page(App()) page1 = Page(page) page2 = Page(page) page3 = Page(page) self.assertEqual(page1.nextSibling(), page2) self.assertEqual(page2.nextSibling(), page3) self.assertEqual(page3.nextSibling(), page1) self.assertEqual(page3.previousSibling(), page2) self.assertEqual(page1.previousSibling(), page3)
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))
def test_children(self): for page in Page(App()), Page(App(), width=200, height=200): self.assertEqual(page.getChildren(), []) page.showChildren(mainloop=False) page.hideChildren() page.removeChildren() page2 = Page(page) self.assertEqual(page.getChildren(), [page2]) self.assertFalse(page2.isShown()) page.showChildren(mainloop=False) self.assertTrue(page2.isShown()) page.hideChildren() self.assertFalse(page2.isShown()) page.removeChildren() self.assertRaises(tk.TclError, page2.isShown) self.assertEqual(page.getChildren(), []) page2 = Page(page) page3 = Page(page) self.assertEqual(page.getChildren(), [page2, page3]) self.assertEqual(page.getChildren(ignore=page2), [page3]) self.assertEqual(page.getChildren(ignore=page3), [page2]) self.assertEqual(page.getChildren(ignore=(page2, page3)), []) self.assertEqual(page.getChildren(ignore=[page2, page3]), []) self.assertEqual([page, page2, page3], page.app.getChildren(recurrent=True)) self.assertFalse(page2.isShown()) self.assertFalse(page3.isShown()) page.showChildren(ignore=(page2, page3), mainloop=False) self.assertFalse(page2.isShown()) self.assertFalse(page3.isShown()) page.showChildren(ignore=page2, mainloop=False) self.assertFalse(page2.isShown()) self.assertTrue(page3.isShown()) page.hideChildren() self.assertFalse(page2.isShown()) self.assertFalse(page3.isShown()) page.showChildren(mainloop=False) self.assertTrue(page2.isShown()) self.assertTrue(page3.isShown()) page.removeChildren() self.assertEqual(page.getChildren(), []) page.remove() self.assertRaises(tk.TclError, page.isShown)
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)
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()])
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_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()
def test_parents(self): for page in Page(App()), Page(App(), width=200, height=200): page2 = Page(page) page3 = Page(page2) self.assertEqual(page3.getParents(), [page2, page]) self.assertEqual(page3.getParents(includeSelf=True), [page3, page2, page]) self.assertEqual(page3.getTopPage(), page) page3.show(mainloop=False) self.assertTrue(page3.isShown()) self.assertTrue(page2.isShown()) self.assertTrue(page.isShown()) self.assertTrue(page3.app.isShown()) self.assertTrue(page2.app.isShown()) self.assertTrue(page.app.isShown())
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)
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))
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()
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())
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))
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))
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())
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())
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())
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_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)
def test_parents(self): app = App() for page in Page(app), Page(app, width=200, height=200): Label(page, "hello") Label(page, "there") page2 = Page(page) text3 = Label(page2, "in page 2") self.assertIs(text3.getTopPage(), page) self.assertEqual(text3.getParents(), [page2, page]) self.assertEqual(text3.getParents(includeSelf=True), [text3, page2, page]) self.assertEqual([page2.frame, page2, page.frame, page], text3.getParents(includeParts=True)) page3 = Page(page2, scrollable=True) text4 = Label(page3, "in page 3") self.assertEqual([page2.frame, page2, page.frame, page], page3.getParents(includeParts=True)) self.assertEqual([page3.canvasFrame, page3.canvas, page3.frame, page3, page2.frame, page2, page.frame, page], text4.getParents(includeParts=True))
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"])
def test_siblings(self): for page in Page(App()), Page(App(), width=200, height=200): self.assertEqual(page.getChildren(), []) self.assertEqual(page.getParents(), []) self.assertEqual(page.getParents(includeSelf=True), [page]) self.assertEqual(page.getTopPage(), page) self.assertEqual(page.getSiblings(), []) page.showSiblings(mainloop=False) page.hideSiblings() page.removeSiblings() page.show(mainloop=False) self.assertTrue(page.isShown()) page.hide() self.assertFalse(page.isShown()) page.toggleShow(mainloop=False) self.assertTrue(page.isShown()) page.toggleShow(mainloop=False) self.assertFalse(page.isShown()) page3 = Page(page.app) page2 = Page(page.app) self.assertEqual(page.getSiblings(), [page3, page2]) page.showSiblings(mainloop=False) self.assertTrue(page2.isShown()) self.assertTrue(page3.isShown()) page.hideSiblings() self.assertFalse(page2.isShown()) self.assertFalse(page3.isShown()) page.showSiblings(ignore=page2, mainloop=False) self.assertFalse(page2.isShown()) self.assertTrue(page3.isShown()) page.hideSiblings(ignore=page3) self.assertFalse(page2.isShown()) self.assertTrue(page3.isShown()) page.remove() self.assertRaises(tk.TclError, page.isShown)
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())
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()
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")
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())