Example #1
0
 def __init__(self):
     # points
     self.old_point = (None, None)
     self.points = []
     self.recognizer = Dollar()
     # root
     self.root = Tk()
     self.root.title(self.WINDOW_TITLE)
     # left frame
     left_frame = Frame(self.root)
     left_frame.grid(row=1, column=1)
     # canvas
     self.canvas = Canvas(left_frame, bg='white', width=350, height=330)
     self.canvas.pack()
     self.canvas.bind('<B1-Motion>', self.paint)
     self.canvas.bind('<ButtonRelease-1>', self.reset)
     # label
     self.label_text = StringVar()
     self.label_text.set('Draw something')
     self.label = Label(left_frame, textvariable=self.label_text)
     self.label.pack()
     # image
     self.image = Canvas(self.root, width=352, height=348)
     file = PhotoImage(file=self.TEMPLATES_IMAGE_PATH)
     self.image.create_image(177, 175, image=file)
     self.image.grid(row=1, column=2)
     # start
     self.root.mainloop()
Example #2
0
 def create_test(self):
     aDate = datetime.date(2019, 6, 15)
     dolar1 = Dollar('dolar a', '120.0', aDate)
     aDate2 = datetime.date(2019, 6, 16)
     dolar2 = Dollar('dolar b', '122.0', aDate2)
     self.dollar_saver.append_dollar(dolar1)
     self.dollar_saver.append_dollar(dolar2)
Example #3
0
    def __init__(self, rows=40, cols=50, game=None):
        self.ticks = 0
        self.header = ""
        self.needs_clearing = False
        self.space = pymunk.Space()
        self.space.gravity = (0.0, 0.0)
        self.space.damping = .9
        self.space.idle_speed_threshold = .1
        self.space.sleep_time_threshold = 1
        self.show_turn_message = False

        def collide(arbiter, space, data):
            shape1, shape2 = arbiter.shapes
            coin1, coin2 = shape1.coin, shape2.coin
            coin1.collide(coin2)
            coin2.collide(coin1)

        collision_handler = self.space.add_collision_handler(1, 1)
        collision_handler.post_solve = collide

        self.cells = defaultdict(lambda: defaultdict(lambda: " "))
        self.rows = rows
        self.cols = cols

        self.coins = []

        self.coins.append(Coin(x=10, y=10, is_heads=True, game=game))
        self.coins.append(Coin(x=20, y=10, is_heads=True, game=game))
        self.coins.append(Coin(x=30, y=10, is_heads=True, game=game))
        self.coins.append(Coin(x=40, y=10, is_heads=True, game=game))
        self.coins.append(Dime(x=15, y=14, is_heads=True, game=game))
        self.coins.append(Dollar(x=25, y=14, is_heads=True, game=game))
        self.coins.append(Nickel(x=35, y=14, is_heads=True, game=game))

        self.coins.append(Coin(x=10, y=30, is_heads=False, game=game))
        self.coins.append(Coin(x=20, y=30, is_heads=False, game=game))
        self.coins.append(Coin(x=30, y=30, is_heads=False, game=game))
        self.coins.append(Coin(x=40, y=30, is_heads=False, game=game))
        self.coins.append(Dime(x=15, y=26, is_heads=False, game=game))
        self.coins.append(Dollar(x=25, y=26, is_heads=False, game=game))
        self.coins.append(Nickel(x=35, y=26, is_heads=False, game=game))

        self.reformat_coin_hud()

        for coin in self.coins:
            self.space.add(coin.body, coin.shape)
Example #4
0
class Paint:

    PEN_SIZE = 3
    WINDOW_TITLE = 'Recognizer'
    # TEMPLATES_IMAGE_PATH = './templates.gif'
    TEMPLATES_IMAGE_PATH = './palm_pilot_graffiti.gif'
    INITIAL_MESSAGE = 'Draw something'
    MIN_N_POINTS = 10
    NOT_ENOUGH_POINTS_MESSAGE = 'Not enough points'

    def __init__(self):
        # points
        self.old_point = (None, None)
        self.points = []
        self.recognizer = Dollar()
        # root
        self.root = Tk()
        self.root.title(self.WINDOW_TITLE)
        # left frame
        left_frame = Frame(self.root)
        left_frame.grid(row=1, column=1)
        # canvas
        self.canvas = Canvas(left_frame, bg='white', width=350, height=330)
        self.canvas.pack()
        self.canvas.bind('<B1-Motion>', self.paint)
        self.canvas.bind('<ButtonRelease-1>', self.reset)
        # label
        self.label_text = StringVar()
        self.label_text.set('Draw something')
        self.label = Label(left_frame, textvariable=self.label_text)
        self.label.pack()
        # image
        self.image = Canvas(self.root, width=352, height=348)
        file = PhotoImage(file=self.TEMPLATES_IMAGE_PATH)
        self.image.create_image(177, 175, image=file)
        self.image.grid(row=1, column=2)
        # start
        self.root.mainloop()

    def paint(self, event):
        point = (event.x, event.y)
        print("[" + str(point[0]) + "," + str(point[1]) + "],")
        if self.old_point != (None, None):
            self.canvas.create_line(self.old_point, point, width=self.PEN_SIZE)
        else:
            self.canvas.delete('all')
        self.points.append(point)
        self.old_point = point

    def reset(self, event):
        self.old_point = (None, None)
        if (len(self.points) < self.MIN_N_POINTS):
            self.label_text.set(self.NOT_ENOUGH_POINTS_MESSAGE)
            return
        self.label_text.set(self.recognizer.get_gesture(self.points))
        self.points = []
Example #5
0
 def dollar(request):
     return Dollar(5)
Example #6
0
 def test_multiplication(self):
     five = Dollar(5)
     product = five.times(2)
     self.assertEqual(10, product.amount)
     product = five.times(3)
     self.assertEqual(15, product.amount)
Example #7
0
 def test_equality(self):
     # TODO nullとの等価性比較
     # TODO 他のオブジェクトとの等価性比較
     self.assertTrue(Dollar(5).equals(Dollar(5)))
     self.assertFalse(Dollar(5).equals(Dollar(6)))
Example #8
0
 def testMultiplicaton(self):
     five = Dollar(5)
     five.times(2)
     # OK
     eq_(10, five.amount)
Example #9
0
 def __init__(self):
     self.products = {"apple": Product("apple", Dollar(2), 10),
                      "avocado": Product("avocado", Euro(3), 10),
                      "dress": Product("dress", Rubles(2000), 5)}
Example #10
0
    if desicion == 2:
        allhistoric = dolar_saver.read_all()
        try:
            last_dollar_saved = allhistoric[len(allhistoric) - 1]
            if last_dollar_saved is not None:
                if dolar_blue.date > last_dollar_saved.date:
                    dolar_saver.append_dollar(dolar_blue)
                else:
                    #equals or less
                    if last_dollar_saved.price != dolar_blue.price:
                        print('sobre escribo el ultimo registro')
                        dolar_saver.update_last_one(dolar_blue)
                    else:
                        print('same price not update')
            else:
                dolar_saver.append_dollar(dolar_blue)
        except Exception:
            # traceback.print_exc(file=sys.stdout)
            print('exception')
            dolar_saver.save_dollar(dolar_blue)
    if desicion == 3:
        calcular_compra_dolar()
    if desicion == 9:
        dollar1 = Dollar('dollar1', '300', date.today())
        dollar2 = Dollar('dollar2', '400', date.today())
        dolar_saver.append_dollar(dollar1)
        dolar_saver.append_dollar(dollar2)
    if desicion == 0:
        break
    input()