forked from ThomasGerstenberg/serial_monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_settings.py
57 lines (48 loc) · 1.64 KB
/
serial_settings.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
import sublime
class SerialSettings(object):
SETTINGS_FILE = "serial_monitor.sublime-settings"
_SETTINGS_LIST = [
"comport",
"baud",
"text",
"override_selection",
"enable_timestamps",
"line_endings",
"local_echo",
"full_config_on_connect"
"data_bits",
"parity",
"stop_bits",
]
def __init__(self, callback, **args):
self.callback = callback
self.comport = None
self.baud = None
self.text = None
self.override_selection = None
self.enable_timestamps = None
self.line_endings = None
self.local_echo = None
self.full_config_on_connect = None
self.data_bits = None
self.parity = None
self.stop_bits = None
for attr in self._SETTINGS_LIST:
setattr(self, attr, args.get(attr))
@staticmethod
def load_defaults(comport):
defaults = sublime.load_settings(SerialSettings.SETTINGS_FILE)
settings = SerialSettings(None)
for attr in SerialSettings._SETTINGS_LIST:
v = defaults.get(attr, None)
if v is not None:
setattr(settings, attr, v)
# Check if there's any port-specific settings
if comport:
comport_settings = defaults.get(comport, None)
if comport_settings:
for attr in SerialSettings._SETTINGS_LIST:
v = comport_settings.get(attr, None)
if v is not None:
setattr(settings, attr, v)
return settings