3 mavgenerate.py is a GUI front-end for mavgen, a python based MAVLink 4 header generation tool. 8 * 2012-7-16 -- dagoodman 9 Working on Mac 10.6.8 darwin, with Python 2.7.1 11 * 2012-7-17 -- dagoodman 12 Only GUI code working on Mac 10.6.8 darwin, with Python 3.2.3 13 Working on Windows 7 SP1, with Python 2.7.3 and 3.2.3 14 Mavgen doesn't work with Python 3.x yet 16 * 2012-9-25 -- dagoodman 17 Passing error limit into mavgen to make output cleaner. 19 Copyright 2012 David Goodman (dagoodman@soe.ucsc.edu) 20 Released under GNU GPL version 3 or later 28 if sys.version_info[0] == 3:
30 import tkinter.filedialog
31 import tkinter.messagebox
38 tkinter.filedialog = tkFileDialog
40 tkinter.messagebox = tkMessageBox
47 title =
"MAVLink Generator" 53 Frame.__init__(self, master)
54 self.pack_propagate(0)
55 self.grid( sticky=N+S+E+W)
59 Creates the gui and all of its content. 69 self.xml_label.grid(row=0, column = 0)
71 self.xml_entry.grid(row=0, column = 1)
73 self.xml_button.grid(row=0, column = 2)
80 self.out_label.grid(row=1,column = 0)
82 self.out_entry.grid(row=1, column = 1)
84 self.out_button.grid(row=1, column = 2)
92 self.language_label.grid(row=2, column=0)
94 self.language_value.set(mavgen.DEFAULT_LANGUAGE)
95 self.language_menu.config(width=10)
96 self.language_menu.grid(row=2, column=1,sticky=W)
104 self.protocol_label.grid(row=3, column=0)
106 self.protocol_value.set(mavgen.DEFAULT_WIRE_PROTOCOL)
107 self.protocol_menu.config(width=10)
108 self.protocol_menu.grid(row=3, column=1,sticky=W)
115 self.validate_label.grid(row=4, column=0)
117 self.validate_value.set(mavgen.DEFAULT_VALIDATE)
118 self.validate_button.config(width=10)
119 self.validate_button.grid(row=4, column=1,sticky=W)
126 self.strict_units_label.grid(row=5, column=0)
128 self.strict_units_value.set(mavgen.DEFAULT_STRICT_UNITS)
129 self.strict_units_button.config(width=10)
130 self.strict_units_button.grid(row=5, column=1,sticky=W)
136 self.generate_button.grid(row=6,column=1)
139 Open a file selection window to choose the XML message definition. 143 xml_file = tkinter.filedialog.askopenfilename(parent=self, title=
'Choose a definition file')
145 self.xml_value.set(xml_file)
148 Open a directory selection window to choose an output directory for 152 mavlinkFolder = os.path.dirname(os.path.realpath(__file__))
153 out_dir = tkinter.filedialog.askdirectory(parent=self,initialdir=mavlinkFolder,title=
'Please select an output directory')
155 self.out_value.set(out_dir)
158 Generates the header files and place them in the output directory. 162 rex = re.compile(
".*\\.xml$", re.IGNORECASE)
163 if not self.xml_value.get():
164 tkinter.messagebox.showerror(
'Error Generating Headers',
'An XML message definition file must be specified.')
167 if not self.out_value.get():
168 tkinter.messagebox.showerror(
'Error Generating Headers',
'An output directory must be specified.')
172 if os.path.isdir(self.out_value.get()):
173 if not tkinter.messagebox.askokcancel(
'Overwrite Headers?',
'The output directory \'{0}\' already exists. Headers may be overwritten if they already exist.'.format(self.out_value.get())):
177 opts = mavgen.Opts(self.out_value.get(), wire_protocol=self.protocol_value.get(), language=self.language_value.get(), validate=self.validate_value.get(), error_limit=error_limit, strict_units=self.strict_units_value.get());
178 args = [self.xml_value.get()]
180 mavgen.mavgen(opts,args)
181 tkinter.messagebox.showinfo(
'Successfully Generated Headers',
'Headers generated successfully.')
183 except Exception
as ex:
185 tkinter.messagebox.showerror(
'Error Generating Headers',
'{0!s}'.format(exStr))
189 Format the mavgen exceptions by removing 'ERROR: '. 192 reObj = re.compile(
r'^(ERROR):\s+',re.M);
193 matches = re.findall(reObj, message);
194 prefix = (
"An error occurred in mavgen:" if len(matches) == 1
else "Errors occurred in mavgen:\n")
195 message = re.sub(reObj,
'\n', message);
197 return prefix + message
206 if __name__ ==
'__main__':
208 app.master.title(title)
def browseOutDirectory(self)
def formatErrorMessage(message)
def __init__(self, master=None)
def generateHeaders(self)