Beispiel #1
0
    def test_fancycontrols(self):
        self.imgbutton = InputImageButton(
            "ggame/images/button-round.png",
            self.pressbutton,
            (0, 0),
            frame=Frame(0, 0, 100, 100),
            qty=2,
        )
        self.imgbutton.scale = 0.5
        self.ii = ImageIndicator(
            "ggame/images/red-led-off-on.png",
            (300, 500),
            self.imgbutton,
            positioning="physical",
            frame=Frame(0, 0, 600, 600),
            qty=2,
        )
        self.ii.scale = 0.1
        self.glassbutton = GlassButton(None, (0, -0.5))
        self.toggle = MetalToggle(0, (0, -1))
        self.Li = LEDIndicator((300, 450), self.glassbutton, positioning="physical")
        self.Lit = LEDIndicator((300, 480), self.toggle, positioning="physical")

        ma = MathApp()
        ma.run()

        self.imgbutton.destroy()
        self.ii.destroy()
        self.glassbutton.destroy()
        self.toggle.destroy()
        self.Li.destroy()
        self.Lit.destroy()
Beispiel #2
0
    def test_SRGate(self):
        IC1 = BoolSRFF(gateclass=BoolNAND)
        Inv1 = BoolNOT()
        Inv2 = BoolNOT()

        b1 = GlassButton(None, (0, 0))
        b2 = GlassButton(None, (0, -0.5))
        Inv1.In = b1
        Inv2.In = b2

        IC1.SetInput('R', Inv1)
        IC1.SetInput('S', Inv2)

        d1 = LEDIndicator((0.5, 0), IC1)
        d2 = LEDIndicator((0.5, -0.5), IC1.Q_)

        ma = MathApp()
        ma.run()

        for i in range(10):
            time.sleep(1 / 60)
            ma.step()

        for o in [IC1, Inv1, Inv2, b1, b2, d1, d2]:
            o.destroy()
Beispiel #3
0
    def test_fancycontrols(self):
        self.imgbutton = InputImageButton("ggimages/button-round.png",
                                          self.pressbutton, (0, 0),
                                          frame=Frame(0, 0, 100, 100),
                                          qty=2)
        self.imgbutton.scale = 0.5
        self.ii = ImageIndicator("ggimages/red-led-off-on.png", (300, 500),
                                 self.imgbutton,
                                 positioning="physical",
                                 frame=Frame(0, 0, 600, 600),
                                 qty=2)
        self.ii.scale = 0.1
        self.glassbutton = GlassButton(None, (0, -0.5))
        self.toggle = MetalToggle(0, (0, -1))
        self.Li = LEDIndicator((300, 450),
                               self.glassbutton,
                               positioning="physical")
        self.Lit = LEDIndicator((300, 480),
                                self.toggle,
                                positioning="physical")

        ma = MathApp()
        ma.run()

        self.imgbutton.destroy()
        self.ii.destroy()
        self.glassbutton.destroy()
        self.toggle.destroy()
        self.Li.destroy()
        self.Lit.destroy()
Beispiel #4
0
    def test_gates(self):
        IC1 = BoolNOT()
        IC2 = BoolAND()

        b1 = MetalToggle(1, (1, 0))
        b2 = MetalToggle(1, (1, 0.3))
        db1 = LEDIndicator((1.3, 0), b1)
        db2 = LEDIndicator((1.3, 0.3), b2)

        b3 = MetalToggle(1, (1, 0.6))
        b4 = MetalToggle(1, (1, 0.9))
        db1 = LEDIndicator((1.3, 0.6), b3)
        db2 = LEDIndicator((1.3, 0.9), b4)

        d2 = LEDIndicator((1.5, 0.45), IC2)

        IC2.In = b1, b2
        IC2.In = IC2.In + [b3, b4]

        button = GlassButton(None, (0, 0))
        LED = LEDIndicator((0, -1), IC1)
        IC1.In = button

        t1 = MetalToggle(1, (1, -1))
        t2 = MetalToggle(1, (1, -1.3))
        dt1 = LEDIndicator((1.3, -1), t1)
        dt2 = LEDIndicator((1.3, -1.3), t2)

        ma = MathApp()
        ma.run()

        for i in range(10):
            time.sleep(1 / 60)
            ma.step()

        for o in [
                b1, b2, db1, db2, b3, b4, IC1, IC2, button, LED, t1, t2, dt1,
                dt2
        ]:
            o.destroy()
Beispiel #5
0
"""
Example of using MathApp LEDIndicator class.
"""
from ggame.mathapp import MathApp
from ggame.indicator import LEDIndicator
from ggame.inputpoint import MetalToggle

TOGGLE = MetalToggle(0, (-1, 0))

SWITCH = LEDIndicator((-1, 0.5), TOGGLE)

MathApp().run()
Beispiel #6
0
class TestMathMethods(unittest.TestCase):
    def buttonstatus(self):
        return "True" if self.imgbutton() else "False"

    def labelcoords(self):
        return (100 + self.vslider1(), 175)

    def buttoncoords(self):
        return (300 + self.vslider1(), 175)

    def labelcolor(self):
        colorval = self.vslider1()
        return Color(colorval * 256, 1)

    def pressbutton(self, caller):
        print("button pressed: ", caller)

    def __init__(self, arg):
        super().__init__(arg)

    def test_controls(self):
        self.imgbutton = InputImageButton(
            "ggame/images/button-round.png",
            self.pressbutton,
            (0, 0),
            frame=Frame(0, 0, 100, 100),
            qty=2,
        )
        self.imgbutton.scale = 0.5
        self.vslider1 = Slider(
            (100, 150), 0, 250, 125, positioning="physical", steps=10
        )
        self.label = Label(
            self.labelcoords,
            self.buttonstatus,
            size=15,
            positioning="physical",
            color=self.labelcolor,
        )
        self.button = InputButton(
            self.pressbutton,
            self.buttoncoords,
            "Press Me",
            size=15,
            positioning="physical",
        )
        self.numinput = InputNumeric((300, 275), 3.14, positioning="physical")

        ma = MathApp()
        ma.run()

        self.vslider1.destroy()
        self.label.destroy()
        self.button.destroy()
        self.numinput.destroy()
        self.imgbutton.destroy()

    def test_geometry(self):
        self.ip = ImagePoint("bunny.png", (0, 0))
        self.ip.movable = True
        self.p1 = Point((0, 0), color=Color(0x008000, 1))
        self.p1.movable = True
        self.p2 = Point((0, -1))
        self.p3 = Point((1.2, 0))
        self.l1 = LineSegment(self.p2, self.p3, style=LineStyle(3, Color(0, 1)))
        self.l2 = LineSegment(self.p2, self.p1, style=LineStyle(3, Color(0, 1)))
        self.c2 = Circle((-1, -1), self.p1)

        ma = MathApp()
        ma.run()

        self.ip.destroy()
        self.p1.destroy()
        self.p2.destroy()
        self.p3.destroy()
        self.c2.destroy()
        self.l1.destroy()
        self.l2.destroy()

    def test_fancycontrols(self):
        self.imgbutton = InputImageButton(
            "ggame/images/button-round.png",
            self.pressbutton,
            (0, 0),
            frame=Frame(0, 0, 100, 100),
            qty=2,
        )
        self.imgbutton.scale = 0.5
        self.ii = ImageIndicator(
            "ggame/images/red-led-off-on.png",
            (300, 500),
            self.imgbutton,
            positioning="physical",
            frame=Frame(0, 0, 600, 600),
            qty=2,
        )
        self.ii.scale = 0.1
        self.glassbutton = GlassButton(None, (0, -0.5))
        self.toggle = MetalToggle(0, (0, -1))
        self.Li = LEDIndicator((300, 450), self.glassbutton, positioning="physical")
        self.Lit = LEDIndicator((300, 480), self.toggle, positioning="physical")

        ma = MathApp()
        ma.run()

        self.imgbutton.destroy()
        self.ii.destroy()
        self.glassbutton.destroy()
        self.toggle.destroy()
        self.Li.destroy()
        self.Lit.destroy()

    def timercallback(self, timer):
        self.assertEqual(timer, self.timer)
        self.callbackcomplete = True

    def test_timer(self):
        self.callbackcomplete = False
        self.timer = Timer()
        self.timer.callAfter(0.1, self.timercallback)
        ma = MathApp()
        ma.run()

        for i in range(10):
            time.sleep(1 / 60)
            ma._animate(1)

        self.assertEquals(self.callbackcomplete, True)

        self.timer.destroy()
Beispiel #7
0
class TestMathMethods(unittest.TestCase):
    def buttonstatus(self):
        return "True" if self.imgbutton() else "False"

    def labelcoords(self):
        return (100 + self.vslider1(), 175)

    def buttoncoords(self):
        return (300 + self.vslider1(), 175)

    def labelcolor(self):
        colorval = self.vslider1()
        return Color(colorval * 256, 1)

    def pressbutton(self, caller):
        print("button pressed: ", caller)

    def __init__(self, arg):
        super().__init__(arg)

    def test_controls(self):
        self.imgbutton = InputImageButton(
            "images/button-round.png",
            self.pressbutton,
            (0, 0),
            frame=Frame(0, 0, 100, 100),
            qty=2,
        )
        self.imgbutton.scale = 0.5
        self.vslider1 = Slider((100, 150),
                               0,
                               250,
                               125,
                               positioning="physical",
                               steps=10)
        self.label = Label(
            self.labelcoords,
            self.buttonstatus,
            size=15,
            positioning="physical",
            color=self.labelcolor,
        )
        self.button = InputButton(
            self.pressbutton,
            self.buttoncoords,
            "Press Me",
            size=15,
            positioning="physical",
        )
        self.numinput = InputNumeric((300, 275), 3.14, positioning="physical")

        ma = MathApp()
        ma.run()

        self.vslider1.destroy()
        self.label.destroy()
        self.button.destroy()
        self.numinput.destroy()
        self.imgbutton.destroy()

    def test_geometry(self):
        self.ip = ImagePoint("bunny.png", (0, 0))
        self.ip.movable = True
        self.p1 = Point((0, 0), color=Color(0x008000, 1))
        self.p1.movable = True
        self.p2 = Point((0, -1))
        self.p3 = Point((1.2, 0))
        self.l1 = LineSegment(self.p2,
                              self.p3,
                              style=LineStyle(3, Color(0, 1)))
        self.l2 = LineSegment(self.p2,
                              self.p1,
                              style=LineStyle(3, Color(0, 1)))
        self.c2 = Circle((-1, -1), self.p1)

        ma = MathApp()
        ma.run()

        self.ip.destroy()
        self.p1.destroy()
        self.p2.destroy()
        self.p3.destroy()
        self.c2.destroy()
        self.l1.destroy()
        self.l2.destroy()

    def test_fancycontrols(self):
        self.imgbutton = InputImageButton(
            "images/button-round.png",
            self.pressbutton,
            (0, 0),
            frame=Frame(0, 0, 100, 100),
            qty=2,
        )
        self.imgbutton.scale = 0.5
        self.ii = ImageIndicator(
            "images/red-led-off-on.png",
            (300, 500),
            self.imgbutton,
            positioning="physical",
            frame=Frame(0, 0, 600, 600),
            qty=2,
        )
        self.ii.scale = 0.1
        self.glassbutton = GlassButton(None, (0, -0.5))
        self.toggle = MetalToggle(0, (0, -1))
        self.Li = LEDIndicator((300, 450),
                               self.glassbutton,
                               positioning="physical")
        self.Lit = LEDIndicator((300, 480),
                                self.toggle,
                                positioning="physical")

        ma = MathApp()
        ma.run()

        self.imgbutton.destroy()
        self.ii.destroy()
        self.glassbutton.destroy()
        self.toggle.destroy()
        self.Li.destroy()
        self.Lit.destroy()

    def timercallback(self, timer):
        self.assertEqual(timer, self.timer)
        self.callbackcomplete = True

    def test_timer(self):
        self.callbackcomplete = False
        self.timer = Timer()
        self.timer.callAfter(0.1, self.timercallback)
        ma = MathApp()
        ma.run()

        for i in range(10):
            time.sleep(1 / 60)
            ma._animate(1)

        self.assertEquals(self.callbackcomplete, True)

        self.timer.destroy()