예제 #1
0
    def __init__(self):
        self.button_manager = Button_Manager([("Jog_push", 27), ("Top", 5),
                                              ("Mid", 6), ("Low", 12),
                                              ("Shutdown", 26)])

        self.dial = Dial(10, "Jog")
        self.dial.start()
예제 #2
0
	def test_create_team_from_list(self):
		dials = [
			Dial(self.dial_1_data),
			Dial(self.dial_2_data)
		]

		team = Team(dials)
		self.assertLess(team.points, team.max_points)
예제 #3
0
	def test_add_to_sideteam_single_dial(self):
		dial = Dial(self.dial_side_1_data)
		dials = [
			Dial(self.dial_1_data),
			Dial(self.dial_2_data)
		]

		team = Team(dials=dials, points= 300, sideteam=dial)
예제 #4
0
	def test_create_team_to_big(self):
		dials = [
			Dial(self.dial_1_data), 
			Dial(self.dial_2_data), 
			Dial(self.dial_3_data)
			]

		with self.assertRaises(DialListCostTooHigh):
			team = Team(dials)
예제 #5
0
class UI_Manager:
    def __init__(self):
        self.button_manager = Button_Manager([("Jog_push", 27), ("Top", 5),
                                              ("Mid", 6), ("Low", 12),
                                              ("Shutdown", 26)])

        self.dial = Dial(10, "Jog")
        self.dial.start()

    def __del__(self):
        del (self.button_manager)
        del (self.dial)

    def update(self, receiving_queue: list):
        # Get control events
        dial_direction = self.dial.get_direction()

        ui_events = []
        if dial_direction != 0:
            ui_events.append(["Jog", dial_direction])

        button_events = []
        self.button_manager.update(button_events)

        # Convert button events into ui_events
        for event in button_events:
            if event[0] == "Shutdown" and event[1] > SHUTDOWN_HOLD_TIME:
                # Just overwrite the queue as there's no point in doing anything else
                ui_events = [["Shutdown", 0]]
                self.button_manager.clear("Shutdown")
                break
            elif event[0] == "Jog_push":
                if event[1] > SHUTDOWN_HOLD_TIME:
                    # Just overwrite the queue as there's no point in doing anything else
                    ui_events = [["Shutdown", 0]]
                    self.button_manager.clear("Jog_push")
                    break
                else:
                    ui_events.append(["Random", 0])
            elif event[0] == "Mid":
                if event[1] > CALIBRATE_HOLD_TIME:
                    ui_events.append(["Calibrate", 0])
                    self.button_manager.clear("Mid")
                else:
                    ui_events.append(["Confirm", 0])
            elif event[0] == "Top":
                ui_events.append(["Volume", 1])
            elif event[0] == "Low":
                ui_events.append(["Volume", -1])

        # Put the button events into the supplied queue (a list)
        receiving_queue.extend(ui_events)
예제 #6
0
	def test_add_to_sideteam(self):
		dials = [
			Dial(self.dial_1_data),
			Dial(self.dial_2_data)
		]

		sidedials = [
			Dial(self.dial_side_1_data),
			Dial(self.dial_side_2_data),
			Dial(self.dial_side_3_data)
		]

		team = Team(dials = dials, points = 300, sideteam = sidedials)
예제 #7
0
 def test_action_tokens_add_one(self):
     dial = Dial(self.dial_data)
     current_action_tokens = dial.get_current_action_tokens()
     dial.add_action_tokens(1)
     new_action_tokens = dial.get_current_action_tokens()
     dial.add_action_tokens(1)
     two_action_tokens = dial.get_current_action_tokens()
     self.assertEqual(current_action_tokens, 0)
     self.assertEqual(new_action_tokens, 1)
     self.assertEqual(two_action_tokens, 2)
예제 #8
0
    def __init__(self, controller, board=None):
        Table.__init__(self, 2, 2)

        self.dial = Dial(Adjustment(lower=-100, value=0, upper=100))
        self.attach(self.dial, 0, 1, 0, 1)

        right_box = VBox()
        right_box.add(Label("Motor"))

        self.selected_motor = 0
        self.labels = [SelectableLabel(str(num)) for num in range(2)]
        self.labels[self.selected_motor].set_state(STATE_SELECTED)
        for label in self.labels:
            right_box.add(label)

        self.attach(right_box, 1, 2, 0, 1)

        self.help_bar = Label(_HELP_MESSAGE)
        self.attach(self.help_bar, 0, 2, 1, 2)

        self.show_all()

        ## Signals ##
        self.connect("key-press-event", self.key_press)

        self.board = board
        self.controller = controller

        if board <> None:
            self.panel_update(None)
            self.connect("panel-update", self.panel_update)
예제 #9
0
def _main(args):
    win = Window()
    win.set_border_width(5)
    win.set_title('Widget test')
    win.connect('delete-event', main_quit)

    t = Table(5, 2, True)

    l1 = SelectableLabel("1")
    l1.set_state(STATE_SELECTED)
    t.attach(l1, 0, 1, 0, 1)
    l2 = SelectableLabel("2")
    t.attach(l2, 1, 2, 0, 1)

    w = DigitalInput(1)
    t.attach(w, 0, 1, 1, 2)
    x = DigitalInput(0)
    t.attach(x, 0, 1, 2, 3)
    y = AnalogueInput(2.4578)
    t.attach(y, 1, 2, 1, 2)
    z = AnalogueInput(0.0001)
    t.attach(z, 1, 2, 2, 3)

    d = Dial(Adjustment(value=53, lower=-100, upper=100))
    t.attach(d, 0, 3, 3, 5)
    win.add(t)

    win.show_all()

    main()
예제 #10
0
 def test_action_tokens_is_pushed(self):
     dial = Dial(self.dial_data)
     current_action_tokens = dial.get_current_action_tokens()
     dial.add_action_tokens(1)
     new_action_tokens = dial.get_current_action_tokens()
     self.assertEqual(new_action_tokens, 1)
     self.assertTrue(
         dial.can_push)  # has 1 action token, can push by adding one more.
     dial.add_action_tokens(1)
     pushed_action_tokens = dial.get_current_action_tokens()
     self.assertEqual(pushed_action_tokens, 2)
     self.assertFalse(
         dial.can_push)  # has 1 action token, can push by adding one more.
예제 #11
0
    def test_make_attack_misses(self, mockRoll):
        attacker_dial = Dial(self.attacker_dial_data)
        target_dial = Dial(self.target_dial_data)
        mockRoll.return_value = 12  # will hit
        attack_roll = attacker_dial.roll_to_hit(target_dial)
        if attack_roll:
            attack_damage = attacker_dial.calculate_damage()
            target_dial.add_damage(attack_damage)

        self.assertTrue(attack_roll)
예제 #12
0
 def test_action_tokens_on_create(self):
     dial = Dial(self.dial_data)
     current_action_tokens = dial.get_current_action_tokens()
     self.assertEqual(current_action_tokens, 0)
예제 #13
0
# Find positions of dials in image
dial_properties = meter_img.find_dials(num_dials=int(cmd_args['dials']))

# Read in the template image for the dial needle
template = cv2.imread(cmd_args['template'], 0)

dials = []
for (x,y,r) in dial_properties: 
    # Draw each dial on output image
    cv2.circle(output_img, (x,y), r, (0,255,0), 2)

    # Rightmost dial (dials[0]) is clockwise, then 
    # alternates clockwise and anti-clockwise
    dial_clockwise = (len(dials) % 2 == 1)

    # Create new Dial instance, determine position of hand, 
    # draw orientation on output image and add to list of dials
    d = Dial(center=(x,y), radius=r, image=meter_img, dial_template=template, clockwise=dial_clockwise)
    d.draw_needle_orientation(output_img)
    dials.append(d)

# Re-order dials from L to R
dials.reverse()

# Calculate and print meter reading to console
print "Meter Reading: ", calculate_reading(dials)

# Display image in viewer, press any key to exit viewer
cv2.imshow('found dials', np.hstack([output_img]))
cv2.waitKey(0)
예제 #14
0
 def test_heal_damage(self):
     testUnit = Dial(self.attacker_dial_data)
     testUnit.add_damage(3)
     self.assertEqual(3, testUnit.damage_received)
     testUnit.heal_damage(2)
     self.assertEqual(1, testUnit.damage_received)
예제 #15
0
 def test_roll(self):
     testUnit = Dial(self.attacker_dial_data)
     roll = testUnit.roll(2)
     self.assertGreater(roll, 0)
     self.assertLess(roll, 13)
예제 #16
0
 def test_make_attack_hits(self, mockRoll):
     attacker_dial = Dial(self.attacker_dial_data)
     target_dial = Dial(self.target_dial_data)
     mockRoll.return_value = 2  # will miss
     attack_roll = attacker_dial.roll_to_hit(target_dial)
     self.assertFalse(attack_roll)
예제 #17
0
 def test_has_willpower_false(self):
     dial = Dial(self.dial_data)
     hasWillpower = dial.has_willpower
     self.assertFalse(hasWillpower)
예제 #18
0
 def test_set_range(self):
     dial = Dial(self.dial_data)
     rangeval = self.dial_data.get("range")
     dial.set_range(self.dial_data)
     self.assertEqual(rangeval, dial.range)
예제 #19
0
 def test_print_get_click(self):
     dial = Dial(self.dial_data)
     current_click = dial.get_current_click()
     self.assertIsInstance(current_click, dict)
예제 #20
0
 def test_has_willpower_true(self):
     dial = Dial(self.willpower_dial_data)
     self.assertTrue(dial.has_willpower)
예제 #21
0
 def test_has_power(self):
     dial = Dial(self.willpower_dial_data)
     self.assertTrue(dial.has_power("energy explosion"))
예제 #22
0
 def test_set_name(self):
     dial = Dial(self.dial_data)
     name = self.dial_data.get("name")
     dial.set_name(self.dial_data)
     self.assertEqual(name, dial.name)
예제 #23
0
 def test_dial_roll(self):
     dial = Dial(self.dial_data)
     roll = 0
     self.assertIsNotNone(roll)
     self.assertIsInstance(roll, int)
예제 #24
0
 def test_create_dial(self):
     dial = Dial(self.dial_data)
     self.assertIsInstance(dial, Dial)
예제 #25
0
 def test_has_power_invalid_power(self):
     dial = Dial(self.willpower_dial_data)
     self.assertFalse(dial.has_power("notApower"))
예제 #26
0
	def test_create_team_from_dial(self):
		dial = Dial(self.dial_1_data)
		team = Team(dials = dial, points = 300, sideteam = [])
		self.assertLess(team.points, team.max_points)
예제 #27
0
 def test_set_cost(self):
     dial = Dial(self.dial_data)
     cost = self.dial_data.get("points")
     dial.set_cost(self.dial_data)
     self.assertEqual(cost, dial.cost)
예제 #28
0
 def test_set_id(self):
     dial = Dial(self.dial_data)
     uid = self.dial_data.get("id")
     dial.set_id(self.dial_data)
     self.assertEqual(uid, dial.id)
예제 #29
0
 def test_set_targets(self):
     dial = Dial(self.dial_data)
     targets = self.dial_data.get("targets")
     dial.set_targets(self.dial_data)
     self.assertEqual(targets, dial.targets)
예제 #30
0
    def __init__(self, master, image_path, label, width, column, row, values, continuous=True, columnspan=1, rowspan=1, interval=None, unit='', maxRot=5, precision=0, secondary=None, initial=None):
        self.frame = tk.Frame(master)
        self.frame.pack(side=tk.TOP, anchor=tk.NW)

        self.center_frame = tk.Frame(self.frame, height=dial_height, width=60)
        self.bottom_frame = tk.Frame(self.center_frame)
        self.right_frame = tk.Frame(self.frame, height=dial_height, width=dial_height)

        img = Image.open(image_path)
        img = img.resize((dial_height - border, dial_height - border), Image.ANTIALIAS)
        self.img = ImageTk.PhotoImage(img)
        self.canvas = tk.Canvas(self.frame, width=dial_height, height=dial_height, bg='black')
        self.canvas.create_image(4, 4, anchor=tk.NW, image=self.img)

        self.last_degree = 0
        self.rotations = 0
        self.degree = 0
        # self.entry = entry
        self.values = values
        self.continuous = continuous
        self.interval = interval

        self.precision = precision
        self.label = tk.Label(self.center_frame, text=label, font=FONT)
        self.entry = tk.Entry(self.bottom_frame, width=width, justify='right', state='readonly', font=FONT)
        self.unit = tk.Label(self.bottom_frame, text=unit, font=FONT)

        if continuous:
            assert(len(values) == 2)
            self.m = (self.values[1] - self.values[0]) / (720.0 * maxRot)
            self.b = 0.5 * (self.values[0] + self.values[1])
            self.dial = Dial(self.right_frame, radius=f'{dial_height * 0.004:.2f}i', maxRot=maxRot, command=self.command_continuous, zeroAxis='y', rotDir='clockwise')
            self.init = self.b if initial is None else initial
            self.state = self.init
        else:
            assert(len(values) > 0)
            angles = [-180. + 360. * i / (len(values) + 1) for i in range(1, len(values) + 1)]
            self.dial = DiscreteDial(self.right_frame, angles=angles, initAngleIndex=len(values)//2, radius=f'{dial_height * 0.004:.2f}i', command=self.command_discrete, zeroAxis='y', rotDir='clockwise')
            self.init = self.values[len(values)//2] if initial is None or initial not in values else initial
            self.state = self.init
        # self.dial.widget.grid(column=column, row=row, columnspan=columnspan, rowspan=rowspan)
        self.insert_entry()

        self.entry.pack(side=tk.LEFT)
        self.unit.pack(side=tk.LEFT)

        self.label.pack(anchor=tk.NW)
        self.bottom_frame.pack(anchor=tk.NW)

        self.canvas.pack(side=tk.LEFT)
        self.center_frame.pack(side=tk.LEFT)
        self.right_frame.pack(side=tk.LEFT)

        self.dial.widget.grid(column=1, row=1)
        self.right_frame.grid_rowconfigure(0, weight=1)
        self.right_frame.grid_rowconfigure(2, weight=1)
        self.right_frame.grid_columnconfigure(0, weight=1)
        self.right_frame.grid_columnconfigure(2, weight=1)

        self.center_frame.pack_propagate(0)
        self.right_frame.grid_propagate(0)

        self.secondary_function = secondary # function to calculate a secondary value whenever the dial moves
        self.secondary_value = None
        if self.secondary_function is None:
            self.secondary_value = None
        else:
            self.secondary_value = self.secondary_function(self.state)

        if continuous:
            self.set(self.state)
예제 #31
0
 def test_set_set(self):
     dial = Dial(self.dial_data)
     setid = self.dial_data.get("set")
     dial.set_set(self.dial_data)
     self.assertEqual(setid, dial.set)