-
Notifications
You must be signed in to change notification settings - Fork 1
/
kiyoproctrlsgui.py
executable file
·132 lines (104 loc) · 5.23 KB
/
kiyoproctrlsgui.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3
import os, logging, sys, webbrowser
from kiyoproctrls import KiyoProCtrls, find_usb_ids_in_sysfs, get_device_capabilities, V4L2_CAP_VIDEO_CAPTURE
try:
from tkinter import Tk, ttk, PhotoImage
except Exception as e:
logging.error(f'tkinter import failed: {e}, please install the python3-tk package')
sys.exit(3)
v4ldir = '/dev/v4l/by-id/'
ghurl = 'https://github.com/soyersoyer/kiyoproctrls'
def get_kiyo_pro_devices(dir):
if not os.path.isdir(dir):
return []
devices = os.listdir(dir)
devices.sort()
devices = list(filter(lambda device: find_usb_ids_in_sysfs(dir + device) == KiyoProCtrls.KIYO_PRO_USB_ID, devices))
devices = list(filter(lambda device: get_device_capabilities(dir + device) & V4L2_CAP_VIDEO_CAPTURE, devices))
return devices
class KiyoProCtrlsGui:
def __init__(self):
self.devices = []
self.fd = 0
self.device = ''
self.kiyo_pro = None
self.window = None
self.kpimg = None
self.frame = None
self.devicescb = None
self.init_window()
self.refresh_devices()
def init_window(self):
self.window = Tk(className='kiyoproctrls')
self.kpsmallimg = PhotoImage(file='kiyopro_240.png')
self.kpimg = PhotoImage(file='kiyopro_big.png')
self.window.wm_iconphoto(True, self.kpsmallimg)
self.window.title('kiyoproctrls')
self.window.winfo_toplevel().title('kiyoproctrls')
ttk.Label(self.window, image=self.kpimg, padding=10).grid()
gh = ttk.Label(self.frame, text='Github page', foreground='blue', cursor='hand2', padding=5)
gh.grid(sticky='NW', row=0)
gh.bind('<Button-1>', lambda e: webbrowser.open(ghurl))
def refresh_devices(self):
self.devices = get_kiyo_pro_devices(v4ldir)
if self.device not in self.devices:
self.close_device()
if len(self.devices):
self.open_device(self.devices[0])
self.init_gui_device()
if self.devicescb:
self.devicescb['values'] = self.devices
def gui_open_device(self, device):
self.close_device()
self.open_device(device)
self.init_gui_device()
def open_device(self, device):
devpath = v4ldir + device
logging.info(f'opening device: {device}')
try:
self.fd = os.open(devpath, os.O_RDWR, 0)
except Exception as e:
logging.error(f'os.open({devpath}, os.O_RDWR, 0) failed: {e}')
self.kiyo_pro = KiyoProCtrls(devpath, self.fd)
self.device = device
def close_device(self):
if self.fd:
os.close(self.fd)
self.fd = 0
self.device = ''
self.kiyo_pro = None
def init_gui_device(self):
if self.frame:
self.frame.destroy()
self.frame = None
self.devicescb = None
self.frame = ttk.Frame(self.window, padding=10)
self.frame.grid()
if len(self.devices) == 0:
ttk.Label(self.frame, text='0 device found', padding=10).grid()
ttk.Button(self.frame, text='Refresh', command=self.refresh_devices).grid(sticky='NESW')
return
self.devicescb = ttk.Combobox(self.frame, state='readonly', values=self.devices, postcommand=self.refresh_devices)
self.devicescb.set(self.device)
self.devicescb.grid(sticky='NESW', pady=10)
self.devicescb.bind('<<ComboboxSelected>>', lambda e: self.gui_open_device(self.devicescb.get()))
ctrls = ttk.Frame(self.frame)
ctrls.grid()
ttk.Label(ctrls, text='AF Mode').grid(column=0, row=0, sticky='W')
ttk.Button(ctrls, text='Passive', command=lambda: self.kiyo_pro.setup_ctrls({'af_mode': 'passive'}) ).grid(column=1, row=0, sticky='NESW')
ttk.Button(ctrls, text='Responsive', command=lambda: self.kiyo_pro.setup_ctrls({'af_mode': 'responsive'})).grid(column=2, row=0, sticky='NESW')
ttk.Label(ctrls, text='HDR', width=10).grid(column=0, row=1, sticky='W')
ttk.Button(ctrls, text='Off', command=lambda: self.kiyo_pro.setup_ctrls({'hdr': 'off'})).grid(column=1, row=1, sticky='NESW')
ttk.Button(ctrls, text='On', command=lambda: self.kiyo_pro.setup_ctrls({'hdr': 'on'})).grid(column=2, row=1, sticky='NESW')
ttk.Label(ctrls, text='HDR Mode').grid(column=0, row=2, sticky='W')
ttk.Button(ctrls, text='Dark', command=lambda: self.kiyo_pro.setup_ctrls({'hdr_mode': 'dark'})).grid(column=1, row=2, sticky='NESW')
ttk.Button(ctrls, text='Bright', command=lambda: self.kiyo_pro.setup_ctrls({'hdr_mode': 'bright'})).grid(column=2, row=2, sticky='NESW')
ttk.Label(ctrls, text='FoV').grid(column=0, row=3, sticky='W')
ttk.Button(ctrls, text='Narrow', command=lambda: self.kiyo_pro.setup_ctrls({'fov': 'narrow'})).grid(column=1, row=3, sticky='NESW')
ttk.Button(ctrls, text='Medium', command=lambda: self.kiyo_pro.setup_ctrls({'fov': 'medium'})).grid(column=2, row=3, sticky='NESW')
ttk.Button(ctrls, text='Wide', command=lambda: self.kiyo_pro.setup_ctrls({'fov': 'wide'})).grid(column=3, row=3, sticky='NESW')
def start(self):
self.window.mainloop()
if __name__ == '__main__':
gui = KiyoProCtrlsGui()
gui.start()