本文整理汇总了Python中gui.Gui.add_element方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.add_element方法的具体用法?Python Gui.add_element怎么用?Python Gui.add_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gui.Gui
的用法示例。
在下文中一共展示了Gui.add_element方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Recorder
# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import add_element [as 别名]
class Recorder(object):
def __init__(self, num_frames=settings.BUFFER_LENGTH, limit_fps=None):
if SHOW_WINDOW:
cv2.namedWindow("preview")
self.last_video_frame = None
self.num_frames = num_frames
self.frames = [None] * self.num_frames
self.current_jpg_frame = None
self.buffer_index = 0
self.keep_running = True
self.frame_rate = 0
self.last_frame = time.time()
self.limit_fps = limit_fps
self.api = Api(self)
self.api_lock = threading.Lock()
self.motion_detector = MotionDetector()
self.ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
self.encoding_subprocesses = []
self.last_serial_command = None
self.encoding_started = datetime.datetime.now()
if settings.UI_ENABLED:
if settings.UI_RESOLUTION:
self.gui = Gui(width=settings.UI_RESOLUTION[0], height=settings.UI_RESOLUTION[1])
else:
self.gui = Gui()
# Test recording button
base_state = (
self.gui.recording_button,
[150, 150, 90],
{}
)
hover_state = (
self.gui.recording_button,
[150, 150, 90],
{'highlight':True}
)
active_state = (
self.gui.recording_button,
[150, 150, 90],
{'active':True}
)
callback = lambda: self.log("triggered")#self.calibrate
self.gui.add_element(element_id=2, base_state=base_state, hover_state=hover_state, active_state=active_state, callback=callback)
base_state = (
self.gui.button,
[100, 100, 200, 30, 'Yeah buttons Baby'],
{}
)
hover_state = (
self.gui.button,
[98, 98, 204, 34, 'Yeah buttons Baby'],
{'fill_color': Color(0.95, 0.95, 0.95), 'bold':True}
)
active_state = (
self.gui.button,
[98, 98, 204, 34, 'Yeah buttons Baby'],
{'fill_color': Color(0.9, 0.9, 0.9), 'bold': True}
)
callback = self.calibrate
#self.gui.add_element(element_id=1, base_state=base_state, hover_state=hover_state, active_state=active_state, callback=callback)
self.gui.update()
else:
self.gui = None
def start_encoding_animation(self):
self.encoding_started = datetime.datetime.now()
self.last_serial_command = 'f'
self.ser.write('f')
def stop_encoding_animation(self):
if self.last_serial_command != 's':
self.last_serial_command = 's'
self.ser.write('s')
def log(self, text):
print text
def array(self, image):
return numpy.asarray(image[:,:])
def threshold(self, grayscale_array, low, high, value=1):
grayscale_array = value * numpy.logical_and(grayscale_array >= low, grayscale_array < high)
return grayscale_array
def update_frame_rate(self):
# FIXME: save some kind of average for the fps
self.frame_diff = time.time() - self.last_frame
if self.limit_fps:
#.........这里部分代码省略.........