This repository has been archived by the owner on Oct 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omnioverlay.py
172 lines (139 loc) · 5.88 KB
/
omnioverlay.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
""""
Overlay manager
"""
from config import config
import omniconfig
import omniutils as ou
from omniconfig import configuration as oc
import omniinara
import omniroa
FLUSH = " "
class OverlayManager:
_line_template = u"{}: {}"
def __init__(self, overlay_instance):
self._overlay = overlay_instance
def __send_to_socket(self, text, row, col, color, ttl, size):
try:
self._overlay.send_message("omniscanner_{}_{}".format(row, col), text, color, col, row, ttl, size)
except Exception as e:
ou.warn("Exception sending message to overlay: {}".format(e))
def display(self, text, row, col, color, size="normal"):
self.__send_to_socket(text, row, col, color,
ttl=config.get(omniconfig.TTL_CONFIG_KEY),
size=size)
def version_message(self, text, color):
self.__send_to_socket(text,
row=oc.get_overlay_layout("version_row"),
col=oc.get_overlay_layout("version_col"),
color=color,
ttl=oc.get_overlay_ttl("version_ttl"),
size="large")
def service_message(self, text, color):
self.__send_to_socket(text,
row=oc.get_overlay_layout("service_row"),
col=oc.get_overlay_layout("service_col"),
color=color,
ttl=oc.get_overlay_ttl("service_ttl"),
size="large")
def flush(self):
"""
Try to flush the overlay with empty lines
:return:
"""
self.display(FLUSH,
oc.get_overlay_layout("sub_header_row"),
oc.get_overlay_layout("first_col"),
oc.get_overlay_color("text"))
self.display(FLUSH,
oc.get_overlay_layout("detail_row"),
oc.get_overlay_layout("first_col"),
oc.get_overlay_color("text"))
self.display(FLUSH,
oc.get_overlay_layout("detail_row"),
oc.get_overlay_layout("second_col"),
oc.get_overlay_color("text"))
def display_notification(self, text):
self.display(text,
row=oc.get_overlay_layout("header_row"),
col=oc.get_overlay_layout("first_col"),
color=oc.get_overlay_color("notification"),
size="large")
def display_error(self, text):
self.display(text,
row=oc.get_overlay_layout("detail_row"),
col=oc.get_overlay_layout("first_col"),
color=oc.get_overlay_color("error"),
size="large")
def display_warning(self, text, col):
self.display(text,
row=oc.get_overlay_layout("detail_row"),
col=col,
color=oc.get_overlay_color("warning"),
size="large")
def display_cmdr_name(self, text):
self.display(text,
row=oc.get_overlay_layout("header_row"),
col=oc.get_overlay_layout("first_col"),
color=oc.get_overlay_color("cmdr_name"),
size="large")
def _display_role(self, text):
self.display(text,
row=oc.get_overlay_layout("sub_header_row"),
col=oc.get_overlay_layout("first_col"),
color=oc.get_overlay_color("cmdr_role"))
def _display_section_header(self, title, col):
self.display(title,
row=oc.get_overlay_layout("info_row"),
col=col,
color=oc.get_overlay_color("sect_title"),
size="large")
def _display_section(self, text, col):
self.display(text,
row=oc.get_overlay_layout("detail_row"),
col=col,
color=oc.get_overlay_color("text"))
def display_info(self, pilot_name, cmdrData):
"""
Display an entry
:param pilot_name:
:param cmdrData:
:return:
"""
# Display cmdr name
self.display_cmdr_name(pilot_name)
# Display section headers
self._display_section_header("Inara", oc.get_overlay_layout("first_col"))
self._display_section_header("ROA DB", oc.get_overlay_layout("second_col"))
# Inara
inara_data = omniinara.parse_reply_for_overlay(cmdrData['inara'])
if inara_data:
if 'role' in inara_data:
self._display_role(inara_data['role'])
lines = []
if 'wing' in inara_data:
for line in inara_data['wing']:
lines.append(line)
for line in inara_data['base']:
lines.append(line)
for line in inara_data['rank']:
lines.append(line)
text = "\n".join(lines)
self._display_section(text, oc.get_overlay_layout("first_col"))
else:
self.display_warning("No results", oc.get_overlay_layout("first_col"))
roa_data = omniroa.parse_reply_for_overlay(cmdrData['roa'])
if roa_data:
# Remove 'Clan' if 'wing' is in already in inara
# 'Clan' is always returned from roa.parse_reply
# or this will not work
if inara_data and 'wing' in inara_data:
text = "\n".join(roa_data[1:])
else:
text = "\n".join(roa_data)
self._display_section(text, oc.get_overlay_layout("second_col"))
else:
self.display_warning("No results", oc.get_overlay_layout("second_col"))
def shutdown(self):
self._overlay.send_raw({
"command": "exit"
})