mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-01 04:46:51 +08:00
[python] style, partial python3 compat
- pep8: 4 spaces - use 'in' instead of has_key for checking dicts - some fixes for settingsapp
This commit is contained in:
@@ -19,7 +19,7 @@ BORDER = 1
|
|||||||
|
|
||||||
class MessagesFrame(wx.Frame):
|
class MessagesFrame(wx.Frame):
|
||||||
def message_recv(self, ac_id, name, values):
|
def message_recv(self, ac_id, name, values):
|
||||||
if self.aircrafts.has_key(ac_id) and self.aircrafts[ac_id].messages.has_key(name):
|
if ac_id in self.aircrafts and name in self.aircrafts[ac_id].messages:
|
||||||
if time.time() - self.aircrafts[ac_id].messages[name].last_seen < 0.2:
|
if time.time() - self.aircrafts[ac_id].messages[name].last_seen < 0.2:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -109,12 +109,12 @@ class MessagesFrame(wx.Frame):
|
|||||||
field_panel.Layout()
|
field_panel.Layout()
|
||||||
|
|
||||||
def gui_update(self, ac_id, name, values):
|
def gui_update(self, ac_id, name, values):
|
||||||
if not self.aircrafts.has_key(ac_id):
|
if ac_id not in self.aircrafts:
|
||||||
self.add_new_aircraft(ac_id)
|
self.add_new_aircraft(ac_id)
|
||||||
|
|
||||||
aircraft = self.aircrafts[ac_id]
|
aircraft = self.aircrafts[ac_id]
|
||||||
|
|
||||||
if not aircraft.messages.has_key(name):
|
if name not in aircraft.messages:
|
||||||
self.add_new_message(aircraft, name)
|
self.add_new_message(aircraft, name)
|
||||||
|
|
||||||
aircraft.messages_book.SetPageImage(aircraft.messages[name].index, 1)
|
aircraft.messages_book.SetPageImage(aircraft.messages[name].index, 1)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ where
|
|||||||
\t-h | --help print this message
|
\t-h | --help print this message
|
||||||
\t-a AC_ID | --ac_id=AC_ID where AC_ID is an aircraft ID to use for settings (multiple IDs may passed)
|
\t-a AC_ID | --ac_id=AC_ID where AC_ID is an aircraft ID to use for settings (multiple IDs may passed)
|
||||||
'''
|
'''
|
||||||
print fmt % lpathitem[-1]
|
print(fmt % lpathitem[-1])
|
||||||
|
|
||||||
def GetOptions():
|
def GetOptions():
|
||||||
options = {'ac_id':[]}
|
options = {'ac_id':[]}
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ class SettingsFrame(wx.Frame):
|
|||||||
vert_box.AddWindow(horz_box)
|
vert_box.AddWindow(horz_box)
|
||||||
|
|
||||||
page.SetSizer(vert_box)
|
page.SetSizer(vert_box)
|
||||||
|
|
||||||
self.book.AddPage(page, setting_group.name)
|
self.book.AddPage(page, setting_group.name)
|
||||||
|
|
||||||
self.settings.RegisterCallback(self.onUpdate)
|
self.settings.RegisterCallback(self.onUpdate)
|
||||||
@@ -179,4 +180,3 @@ class SettingsFrame(wx.Frame):
|
|||||||
# need to forward close to canvas so that ivy is shut down, otherwise ivy hangs the shutdown
|
# need to forward close to canvas so that ivy is shut down, otherwise ivy hangs the shutdown
|
||||||
self.settings.OnClose()
|
self.settings.OnClose()
|
||||||
self.Destroy()
|
self.Destroy()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from __future__ import print_function
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
import messages_xml_map
|
import messages_xml_map
|
||||||
from ivy.std_api import *
|
from ivy.std_api import *
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -42,14 +42,14 @@ def ParseMessages():
|
|||||||
tree = etree.parse( messages_path)
|
tree = etree.parse( messages_path)
|
||||||
for the_class in tree.xpath("//class[@name]"):
|
for the_class in tree.xpath("//class[@name]"):
|
||||||
class_name = the_class.attrib['name']
|
class_name = the_class.attrib['name']
|
||||||
if not message_dictionary.has_key(class_name):
|
if class_name not in message_dictionary:
|
||||||
message_dictionary_id_name[class_name] = {}
|
message_dictionary_id_name[class_name] = {}
|
||||||
message_dictionary_name_id[class_name] = {}
|
message_dictionary_name_id[class_name] = {}
|
||||||
message_dictionary[class_name] = {}
|
message_dictionary[class_name] = {}
|
||||||
message_dictionary_types[class_name] = {}
|
message_dictionary_types[class_name] = {}
|
||||||
for the_message in the_class.xpath("message[@name]"):
|
for the_message in the_class.xpath("message[@name]"):
|
||||||
message_name = the_message.attrib['name']
|
message_name = the_message.attrib['name']
|
||||||
if the_message.attrib.has_key('id'):
|
if 'id' in the_message.attrib:
|
||||||
message_id = the_message.attrib['id']
|
message_id = the_message.attrib['id']
|
||||||
else:
|
else:
|
||||||
message_id = the_message.attrib['ID']
|
message_id = the_message.attrib['ID']
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
from ivy.std_api import *
|
from ivy.std_api import *
|
||||||
import os
|
import os
|
||||||
@@ -29,6 +29,9 @@ class IvySettingsInterface(PaparazziACSettings):
|
|||||||
setting_index = int(message_values[1])
|
setting_index = int(message_values[1])
|
||||||
setting_value = message_values[2]
|
setting_value = message_values[2]
|
||||||
|
|
||||||
|
if _SHOW_IVY_MSGS_:
|
||||||
|
print("Got setting with index: %s value %s " % (setting_index, setting_value))
|
||||||
|
|
||||||
# Store value from message
|
# Store value from message
|
||||||
self.lookup[setting_index].value = setting_value
|
self.lookup[setting_index].value = setting_value
|
||||||
|
|
||||||
@@ -36,20 +39,17 @@ class IvySettingsInterface(PaparazziACSettings):
|
|||||||
if self.update_callback != None:
|
if self.update_callback != None:
|
||||||
self.update_callback(setting_index, setting_value, fromRemote)
|
self.update_callback(setting_index, setting_value, fromRemote)
|
||||||
|
|
||||||
if _SHOW_IVY_MSGS_:
|
|
||||||
print("index: %s value %s " % (setting_index, setting_value))
|
|
||||||
|
|
||||||
# Called for DL_VALUE (from aircraft)
|
# Called for DL_VALUE (from aircraft)
|
||||||
def OnValueMsg(self, agent, *larg):
|
def OnValueMsg(self, agent, *larg):
|
||||||
# Extract field values
|
# Extract field values
|
||||||
message_values = larg[0].split(' ')
|
message_values = filter(None, larg[0].split(' '))
|
||||||
message_values = message_values[0:1] + message_values[2:]
|
message_values = message_values[0:1] + message_values[2:]
|
||||||
self.ProcessMessage(message_values, True)
|
self.ProcessMessage(message_values, True)
|
||||||
|
|
||||||
# Called for DL_SETTING (from ground)
|
# Called for DL_SETTING (from ground)
|
||||||
def OnSettingMsg(self, agent, *larg):
|
def OnSettingMsg(self, agent, *larg):
|
||||||
# Extract field values
|
# Extract field values
|
||||||
message_values = larg[0].split(' ')
|
message_values = filter(None, larg[0].split(' '))
|
||||||
self.ProcessMessage(message_values, False)
|
self.ProcessMessage(message_values, False)
|
||||||
|
|
||||||
def RegisterCallback(self, callback_function):
|
def RegisterCallback(self, callback_function):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@@ -19,7 +19,8 @@ class PaparazziACSettings:
|
|||||||
def __init__(self, ac_id):
|
def __init__(self, ac_id):
|
||||||
self.ac_id = ac_id
|
self.ac_id = ac_id
|
||||||
paparazzi_home = os.getenv("PAPARAZZI_HOME")
|
paparazzi_home = os.getenv("PAPARAZZI_HOME")
|
||||||
conf_xml_path = "%s/conf/conf.xml" % paparazzi_home
|
paparazzi_conf = os.path.join(paparazzi_home, 'conf')
|
||||||
|
conf_xml_path = os.path.join(paparazzi_conf, 'conf.xml')
|
||||||
conf_tree = etree.parse(conf_xml_path)
|
conf_tree = etree.parse(conf_xml_path)
|
||||||
# extract aircraft node from conf.xml file
|
# extract aircraft node from conf.xml file
|
||||||
ac_node = conf_tree.xpath('/conf/aircraft[@ac_id=%i]' % ac_id)
|
ac_node = conf_tree.xpath('/conf/aircraft[@ac_id=%i]' % ac_id)
|
||||||
@@ -27,49 +28,71 @@ class PaparazziACSettings:
|
|||||||
print("Aircraft ID %i not found." % ac_id)
|
print("Aircraft ID %i not found." % ac_id)
|
||||||
|
|
||||||
# get settings file path from aircraft xml node
|
# get settings file path from aircraft xml node
|
||||||
settings_xml_path = "%s/conf/%s" % (paparazzi_home, ac_node[0].attrib['settings'])
|
settings_xml_files = filter(None, ac_node[0].attrib['settings'].split(' '))
|
||||||
|
settings_xml_paths = [os.path.join(paparazzi_conf, s) for s in settings_xml_files]
|
||||||
|
#print("settings_xml_paths: %s" % settings_xml_paths)
|
||||||
|
|
||||||
# save AC name for reference
|
# save AC name for reference
|
||||||
self.name = ac_node[0].attrib['name']
|
self.name = ac_node[0].attrib['name']
|
||||||
|
|
||||||
tree = etree.parse(settings_xml_path)
|
|
||||||
|
|
||||||
index = 0 # keep track of index/id of setting starting at 0
|
index = 0 # keep track of index/id of setting starting at 0
|
||||||
|
for settings_file in settings_xml_paths:
|
||||||
|
#print("parsing settings file", settings_file)
|
||||||
|
tree = etree.parse(settings_file)
|
||||||
|
|
||||||
for the_tab in tree.xpath("//dl_settings"):
|
for the_tab in tree.xpath("//dl_settings"):
|
||||||
if the_tab.attrib.has_key('NAME'):
|
try:
|
||||||
setting_group = PaparazziSettingsGroup(the_tab.attrib['NAME'])
|
if 'NAME' in the_tab.attrib:
|
||||||
elif the_tab.attrib.has_key('NAME'):
|
setting_group_name = the_tab.attrib['NAME']
|
||||||
setting_group = PaparazziSettingsGroup(the_tab.attrib['name'])
|
|
||||||
else:
|
else:
|
||||||
|
setting_group_name = the_tab.attrib['name']
|
||||||
|
except:
|
||||||
|
#print("Could not read name of settings group")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
#print("parsing setting group:", setting_group_name)
|
||||||
|
setting_group = PaparazziSettingsGroup(setting_group_name)
|
||||||
|
|
||||||
for the_setting in the_tab.xpath('dl_setting'):
|
for the_setting in the_tab.xpath('dl_setting'):
|
||||||
if the_setting.attrib.has_key('shortname'):
|
try:
|
||||||
|
if 'shortname' in the_setting.attrib:
|
||||||
name = the_setting.attrib['shortname']
|
name = the_setting.attrib['shortname']
|
||||||
elif the_setting.attrib.has_key('VAR'):
|
elif 'VAR' in the_setting.attrib:
|
||||||
name = the_setting.attrib['VAR']
|
name = the_setting.attrib['VAR']
|
||||||
else:
|
else:
|
||||||
name = the_setting.attrib['var']
|
name = the_setting.attrib['var']
|
||||||
|
except:
|
||||||
|
print("Could not get name for setting in group", setting_group)
|
||||||
|
continue
|
||||||
|
|
||||||
settings = PaparazziSetting(name)
|
settings = PaparazziSetting(name)
|
||||||
settings.index = index
|
settings.index = index
|
||||||
if the_setting.attrib.has_key('MIN'):
|
print("add setting with index", index)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if 'MIN' in the_setting.attrib:
|
||||||
settings.min_value = float(the_setting.attrib['MIN'])
|
settings.min_value = float(the_setting.attrib['MIN'])
|
||||||
else:
|
else:
|
||||||
settings.min_value = float(the_setting.attrib['min'])
|
settings.min_value = float(the_setting.attrib['min'])
|
||||||
if the_setting.attrib.has_key('MAX'):
|
|
||||||
|
if 'MAX' in the_setting.attrib:
|
||||||
settings.max_value = float(the_setting.attrib['MAX'])
|
settings.max_value = float(the_setting.attrib['MAX'])
|
||||||
else:
|
else:
|
||||||
settings.max_value = float(the_setting.attrib['max'])
|
settings.max_value = float(the_setting.attrib['max'])
|
||||||
if the_setting.attrib.has_key('STEP'):
|
|
||||||
|
if 'STEP' in the_setting.attrib:
|
||||||
settings.step = float(the_setting.attrib['STEP'])
|
settings.step = float(the_setting.attrib['STEP'])
|
||||||
else:
|
else:
|
||||||
settings.step = float(the_setting.attrib['step'])
|
settings.step = float(the_setting.attrib['step'])
|
||||||
|
except:
|
||||||
|
print("Could not get min/max/step for setting", name)
|
||||||
|
continue
|
||||||
|
|
||||||
if (the_setting.attrib.has_key('values')):
|
if 'values' in the_setting.attrib:
|
||||||
settings.values = the_setting.attrib['values'].split('|')
|
settings.values = the_setting.attrib['values'].split('|')
|
||||||
count = int((settings.max_value - settings.min_value + settings.step) / settings.step)
|
count = int((settings.max_value - settings.min_value + settings.step) / settings.step)
|
||||||
if (len(settings.values) != count):
|
if (len(settings.values) != count):
|
||||||
print("Warning: wrong number of values (%i) for %s (expected %i)" % (len(settings.values), name, count))
|
print("Warning: possibly wrong number of values (%i) for %s (expected %i)" % (len(settings.values), name, count))
|
||||||
|
|
||||||
setting_group.member_list.append(settings)
|
setting_group.member_list.append(settings)
|
||||||
self.lookup.append(settings)
|
self.lookup.append(settings)
|
||||||
|
|||||||
Reference in New Issue
Block a user