-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest6.py
98 lines (74 loc) · 3.09 KB
/
test6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
This is the first of development phase and using the rough framework. Test5 should be the same as
test4 but using the local library.
"""
import numpy as np
import struct
from subprocess import Popen
from time import sleep
import usb.core
from usb.core import USBTimeoutError
from pydatacolor import DataColor
"""Aim to really simple measurement app"""
from textual.app import App, ComposeResult
from textual.containers import ScrollableContainer
from textual.widgets import Button, Footer, Header, Static
class ColourDisplay(Static):
"""A widget to display a measured colour."""
class Calibrate(Static):
"""A colour measurement widget."""
def on_button_pressed(self, event: Button.Pressed) -> None:
"""Event handler called when a button is pressed."""
if event.button.id == "calibrate":
if "started" in self.classes:
self.remove_class("started")
else:
self.app.add_colourimeter()
if self.app.dc:
r = self.get_child_by_id("calibresult")
tile = self.app.dc.calibration_and_measure()
r.update(f"White = {tile} SN = {self.app.dc.get_serial_number()}")
self.add_class("started")
def compose(self) -> ComposeResult:
"""Create child widgets of a stopwatch."""
yield Button("Calibrate", id="calibrate", variant="success")
yield ColourDisplay("#FF0000", id="calibresult")
class Measurement(Static):
"""A colour measurement widget."""
def on_button_pressed(self, event: Button.Pressed) -> None:
"""Event handler called when a button is pressed."""
if event.button.id == "measure":
if "started" in self.classes:
self.remove_class("started")
else:
if self.app.dc:
r = self.get_child_by_id("result")
tile = self.app.dc.measure_array_n(100)
r.update(f"L*ab = {tile}")
self.add_class("started")
def compose(self) -> ComposeResult:
"""Create child widgets of a stopwatch."""
yield Button("Measure", id="measure", variant="success")
yield ColourDisplay("#FFEFDF", id="result")
class Measurer(App):
"""A Textual app to calibrate and make measurements with a Datacolor Colorimeter."""
CSS_PATH = "test6.css"
BINDINGS = [("q", "quit", "Quit the app"), ("d", "toggle_dark", "Toggle dark mode")]
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Header()
yield ScrollableContainer(Calibrate(), Measurement(), Measurement())
yield Footer()
def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
def add_colourimeter(self):
self.dev = usb.core.find()
self.dc = DataColor(verbose=False)
if self.dc:
self.dc.reset()
# print(f"Serial number = {dc.serial_nuber}")
self.dc.drain(verbose=False)
if __name__ == "__main__":
app = Measurer()
app.run()