-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.py
177 lines (154 loc) · 5.38 KB
/
console.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import piksi_tools.serial_link as s
import sbp.client as sbpc
import signal
import sys
# Shut chaco up for now
import warnings
warnings.simplefilter(action = "ignore", category = FutureWarning)
def get_args():
import argparse
parser = argparse.ArgumentParser(description='Swift Nav Console.')
parser.add_argument('-p', '--port', nargs=1, default=[None],
help='specify the serial port to use.')
parser.add_argument('-b', '--baud', nargs=1, default=[s.SERIAL_BAUD],
help='specify the baud rate to use.')
return parser.parse_args()
args = get_args()
port = args.port[0]
baud = args.baud[0]
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'
from piksi_tools.console.utils import determine_path
from traits.api import Bool, Str, Instance, Dict, HasTraits, Int, Button, List, Enum
from traitsui.api import Item, Label, View, HGroup, VGroup, VSplit, HSplit, Tabbed, \
InstanceEditor, EnumEditor, ShellEditor, Handler, Spring, \
TableEditor, UItem, Action
# When bundled with pyInstaller, PythonLexer can't be found. The problem is
# pygments.lexers is doing some crazy magic to load up all of the available
# lexers at runtime which seems to break when frozen.
#
# The horrible workaround is to load the PythonLexer class explicitly and then
# manually insert it into the pygments.lexers module.
from pygments.lexers.agile import PythonLexer
import pygments.lexers
pygments.lexers.PythonLexer = PythonLexer
try:
import pygments.lexers.c_cpp
except ImportError:
pass
# These imports seem to be required to make pyinstaller work?
# (usually traitsui would load them automatically)
if ETSConfig.toolkit == 'qt4':
import pyface.ui.qt4.resource_manager
import pyface.ui.qt4.python_shell
from pyface.image_resource import ImageResource
basedir = determine_path()
icon = ImageResource('icon', search_path=['images', os.path.join(basedir, 'images')])
from piksi_tools.console.data_view import DataView
from piksi_tools.console.baseline_view import BaselineView
from piksi_tools.console.summary_view import SummaryView
if ETSConfig.toolkit != 'null':
from enable.savage.trait_defs.ui.svg_button import SVGButton
else:
SVGButton = dict
from piksi_tools.console.views_utils import ViewsUtils
CONSOLE_TITLE = u'RTK监控系统'
class SwiftConsole(HasTraits):
link = Instance(sbpc.Handler)
data_view = Instance(DataView)
baseline_view = Instance(BaselineView)
summary_view = Instance(SummaryView)
utils = Instance(ViewsUtils)
view = View(
VSplit(
Tabbed(
Item('data_view', style='custom', label=u'数据采集'),
Item('baseline_view', style='custom', label=u'实时'),
Item('summary_view', style='custom', label=u'总结'),
show_labels=False
),
),
icon = icon,
dock = 'fixed',
resizable = False,
width = 800,
height = 600,
title = CONSOLE_TITLE,
)
def _summary_view_fired(self):
self.summary_view.position_threshold = self.baseline_view.position_threshold
self.summary_view.depth_threshold = self.baseline_view.depth_threshold
self.summary_view.time_threshold = self.baseline_view.time_threshold
def __init__(self, link):
try:
self.link = link
self.data_view = DataView()
self.baseline_view = BaselineView(self.link)
self.summary_view = SummaryView(self.link)
self.utils = ViewsUtils(self.data_view, self.baseline_view, self.summary_view)
self.data_view.set_utils(self.utils)
self.baseline_view.set_utils(self.utils)
self.summary_view.set_utils(self.utils)
except:
import traceback
traceback.print_exc()
# Make sure that SIGINT (i.e. Ctrl-C from command line) actually stops the
# application event loop (otherwise Qt swallows KeyboardInterrupt exceptions)
signal.signal(signal.SIGINT, signal.SIG_DFL)
# If using a device connected to an actual port, then invoke the
# regular console dialog for port selection
class PortChooser(HasTraits):
ports = List()
bauds = List()
port = Str()
baud = Int(115200)
traits_view = View(
VGroup(
HGroup(
Label(u'端口号:'),
Item('port', editor=EnumEditor(name='ports'), show_label=False),
),
HGroup(
Label(u'波特率:'),
Item('baud', editor=EnumEditor(name='bauds'), show_label=False),
),
),
buttons = ['OK'],
close_result=False,
resizable = False,
scrollable = False,
icon = icon,
width = 250,
title = u'选择串口设备',
)
def __init__(self):
try:
self.ports = [p for p, _, _ in s.get_ports()]
if self.ports:
self.port = self.ports[0]
self.bauds = [4800, 9600, 19200, 38400, 43000, 56000, 57600, 115200]
except TypeError:
pass
if not port:
port_chooser = PortChooser()
is_ok = port_chooser.configure_traits()
port = port_chooser.port
baud = port_chooser.baud
if not port or not is_ok:
print "No serial device selected!"
sys.exit(1)
else:
print "Using serial device '%s', bauderate %d" % (port, baud)
with s.get_driver(False, port, baud) as driver:
with sbpc.Handler(sbpc.Framer(driver.read, driver.write, False)) as link:
with s.get_logger() as logger:
sbpc.Forwarder(link, logger).start()
SwiftConsole(link).configure_traits()
# Force exit, even if threads haven't joined
try:
os._exit(0)
except:
pass