-
Notifications
You must be signed in to change notification settings - Fork 10
/
pyAvMap.py
executable file
·157 lines (134 loc) · 5.11 KB
/
pyAvMap.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
#!/usr/bin/env python3
# Copyright (c) 2019 Garrett Herschleb
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import sys, os, time
import logging
import logging.config
import argparse
try:
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
PYQT = 5
except:
from PyQt4.QtGui import *
from PyQt4.QtCore import *
PYQT = 4
import yaml
import gui
import hmi
from hmi import Menu
if "pyAvTools" not in ''.join(sys.path):
neighbor_tools = os.path.join ('..', 'pyAvTools')
if os.path.isdir (neighbor_tools):
sys.path.append (neighbor_tools)
elif 'TOOLS_PATH' in os.environ:
sys.path.append (os.environ['TOOLS_PATH'])
try:
import pyavui
import pyavtools.fix as fix
except:
print ("You need to have pyAvTools installed, or in an adjacent directory to pyAvMap.")
print ("Or set the environment variable 'TOOLS_PATH' to point to the location of pyAvTools.")
sys.exit(-1)
import pyavmap
class Main(QMainWindow):
keyPress = pyqtSignal(QEvent)
keyRelease = pyqtSignal(QEvent)
def keyPressEvent(self, event):
self.keyPress.emit(event)
def keyReleaseEvent(self, event):
self.keyRelease.emit(event)
if __name__ == "__main__":
app = QApplication(sys.argv)
parser = argparse.ArgumentParser(description='pyAvMap')
parser.add_argument('--debug', action='store_true',
help='Run in debug mode')
parser.add_argument('--verbose', '-v', action='store_true',
help='Run in verbose mode')
parser.add_argument('--config-file', default='config/main.yaml', type=argparse.FileType('r'),
help='Alternate configuration file')
args = parser.parse_args()
# if we passed in a configuration file on the command line...
config = yaml.load(args.config_file)
if 'logging' in config:
logging.config.dictConfig(config['logging'])
else:
logging.basicConfig()
log = logging.getLogger()
if args.verbose:
log.setLevel(logging.INFO)
if args.debug:
log.setLevel(logging.DEBUG)
log.info("Starting pyAvMap")
log.debug("PyQT Version = %d" % PYQT)
fix.initialize(config)
pyavmap.configure_charts (config['charts_dir'])
main_window = Main()
screenWidth = int(config["main"]["screenWidth"])
screenHeight = int(config["main"]["screenHeight"])
main_window.resize(screenWidth, screenHeight)
avmap = pyavmap.AvMap (config, main_window)
avmap.resize(screenWidth, screenHeight)
hmi.initialize(config)
hmi.keys.initialize(main_window, config["keybindings"])
if 'menu' in config:
menu = Menu(main_window, config["menu"])
menu.start()
menu.register_map(avmap)
enc = "ENC1" if "rotary_encoder" not in config else config["rotary_encoder"]
enc_sel = "BTN6" if "rotary_select" not in config else config["rotary_select"]
ctsel_widget = gui.ChartTypeSel(enc, enc_sel, pyavmap.chart_types(),
avmap.set_chart_type, main_window)
ctsel_widget.resize (100, 65)
ctsel_widget.move (30, 32)
menu.register_target ("Chart Type", ctsel_widget)
if 'displays' in config:
for title,contents in config['displays'].items():
position = [0,0]
kwargs = {'parent': main_window}
dbitems = list()
for k,v in contents.items():
if k == 'keys':
for key in v:
item = fix.db.get_item(key)
dbitems.append(item)
elif k == 'position':
position = v
else:
kwargs[k] = v
d = pyavui.FIXDisplay(title, dbitems, **kwargs)
if position[0] < 0:
position[0] = screenWidth+position[0]-d.width()
if position[1] < 0:
position[1] = screenHeight+position[1]-d.height()
d.move (*tuple(position))
main_window.show()
track = fix.db.get_item("TRACK")
avmap.setTrack(track.value)
lat = fix.db.get_item("LAT")
avmap.setLat(lat.value)
lon = fix.db.get_item("LONG")
avmap.setLon (lon.value)
lat.valueChanged[float].connect(avmap.setLat)
lon.valueChanged[float].connect(avmap.setLon)
track.valueChanged[float].connect(avmap.setTrack)
# Main program loop
result = app.exec_()
# Clean up and get out
fix.stop()
log.info("PyAvMap Exiting Normally")
sys.exit(result)