def main(): def usage(): print('usage: ' + sys.argv[0] + ' [host] [VAR1] [VAR2] .. [VARN]') exit(1) if len(sys.argv) < 2: usage() plot = pypilotPlot() def on_con(client): plot.on_con(client) client = pypilotClientFromArgs(sys.argv, True, on_con) if not client.have_watches: usage() print('connected') def idle(): while True: try: result = client.receive_single() if result: plot.read_data(result) else: time.sleep(.01) break except: pass glutInit(sys.argv) glutInitWindowPosition(250, 0) glutInitWindowSize(1000, 500) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutCreateWindow("glplot") def display(): plot.display() glutSwapBuffers() glutDisplayFunc(display) glutReshapeFunc(plot.reshape) glutKeyboardFunc(plot.key) glutSpecialFunc(plot.special) glutIdleFunc(idle) plot.init(client.list_values(10)) def timeout(arg): glutPostRedisplay() glutTimerFunc(arg, timeout, arg) fps = 30 glutTimerFunc(0, timeout, 1000 / fps) glutMainLoop()
def __init__(self): super(pypilotScope, self).__init__(None) self.plot = pypilotPlot() self.glContext = wx.glcanvas.GLContext(self.glArea) self.client = pypilotClientFromArgs(sys.argv) self.client.watch('timestamp') self.watches = {} self.timer = wx.Timer(self, wx.ID_ANY) self.Bind(wx.EVT_TIMER, self.receive_messages, id=wx.ID_ANY) self.timer.Start(100) self.sTime.SetValue(self.plot.disptime) self.plot_reshape = False
def main(): plot = pypilotPlot() client = pypilotClientFromArgs(sys.argv) print('connected') def idle(): while True: try: result = client.receive_single() if result: plot.read_data(result) else: time.sleep(.01) break except: pass glutInit(sys.argv) glutInitWindowPosition(250, 0) glutInitWindowSize(1000, 500) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) glutCreateWindow('glplot') def display(): plot.display() glutSwapBuffers() glutDisplayFunc(display) glutReshapeFunc(plot.reshape) glutKeyboardFunc(plot.key) glutSpecialFunc(plot.special) glutIdleFunc(idle) plot.init(client.list_values(10)) fps = 30 def timeout(arg): glutPostRedisplay() glutTimerFunc(int(1000 / fps), timeout, arg) glutTimerFunc(0, timeout, None) glutMainLoop()
def __init__(self): super(pypilotScope, self).__init__(None) self.plot = pypilotPlot() self.glContext = wx.glcanvas.GLContext(self.glArea) def on_con(client): self.plot.on_con(client) self.client = pypilotClientFromArgs(sys.argv[:2], True, on_con) self.host_port = self.client.host_port self.client.autoreconnect = False self.value_list = self.client.list_values() self.plot.init(self.value_list) self.watches = {} watches = sys.argv[1:] for name in sorted(self.value_list): if self.value_list[name]['type'] != 'SensorValue': continue i = self.clValues.Append(name) self.watches[name] = False for arg in watches: if arg == name: self.clValues.Check(i, True) self.watches[name] = True watches.remove(name) for arg in watches: print('value not found:', arg) self.on_con(self.client) self.timer = wx.Timer(self, wx.ID_ANY) self.Bind(wx.EVT_TIMER, self.receive_messages, id=wx.ID_ANY) self.timer.Start(50) self.sTime.SetValue(self.plot.disptime) self.plot_reshape = False
def __init__(self): wx.Frame.__init__(self, None, title="pypilot client", size=(1000, 600)) self.value_list = [] self.client = pypilotClientFromArgs(sys.argv, True, self.on_con) self.host_port = self.client.host_port self.client.autoreconnect = False ssizer = wx.FlexGridSizer(0, 1, 0, 0) ssizer.AddGrowableRow(0) ssizer.AddGrowableCol(0) ssizer.SetFlexibleDirection(wx.BOTH) ssizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.scrolledWindow = wx.ScrolledWindow(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL | wx.VSCROLL) self.scrolledWindow.SetScrollRate(5, 5) sizer = wx.FlexGridSizer(0, 3, 0, 0) sizer.AddGrowableCol(2) sizer.SetFlexibleDirection(wx.BOTH) sizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.values = {} self.controls = {} self.sliderrange = {} self.value_list = self.client.list_values() self.on_con(self.client) for name in sorted(self.value_list): sizer.Add(wx.StaticText(self.scrolledWindow, wx.ID_ANY, name), 0, wx.ALL, 5) self.values[name] = wx.StaticText(self.scrolledWindow, wx.ID_ANY) sizer.Add(self.values[name], 0, wx.ALL, 5) t = self.value_list[name]['type'] if t == 'Property': tb = wx.TextCtrl(self.scrolledWindow, wx.ID_ANY) sizer.Add(tb) self.controls[name] = tb elif t == 'BooleanProperty': def proc(): # encapsulate to fix scope cb = wx.CheckBox(self.scrolledWindow, wx.ID_ANY, '') sizer.Add(cb, 0, wx.EXPAND) self.controls[name] = cb cbname = name def oncheck(event): self.client.set(cbname, cb.GetValue()) cb.Bind(wx.EVT_CHECKBOX, oncheck) proc() elif t == 'RangeProperty' or t == 'RangeSetting': useSlider = True def proc(): r = self.value_list[name]['min'], self.value_list[name][ 'max'] if useSlider: s = wx.Slider(self.scrolledWindow) s.SetRange(0, 1000) else: s = wx.SpinCtrlDouble(self.scrolledWindow) s.SetRange(r[0], r[1]) s.SetIncrement(min(1, (r[1] - r[0]) / 100.0)) s.SetDigits(-math.log(s.GetIncrement()) / math.log(10) + 1) sizer.Add(s, 0, wx.EXPAND) self.controls[name] = s sname = name def onspin(event): if useSlider: v = s.GetValue() / 1000.0 * (r[1] - r[0]) + r[0] self.client.set(sname, v) else: self.client.set(sname, s.GetValue()) if useSlider: s.Bind(wx.EVT_SLIDER, onspin) self.sliderrange[name] = r else: s.Bind(wx.EVT_SPINCTRLDOUBLE, onspin) proc() elif t == 'EnumProperty': def proc(): c = wx.Choice(self.scrolledWindow, wx.ID_ANY) for choice in self.value_list[name]['choices']: c.Append(str(choice)) sizer.Add(c, 0, wx.EXPAND) self.controls[name] = c cname = name def onchoice(event): self.client.set(cname, str(c.GetStringSelection())) c.Bind(wx.EVT_CHOICE, onchoice) proc() elif t == 'ResettableValue': def proc(): b = wx.Button(self.scrolledWindow, wx.ID_ANY, 'Reset') sizer.Add(b, 0, wx.EXPAND) bname = name def onclick(event): self.client.set(bname, 0) b.Bind(wx.EVT_BUTTON, onclick) proc() else: sizer.Add(wx.StaticText(self.scrolledWindow, wx.ID_ANY, '')) self.scrolledWindow.SetSizer(sizer) self.scrolledWindow.Layout() sizer.Fit(self.scrolledWindow) ssizer.Add(self.scrolledWindow, 1, wx.EXPAND | wx.ALL, 5) bsizer = wx.FlexGridSizer(1, 0, 0, 0) self.bRefresh = wx.Button(self, wx.ID_ANY, 'Refresh') self.bRefresh.Bind(wx.EVT_BUTTON, self.Refresh) bsizer.Add(self.bRefresh) self.bScope = wx.Button(self, wx.ID_ANY, 'Scope') self.bScope.Bind( wx.EVT_BUTTON, lambda event: subprocess.Popen([ 'python', os.path.abspath(os.path.dirname(__file__)) + '/' + 'scope_wx.py' ] + sys.argv[1:])) bsizer.Add(self.bScope) self.bClose = wx.Button(self, wx.ID_ANY, 'Close') self.bClose.Bind(wx.EVT_BUTTON, exit) bsizer.Add(self.bClose) ssizer.Add(bsizer, 1, wx.EXPAND) self.SetSizer(ssizer) self.Layout() self.timer = wx.Timer(self, wx.ID_ANY) self.timer.Start(500) self.Bind(wx.EVT_TIMER, self.receive_messages, id=wx.ID_ANY) self.Refresh()