repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ArduPilot/MAVProxy | MAVProxy/tools/MAVExplorer.py | cmd_fft | def cmd_fft(args):
'''display fft from log'''
from MAVProxy.modules.lib import mav_fft
if len(args) > 0:
condition = args[0]
else:
condition = None
child = multiproc.Process(target=mav_fft.mavfft_display, args=[mestate.filename,condition])
child.start() | python | def cmd_fft(args):
'''display fft from log'''
from MAVProxy.modules.lib import mav_fft
if len(args) > 0:
condition = args[0]
else:
condition = None
child = multiproc.Process(target=mav_fft.mavfft_display, args=[mestate.filename,condition])
child.start() | [
"def",
"cmd_fft",
"(",
"args",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"lib",
"import",
"mav_fft",
"if",
"len",
"(",
"args",
")",
">",
"0",
":",
"condition",
"=",
"args",
"[",
"0",
"]",
"else",
":",
"condition",
"=",
"None",
"child",
"="... | display fft from log | [
"display",
"fft",
"from",
"log"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/MAVExplorer.py#L354-L362 | train | 230,400 |
ArduPilot/MAVProxy | MAVProxy/tools/MAVExplorer.py | cmd_save | def cmd_save(args):
'''save a graph'''
child = multiproc.Process(target=save_process, args=[mestate.last_graph, mestate.child_pipe_send_console, mestate.child_pipe_send_graph, mestate.status.msgs])
child.start() | python | def cmd_save(args):
'''save a graph'''
child = multiproc.Process(target=save_process, args=[mestate.last_graph, mestate.child_pipe_send_console, mestate.child_pipe_send_graph, mestate.status.msgs])
child.start() | [
"def",
"cmd_save",
"(",
"args",
")",
":",
"child",
"=",
"multiproc",
".",
"Process",
"(",
"target",
"=",
"save_process",
",",
"args",
"=",
"[",
"mestate",
".",
"last_graph",
",",
"mestate",
".",
"child_pipe_send_console",
",",
"mestate",
".",
"child_pipe_sen... | save a graph | [
"save",
"a",
"graph"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/MAVExplorer.py#L450-L453 | train | 230,401 |
ArduPilot/MAVProxy | MAVProxy/tools/MAVExplorer.py | cmd_loadfile | def cmd_loadfile(args):
'''callback from menu to load a log file'''
if len(args) != 1:
fileargs = " ".join(args)
else:
fileargs = args[0]
if not os.path.exists(fileargs):
print("Error loading file ", fileargs);
return
if os.name == 'nt':
#convert slashes in Windows
fileargs = fileargs.replace("\\", "/")
loadfile(fileargs.strip('"')) | python | def cmd_loadfile(args):
'''callback from menu to load a log file'''
if len(args) != 1:
fileargs = " ".join(args)
else:
fileargs = args[0]
if not os.path.exists(fileargs):
print("Error loading file ", fileargs);
return
if os.name == 'nt':
#convert slashes in Windows
fileargs = fileargs.replace("\\", "/")
loadfile(fileargs.strip('"')) | [
"def",
"cmd_loadfile",
"(",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
":",
"fileargs",
"=",
"\" \"",
".",
"join",
"(",
"args",
")",
"else",
":",
"fileargs",
"=",
"args",
"[",
"0",
"]",
"if",
"not",
"os",
".",
"path",
".",
"exi... | callback from menu to load a log file | [
"callback",
"from",
"menu",
"to",
"load",
"a",
"log",
"file"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/tools/MAVExplorer.py#L499-L511 | train | 230,402 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_GPSInput.py | GPSInputModule.cmd_port | def cmd_port(self, args):
'handle port selection'
if len(args) != 1:
print("Usage: port <number>")
return
self.port.close()
self.portnum = int(args[0])
self.port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.port.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.port.bind((self.ip, self.portnum))
self.port.setblocking(0)
mavutil.set_close_on_exec(self.port.fileno())
print("Listening for GPS INPUT packets on UDP://%s:%s" % (self.ip, self.portnum)) | python | def cmd_port(self, args):
'handle port selection'
if len(args) != 1:
print("Usage: port <number>")
return
self.port.close()
self.portnum = int(args[0])
self.port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.port.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.port.bind((self.ip, self.portnum))
self.port.setblocking(0)
mavutil.set_close_on_exec(self.port.fileno())
print("Listening for GPS INPUT packets on UDP://%s:%s" % (self.ip, self.portnum)) | [
"def",
"cmd_port",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
":",
"print",
"(",
"\"Usage: port <number>\"",
")",
"return",
"self",
".",
"port",
".",
"close",
"(",
")",
"self",
".",
"portnum",
"=",
"int",
"(",
"ar... | handle port selection | [
"handle",
"port",
"selection"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_GPSInput.py#L97-L110 | train | 230,403 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_magical/wxvehicle.py | Vehicle.RunScript | def RunScript(self, script):
'''
Actuate on the vehicle through a script. The script is a sequence of
commands. Each command is a sequence with the first element as the
command name and the remaining values as parameters.
The script is executed asynchronously by a timer with a period of 0.1
seconds. At each timer tick, the next command is executed if it's ready
for execution.
If a command name starts with '.', then the remaining characters are a
method name and the arguments are passed to the method call. For
example, the command ('.SetEuler', 0, math.pi / 2, 0) sets the vehicle
nose up. The methods available for that type of command are in the
class property script_available_methods.
The other possible commands are:
- wait(sec): wait for sec seconds. Because of the timer period, some
inaccuracy is expected depending on the value of sec.
- restart: go back to the first command.
Example::
vehicle.RunScript((
('.SetEuler', 0, 0, 0), # Set vehicle level
('wait', 2), # Wait for 2 seconds
# Rotate continuously on the x-axis at a rate of 90 degrees per
# second
('.SetAngvel', (1, 0, 0), math.pi / 2),
('wait', 5), # Let the vehicle rotating for 5 seconds
('restart',), # Restart the script
))
'''
self.script = script
self.script_command = 0
self.script_command_start_time = 0
self.script_command_state = 'ready'
self.script_timer.Start(100)
self.script_wait_time = 0 | python | def RunScript(self, script):
'''
Actuate on the vehicle through a script. The script is a sequence of
commands. Each command is a sequence with the first element as the
command name and the remaining values as parameters.
The script is executed asynchronously by a timer with a period of 0.1
seconds. At each timer tick, the next command is executed if it's ready
for execution.
If a command name starts with '.', then the remaining characters are a
method name and the arguments are passed to the method call. For
example, the command ('.SetEuler', 0, math.pi / 2, 0) sets the vehicle
nose up. The methods available for that type of command are in the
class property script_available_methods.
The other possible commands are:
- wait(sec): wait for sec seconds. Because of the timer period, some
inaccuracy is expected depending on the value of sec.
- restart: go back to the first command.
Example::
vehicle.RunScript((
('.SetEuler', 0, 0, 0), # Set vehicle level
('wait', 2), # Wait for 2 seconds
# Rotate continuously on the x-axis at a rate of 90 degrees per
# second
('.SetAngvel', (1, 0, 0), math.pi / 2),
('wait', 5), # Let the vehicle rotating for 5 seconds
('restart',), # Restart the script
))
'''
self.script = script
self.script_command = 0
self.script_command_start_time = 0
self.script_command_state = 'ready'
self.script_timer.Start(100)
self.script_wait_time = 0 | [
"def",
"RunScript",
"(",
"self",
",",
"script",
")",
":",
"self",
".",
"script",
"=",
"script",
"self",
".",
"script_command",
"=",
"0",
"self",
".",
"script_command_start_time",
"=",
"0",
"self",
".",
"script_command_state",
"=",
"'ready'",
"self",
".",
"... | Actuate on the vehicle through a script. The script is a sequence of
commands. Each command is a sequence with the first element as the
command name and the remaining values as parameters.
The script is executed asynchronously by a timer with a period of 0.1
seconds. At each timer tick, the next command is executed if it's ready
for execution.
If a command name starts with '.', then the remaining characters are a
method name and the arguments are passed to the method call. For
example, the command ('.SetEuler', 0, math.pi / 2, 0) sets the vehicle
nose up. The methods available for that type of command are in the
class property script_available_methods.
The other possible commands are:
- wait(sec): wait for sec seconds. Because of the timer period, some
inaccuracy is expected depending on the value of sec.
- restart: go back to the first command.
Example::
vehicle.RunScript((
('.SetEuler', 0, 0, 0), # Set vehicle level
('wait', 2), # Wait for 2 seconds
# Rotate continuously on the x-axis at a rate of 90 degrees per
# second
('.SetAngvel', (1, 0, 0), math.pi / 2),
('wait', 5), # Let the vehicle rotating for 5 seconds
('restart',), # Restart the script
)) | [
"Actuate",
"on",
"the",
"vehicle",
"through",
"a",
"script",
".",
"The",
"script",
"is",
"a",
"sequence",
"of",
"commands",
".",
"Each",
"command",
"is",
"a",
"sequence",
"with",
"the",
"first",
"element",
"as",
"the",
"command",
"name",
"and",
"the",
"r... | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_magical/wxvehicle.py#L140-L178 | train | 230,404 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_ppp.py | PPPModule.ppp_read | def ppp_read(self, ppp_fd):
'''called from main select loop in mavproxy when the pppd child
sends us some data'''
buf = os.read(ppp_fd, 100)
if len(buf) == 0:
# EOF on the child fd
self.stop_ppp_link()
return
print("ppp packet len=%u" % len(buf))
master = self.master
master.mav.ppp_send(len(buf), buf) | python | def ppp_read(self, ppp_fd):
'''called from main select loop in mavproxy when the pppd child
sends us some data'''
buf = os.read(ppp_fd, 100)
if len(buf) == 0:
# EOF on the child fd
self.stop_ppp_link()
return
print("ppp packet len=%u" % len(buf))
master = self.master
master.mav.ppp_send(len(buf), buf) | [
"def",
"ppp_read",
"(",
"self",
",",
"ppp_fd",
")",
":",
"buf",
"=",
"os",
".",
"read",
"(",
"ppp_fd",
",",
"100",
")",
"if",
"len",
"(",
"buf",
")",
"==",
"0",
":",
"# EOF on the child fd",
"self",
".",
"stop_ppp_link",
"(",
")",
"return",
"print",
... | called from main select loop in mavproxy when the pppd child
sends us some data | [
"called",
"from",
"main",
"select",
"loop",
"in",
"mavproxy",
"when",
"the",
"pppd",
"child",
"sends",
"us",
"some",
"data"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L23-L33 | train | 230,405 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_ppp.py | PPPModule.start_ppp_link | def start_ppp_link(self):
'''startup the link'''
cmd = ['pppd']
cmd.extend(self.command)
(self.pid, self.ppp_fd) = pty.fork()
if self.pid == 0:
os.execvp("pppd", cmd)
raise RuntimeError("pppd exited")
if self.ppp_fd == -1:
print("Failed to create link fd")
return
# ensure fd is non-blocking
fcntl.fcntl(self.ppp_fd, fcntl.F_SETFL, fcntl.fcntl(self.ppp_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
self.byte_count = 0
self.packet_count = 0
# ask mavproxy to add us to the select loop
self.mpself.select_extra[self.ppp_fd] = (self.ppp_read, self.ppp_fd) | python | def start_ppp_link(self):
'''startup the link'''
cmd = ['pppd']
cmd.extend(self.command)
(self.pid, self.ppp_fd) = pty.fork()
if self.pid == 0:
os.execvp("pppd", cmd)
raise RuntimeError("pppd exited")
if self.ppp_fd == -1:
print("Failed to create link fd")
return
# ensure fd is non-blocking
fcntl.fcntl(self.ppp_fd, fcntl.F_SETFL, fcntl.fcntl(self.ppp_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
self.byte_count = 0
self.packet_count = 0
# ask mavproxy to add us to the select loop
self.mpself.select_extra[self.ppp_fd] = (self.ppp_read, self.ppp_fd) | [
"def",
"start_ppp_link",
"(",
"self",
")",
":",
"cmd",
"=",
"[",
"'pppd'",
"]",
"cmd",
".",
"extend",
"(",
"self",
".",
"command",
")",
"(",
"self",
".",
"pid",
",",
"self",
".",
"ppp_fd",
")",
"=",
"pty",
".",
"fork",
"(",
")",
"if",
"self",
"... | startup the link | [
"startup",
"the",
"link"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L35-L53 | train | 230,406 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_ppp.py | PPPModule.stop_ppp_link | def stop_ppp_link(self):
'''stop the link'''
if self.ppp_fd == -1:
return
try:
self.mpself.select_extra.pop(self.ppp_fd)
os.close(self.ppp_fd)
os.waitpid(self.pid, 0)
except Exception:
pass
self.pid = -1
self.ppp_fd = -1
print("stopped ppp link") | python | def stop_ppp_link(self):
'''stop the link'''
if self.ppp_fd == -1:
return
try:
self.mpself.select_extra.pop(self.ppp_fd)
os.close(self.ppp_fd)
os.waitpid(self.pid, 0)
except Exception:
pass
self.pid = -1
self.ppp_fd = -1
print("stopped ppp link") | [
"def",
"stop_ppp_link",
"(",
"self",
")",
":",
"if",
"self",
".",
"ppp_fd",
"==",
"-",
"1",
":",
"return",
"try",
":",
"self",
".",
"mpself",
".",
"select_extra",
".",
"pop",
"(",
"self",
".",
"ppp_fd",
")",
"os",
".",
"close",
"(",
"self",
".",
... | stop the link | [
"stop",
"the",
"link"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L56-L68 | train | 230,407 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_ppp.py | PPPModule.cmd_ppp | def cmd_ppp(self, args):
'''set ppp parameters and start link'''
usage = "ppp <command|start|stop>"
if len(args) == 0:
print(usage)
return
if args[0] == "command":
if len(args) == 1:
print("ppp.command=%s" % " ".join(self.command))
else:
self.command = args[1:]
elif args[0] == "start":
self.start_ppp_link()
elif args[0] == "stop":
self.stop_ppp_link()
elif args[0] == "status":
self.console.writeln("%u packets %u bytes" % (self.packet_count, self.byte_count)) | python | def cmd_ppp(self, args):
'''set ppp parameters and start link'''
usage = "ppp <command|start|stop>"
if len(args) == 0:
print(usage)
return
if args[0] == "command":
if len(args) == 1:
print("ppp.command=%s" % " ".join(self.command))
else:
self.command = args[1:]
elif args[0] == "start":
self.start_ppp_link()
elif args[0] == "stop":
self.stop_ppp_link()
elif args[0] == "status":
self.console.writeln("%u packets %u bytes" % (self.packet_count, self.byte_count)) | [
"def",
"cmd_ppp",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"ppp <command|start|stop>\"",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"usage",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"\"command\"",
":",
"if",
"len... | set ppp parameters and start link | [
"set",
"ppp",
"parameters",
"and",
"start",
"link"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_ppp.py#L71-L87 | train | 230,408 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_module.py | MPModule.module_matching | def module_matching(self, name):
'''Find a list of modules matching a wildcard pattern'''
import fnmatch
ret = []
for mname in self.mpstate.public_modules.keys():
if fnmatch.fnmatch(mname, name):
ret.append(self.mpstate.public_modules[mname])
return ret | python | def module_matching(self, name):
'''Find a list of modules matching a wildcard pattern'''
import fnmatch
ret = []
for mname in self.mpstate.public_modules.keys():
if fnmatch.fnmatch(mname, name):
ret.append(self.mpstate.public_modules[mname])
return ret | [
"def",
"module_matching",
"(",
"self",
",",
"name",
")",
":",
"import",
"fnmatch",
"ret",
"=",
"[",
"]",
"for",
"mname",
"in",
"self",
".",
"mpstate",
".",
"public_modules",
".",
"keys",
"(",
")",
":",
"if",
"fnmatch",
".",
"fnmatch",
"(",
"mname",
"... | Find a list of modules matching a wildcard pattern | [
"Find",
"a",
"list",
"of",
"modules",
"matching",
"a",
"wildcard",
"pattern"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L63-L70 | train | 230,409 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_module.py | MPModule.get_time | def get_time(self):
'''get time, using ATTITUDE.time_boot_ms if in SITL with SIM_SPEEDUP != 1'''
systime = time.time() - self.mpstate.start_time_s
if not self.mpstate.is_sitl:
return systime
try:
speedup = int(self.get_mav_param('SIM_SPEEDUP',1))
except Exception:
return systime
if speedup != 1:
return self.mpstate.attitude_time_s
return systime | python | def get_time(self):
'''get time, using ATTITUDE.time_boot_ms if in SITL with SIM_SPEEDUP != 1'''
systime = time.time() - self.mpstate.start_time_s
if not self.mpstate.is_sitl:
return systime
try:
speedup = int(self.get_mav_param('SIM_SPEEDUP',1))
except Exception:
return systime
if speedup != 1:
return self.mpstate.attitude_time_s
return systime | [
"def",
"get_time",
"(",
"self",
")",
":",
"systime",
"=",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"mpstate",
".",
"start_time_s",
"if",
"not",
"self",
".",
"mpstate",
".",
"is_sitl",
":",
"return",
"systime",
"try",
":",
"speedup",
"=",
"int... | get time, using ATTITUDE.time_boot_ms if in SITL with SIM_SPEEDUP != 1 | [
"get",
"time",
"using",
"ATTITUDE",
".",
"time_boot_ms",
"if",
"in",
"SITL",
"with",
"SIM_SPEEDUP",
"!",
"=",
"1"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L72-L83 | train | 230,410 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_module.py | MPModule.dist_string | def dist_string(self, val_meters):
'''return a distance as a string'''
if self.settings.dist_unit == 'nm':
return "%.1fnm" % (val_meters * 0.000539957)
if self.settings.dist_unit == 'miles':
return "%.1fmiles" % (val_meters * 0.000621371)
return "%um" % val_meters | python | def dist_string(self, val_meters):
'''return a distance as a string'''
if self.settings.dist_unit == 'nm':
return "%.1fnm" % (val_meters * 0.000539957)
if self.settings.dist_unit == 'miles':
return "%.1fmiles" % (val_meters * 0.000621371)
return "%um" % val_meters | [
"def",
"dist_string",
"(",
"self",
",",
"val_meters",
")",
":",
"if",
"self",
".",
"settings",
".",
"dist_unit",
"==",
"'nm'",
":",
"return",
"\"%.1fnm\"",
"%",
"(",
"val_meters",
"*",
"0.000539957",
")",
"if",
"self",
".",
"settings",
".",
"dist_unit",
... | return a distance as a string | [
"return",
"a",
"distance",
"as",
"a",
"string"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L150-L156 | train | 230,411 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_module.py | MPModule.speed_convert_units | def speed_convert_units(self, val_ms):
'''return a speed in configured units'''
if self.settings.speed_unit == 'knots':
return val_ms * 1.94384
elif self.settings.speed_unit == 'mph':
return val_ms * 2.23694
return val_ms | python | def speed_convert_units(self, val_ms):
'''return a speed in configured units'''
if self.settings.speed_unit == 'knots':
return val_ms * 1.94384
elif self.settings.speed_unit == 'mph':
return val_ms * 2.23694
return val_ms | [
"def",
"speed_convert_units",
"(",
"self",
",",
"val_ms",
")",
":",
"if",
"self",
".",
"settings",
".",
"speed_unit",
"==",
"'knots'",
":",
"return",
"val_ms",
"*",
"1.94384",
"elif",
"self",
".",
"settings",
".",
"speed_unit",
"==",
"'mph'",
":",
"return"... | return a speed in configured units | [
"return",
"a",
"speed",
"in",
"configured",
"units"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L170-L176 | train | 230,412 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_module.py | MPModule.set_prompt | def set_prompt(self, prompt):
'''set prompt for command line'''
if prompt and self.settings.vehicle_name:
# add in optional vehicle name
prompt = self.settings.vehicle_name + ':' + prompt
self.mpstate.rl.set_prompt(prompt) | python | def set_prompt(self, prompt):
'''set prompt for command line'''
if prompt and self.settings.vehicle_name:
# add in optional vehicle name
prompt = self.settings.vehicle_name + ':' + prompt
self.mpstate.rl.set_prompt(prompt) | [
"def",
"set_prompt",
"(",
"self",
",",
"prompt",
")",
":",
"if",
"prompt",
"and",
"self",
".",
"settings",
".",
"vehicle_name",
":",
"# add in optional vehicle name",
"prompt",
"=",
"self",
".",
"settings",
".",
"vehicle_name",
"+",
"':'",
"+",
"prompt",
"se... | set prompt for command line | [
"set",
"prompt",
"for",
"command",
"line"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L184-L189 | train | 230,413 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_module.py | MPModule.link_label | def link_label(link):
'''return a link label as a string'''
if hasattr(link, 'label'):
label = link.label
else:
label = str(link.linknum+1)
return label | python | def link_label(link):
'''return a link label as a string'''
if hasattr(link, 'label'):
label = link.label
else:
label = str(link.linknum+1)
return label | [
"def",
"link_label",
"(",
"link",
")",
":",
"if",
"hasattr",
"(",
"link",
",",
"'label'",
")",
":",
"label",
"=",
"link",
".",
"label",
"else",
":",
"label",
"=",
"str",
"(",
"link",
".",
"linknum",
"+",
"1",
")",
"return",
"label"
] | return a link label as a string | [
"return",
"a",
"link",
"label",
"as",
"a",
"string"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L192-L198 | train | 230,414 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_module.py | MPModule.is_primary_vehicle | def is_primary_vehicle(self, msg):
'''see if a msg is from our primary vehicle'''
sysid = msg.get_srcSystem()
if self.target_system == 0 or self.target_system == sysid:
return True
return False | python | def is_primary_vehicle(self, msg):
'''see if a msg is from our primary vehicle'''
sysid = msg.get_srcSystem()
if self.target_system == 0 or self.target_system == sysid:
return True
return False | [
"def",
"is_primary_vehicle",
"(",
"self",
",",
"msg",
")",
":",
"sysid",
"=",
"msg",
".",
"get_srcSystem",
"(",
")",
"if",
"self",
".",
"target_system",
"==",
"0",
"or",
"self",
".",
"target_system",
"==",
"sysid",
":",
"return",
"True",
"return",
"False... | see if a msg is from our primary vehicle | [
"see",
"if",
"a",
"msg",
"is",
"from",
"our",
"primary",
"vehicle"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_module.py#L200-L205 | train | 230,415 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/grapher.py | MavGraph.next_flightmode_colour | def next_flightmode_colour(self):
'''allocate a colour to be used for a flight mode'''
if self.flightmode_colour_index > len(flightmode_colours):
print("Out of colours; reusing")
self.flightmode_colour_index = 0
ret = flightmode_colours[self.flightmode_colour_index]
self.flightmode_colour_index += 1
return ret | python | def next_flightmode_colour(self):
'''allocate a colour to be used for a flight mode'''
if self.flightmode_colour_index > len(flightmode_colours):
print("Out of colours; reusing")
self.flightmode_colour_index = 0
ret = flightmode_colours[self.flightmode_colour_index]
self.flightmode_colour_index += 1
return ret | [
"def",
"next_flightmode_colour",
"(",
"self",
")",
":",
"if",
"self",
".",
"flightmode_colour_index",
">",
"len",
"(",
"flightmode_colours",
")",
":",
"print",
"(",
"\"Out of colours; reusing\"",
")",
"self",
".",
"flightmode_colour_index",
"=",
"0",
"ret",
"=",
... | allocate a colour to be used for a flight mode | [
"allocate",
"a",
"colour",
"to",
"be",
"used",
"for",
"a",
"flight",
"mode"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L146-L153 | train | 230,416 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/grapher.py | MavGraph.flightmode_colour | def flightmode_colour(self, flightmode):
'''return colour to be used for rendering a flight mode background'''
if flightmode not in self.flightmode_colourmap:
self.flightmode_colourmap[flightmode] = self.next_flightmode_colour()
return self.flightmode_colourmap[flightmode] | python | def flightmode_colour(self, flightmode):
'''return colour to be used for rendering a flight mode background'''
if flightmode not in self.flightmode_colourmap:
self.flightmode_colourmap[flightmode] = self.next_flightmode_colour()
return self.flightmode_colourmap[flightmode] | [
"def",
"flightmode_colour",
"(",
"self",
",",
"flightmode",
")",
":",
"if",
"flightmode",
"not",
"in",
"self",
".",
"flightmode_colourmap",
":",
"self",
".",
"flightmode_colourmap",
"[",
"flightmode",
"]",
"=",
"self",
".",
"next_flightmode_colour",
"(",
")",
... | return colour to be used for rendering a flight mode background | [
"return",
"colour",
"to",
"be",
"used",
"for",
"rendering",
"a",
"flight",
"mode",
"background"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L155-L159 | train | 230,417 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/grapher.py | MavGraph.setup_xrange | def setup_xrange(self, xrange):
'''setup plotting ticks on x axis'''
if self.xaxis:
return
xrange *= 24 * 60 * 60
interval = 1
intervals = [ 1, 2, 5, 10, 15, 30, 60, 120, 240, 300, 600,
900, 1800, 3600, 7200, 5*3600, 10*3600, 24*3600 ]
for interval in intervals:
if xrange / interval < 12:
break
self.locator = matplotlib.dates.SecondLocator(interval=interval)
self.ax1.xaxis.set_major_locator(self.locator) | python | def setup_xrange(self, xrange):
'''setup plotting ticks on x axis'''
if self.xaxis:
return
xrange *= 24 * 60 * 60
interval = 1
intervals = [ 1, 2, 5, 10, 15, 30, 60, 120, 240, 300, 600,
900, 1800, 3600, 7200, 5*3600, 10*3600, 24*3600 ]
for interval in intervals:
if xrange / interval < 12:
break
self.locator = matplotlib.dates.SecondLocator(interval=interval)
self.ax1.xaxis.set_major_locator(self.locator) | [
"def",
"setup_xrange",
"(",
"self",
",",
"xrange",
")",
":",
"if",
"self",
".",
"xaxis",
":",
"return",
"xrange",
"*=",
"24",
"*",
"60",
"*",
"60",
"interval",
"=",
"1",
"intervals",
"=",
"[",
"1",
",",
"2",
",",
"5",
",",
"10",
",",
"15",
",",... | setup plotting ticks on x axis | [
"setup",
"plotting",
"ticks",
"on",
"x",
"axis"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L161-L173 | train | 230,418 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/grapher.py | MavGraph.xlim_changed | def xlim_changed(self, axsubplot):
'''called when x limits are changed'''
xrange = axsubplot.get_xbound()
xlim = axsubplot.get_xlim()
self.setup_xrange(xrange[1] - xrange[0])
if self.draw_events == 0:
# ignore limit change before first draw event
return
if self.xlim_pipe is not None and axsubplot == self.ax1 and xlim != self.xlim:
self.xlim = xlim
#print('send', self.graph_num, xlim)
self.xlim_pipe[1].send(xlim) | python | def xlim_changed(self, axsubplot):
'''called when x limits are changed'''
xrange = axsubplot.get_xbound()
xlim = axsubplot.get_xlim()
self.setup_xrange(xrange[1] - xrange[0])
if self.draw_events == 0:
# ignore limit change before first draw event
return
if self.xlim_pipe is not None and axsubplot == self.ax1 and xlim != self.xlim:
self.xlim = xlim
#print('send', self.graph_num, xlim)
self.xlim_pipe[1].send(xlim) | [
"def",
"xlim_changed",
"(",
"self",
",",
"axsubplot",
")",
":",
"xrange",
"=",
"axsubplot",
".",
"get_xbound",
"(",
")",
"xlim",
"=",
"axsubplot",
".",
"get_xlim",
"(",
")",
"self",
".",
"setup_xrange",
"(",
"xrange",
"[",
"1",
"]",
"-",
"xrange",
"[",... | called when x limits are changed | [
"called",
"when",
"x",
"limits",
"are",
"changed"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L175-L186 | train | 230,419 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/grapher.py | MavGraph.timestamp_to_days | def timestamp_to_days(self, timestamp):
'''convert log timestamp to days'''
if self.tday_base is None:
try:
self.tday_base = matplotlib.dates.date2num(datetime.datetime.fromtimestamp(timestamp+self.timeshift))
self.tday_basetime = timestamp
except ValueError:
# this can happen if the log is corrupt
# ValueError: year is out of range
return 0
sec_to_days = 1.0 / (60*60*24)
return self.tday_base + (timestamp - self.tday_basetime) * sec_to_days | python | def timestamp_to_days(self, timestamp):
'''convert log timestamp to days'''
if self.tday_base is None:
try:
self.tday_base = matplotlib.dates.date2num(datetime.datetime.fromtimestamp(timestamp+self.timeshift))
self.tday_basetime = timestamp
except ValueError:
# this can happen if the log is corrupt
# ValueError: year is out of range
return 0
sec_to_days = 1.0 / (60*60*24)
return self.tday_base + (timestamp - self.tday_basetime) * sec_to_days | [
"def",
"timestamp_to_days",
"(",
"self",
",",
"timestamp",
")",
":",
"if",
"self",
".",
"tday_base",
"is",
"None",
":",
"try",
":",
"self",
".",
"tday_base",
"=",
"matplotlib",
".",
"dates",
".",
"date2num",
"(",
"datetime",
".",
"datetime",
".",
"fromti... | convert log timestamp to days | [
"convert",
"log",
"timestamp",
"to",
"days"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L362-L373 | train | 230,420 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/grapher.py | MavGraph.xlim_change_check | def xlim_change_check(self, idx):
'''handle xlim change requests from queue'''
if not self.xlim_pipe[1].poll():
return
xlim = self.xlim_pipe[1].recv()
if xlim is None:
return
#print("recv: ", self.graph_num, xlim)
if self.ax1 is not None and xlim != self.xlim:
self.xlim = xlim
self.fig.canvas.toolbar.push_current()
#print("setting: ", self.graph_num, xlim)
self.ax1.set_xlim(xlim)
# trigger the timer, this allows us to setup a v slow animation,
# which saves a lot of CPU
self.ani.event_source._on_timer() | python | def xlim_change_check(self, idx):
'''handle xlim change requests from queue'''
if not self.xlim_pipe[1].poll():
return
xlim = self.xlim_pipe[1].recv()
if xlim is None:
return
#print("recv: ", self.graph_num, xlim)
if self.ax1 is not None and xlim != self.xlim:
self.xlim = xlim
self.fig.canvas.toolbar.push_current()
#print("setting: ", self.graph_num, xlim)
self.ax1.set_xlim(xlim)
# trigger the timer, this allows us to setup a v slow animation,
# which saves a lot of CPU
self.ani.event_source._on_timer() | [
"def",
"xlim_change_check",
"(",
"self",
",",
"idx",
")",
":",
"if",
"not",
"self",
".",
"xlim_pipe",
"[",
"1",
"]",
".",
"poll",
"(",
")",
":",
"return",
"xlim",
"=",
"self",
".",
"xlim_pipe",
"[",
"1",
"]",
".",
"recv",
"(",
")",
"if",
"xlim",
... | handle xlim change requests from queue | [
"handle",
"xlim",
"change",
"requests",
"from",
"queue"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/grapher.py#L429-L444 | train | 230,421 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misc.py | MiscModule.cmd_lockup_autopilot | def cmd_lockup_autopilot(self, args):
'''lockup autopilot for watchdog testing'''
if len(args) > 0 and args[0] == 'IREALLYMEANIT':
print("Sending lockup command")
self.master.mav.command_long_send(self.settings.target_system, self.settings.target_component,
mavutil.mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
42, 24, 71, 93, 0, 0, 0)
else:
print("Invalid lockup command") | python | def cmd_lockup_autopilot(self, args):
'''lockup autopilot for watchdog testing'''
if len(args) > 0 and args[0] == 'IREALLYMEANIT':
print("Sending lockup command")
self.master.mav.command_long_send(self.settings.target_system, self.settings.target_component,
mavutil.mavlink.MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, 0,
42, 24, 71, 93, 0, 0, 0)
else:
print("Invalid lockup command") | [
"def",
"cmd_lockup_autopilot",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
">",
"0",
"and",
"args",
"[",
"0",
"]",
"==",
"'IREALLYMEANIT'",
":",
"print",
"(",
"\"Sending lockup command\"",
")",
"self",
".",
"master",
".",
"mav",
... | lockup autopilot for watchdog testing | [
"lockup",
"autopilot",
"for",
"watchdog",
"testing"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L147-L155 | train | 230,422 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misc.py | MiscModule.cmd_gethome | def cmd_gethome(self, args):
'''get home position'''
self.master.mav.command_long_send(self.settings.target_system,
0,
mavutil.mavlink.MAV_CMD_GET_HOME_POSITION,
0, 0, 0, 0, 0, 0, 0, 0) | python | def cmd_gethome(self, args):
'''get home position'''
self.master.mav.command_long_send(self.settings.target_system,
0,
mavutil.mavlink.MAV_CMD_GET_HOME_POSITION,
0, 0, 0, 0, 0, 0, 0, 0) | [
"def",
"cmd_gethome",
"(",
"self",
",",
"args",
")",
":",
"self",
".",
"master",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"0",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_GET_HOME_POSITION",
",",
"0",... | get home position | [
"get",
"home",
"position"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L215-L220 | train | 230,423 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misc.py | MiscModule.cmd_led | def cmd_led(self, args):
'''send LED pattern as override'''
if len(args) < 3:
print("Usage: led RED GREEN BLUE <RATE>")
return
pattern = [0] * 24
pattern[0] = int(args[0])
pattern[1] = int(args[1])
pattern[2] = int(args[2])
if len(args) == 4:
plen = 4
pattern[3] = int(args[3])
else:
plen = 3
self.master.mav.led_control_send(self.settings.target_system,
self.settings.target_component,
0, 0, plen, pattern) | python | def cmd_led(self, args):
'''send LED pattern as override'''
if len(args) < 3:
print("Usage: led RED GREEN BLUE <RATE>")
return
pattern = [0] * 24
pattern[0] = int(args[0])
pattern[1] = int(args[1])
pattern[2] = int(args[2])
if len(args) == 4:
plen = 4
pattern[3] = int(args[3])
else:
plen = 3
self.master.mav.led_control_send(self.settings.target_system,
self.settings.target_component,
0, 0, plen, pattern) | [
"def",
"cmd_led",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"3",
":",
"print",
"(",
"\"Usage: led RED GREEN BLUE <RATE>\"",
")",
"return",
"pattern",
"=",
"[",
"0",
"]",
"*",
"24",
"pattern",
"[",
"0",
"]",
"=",
"int",
... | send LED pattern as override | [
"send",
"LED",
"pattern",
"as",
"override"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L222-L240 | train | 230,424 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misc.py | MiscModule.cmd_oreoled | def cmd_oreoled(self, args):
'''send LED pattern as override, using OreoLED conventions'''
if len(args) < 4:
print("Usage: oreoled LEDNUM RED GREEN BLUE <RATE>")
return
lednum = int(args[0])
pattern = [0] * 24
pattern[0] = ord('R')
pattern[1] = ord('G')
pattern[2] = ord('B')
pattern[3] = ord('0')
pattern[4] = 0
pattern[5] = int(args[1])
pattern[6] = int(args[2])
pattern[7] = int(args[3])
self.master.mav.led_control_send(self.settings.target_system,
self.settings.target_component,
lednum, 255, 8, pattern) | python | def cmd_oreoled(self, args):
'''send LED pattern as override, using OreoLED conventions'''
if len(args) < 4:
print("Usage: oreoled LEDNUM RED GREEN BLUE <RATE>")
return
lednum = int(args[0])
pattern = [0] * 24
pattern[0] = ord('R')
pattern[1] = ord('G')
pattern[2] = ord('B')
pattern[3] = ord('0')
pattern[4] = 0
pattern[5] = int(args[1])
pattern[6] = int(args[2])
pattern[7] = int(args[3])
self.master.mav.led_control_send(self.settings.target_system,
self.settings.target_component,
lednum, 255, 8, pattern) | [
"def",
"cmd_oreoled",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"4",
":",
"print",
"(",
"\"Usage: oreoled LEDNUM RED GREEN BLUE <RATE>\"",
")",
"return",
"lednum",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"pattern",
"=",... | send LED pattern as override, using OreoLED conventions | [
"send",
"LED",
"pattern",
"as",
"override",
"using",
"OreoLED",
"conventions"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L242-L260 | train | 230,425 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misc.py | MiscModule.cmd_playtune | def cmd_playtune(self, args):
'''send PLAY_TUNE message'''
if len(args) < 1:
print("Usage: playtune TUNE")
return
tune = args[0]
str1 = tune[0:30]
str2 = tune[30:]
if sys.version_info.major >= 3 and not isinstance(str1, bytes):
str1 = bytes(str1, "ascii")
if sys.version_info.major >= 3 and not isinstance(str2, bytes):
str2 = bytes(str2, "ascii")
self.master.mav.play_tune_send(self.settings.target_system,
self.settings.target_component,
str1, str2) | python | def cmd_playtune(self, args):
'''send PLAY_TUNE message'''
if len(args) < 1:
print("Usage: playtune TUNE")
return
tune = args[0]
str1 = tune[0:30]
str2 = tune[30:]
if sys.version_info.major >= 3 and not isinstance(str1, bytes):
str1 = bytes(str1, "ascii")
if sys.version_info.major >= 3 and not isinstance(str2, bytes):
str2 = bytes(str2, "ascii")
self.master.mav.play_tune_send(self.settings.target_system,
self.settings.target_component,
str1, str2) | [
"def",
"cmd_playtune",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"\"Usage: playtune TUNE\"",
")",
"return",
"tune",
"=",
"args",
"[",
"0",
"]",
"str1",
"=",
"tune",
"[",
"0",
":",
"30",
"]",
"... | send PLAY_TUNE message | [
"send",
"PLAY_TUNE",
"message"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L269-L283 | train | 230,426 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misc.py | MiscModule.cmd_devid | def cmd_devid(self, args):
'''decode device IDs from parameters'''
for p in self.mav_param.keys():
if p.startswith('COMPASS_DEV_ID'):
mp_util.decode_devid(self.mav_param[p], p)
if p.startswith('INS_') and p.endswith('_ID'):
mp_util.decode_devid(self.mav_param[p], p) | python | def cmd_devid(self, args):
'''decode device IDs from parameters'''
for p in self.mav_param.keys():
if p.startswith('COMPASS_DEV_ID'):
mp_util.decode_devid(self.mav_param[p], p)
if p.startswith('INS_') and p.endswith('_ID'):
mp_util.decode_devid(self.mav_param[p], p) | [
"def",
"cmd_devid",
"(",
"self",
",",
"args",
")",
":",
"for",
"p",
"in",
"self",
".",
"mav_param",
".",
"keys",
"(",
")",
":",
"if",
"p",
".",
"startswith",
"(",
"'COMPASS_DEV_ID'",
")",
":",
"mp_util",
".",
"decode_devid",
"(",
"self",
".",
"mav_pa... | decode device IDs from parameters | [
"decode",
"device",
"IDs",
"from",
"parameters"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misc.py#L314-L320 | train | 230,427 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.add_menu | def add_menu(self, menu):
'''add to the default popup menu'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
self.default_popup.add(menu)
self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True)) | python | def add_menu(self, menu):
'''add to the default popup menu'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
self.default_popup.add(menu)
self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True)) | [
"def",
"add_menu",
"(",
"self",
",",
"menu",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"mavproxy_map",
"import",
"mp_slipmap",
"self",
".",
"default_popup",
".",
"add",
"(",
"menu",
")",
"self",
".",
"map",
".",
"add_object",
"(",
"mp_slipmap",
... | add to the default popup menu | [
"add",
"to",
"the",
"default",
"popup",
"menu"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L114-L118 | train | 230,428 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.colour_for_wp | def colour_for_wp(self, wp_num):
'''return a tuple describing the colour a waypoint should appear on the map'''
wp = self.module('wp').wploader.wp(wp_num)
command = wp.command
return self._colour_for_wp_command.get(command, (0,255,0)) | python | def colour_for_wp(self, wp_num):
'''return a tuple describing the colour a waypoint should appear on the map'''
wp = self.module('wp').wploader.wp(wp_num)
command = wp.command
return self._colour_for_wp_command.get(command, (0,255,0)) | [
"def",
"colour_for_wp",
"(",
"self",
",",
"wp_num",
")",
":",
"wp",
"=",
"self",
".",
"module",
"(",
"'wp'",
")",
".",
"wploader",
".",
"wp",
"(",
"wp_num",
")",
"command",
"=",
"wp",
".",
"command",
"return",
"self",
".",
"_colour_for_wp_command",
"."... | return a tuple describing the colour a waypoint should appear on the map | [
"return",
"a",
"tuple",
"describing",
"the",
"colour",
"a",
"waypoint",
"should",
"appear",
"on",
"the",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L175-L179 | train | 230,429 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.label_for_waypoint | def label_for_waypoint(self, wp_num):
'''return the label the waypoint which should appear on the map'''
wp = self.module('wp').wploader.wp(wp_num)
command = wp.command
if command not in self._label_suffix_for_wp_command:
return str(wp_num)
return str(wp_num) + "(" + self._label_suffix_for_wp_command[command] + ")" | python | def label_for_waypoint(self, wp_num):
'''return the label the waypoint which should appear on the map'''
wp = self.module('wp').wploader.wp(wp_num)
command = wp.command
if command not in self._label_suffix_for_wp_command:
return str(wp_num)
return str(wp_num) + "(" + self._label_suffix_for_wp_command[command] + ")" | [
"def",
"label_for_waypoint",
"(",
"self",
",",
"wp_num",
")",
":",
"wp",
"=",
"self",
".",
"module",
"(",
"'wp'",
")",
".",
"wploader",
".",
"wp",
"(",
"wp_num",
")",
"command",
"=",
"wp",
".",
"command",
"if",
"command",
"not",
"in",
"self",
".",
... | return the label the waypoint which should appear on the map | [
"return",
"the",
"label",
"the",
"waypoint",
"which",
"should",
"appear",
"on",
"the",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L181-L187 | train | 230,430 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.remove_mission_nofly | def remove_mission_nofly(self, key, selection_index):
'''remove a mission nofly polygon'''
if not self.validate_nofly():
print("NoFly invalid")
return
print("NoFly valid")
idx = self.selection_index_to_idx(key, selection_index)
wploader = self.module('wp').wploader
if idx < 0 or idx >= wploader.count():
print("Invalid wp number %u" % idx)
return
wp = wploader.wp(idx)
if wp.command != mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION:
print("Not an exclusion point (%u)" % idx)
return
# we know the list is valid. Search for the start of the sequence to delete
tmp_idx = idx
while tmp_idx > 0:
tmp = wploader.wp(tmp_idx-1)
if (tmp.command != wp.command or
tmp.param1 != wp.param1):
break
tmp_idx -= 1
start_idx_to_delete = idx - ((idx-tmp_idx)%int(wp.param1))
for i in range(int(start_idx_to_delete+wp.param1)-1,start_idx_to_delete-1,-1):
# remove in reverse order as wploader.remove re-indexes
print("Removing at %u" % i)
deadun = wploader.wp(i)
wploader.remove(deadun)
self.module('wp').send_all_waypoints() | python | def remove_mission_nofly(self, key, selection_index):
'''remove a mission nofly polygon'''
if not self.validate_nofly():
print("NoFly invalid")
return
print("NoFly valid")
idx = self.selection_index_to_idx(key, selection_index)
wploader = self.module('wp').wploader
if idx < 0 or idx >= wploader.count():
print("Invalid wp number %u" % idx)
return
wp = wploader.wp(idx)
if wp.command != mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION:
print("Not an exclusion point (%u)" % idx)
return
# we know the list is valid. Search for the start of the sequence to delete
tmp_idx = idx
while tmp_idx > 0:
tmp = wploader.wp(tmp_idx-1)
if (tmp.command != wp.command or
tmp.param1 != wp.param1):
break
tmp_idx -= 1
start_idx_to_delete = idx - ((idx-tmp_idx)%int(wp.param1))
for i in range(int(start_idx_to_delete+wp.param1)-1,start_idx_to_delete-1,-1):
# remove in reverse order as wploader.remove re-indexes
print("Removing at %u" % i)
deadun = wploader.wp(i)
wploader.remove(deadun)
self.module('wp').send_all_waypoints() | [
"def",
"remove_mission_nofly",
"(",
"self",
",",
"key",
",",
"selection_index",
")",
":",
"if",
"not",
"self",
".",
"validate_nofly",
"(",
")",
":",
"print",
"(",
"\"NoFly invalid\"",
")",
"return",
"print",
"(",
"\"NoFly valid\"",
")",
"idx",
"=",
"self",
... | remove a mission nofly polygon | [
"remove",
"a",
"mission",
"nofly",
"polygon"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L345-L378 | train | 230,431 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.handle_menu_event | def handle_menu_event(self, obj):
'''handle a popup menu event from the map'''
menuitem = obj.menuitem
if menuitem.returnkey.startswith('# '):
cmd = menuitem.returnkey[2:]
if menuitem.handler is not None:
if menuitem.handler_result is None:
return
cmd += menuitem.handler_result
self.mpstate.functions.process_stdin(cmd)
elif menuitem.returnkey == 'popupRallyRemove':
self.remove_rally(obj.selected[0].objkey)
elif menuitem.returnkey == 'popupRallyMove':
self.move_rally(obj.selected[0].objkey)
elif menuitem.returnkey == 'popupMissionSet':
self.set_mission(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupMissionRemoveNoFly':
self.remove_mission_nofly(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupMissionRemove':
self.remove_mission(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupMissionMove':
self.move_mission(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupFenceRemove':
self.remove_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupFenceMove':
self.move_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'showPosition':
self.show_position() | python | def handle_menu_event(self, obj):
'''handle a popup menu event from the map'''
menuitem = obj.menuitem
if menuitem.returnkey.startswith('# '):
cmd = menuitem.returnkey[2:]
if menuitem.handler is not None:
if menuitem.handler_result is None:
return
cmd += menuitem.handler_result
self.mpstate.functions.process_stdin(cmd)
elif menuitem.returnkey == 'popupRallyRemove':
self.remove_rally(obj.selected[0].objkey)
elif menuitem.returnkey == 'popupRallyMove':
self.move_rally(obj.selected[0].objkey)
elif menuitem.returnkey == 'popupMissionSet':
self.set_mission(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupMissionRemoveNoFly':
self.remove_mission_nofly(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupMissionRemove':
self.remove_mission(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupMissionMove':
self.move_mission(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupFenceRemove':
self.remove_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'popupFenceMove':
self.move_fencepoint(obj.selected[0].objkey, obj.selected[0].extra_info)
elif menuitem.returnkey == 'showPosition':
self.show_position() | [
"def",
"handle_menu_event",
"(",
"self",
",",
"obj",
")",
":",
"menuitem",
"=",
"obj",
".",
"menuitem",
"if",
"menuitem",
".",
"returnkey",
".",
"startswith",
"(",
"'# '",
")",
":",
"cmd",
"=",
"menuitem",
".",
"returnkey",
"[",
"2",
":",
"]",
"if",
... | handle a popup menu event from the map | [
"handle",
"a",
"popup",
"menu",
"event",
"from",
"the",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L394-L421 | train | 230,432 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.map_callback | def map_callback(self, obj):
'''called when an event happens on the slipmap'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
if isinstance(obj, mp_slipmap.SlipMenuEvent):
self.handle_menu_event(obj)
return
if not isinstance(obj, mp_slipmap.SlipMouseEvent):
return
if obj.event.leftIsDown and self.moving_rally is not None:
self.click_position = obj.latlon
self.click_time = time.time()
self.mpstate.functions.process_stdin("rally move %u" % self.moving_rally)
self.moving_rally = None
return
if obj.event.rightIsDown and self.moving_rally is not None:
print("Cancelled rally move")
self.moving_rally = None
return
if obj.event.leftIsDown and self.moving_wp is not None:
self.click_position = obj.latlon
self.click_time = time.time()
self.mpstate.functions.process_stdin("wp move %u" % self.moving_wp)
self.moving_wp = None
return
if obj.event.leftIsDown and self.moving_fencepoint is not None:
self.click_position = obj.latlon
self.click_time = time.time()
self.mpstate.functions.process_stdin("fence move %u" % (self.moving_fencepoint+1))
self.moving_fencepoint = None
return
if obj.event.rightIsDown and self.moving_wp is not None:
print("Cancelled wp move")
self.moving_wp = None
return
if obj.event.rightIsDown and self.moving_fencepoint is not None:
print("Cancelled fence move")
self.moving_fencepoint = None
return
elif obj.event.leftIsDown:
if time.time() - self.click_time > 0.1:
self.click_position = obj.latlon
self.click_time = time.time()
self.drawing_update()
if self.module('misseditor') is not None:
self.module('misseditor').update_map_click_position(self.click_position)
if obj.event.rightIsDown:
if self.draw_callback is not None:
self.drawing_end()
return
if time.time() - self.click_time > 0.1:
self.click_position = obj.latlon
self.click_time = time.time() | python | def map_callback(self, obj):
'''called when an event happens on the slipmap'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
if isinstance(obj, mp_slipmap.SlipMenuEvent):
self.handle_menu_event(obj)
return
if not isinstance(obj, mp_slipmap.SlipMouseEvent):
return
if obj.event.leftIsDown and self.moving_rally is not None:
self.click_position = obj.latlon
self.click_time = time.time()
self.mpstate.functions.process_stdin("rally move %u" % self.moving_rally)
self.moving_rally = None
return
if obj.event.rightIsDown and self.moving_rally is not None:
print("Cancelled rally move")
self.moving_rally = None
return
if obj.event.leftIsDown and self.moving_wp is not None:
self.click_position = obj.latlon
self.click_time = time.time()
self.mpstate.functions.process_stdin("wp move %u" % self.moving_wp)
self.moving_wp = None
return
if obj.event.leftIsDown and self.moving_fencepoint is not None:
self.click_position = obj.latlon
self.click_time = time.time()
self.mpstate.functions.process_stdin("fence move %u" % (self.moving_fencepoint+1))
self.moving_fencepoint = None
return
if obj.event.rightIsDown and self.moving_wp is not None:
print("Cancelled wp move")
self.moving_wp = None
return
if obj.event.rightIsDown and self.moving_fencepoint is not None:
print("Cancelled fence move")
self.moving_fencepoint = None
return
elif obj.event.leftIsDown:
if time.time() - self.click_time > 0.1:
self.click_position = obj.latlon
self.click_time = time.time()
self.drawing_update()
if self.module('misseditor') is not None:
self.module('misseditor').update_map_click_position(self.click_position)
if obj.event.rightIsDown:
if self.draw_callback is not None:
self.drawing_end()
return
if time.time() - self.click_time > 0.1:
self.click_position = obj.latlon
self.click_time = time.time() | [
"def",
"map_callback",
"(",
"self",
",",
"obj",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"mavproxy_map",
"import",
"mp_slipmap",
"if",
"isinstance",
"(",
"obj",
",",
"mp_slipmap",
".",
"SlipMenuEvent",
")",
":",
"self",
".",
"handle_menu_event",
"(... | called when an event happens on the slipmap | [
"called",
"when",
"an",
"event",
"happens",
"on",
"the",
"slipmap"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L424-L477 | train | 230,433 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.drawing_end | def drawing_end(self):
'''end line drawing'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
if self.draw_callback is None:
return
self.draw_callback(self.draw_line)
self.draw_callback = None
self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True))
self.map.add_object(mp_slipmap.SlipClearLayer('Drawing')) | python | def drawing_end(self):
'''end line drawing'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
if self.draw_callback is None:
return
self.draw_callback(self.draw_line)
self.draw_callback = None
self.map.add_object(mp_slipmap.SlipDefaultPopup(self.default_popup, combine=True))
self.map.add_object(mp_slipmap.SlipClearLayer('Drawing')) | [
"def",
"drawing_end",
"(",
"self",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"mavproxy_map",
"import",
"mp_slipmap",
"if",
"self",
".",
"draw_callback",
"is",
"None",
":",
"return",
"self",
".",
"draw_callback",
"(",
"self",
".",
"draw_line",
")",
... | end line drawing | [
"end",
"line",
"drawing"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L517-L525 | train | 230,434 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.draw_lines | def draw_lines(self, callback):
'''draw a series of connected lines on the map, calling callback when done'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
self.draw_callback = callback
self.draw_line = []
self.map.add_object(mp_slipmap.SlipDefaultPopup(None)) | python | def draw_lines(self, callback):
'''draw a series of connected lines on the map, calling callback when done'''
from MAVProxy.modules.mavproxy_map import mp_slipmap
self.draw_callback = callback
self.draw_line = []
self.map.add_object(mp_slipmap.SlipDefaultPopup(None)) | [
"def",
"draw_lines",
"(",
"self",
",",
"callback",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"mavproxy_map",
"import",
"mp_slipmap",
"self",
".",
"draw_callback",
"=",
"callback",
"self",
".",
"draw_line",
"=",
"[",
"]",
"self",
".",
"map",
".",
... | draw a series of connected lines on the map, calling callback when done | [
"draw",
"a",
"series",
"of",
"connected",
"lines",
"on",
"the",
"map",
"calling",
"callback",
"when",
"done"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L527-L532 | train | 230,435 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.cmd_set_originpos | def cmd_set_originpos(self, args):
'''called when user selects "Set Origin" on map'''
(lat, lon) = (self.click_position[0], self.click_position[1])
print("Setting origin to: ", lat, lon)
self.master.mav.set_gps_global_origin_send(
self.settings.target_system,
lat*10000000, # lat
lon*10000000, # lon
0*1000) | python | def cmd_set_originpos(self, args):
'''called when user selects "Set Origin" on map'''
(lat, lon) = (self.click_position[0], self.click_position[1])
print("Setting origin to: ", lat, lon)
self.master.mav.set_gps_global_origin_send(
self.settings.target_system,
lat*10000000, # lat
lon*10000000, # lon
0*1000) | [
"def",
"cmd_set_originpos",
"(",
"self",
",",
"args",
")",
":",
"(",
"lat",
",",
"lon",
")",
"=",
"(",
"self",
".",
"click_position",
"[",
"0",
"]",
",",
"self",
".",
"click_position",
"[",
"1",
"]",
")",
"print",
"(",
"\"Setting origin to: \"",
",",
... | called when user selects "Set Origin" on map | [
"called",
"when",
"user",
"selects",
"Set",
"Origin",
"on",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L580-L588 | train | 230,436 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.cmd_center | def cmd_center(self, args):
'''control center of view'''
if len(args) < 3:
print("map center LAT LON")
return
lat = float(args[1])
lon = float(args[2])
self.map.set_center(lat, lon) | python | def cmd_center(self, args):
'''control center of view'''
if len(args) < 3:
print("map center LAT LON")
return
lat = float(args[1])
lon = float(args[2])
self.map.set_center(lat, lon) | [
"def",
"cmd_center",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"3",
":",
"print",
"(",
"\"map center LAT LON\"",
")",
"return",
"lat",
"=",
"float",
"(",
"args",
"[",
"1",
"]",
")",
"lon",
"=",
"float",
"(",
"args",
... | control center of view | [
"control",
"center",
"of",
"view"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L598-L605 | train | 230,437 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.cmd_follow | def cmd_follow(self, args):
'''control following of vehicle'''
if len(args) < 2:
print("map follow 0|1")
return
follow = int(args[1])
self.map.set_follow(follow) | python | def cmd_follow(self, args):
'''control following of vehicle'''
if len(args) < 2:
print("map follow 0|1")
return
follow = int(args[1])
self.map.set_follow(follow) | [
"def",
"cmd_follow",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"2",
":",
"print",
"(",
"\"map follow 0|1\"",
")",
"return",
"follow",
"=",
"int",
"(",
"args",
"[",
"1",
"]",
")",
"self",
".",
"map",
".",
"set_follow",
... | control following of vehicle | [
"control",
"following",
"of",
"vehicle"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L607-L613 | train | 230,438 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/__init__.py | MapModule.set_secondary_vehicle_position | def set_secondary_vehicle_position(self, m):
'''show 2nd vehicle on map'''
if m.get_type() != 'GLOBAL_POSITION_INT':
return
(lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01)
if abs(lat) < 1.0e-3 and abs(lon) > 1.0e-3:
return
# hack for OBC2016
alt = self.ElevationMap.GetElevation(lat, lon)
agl = m.alt * 0.001 - alt
agl_s = str(int(agl)) + 'm'
self.create_vehicle_icon('VehiclePos2', 'blue', follow=False, vehicle_type='plane')
self.map.set_position('VehiclePos2', (lat, lon), rotation=heading, label=agl_s, colour=(0,255,255)) | python | def set_secondary_vehicle_position(self, m):
'''show 2nd vehicle on map'''
if m.get_type() != 'GLOBAL_POSITION_INT':
return
(lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01)
if abs(lat) < 1.0e-3 and abs(lon) > 1.0e-3:
return
# hack for OBC2016
alt = self.ElevationMap.GetElevation(lat, lon)
agl = m.alt * 0.001 - alt
agl_s = str(int(agl)) + 'm'
self.create_vehicle_icon('VehiclePos2', 'blue', follow=False, vehicle_type='plane')
self.map.set_position('VehiclePos2', (lat, lon), rotation=heading, label=agl_s, colour=(0,255,255)) | [
"def",
"set_secondary_vehicle_position",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"get_type",
"(",
")",
"!=",
"'GLOBAL_POSITION_INT'",
":",
"return",
"(",
"lat",
",",
"lon",
",",
"heading",
")",
"=",
"(",
"m",
".",
"lat",
"*",
"1.0e-7",
",",
... | show 2nd vehicle on map | [
"show",
"2nd",
"vehicle",
"on",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/__init__.py#L615-L627 | train | 230,439 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.cmd_param | def cmd_param(self, args):
'''control kml reading'''
usage = "Usage: kml <clear | load (filename) | layers | toggle (layername) | fence (layername)>"
if len(args) < 1:
print(usage)
return
elif args[0] == "clear":
self.clearkml()
elif args[0] == "snapwp":
self.cmd_snap_wp(args[1:])
elif args[0] == "snapfence":
self.cmd_snap_fence(args[1:])
elif args[0] == "load":
if len(args) != 2:
print("usage: kml load <filename>")
return
self.loadkml(args[1])
elif args[0] == "layers":
for layer in self.curlayers:
print("Found layer: " + layer)
elif args[0] == "toggle":
self.togglekml(args[1])
elif args[0] == "fence":
self.fencekml(args[1])
else:
print(usage)
return | python | def cmd_param(self, args):
'''control kml reading'''
usage = "Usage: kml <clear | load (filename) | layers | toggle (layername) | fence (layername)>"
if len(args) < 1:
print(usage)
return
elif args[0] == "clear":
self.clearkml()
elif args[0] == "snapwp":
self.cmd_snap_wp(args[1:])
elif args[0] == "snapfence":
self.cmd_snap_fence(args[1:])
elif args[0] == "load":
if len(args) != 2:
print("usage: kml load <filename>")
return
self.loadkml(args[1])
elif args[0] == "layers":
for layer in self.curlayers:
print("Found layer: " + layer)
elif args[0] == "toggle":
self.togglekml(args[1])
elif args[0] == "fence":
self.fencekml(args[1])
else:
print(usage)
return | [
"def",
"cmd_param",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"Usage: kml <clear | load (filename) | layers | toggle (layername) | fence (layername)>\"",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"usage",
")",
"return",
"elif",
"args",
... | control kml reading | [
"control",
"kml",
"reading"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L48-L74 | train | 230,440 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.cmd_snap_wp | def cmd_snap_wp(self, args):
'''snap waypoints to KML'''
threshold = 10.0
if len(args) > 0:
threshold = float(args[0])
wpmod = self.module('wp')
wploader = wpmod.wploader
changed = False
for i in range(1,wploader.count()):
w = wploader.wp(i)
if not wploader.is_location_command(w.command):
continue
lat = w.x
lon = w.y
best = None
best_dist = (threshold+1)*3
for (snap_lat,snap_lon) in self.snap_points:
dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon)
if dist < best_dist:
best_dist = dist
best = (snap_lat, snap_lon)
if best is not None and best_dist <= threshold:
if w.x != best[0] or w.y != best[1]:
w.x = best[0]
w.y = best[1]
print("Snapping WP %u to %f %f" % (i, w.x, w.y))
wploader.set(w, i)
changed = True
elif best is not None:
if best_dist <= (threshold+1)*3:
print("Not snapping wp %u dist %.1f" % (i, best_dist))
if changed:
wpmod.send_all_waypoints() | python | def cmd_snap_wp(self, args):
'''snap waypoints to KML'''
threshold = 10.0
if len(args) > 0:
threshold = float(args[0])
wpmod = self.module('wp')
wploader = wpmod.wploader
changed = False
for i in range(1,wploader.count()):
w = wploader.wp(i)
if not wploader.is_location_command(w.command):
continue
lat = w.x
lon = w.y
best = None
best_dist = (threshold+1)*3
for (snap_lat,snap_lon) in self.snap_points:
dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon)
if dist < best_dist:
best_dist = dist
best = (snap_lat, snap_lon)
if best is not None and best_dist <= threshold:
if w.x != best[0] or w.y != best[1]:
w.x = best[0]
w.y = best[1]
print("Snapping WP %u to %f %f" % (i, w.x, w.y))
wploader.set(w, i)
changed = True
elif best is not None:
if best_dist <= (threshold+1)*3:
print("Not snapping wp %u dist %.1f" % (i, best_dist))
if changed:
wpmod.send_all_waypoints() | [
"def",
"cmd_snap_wp",
"(",
"self",
",",
"args",
")",
":",
"threshold",
"=",
"10.0",
"if",
"len",
"(",
"args",
")",
">",
"0",
":",
"threshold",
"=",
"float",
"(",
"args",
"[",
"0",
"]",
")",
"wpmod",
"=",
"self",
".",
"module",
"(",
"'wp'",
")",
... | snap waypoints to KML | [
"snap",
"waypoints",
"to",
"KML"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L76-L108 | train | 230,441 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.cmd_snap_fence | def cmd_snap_fence(self, args):
'''snap fence to KML'''
threshold = 10.0
if len(args) > 0:
threshold = float(args[0])
fencemod = self.module('fence')
loader = fencemod.fenceloader
changed = False
for i in range(0,loader.count()):
fp = loader.point(i)
lat = fp.lat
lon = fp.lng
best = None
best_dist = (threshold+1)*3
for (snap_lat,snap_lon) in self.snap_points:
dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon)
if dist < best_dist:
best_dist = dist
best = (snap_lat, snap_lon)
if best is not None and best_dist <= threshold:
if best[0] != lat or best[1] != lon:
loader.move(i, best[0], best[1])
print("Snapping fence point %u to %f %f" % (i, best[0], best[1]))
changed = True
elif best is not None:
if best_dist <= (threshold+1)*3:
print("Not snapping fence point %u dist %.1f" % (i, best_dist))
if changed:
fencemod.send_fence() | python | def cmd_snap_fence(self, args):
'''snap fence to KML'''
threshold = 10.0
if len(args) > 0:
threshold = float(args[0])
fencemod = self.module('fence')
loader = fencemod.fenceloader
changed = False
for i in range(0,loader.count()):
fp = loader.point(i)
lat = fp.lat
lon = fp.lng
best = None
best_dist = (threshold+1)*3
for (snap_lat,snap_lon) in self.snap_points:
dist = mp_util.gps_distance(lat, lon, snap_lat, snap_lon)
if dist < best_dist:
best_dist = dist
best = (snap_lat, snap_lon)
if best is not None and best_dist <= threshold:
if best[0] != lat or best[1] != lon:
loader.move(i, best[0], best[1])
print("Snapping fence point %u to %f %f" % (i, best[0], best[1]))
changed = True
elif best is not None:
if best_dist <= (threshold+1)*3:
print("Not snapping fence point %u dist %.1f" % (i, best_dist))
if changed:
fencemod.send_fence() | [
"def",
"cmd_snap_fence",
"(",
"self",
",",
"args",
")",
":",
"threshold",
"=",
"10.0",
"if",
"len",
"(",
"args",
")",
">",
"0",
":",
"threshold",
"=",
"float",
"(",
"args",
"[",
"0",
"]",
")",
"fencemod",
"=",
"self",
".",
"module",
"(",
"'fence'",... | snap fence to KML | [
"snap",
"fence",
"to",
"KML"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L110-L139 | train | 230,442 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.fencekml | def fencekml(self, layername):
'''set a layer as the geofence'''
#Strip quotation marks if neccessary
if layername.startswith('"') and layername.endswith('"'):
layername = layername[1:-1]
#for each point in the layer, add it in
for layer in self.allayers:
if layer.key == layername:
#clear the current fence
self.fenceloader.clear()
if len(layer.points) < 3:
return
self.fenceloader.target_system = self.target_system
self.fenceloader.target_component = self.target_component
#send centrepoint to fence[0] as the return point
bounds = mp_util.polygon_bounds(layer.points)
(lat, lon, width, height) = bounds
center = (lat+width/2, lon+height/2)
self.fenceloader.add_latlon(center[0], center[1])
for lat, lon in layer.points:
#add point
self.fenceloader.add_latlon(lat, lon)
#and send
self.send_fence() | python | def fencekml(self, layername):
'''set a layer as the geofence'''
#Strip quotation marks if neccessary
if layername.startswith('"') and layername.endswith('"'):
layername = layername[1:-1]
#for each point in the layer, add it in
for layer in self.allayers:
if layer.key == layername:
#clear the current fence
self.fenceloader.clear()
if len(layer.points) < 3:
return
self.fenceloader.target_system = self.target_system
self.fenceloader.target_component = self.target_component
#send centrepoint to fence[0] as the return point
bounds = mp_util.polygon_bounds(layer.points)
(lat, lon, width, height) = bounds
center = (lat+width/2, lon+height/2)
self.fenceloader.add_latlon(center[0], center[1])
for lat, lon in layer.points:
#add point
self.fenceloader.add_latlon(lat, lon)
#and send
self.send_fence() | [
"def",
"fencekml",
"(",
"self",
",",
"layername",
")",
":",
"#Strip quotation marks if neccessary",
"if",
"layername",
".",
"startswith",
"(",
"'\"'",
")",
"and",
"layername",
".",
"endswith",
"(",
"'\"'",
")",
":",
"layername",
"=",
"layername",
"[",
"1",
"... | set a layer as the geofence | [
"set",
"a",
"layer",
"as",
"the",
"geofence"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L141-L165 | train | 230,443 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.togglekml | def togglekml(self, layername):
'''toggle the display of a kml'''
#Strip quotation marks if neccessary
if layername.startswith('"') and layername.endswith('"'):
layername = layername[1:-1]
#toggle layer off (plus associated text element)
if layername in self.curlayers:
for layer in self.curlayers:
if layer == layername:
self.mpstate.map.remove_object(layer)
self.curlayers.remove(layername)
if layername in self.curtextlayers:
for clayer in self.curtextlayers:
if clayer == layername:
self.mpstate.map.remove_object(clayer)
self.curtextlayers.remove(clayer)
#toggle layer on (plus associated text element)
else:
for layer in self.allayers:
if layer.key == layername:
self.mpstate.map.add_object(layer)
self.curlayers.append(layername)
for alayer in self.alltextlayers:
if alayer.key == layername:
self.mpstate.map.add_object(alayer)
self.curtextlayers.append(layername)
self.menu_needs_refreshing = True | python | def togglekml(self, layername):
'''toggle the display of a kml'''
#Strip quotation marks if neccessary
if layername.startswith('"') and layername.endswith('"'):
layername = layername[1:-1]
#toggle layer off (plus associated text element)
if layername in self.curlayers:
for layer in self.curlayers:
if layer == layername:
self.mpstate.map.remove_object(layer)
self.curlayers.remove(layername)
if layername in self.curtextlayers:
for clayer in self.curtextlayers:
if clayer == layername:
self.mpstate.map.remove_object(clayer)
self.curtextlayers.remove(clayer)
#toggle layer on (plus associated text element)
else:
for layer in self.allayers:
if layer.key == layername:
self.mpstate.map.add_object(layer)
self.curlayers.append(layername)
for alayer in self.alltextlayers:
if alayer.key == layername:
self.mpstate.map.add_object(alayer)
self.curtextlayers.append(layername)
self.menu_needs_refreshing = True | [
"def",
"togglekml",
"(",
"self",
",",
"layername",
")",
":",
"#Strip quotation marks if neccessary",
"if",
"layername",
".",
"startswith",
"(",
"'\"'",
")",
"and",
"layername",
".",
"endswith",
"(",
"'\"'",
")",
":",
"layername",
"=",
"layername",
"[",
"1",
... | toggle the display of a kml | [
"toggle",
"the",
"display",
"of",
"a",
"kml"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L209-L235 | train | 230,444 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.clearkml | def clearkml(self):
'''Clear the kmls from the map'''
#go through all the current layers and remove them
for layer in self.curlayers:
self.mpstate.map.remove_object(layer)
for layer in self.curtextlayers:
self.mpstate.map.remove_object(layer)
self.allayers = []
self.curlayers = []
self.alltextlayers = []
self.curtextlayers = []
self.menu_needs_refreshing = True | python | def clearkml(self):
'''Clear the kmls from the map'''
#go through all the current layers and remove them
for layer in self.curlayers:
self.mpstate.map.remove_object(layer)
for layer in self.curtextlayers:
self.mpstate.map.remove_object(layer)
self.allayers = []
self.curlayers = []
self.alltextlayers = []
self.curtextlayers = []
self.menu_needs_refreshing = True | [
"def",
"clearkml",
"(",
"self",
")",
":",
"#go through all the current layers and remove them",
"for",
"layer",
"in",
"self",
".",
"curlayers",
":",
"self",
".",
"mpstate",
".",
"map",
".",
"remove_object",
"(",
"layer",
")",
"for",
"layer",
"in",
"self",
".",... | Clear the kmls from the map | [
"Clear",
"the",
"kmls",
"from",
"the",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L237-L248 | train | 230,445 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.loadkml | def loadkml(self, filename):
'''Load a kml from file and put it on the map'''
#Open the zip file
nodes = self.readkmz(filename)
self.snap_points = []
#go through each object in the kml...
for n in nodes:
point = self.readObject(n)
#and place any polygons on the map
if self.mpstate.map is not None and point[0] == 'Polygon':
self.snap_points.extend(point[2])
#print("Adding " + point[1])
newcolour = (random.randint(0, 255), 0, random.randint(0, 255))
curpoly = mp_slipmap.SlipPolygon(point[1], point[2],
layer=2, linewidth=2, colour=newcolour)
self.mpstate.map.add_object(curpoly)
self.allayers.append(curpoly)
self.curlayers.append(point[1])
#and points - barrell image and text
if self.mpstate.map is not None and point[0] == 'Point':
#print("Adding " + point[1])
icon = self.mpstate.map.icon('barrell.png')
curpoint = mp_slipmap.SlipIcon(point[1], latlon = (point[2][0][0], point[2][0][1]), layer=3, img=icon, rotation=0, follow=False)
curtext = mp_slipmap.SlipLabel(point[1], point = (point[2][0][0], point[2][0][1]), layer=4, label=point[1], colour=(0,255,255))
self.mpstate.map.add_object(curpoint)
self.mpstate.map.add_object(curtext)
self.allayers.append(curpoint)
self.alltextlayers.append(curtext)
self.curlayers.append(point[1])
self.curtextlayers.append(point[1])
self.menu_needs_refreshing = True | python | def loadkml(self, filename):
'''Load a kml from file and put it on the map'''
#Open the zip file
nodes = self.readkmz(filename)
self.snap_points = []
#go through each object in the kml...
for n in nodes:
point = self.readObject(n)
#and place any polygons on the map
if self.mpstate.map is not None and point[0] == 'Polygon':
self.snap_points.extend(point[2])
#print("Adding " + point[1])
newcolour = (random.randint(0, 255), 0, random.randint(0, 255))
curpoly = mp_slipmap.SlipPolygon(point[1], point[2],
layer=2, linewidth=2, colour=newcolour)
self.mpstate.map.add_object(curpoly)
self.allayers.append(curpoly)
self.curlayers.append(point[1])
#and points - barrell image and text
if self.mpstate.map is not None and point[0] == 'Point':
#print("Adding " + point[1])
icon = self.mpstate.map.icon('barrell.png')
curpoint = mp_slipmap.SlipIcon(point[1], latlon = (point[2][0][0], point[2][0][1]), layer=3, img=icon, rotation=0, follow=False)
curtext = mp_slipmap.SlipLabel(point[1], point = (point[2][0][0], point[2][0][1]), layer=4, label=point[1], colour=(0,255,255))
self.mpstate.map.add_object(curpoint)
self.mpstate.map.add_object(curtext)
self.allayers.append(curpoint)
self.alltextlayers.append(curtext)
self.curlayers.append(point[1])
self.curtextlayers.append(point[1])
self.menu_needs_refreshing = True | [
"def",
"loadkml",
"(",
"self",
",",
"filename",
")",
":",
"#Open the zip file",
"nodes",
"=",
"self",
".",
"readkmz",
"(",
"filename",
")",
"self",
".",
"snap_points",
"=",
"[",
"]",
"#go through each object in the kml...",
"for",
"n",
"in",
"nodes",
":",
"p... | Load a kml from file and put it on the map | [
"Load",
"a",
"kml",
"from",
"file",
"and",
"put",
"it",
"on",
"the",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L250-L286 | train | 230,446 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.idle_task | def idle_task(self):
'''handle GUI elements'''
if not self.menu_needs_refreshing:
return
if self.module('map') is not None and not self.menu_added_map:
self.menu_added_map = True
self.module('map').add_menu(self.menu)
#(re)create the menu
if mp_util.has_wxpython and self.menu_added_map:
# we don't dynamically update these yet due to a wx bug
self.menu.items = [ MPMenuItem('Clear', 'Clear', '# kml clear'), MPMenuItem('Load', 'Load', '# kml load ', handler=MPMenuCallFileDialog(flags=('open',), title='KML Load', wildcard='*.kml;*.kmz')), self.menu_fence, MPMenuSeparator() ]
self.menu_fence.items = []
for layer in self.allayers:
#if it's a polygon, add it to the "set Geofence" list
if isinstance(layer, mp_slipmap.SlipPolygon):
self.menu_fence.items.append(MPMenuItem(layer.key, layer.key, '# kml fence \"' + layer.key + '\"'))
#then add all the layers to the menu, ensuring to check the active layers
#text elements aren't included on the menu
if layer.key in self.curlayers and layer.key[-5:] != "-text":
self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=True))
elif layer.key[-5:] != "-text":
self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=False))
#and add the menu to the map popu menu
self.module('map').add_menu(self.menu)
self.menu_needs_refreshing = False | python | def idle_task(self):
'''handle GUI elements'''
if not self.menu_needs_refreshing:
return
if self.module('map') is not None and not self.menu_added_map:
self.menu_added_map = True
self.module('map').add_menu(self.menu)
#(re)create the menu
if mp_util.has_wxpython and self.menu_added_map:
# we don't dynamically update these yet due to a wx bug
self.menu.items = [ MPMenuItem('Clear', 'Clear', '# kml clear'), MPMenuItem('Load', 'Load', '# kml load ', handler=MPMenuCallFileDialog(flags=('open',), title='KML Load', wildcard='*.kml;*.kmz')), self.menu_fence, MPMenuSeparator() ]
self.menu_fence.items = []
for layer in self.allayers:
#if it's a polygon, add it to the "set Geofence" list
if isinstance(layer, mp_slipmap.SlipPolygon):
self.menu_fence.items.append(MPMenuItem(layer.key, layer.key, '# kml fence \"' + layer.key + '\"'))
#then add all the layers to the menu, ensuring to check the active layers
#text elements aren't included on the menu
if layer.key in self.curlayers and layer.key[-5:] != "-text":
self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=True))
elif layer.key[-5:] != "-text":
self.menu.items.append(MPMenuCheckbox(layer.key, layer.key, '# kml toggle \"' + layer.key + '\"', checked=False))
#and add the menu to the map popu menu
self.module('map').add_menu(self.menu)
self.menu_needs_refreshing = False | [
"def",
"idle_task",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"menu_needs_refreshing",
":",
"return",
"if",
"self",
".",
"module",
"(",
"'map'",
")",
"is",
"not",
"None",
"and",
"not",
"self",
".",
"menu_added_map",
":",
"self",
".",
"menu_added_m... | handle GUI elements | [
"handle",
"GUI",
"elements"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L289-L313 | train | 230,447 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_kmlread.py | KmlReadModule.readkmz | def readkmz(self, filename):
'''reads in a kmz file and returns xml nodes'''
#Strip quotation marks if neccessary
filename.strip('"')
#Open the zip file (as applicable)
if filename[-4:] == '.kml':
fo = open(filename, "r")
fstring = fo.read()
fo.close()
elif filename[-4:] == '.kmz':
zip=ZipFile(filename)
for z in zip.filelist:
if z.filename[-4:] == '.kml':
fstring=zip.read(z)
break
else:
raise Exception("Could not find kml file in %s" % filename)
else:
raise Exception("Is not a valid kml or kmz file in %s" % filename)
#send into the xml parser
kmlstring = parseString(fstring)
#get all the placenames
nodes=kmlstring.getElementsByTagName('Placemark')
return nodes | python | def readkmz(self, filename):
'''reads in a kmz file and returns xml nodes'''
#Strip quotation marks if neccessary
filename.strip('"')
#Open the zip file (as applicable)
if filename[-4:] == '.kml':
fo = open(filename, "r")
fstring = fo.read()
fo.close()
elif filename[-4:] == '.kmz':
zip=ZipFile(filename)
for z in zip.filelist:
if z.filename[-4:] == '.kml':
fstring=zip.read(z)
break
else:
raise Exception("Could not find kml file in %s" % filename)
else:
raise Exception("Is not a valid kml or kmz file in %s" % filename)
#send into the xml parser
kmlstring = parseString(fstring)
#get all the placenames
nodes=kmlstring.getElementsByTagName('Placemark')
return nodes | [
"def",
"readkmz",
"(",
"self",
",",
"filename",
")",
":",
"#Strip quotation marks if neccessary",
"filename",
".",
"strip",
"(",
"'\"'",
")",
"#Open the zip file (as applicable) ",
"if",
"filename",
"[",
"-",
"4",
":",
"]",
"==",
"'.kml'",
":",
"fo",
"=",
"... | reads in a kmz file and returns xml nodes | [
"reads",
"in",
"a",
"kmz",
"file",
"and",
"returns",
"xml",
"nodes"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_kmlread.py#L318-L344 | train | 230,448 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_asterix.py | AsterixModule.cmd_asterix | def cmd_asterix(self, args):
'''asterix command parser'''
usage = "usage: asterix <set|start|stop|restart|status>"
if len(args) == 0:
print(usage)
return
if args[0] == "set":
self.asterix_settings.command(args[1:])
elif args[0] == "start":
self.start_listener()
elif args[0] == "stop":
self.stop_listener()
elif args[0] == "restart":
self.stop_listener()
self.start_listener()
elif args[0] == "status":
self.print_status()
else:
print(usage) | python | def cmd_asterix(self, args):
'''asterix command parser'''
usage = "usage: asterix <set|start|stop|restart|status>"
if len(args) == 0:
print(usage)
return
if args[0] == "set":
self.asterix_settings.command(args[1:])
elif args[0] == "start":
self.start_listener()
elif args[0] == "stop":
self.stop_listener()
elif args[0] == "restart":
self.stop_listener()
self.start_listener()
elif args[0] == "status":
self.print_status()
else:
print(usage) | [
"def",
"cmd_asterix",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"usage: asterix <set|start|stop|restart|status>\"",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"usage",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"\"set\"",... | asterix command parser | [
"asterix",
"command",
"parser"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L99-L117 | train | 230,449 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_asterix.py | AsterixModule.start_listener | def start_listener(self):
'''start listening for packets'''
if self.sock is not None:
self.sock.close()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(('', self.asterix_settings.port))
self.sock.setblocking(False)
print("Started on port %u" % self.asterix_settings.port) | python | def start_listener(self):
'''start listening for packets'''
if self.sock is not None:
self.sock.close()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(('', self.asterix_settings.port))
self.sock.setblocking(False)
print("Started on port %u" % self.asterix_settings.port) | [
"def",
"start_listener",
"(",
"self",
")",
":",
"if",
"self",
".",
"sock",
"is",
"not",
"None",
":",
"self",
".",
"sock",
".",
"close",
"(",
")",
"self",
".",
"sock",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
... | start listening for packets | [
"start",
"listening",
"for",
"packets"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L119-L127 | train | 230,450 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_asterix.py | AsterixModule.stop_listener | def stop_listener(self):
'''stop listening for packets'''
if self.sock is not None:
self.sock.close()
self.sock = None
self.tracks = {} | python | def stop_listener(self):
'''stop listening for packets'''
if self.sock is not None:
self.sock.close()
self.sock = None
self.tracks = {} | [
"def",
"stop_listener",
"(",
"self",
")",
":",
"if",
"self",
".",
"sock",
"is",
"not",
"None",
":",
"self",
".",
"sock",
".",
"close",
"(",
")",
"self",
".",
"sock",
"=",
"None",
"self",
".",
"tracks",
"=",
"{",
"}"
] | stop listening for packets | [
"stop",
"listening",
"for",
"packets"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L129-L134 | train | 230,451 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_asterix.py | AsterixModule.set_secondary_vehicle_position | def set_secondary_vehicle_position(self, m):
'''store second vehicle position for filtering purposes'''
if m.get_type() != 'GLOBAL_POSITION_INT':
return
(lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01)
if abs(lat) < 1.0e-3 and abs(lon) < 1.0e-3:
return
self.vehicle2_pos = VehiclePos(m) | python | def set_secondary_vehicle_position(self, m):
'''store second vehicle position for filtering purposes'''
if m.get_type() != 'GLOBAL_POSITION_INT':
return
(lat, lon, heading) = (m.lat*1.0e-7, m.lon*1.0e-7, m.hdg*0.01)
if abs(lat) < 1.0e-3 and abs(lon) < 1.0e-3:
return
self.vehicle2_pos = VehiclePos(m) | [
"def",
"set_secondary_vehicle_position",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"get_type",
"(",
")",
"!=",
"'GLOBAL_POSITION_INT'",
":",
"return",
"(",
"lat",
",",
"lon",
",",
"heading",
")",
"=",
"(",
"m",
".",
"lat",
"*",
"1.0e-7",
",",
... | store second vehicle position for filtering purposes | [
"store",
"second",
"vehicle",
"position",
"for",
"filtering",
"purposes"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L136-L143 | train | 230,452 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_asterix.py | AsterixModule.could_collide_hor | def could_collide_hor(self, vpos, adsb_pkt):
'''return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds'''
margin = self.asterix_settings.filter_dist_xy
timeout = self.asterix_settings.filter_time
alat = adsb_pkt.lat * 1.0e-7
alon = adsb_pkt.lon * 1.0e-7
avel = adsb_pkt.hor_velocity * 0.01
vvel = sqrt(vpos.vx**2 + vpos.vy**2)
dist = mp_util.gps_distance(vpos.lat, vpos.lon, alat, alon)
dist -= avel * timeout
dist -= vvel * timeout
if dist <= margin:
return True
return False | python | def could_collide_hor(self, vpos, adsb_pkt):
'''return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds'''
margin = self.asterix_settings.filter_dist_xy
timeout = self.asterix_settings.filter_time
alat = adsb_pkt.lat * 1.0e-7
alon = adsb_pkt.lon * 1.0e-7
avel = adsb_pkt.hor_velocity * 0.01
vvel = sqrt(vpos.vx**2 + vpos.vy**2)
dist = mp_util.gps_distance(vpos.lat, vpos.lon, alat, alon)
dist -= avel * timeout
dist -= vvel * timeout
if dist <= margin:
return True
return False | [
"def",
"could_collide_hor",
"(",
"self",
",",
"vpos",
",",
"adsb_pkt",
")",
":",
"margin",
"=",
"self",
".",
"asterix_settings",
".",
"filter_dist_xy",
"timeout",
"=",
"self",
".",
"asterix_settings",
".",
"filter_time",
"alat",
"=",
"adsb_pkt",
".",
"lat",
... | return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds | [
"return",
"true",
"if",
"vehicle",
"could",
"come",
"within",
"filter_dist_xy",
"meters",
"of",
"adsb",
"vehicle",
"in",
"timeout",
"seconds"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L145-L158 | train | 230,453 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_asterix.py | AsterixModule.could_collide_ver | def could_collide_ver(self, vpos, adsb_pkt):
'''return true if vehicle could come within filter_dist_z meters of adsb vehicle in timeout seconds'''
if adsb_pkt.emitter_type < 100 or adsb_pkt.emitter_type > 104:
return True
margin = self.asterix_settings.filter_dist_z
vtype = adsb_pkt.emitter_type - 100
valt = vpos.alt
aalt1 = adsb_pkt.altitude * 0.001
if vtype == 2:
# weather, always yes
return True
if vtype == 4:
# bird of prey, always true
return True
# planes and migrating birds have 150m margin
aalt2 = aalt1 + adsb_pkt.ver_velocity * 0.01 * self.asterix_settings.filter_time
altsep1 = abs(valt - aalt1)
altsep2 = abs(valt - aalt2)
if altsep1 > 150 + margin and altsep2 > 150 + margin:
return False
return True | python | def could_collide_ver(self, vpos, adsb_pkt):
'''return true if vehicle could come within filter_dist_z meters of adsb vehicle in timeout seconds'''
if adsb_pkt.emitter_type < 100 or adsb_pkt.emitter_type > 104:
return True
margin = self.asterix_settings.filter_dist_z
vtype = adsb_pkt.emitter_type - 100
valt = vpos.alt
aalt1 = adsb_pkt.altitude * 0.001
if vtype == 2:
# weather, always yes
return True
if vtype == 4:
# bird of prey, always true
return True
# planes and migrating birds have 150m margin
aalt2 = aalt1 + adsb_pkt.ver_velocity * 0.01 * self.asterix_settings.filter_time
altsep1 = abs(valt - aalt1)
altsep2 = abs(valt - aalt2)
if altsep1 > 150 + margin and altsep2 > 150 + margin:
return False
return True | [
"def",
"could_collide_ver",
"(",
"self",
",",
"vpos",
",",
"adsb_pkt",
")",
":",
"if",
"adsb_pkt",
".",
"emitter_type",
"<",
"100",
"or",
"adsb_pkt",
".",
"emitter_type",
">",
"104",
":",
"return",
"True",
"margin",
"=",
"self",
".",
"asterix_settings",
".... | return true if vehicle could come within filter_dist_z meters of adsb vehicle in timeout seconds | [
"return",
"true",
"if",
"vehicle",
"could",
"come",
"within",
"filter_dist_z",
"meters",
"of",
"adsb",
"vehicle",
"in",
"timeout",
"seconds"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L160-L180 | train | 230,454 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_asterix.py | AsterixModule.mavlink_packet | def mavlink_packet(self, m):
'''get time from mavlink ATTITUDE'''
if m.get_type() == 'GLOBAL_POSITION_INT':
if abs(m.lat) < 1000 and abs(m.lon) < 1000:
return
self.vehicle_pos = VehiclePos(m) | python | def mavlink_packet(self, m):
'''get time from mavlink ATTITUDE'''
if m.get_type() == 'GLOBAL_POSITION_INT':
if abs(m.lat) < 1000 and abs(m.lon) < 1000:
return
self.vehicle_pos = VehiclePos(m) | [
"def",
"mavlink_packet",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"'GLOBAL_POSITION_INT'",
":",
"if",
"abs",
"(",
"m",
".",
"lat",
")",
"<",
"1000",
"and",
"abs",
"(",
"m",
".",
"lon",
")",
"<",
"1000",
":",
... | get time from mavlink ATTITUDE | [
"get",
"time",
"from",
"mavlink",
"ATTITUDE"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_asterix.py#L300-L305 | train | 230,455 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.complete_serial_ports | def complete_serial_ports(self, text):
'''return list of serial ports'''
ports = mavutil.auto_detect_serial(preferred_list=preferred_ports)
return [ p.device for p in ports ] | python | def complete_serial_ports(self, text):
'''return list of serial ports'''
ports = mavutil.auto_detect_serial(preferred_list=preferred_ports)
return [ p.device for p in ports ] | [
"def",
"complete_serial_ports",
"(",
"self",
",",
"text",
")",
":",
"ports",
"=",
"mavutil",
".",
"auto_detect_serial",
"(",
"preferred_list",
"=",
"preferred_ports",
")",
"return",
"[",
"p",
".",
"device",
"for",
"p",
"in",
"ports",
"]"
] | return list of serial ports | [
"return",
"list",
"of",
"serial",
"ports"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L77-L80 | train | 230,456 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.complete_links | def complete_links(self, text):
'''return list of links'''
try:
ret = [ m.address for m in self.mpstate.mav_master ]
for m in self.mpstate.mav_master:
ret.append(m.address)
if hasattr(m, 'label'):
ret.append(m.label)
return ret
except Exception as e:
print("Caught exception: %s" % str(e)) | python | def complete_links(self, text):
'''return list of links'''
try:
ret = [ m.address for m in self.mpstate.mav_master ]
for m in self.mpstate.mav_master:
ret.append(m.address)
if hasattr(m, 'label'):
ret.append(m.label)
return ret
except Exception as e:
print("Caught exception: %s" % str(e)) | [
"def",
"complete_links",
"(",
"self",
",",
"text",
")",
":",
"try",
":",
"ret",
"=",
"[",
"m",
".",
"address",
"for",
"m",
"in",
"self",
".",
"mpstate",
".",
"mav_master",
"]",
"for",
"m",
"in",
"self",
".",
"mpstate",
".",
"mav_master",
":",
"ret"... | return list of links | [
"return",
"list",
"of",
"links"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L82-L92 | train | 230,457 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.cmd_link_attributes | def cmd_link_attributes(self, args):
'''change optional link attributes'''
link = args[0]
attributes = args[1]
print("Setting link %s attributes (%s)" % (link, attributes))
self.link_attributes(link, attributes) | python | def cmd_link_attributes(self, args):
'''change optional link attributes'''
link = args[0]
attributes = args[1]
print("Setting link %s attributes (%s)" % (link, attributes))
self.link_attributes(link, attributes) | [
"def",
"cmd_link_attributes",
"(",
"self",
",",
"args",
")",
":",
"link",
"=",
"args",
"[",
"0",
"]",
"attributes",
"=",
"args",
"[",
"1",
"]",
"print",
"(",
"\"Setting link %s attributes (%s)\"",
"%",
"(",
"link",
",",
"attributes",
")",
")",
"self",
".... | change optional link attributes | [
"change",
"optional",
"link",
"attributes"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L242-L247 | train | 230,458 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.find_link | def find_link(self, device):
'''find a device based on number, name or label'''
for i in range(len(self.mpstate.mav_master)):
conn = self.mpstate.mav_master[i]
if (str(i) == device or
conn.address == device or
getattr(conn, 'label', None) == device):
return i
return None | python | def find_link(self, device):
'''find a device based on number, name or label'''
for i in range(len(self.mpstate.mav_master)):
conn = self.mpstate.mav_master[i]
if (str(i) == device or
conn.address == device or
getattr(conn, 'label', None) == device):
return i
return None | [
"def",
"find_link",
"(",
"self",
",",
"device",
")",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"mpstate",
".",
"mav_master",
")",
")",
":",
"conn",
"=",
"self",
".",
"mpstate",
".",
"mav_master",
"[",
"i",
"]",
"if",
"(",
"str... | find a device based on number, name or label | [
"find",
"a",
"device",
"based",
"on",
"number",
"name",
"or",
"label"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L255-L263 | train | 230,459 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.cmd_link_remove | def cmd_link_remove(self, args):
'''remove an link'''
device = args[0]
if len(self.mpstate.mav_master) <= 1:
print("Not removing last link")
return
i = self.find_link(device)
if i is None:
return
conn = self.mpstate.mav_master[i]
print("Removing link %s" % conn.address)
try:
try:
mp_util.child_fd_list_remove(conn.port.fileno())
except Exception:
pass
self.mpstate.mav_master[i].close()
except Exception as msg:
print(msg)
pass
self.mpstate.mav_master.pop(i)
self.status.counters['MasterIn'].pop(i)
# renumber the links
for j in range(len(self.mpstate.mav_master)):
conn = self.mpstate.mav_master[j]
conn.linknum = j | python | def cmd_link_remove(self, args):
'''remove an link'''
device = args[0]
if len(self.mpstate.mav_master) <= 1:
print("Not removing last link")
return
i = self.find_link(device)
if i is None:
return
conn = self.mpstate.mav_master[i]
print("Removing link %s" % conn.address)
try:
try:
mp_util.child_fd_list_remove(conn.port.fileno())
except Exception:
pass
self.mpstate.mav_master[i].close()
except Exception as msg:
print(msg)
pass
self.mpstate.mav_master.pop(i)
self.status.counters['MasterIn'].pop(i)
# renumber the links
for j in range(len(self.mpstate.mav_master)):
conn = self.mpstate.mav_master[j]
conn.linknum = j | [
"def",
"cmd_link_remove",
"(",
"self",
",",
"args",
")",
":",
"device",
"=",
"args",
"[",
"0",
"]",
"if",
"len",
"(",
"self",
".",
"mpstate",
".",
"mav_master",
")",
"<=",
"1",
":",
"print",
"(",
"\"Not removing last link\"",
")",
"return",
"i",
"=",
... | remove an link | [
"remove",
"an",
"link"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L265-L290 | train | 230,460 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.master_send_callback | def master_send_callback(self, m, master):
'''called on sending a message'''
if self.status.watch is not None:
for msg_type in self.status.watch:
if fnmatch.fnmatch(m.get_type().upper(), msg_type.upper()):
self.mpstate.console.writeln('> '+ str(m))
break
mtype = m.get_type()
if mtype != 'BAD_DATA' and self.mpstate.logqueue:
usec = self.get_usec()
usec = (usec & ~3) | 3 # linknum 3
self.mpstate.logqueue.put(bytearray(struct.pack('>Q', usec) + m.get_msgbuf())) | python | def master_send_callback(self, m, master):
'''called on sending a message'''
if self.status.watch is not None:
for msg_type in self.status.watch:
if fnmatch.fnmatch(m.get_type().upper(), msg_type.upper()):
self.mpstate.console.writeln('> '+ str(m))
break
mtype = m.get_type()
if mtype != 'BAD_DATA' and self.mpstate.logqueue:
usec = self.get_usec()
usec = (usec & ~3) | 3 # linknum 3
self.mpstate.logqueue.put(bytearray(struct.pack('>Q', usec) + m.get_msgbuf())) | [
"def",
"master_send_callback",
"(",
"self",
",",
"m",
",",
"master",
")",
":",
"if",
"self",
".",
"status",
".",
"watch",
"is",
"not",
"None",
":",
"for",
"msg_type",
"in",
"self",
".",
"status",
".",
"watch",
":",
"if",
"fnmatch",
".",
"fnmatch",
"(... | called on sending a message | [
"called",
"on",
"sending",
"a",
"message"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L296-L308 | train | 230,461 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.handle_msec_timestamp | def handle_msec_timestamp(self, m, master):
'''special handling for MAVLink packets with a time_boot_ms field'''
if m.get_type() == 'GLOBAL_POSITION_INT':
# this is fix time, not boot time
return
msec = m.time_boot_ms
if msec + 30000 < master.highest_msec:
self.say('Time has wrapped')
print('Time has wrapped', msec, master.highest_msec)
self.status.highest_msec = msec
for mm in self.mpstate.mav_master:
mm.link_delayed = False
mm.highest_msec = msec
return
# we want to detect when a link is delayed
master.highest_msec = msec
if msec > self.status.highest_msec:
self.status.highest_msec = msec
if msec < self.status.highest_msec and len(self.mpstate.mav_master) > 1 and self.mpstate.settings.checkdelay:
master.link_delayed = True
else:
master.link_delayed = False | python | def handle_msec_timestamp(self, m, master):
'''special handling for MAVLink packets with a time_boot_ms field'''
if m.get_type() == 'GLOBAL_POSITION_INT':
# this is fix time, not boot time
return
msec = m.time_boot_ms
if msec + 30000 < master.highest_msec:
self.say('Time has wrapped')
print('Time has wrapped', msec, master.highest_msec)
self.status.highest_msec = msec
for mm in self.mpstate.mav_master:
mm.link_delayed = False
mm.highest_msec = msec
return
# we want to detect when a link is delayed
master.highest_msec = msec
if msec > self.status.highest_msec:
self.status.highest_msec = msec
if msec < self.status.highest_msec and len(self.mpstate.mav_master) > 1 and self.mpstate.settings.checkdelay:
master.link_delayed = True
else:
master.link_delayed = False | [
"def",
"handle_msec_timestamp",
"(",
"self",
",",
"m",
",",
"master",
")",
":",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"'GLOBAL_POSITION_INT'",
":",
"# this is fix time, not boot time",
"return",
"msec",
"=",
"m",
".",
"time_boot_ms",
"if",
"msec",
"+",
... | special handling for MAVLink packets with a time_boot_ms field | [
"special",
"handling",
"for",
"MAVLink",
"packets",
"with",
"a",
"time_boot_ms",
"field"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L310-L334 | train | 230,462 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.report_altitude | def report_altitude(self, altitude):
'''possibly report a new altitude'''
master = self.master
if getattr(self.console, 'ElevationMap', None) is not None and self.mpstate.settings.basealt != 0:
lat = master.field('GLOBAL_POSITION_INT', 'lat', 0)*1.0e-7
lon = master.field('GLOBAL_POSITION_INT', 'lon', 0)*1.0e-7
alt1 = self.console.ElevationMap.GetElevation(lat, lon)
if alt1 is not None:
alt2 = self.mpstate.settings.basealt
altitude += alt2 - alt1
self.status.altitude = altitude
altitude_converted = self.height_convert_units(altitude)
if (int(self.mpstate.settings.altreadout) > 0 and
math.fabs(altitude_converted - self.last_altitude_announce) >=
int(self.settings.altreadout)):
self.last_altitude_announce = altitude_converted
rounded_alt = int(self.settings.altreadout) * ((self.settings.altreadout/2 + int(altitude_converted)) / int(self.settings.altreadout))
self.say("height %u" % rounded_alt, priority='notification') | python | def report_altitude(self, altitude):
'''possibly report a new altitude'''
master = self.master
if getattr(self.console, 'ElevationMap', None) is not None and self.mpstate.settings.basealt != 0:
lat = master.field('GLOBAL_POSITION_INT', 'lat', 0)*1.0e-7
lon = master.field('GLOBAL_POSITION_INT', 'lon', 0)*1.0e-7
alt1 = self.console.ElevationMap.GetElevation(lat, lon)
if alt1 is not None:
alt2 = self.mpstate.settings.basealt
altitude += alt2 - alt1
self.status.altitude = altitude
altitude_converted = self.height_convert_units(altitude)
if (int(self.mpstate.settings.altreadout) > 0 and
math.fabs(altitude_converted - self.last_altitude_announce) >=
int(self.settings.altreadout)):
self.last_altitude_announce = altitude_converted
rounded_alt = int(self.settings.altreadout) * ((self.settings.altreadout/2 + int(altitude_converted)) / int(self.settings.altreadout))
self.say("height %u" % rounded_alt, priority='notification') | [
"def",
"report_altitude",
"(",
"self",
",",
"altitude",
")",
":",
"master",
"=",
"self",
".",
"master",
"if",
"getattr",
"(",
"self",
".",
"console",
",",
"'ElevationMap'",
",",
"None",
")",
"is",
"not",
"None",
"and",
"self",
".",
"mpstate",
".",
"set... | possibly report a new altitude | [
"possibly",
"report",
"a",
"new",
"altitude"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L354-L371 | train | 230,463 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_link.py | LinkModule.cmd_vehicle | def cmd_vehicle(self, args):
'''handle vehicle commands'''
if len(args) < 1:
print("Usage: vehicle SYSID[:COMPID]")
return
a = args[0].split(':')
self.mpstate.settings.target_system = int(a[0])
if len(a) > 1:
self.mpstate.settings.target_component = int(a[1])
# change default link based on most recent HEARTBEAT
best_link = 0
best_timestamp = 0
for i in range(len(self.mpstate.mav_master)):
m = self.mpstate.mav_master[i]
m.target_system = self.mpstate.settings.target_system
m.target_component = self.mpstate.settings.target_component
if 'HEARTBEAT' in m.messages:
stamp = m.messages['HEARTBEAT']._timestamp
src_system = m.messages['HEARTBEAT'].get_srcSystem()
if stamp > best_timestamp:
best_link = i
best_timestamp = stamp
self.mpstate.settings.link = best_link + 1
print("Set vehicle %s (link %u)" % (args[0], best_link+1)) | python | def cmd_vehicle(self, args):
'''handle vehicle commands'''
if len(args) < 1:
print("Usage: vehicle SYSID[:COMPID]")
return
a = args[0].split(':')
self.mpstate.settings.target_system = int(a[0])
if len(a) > 1:
self.mpstate.settings.target_component = int(a[1])
# change default link based on most recent HEARTBEAT
best_link = 0
best_timestamp = 0
for i in range(len(self.mpstate.mav_master)):
m = self.mpstate.mav_master[i]
m.target_system = self.mpstate.settings.target_system
m.target_component = self.mpstate.settings.target_component
if 'HEARTBEAT' in m.messages:
stamp = m.messages['HEARTBEAT']._timestamp
src_system = m.messages['HEARTBEAT'].get_srcSystem()
if stamp > best_timestamp:
best_link = i
best_timestamp = stamp
self.mpstate.settings.link = best_link + 1
print("Set vehicle %s (link %u)" % (args[0], best_link+1)) | [
"def",
"cmd_vehicle",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"\"Usage: vehicle SYSID[:COMPID]\"",
")",
"return",
"a",
"=",
"args",
"[",
"0",
"]",
".",
"split",
"(",
"':'",
")",
"self",
".",
"... | handle vehicle commands | [
"handle",
"vehicle",
"commands"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_link.py#L635-L659 | train | 230,464 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_devop.py | DeviceOpModule.devop_read | def devop_read(self, args, bustype):
'''read from device'''
if len(args) < 5:
print("Usage: devop read <spi|i2c> name bus address regstart count")
return
name = args[0]
bus = int(args[1],base=0)
address = int(args[2],base=0)
reg = int(args[3],base=0)
count = int(args[4],base=0)
self.master.mav.device_op_read_send(self.target_system,
self.target_component,
self.request_id,
bustype,
bus,
address,
name,
reg,
count)
self.request_id += 1 | python | def devop_read(self, args, bustype):
'''read from device'''
if len(args) < 5:
print("Usage: devop read <spi|i2c> name bus address regstart count")
return
name = args[0]
bus = int(args[1],base=0)
address = int(args[2],base=0)
reg = int(args[3],base=0)
count = int(args[4],base=0)
self.master.mav.device_op_read_send(self.target_system,
self.target_component,
self.request_id,
bustype,
bus,
address,
name,
reg,
count)
self.request_id += 1 | [
"def",
"devop_read",
"(",
"self",
",",
"args",
",",
"bustype",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"5",
":",
"print",
"(",
"\"Usage: devop read <spi|i2c> name bus address regstart count\"",
")",
"return",
"name",
"=",
"args",
"[",
"0",
"]",
"bus",
... | read from device | [
"read",
"from",
"device"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_devop.py#L37-L56 | train | 230,465 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_devop.py | DeviceOpModule.devop_write | def devop_write(self, args, bustype):
'''write to a device'''
usage = "Usage: devop write <spi|i2c> name bus address regstart count <bytes>"
if len(args) < 5:
print(usage)
return
name = args[0]
bus = int(args[1],base=0)
address = int(args[2],base=0)
reg = int(args[3],base=0)
count = int(args[4],base=0)
args = args[5:]
if len(args) < count:
print(usage)
return
bytes = [0]*128
for i in range(count):
bytes[i] = int(args[i],base=0)
self.master.mav.device_op_write_send(self.target_system,
self.target_component,
self.request_id,
bustype,
bus,
address,
name,
reg,
count,
bytes)
self.request_id += 1 | python | def devop_write(self, args, bustype):
'''write to a device'''
usage = "Usage: devop write <spi|i2c> name bus address regstart count <bytes>"
if len(args) < 5:
print(usage)
return
name = args[0]
bus = int(args[1],base=0)
address = int(args[2],base=0)
reg = int(args[3],base=0)
count = int(args[4],base=0)
args = args[5:]
if len(args) < count:
print(usage)
return
bytes = [0]*128
for i in range(count):
bytes[i] = int(args[i],base=0)
self.master.mav.device_op_write_send(self.target_system,
self.target_component,
self.request_id,
bustype,
bus,
address,
name,
reg,
count,
bytes)
self.request_id += 1 | [
"def",
"devop_write",
"(",
"self",
",",
"args",
",",
"bustype",
")",
":",
"usage",
"=",
"\"Usage: devop write <spi|i2c> name bus address regstart count <bytes>\"",
"if",
"len",
"(",
"args",
")",
"<",
"5",
":",
"print",
"(",
"usage",
")",
"return",
"name",
"=",
... | write to a device | [
"write",
"to",
"a",
"device"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_devop.py#L58-L86 | train | 230,466 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/ANUGA/geo_reference.py | Geo_reference.get_absolute | def get_absolute(self, points):
"""Given a set of points geo referenced to this instance,
return the points as absolute values.
"""
# remember if we got a list
is_list = isinstance(points, list)
points = ensure_numeric(points, num.float)
if len(points.shape) == 1:
# One point has been passed
msg = 'Single point must have two elements'
if not len(points) == 2:
raise ValueError(msg)
msg = 'Input must be an N x 2 array or list of (x,y) values. '
msg += 'I got an %d x %d array' %points.shape
if not points.shape[1] == 2:
raise ValueError(msg)
# Add geo ref to points
if not self.is_absolute():
points = copy.copy(points) # Don't destroy input
points[:,0] += self.xllcorner
points[:,1] += self.yllcorner
if is_list:
points = points.tolist()
return points | python | def get_absolute(self, points):
"""Given a set of points geo referenced to this instance,
return the points as absolute values.
"""
# remember if we got a list
is_list = isinstance(points, list)
points = ensure_numeric(points, num.float)
if len(points.shape) == 1:
# One point has been passed
msg = 'Single point must have two elements'
if not len(points) == 2:
raise ValueError(msg)
msg = 'Input must be an N x 2 array or list of (x,y) values. '
msg += 'I got an %d x %d array' %points.shape
if not points.shape[1] == 2:
raise ValueError(msg)
# Add geo ref to points
if not self.is_absolute():
points = copy.copy(points) # Don't destroy input
points[:,0] += self.xllcorner
points[:,1] += self.yllcorner
if is_list:
points = points.tolist()
return points | [
"def",
"get_absolute",
"(",
"self",
",",
"points",
")",
":",
"# remember if we got a list",
"is_list",
"=",
"isinstance",
"(",
"points",
",",
"list",
")",
"points",
"=",
"ensure_numeric",
"(",
"points",
",",
"num",
".",
"float",
")",
"if",
"len",
"(",
"poi... | Given a set of points geo referenced to this instance,
return the points as absolute values. | [
"Given",
"a",
"set",
"of",
"points",
"geo",
"referenced",
"to",
"this",
"instance",
"return",
"the",
"points",
"as",
"absolute",
"values",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/ANUGA/geo_reference.py#L295-L327 | train | 230,467 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_cameraview.py | CameraViewModule.cmd_cameraview | def cmd_cameraview(self, args):
'''camera view commands'''
state = self
if args and args[0] == 'set':
if len(args) < 3:
state.view_settings.show_all()
else:
state.view_settings.set(args[1], args[2])
state.update_col()
else:
print('usage: cameraview set') | python | def cmd_cameraview(self, args):
'''camera view commands'''
state = self
if args and args[0] == 'set':
if len(args) < 3:
state.view_settings.show_all()
else:
state.view_settings.set(args[1], args[2])
state.update_col()
else:
print('usage: cameraview set') | [
"def",
"cmd_cameraview",
"(",
"self",
",",
"args",
")",
":",
"state",
"=",
"self",
"if",
"args",
"and",
"args",
"[",
"0",
"]",
"==",
"'set'",
":",
"if",
"len",
"(",
"args",
")",
"<",
"3",
":",
"state",
".",
"view_settings",
".",
"show_all",
"(",
... | camera view commands | [
"camera",
"view",
"commands"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_cameraview.py#L50-L60 | train | 230,468 |
ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_cameraview.py | CameraViewModule.scale_rc | def scale_rc(self, servo, min, max, param):
'''scale a PWM value'''
# default to servo range of 1000 to 2000
min_pwm = self.get_mav_param('%s_MIN' % param, 0)
max_pwm = self.get_mav_param('%s_MAX' % param, 0)
if min_pwm == 0 or max_pwm == 0:
return 0
if max_pwm == min_pwm:
p = 0.0
else:
p = (servo-min_pwm) / float(max_pwm-min_pwm)
v = min + p*(max-min)
if v < min:
v = min
if v > max:
v = max
return v | python | def scale_rc(self, servo, min, max, param):
'''scale a PWM value'''
# default to servo range of 1000 to 2000
min_pwm = self.get_mav_param('%s_MIN' % param, 0)
max_pwm = self.get_mav_param('%s_MAX' % param, 0)
if min_pwm == 0 or max_pwm == 0:
return 0
if max_pwm == min_pwm:
p = 0.0
else:
p = (servo-min_pwm) / float(max_pwm-min_pwm)
v = min + p*(max-min)
if v < min:
v = min
if v > max:
v = max
return v | [
"def",
"scale_rc",
"(",
"self",
",",
"servo",
",",
"min",
",",
"max",
",",
"param",
")",
":",
"# default to servo range of 1000 to 2000",
"min_pwm",
"=",
"self",
".",
"get_mav_param",
"(",
"'%s_MIN'",
"%",
"param",
",",
"0",
")",
"max_pwm",
"=",
"self",
".... | scale a PWM value | [
"scale",
"a",
"PWM",
"value"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_cameraview.py#L66-L82 | train | 230,469 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | raise_msg_to_str | def raise_msg_to_str(msg):
"""msg is a return arg from a raise. Join with new lines"""
if not is_string_like(msg):
msg = '\n'.join(map(str, msg))
return msg | python | def raise_msg_to_str(msg):
"""msg is a return arg from a raise. Join with new lines"""
if not is_string_like(msg):
msg = '\n'.join(map(str, msg))
return msg | [
"def",
"raise_msg_to_str",
"(",
"msg",
")",
":",
"if",
"not",
"is_string_like",
"(",
"msg",
")",
":",
"msg",
"=",
"'\\n'",
".",
"join",
"(",
"map",
"(",
"str",
",",
"msg",
")",
")",
"return",
"msg"
] | msg is a return arg from a raise. Join with new lines | [
"msg",
"is",
"a",
"return",
"arg",
"from",
"a",
"raise",
".",
"Join",
"with",
"new",
"lines"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L162-L166 | train | 230,470 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | _create_wx_app | def _create_wx_app():
"""
Creates a wx.App instance if it has not been created sofar.
"""
wxapp = wx.GetApp()
if wxapp is None:
wxapp = wx.App(False)
wxapp.SetExitOnFrameDelete(True)
# retain a reference to the app object so it does not get garbage
# collected and cause segmentation faults
_create_wx_app.theWxApp = wxapp | python | def _create_wx_app():
"""
Creates a wx.App instance if it has not been created sofar.
"""
wxapp = wx.GetApp()
if wxapp is None:
wxapp = wx.App(False)
wxapp.SetExitOnFrameDelete(True)
# retain a reference to the app object so it does not get garbage
# collected and cause segmentation faults
_create_wx_app.theWxApp = wxapp | [
"def",
"_create_wx_app",
"(",
")",
":",
"wxapp",
"=",
"wx",
".",
"GetApp",
"(",
")",
"if",
"wxapp",
"is",
"None",
":",
"wxapp",
"=",
"wx",
".",
"App",
"(",
"False",
")",
"wxapp",
".",
"SetExitOnFrameDelete",
"(",
"True",
")",
"# retain a reference to the... | Creates a wx.App instance if it has not been created sofar. | [
"Creates",
"a",
"wx",
".",
"App",
"instance",
"if",
"it",
"has",
"not",
"been",
"created",
"sofar",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1241-L1251 | train | 230,471 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | draw_if_interactive | def draw_if_interactive():
"""
This should be overriden in a windowing environment if drawing
should be done in interactive python mode
"""
DEBUG_MSG("draw_if_interactive()", 1, None)
if matplotlib.is_interactive():
figManager = Gcf.get_active()
if figManager is not None:
figManager.canvas.draw_idle() | python | def draw_if_interactive():
"""
This should be overriden in a windowing environment if drawing
should be done in interactive python mode
"""
DEBUG_MSG("draw_if_interactive()", 1, None)
if matplotlib.is_interactive():
figManager = Gcf.get_active()
if figManager is not None:
figManager.canvas.draw_idle() | [
"def",
"draw_if_interactive",
"(",
")",
":",
"DEBUG_MSG",
"(",
"\"draw_if_interactive()\"",
",",
"1",
",",
"None",
")",
"if",
"matplotlib",
".",
"is_interactive",
"(",
")",
":",
"figManager",
"=",
"Gcf",
".",
"get_active",
"(",
")",
"if",
"figManager",
"is",... | This should be overriden in a windowing environment if drawing
should be done in interactive python mode | [
"This",
"should",
"be",
"overriden",
"in",
"a",
"windowing",
"environment",
"if",
"drawing",
"should",
"be",
"done",
"in",
"interactive",
"python",
"mode"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1254-L1265 | train | 230,472 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | RendererWx.new_gc | def new_gc(self):
"""
Return an instance of a GraphicsContextWx, and sets the current gc copy
"""
DEBUG_MSG('new_gc()', 2, self)
self.gc = GraphicsContextWx(self.bitmap, self)
self.gc.select()
self.gc.unselect()
return self.gc | python | def new_gc(self):
"""
Return an instance of a GraphicsContextWx, and sets the current gc copy
"""
DEBUG_MSG('new_gc()', 2, self)
self.gc = GraphicsContextWx(self.bitmap, self)
self.gc.select()
self.gc.unselect()
return self.gc | [
"def",
"new_gc",
"(",
"self",
")",
":",
"DEBUG_MSG",
"(",
"'new_gc()'",
",",
"2",
",",
"self",
")",
"self",
".",
"gc",
"=",
"GraphicsContextWx",
"(",
"self",
".",
"bitmap",
",",
"self",
")",
"self",
".",
"gc",
".",
"select",
"(",
")",
"self",
".",
... | Return an instance of a GraphicsContextWx, and sets the current gc copy | [
"Return",
"an",
"instance",
"of",
"a",
"GraphicsContextWx",
"and",
"sets",
"the",
"current",
"gc",
"copy"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L392-L400 | train | 230,473 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | RendererWx.get_wx_font | def get_wx_font(self, s, prop):
"""
Return a wx font. Cache instances in a font dictionary for
efficiency
"""
DEBUG_MSG("get_wx_font()", 1, self)
key = hash(prop)
fontprop = prop
fontname = fontprop.get_name()
font = self.fontd.get(key)
if font is not None:
return font
# Allow use of platform independent and dependent font names
wxFontname = self.fontnames.get(fontname, wx.ROMAN)
wxFacename = '' # Empty => wxPython chooses based on wx_fontname
# Font colour is determined by the active wx.Pen
# TODO: It may be wise to cache font information
size = self.points_to_pixels(fontprop.get_size_in_points())
font =wx.Font(int(size+0.5), # Size
wxFontname, # 'Generic' name
self.fontangles[fontprop.get_style()], # Angle
self.fontweights[fontprop.get_weight()], # Weight
False, # Underline
wxFacename) # Platform font name
# cache the font and gc and return it
self.fontd[key] = font
return font | python | def get_wx_font(self, s, prop):
"""
Return a wx font. Cache instances in a font dictionary for
efficiency
"""
DEBUG_MSG("get_wx_font()", 1, self)
key = hash(prop)
fontprop = prop
fontname = fontprop.get_name()
font = self.fontd.get(key)
if font is not None:
return font
# Allow use of platform independent and dependent font names
wxFontname = self.fontnames.get(fontname, wx.ROMAN)
wxFacename = '' # Empty => wxPython chooses based on wx_fontname
# Font colour is determined by the active wx.Pen
# TODO: It may be wise to cache font information
size = self.points_to_pixels(fontprop.get_size_in_points())
font =wx.Font(int(size+0.5), # Size
wxFontname, # 'Generic' name
self.fontangles[fontprop.get_style()], # Angle
self.fontweights[fontprop.get_weight()], # Weight
False, # Underline
wxFacename) # Platform font name
# cache the font and gc and return it
self.fontd[key] = font
return font | [
"def",
"get_wx_font",
"(",
"self",
",",
"s",
",",
"prop",
")",
":",
"DEBUG_MSG",
"(",
"\"get_wx_font()\"",
",",
"1",
",",
"self",
")",
"key",
"=",
"hash",
"(",
"prop",
")",
"fontprop",
"=",
"prop",
"fontname",
"=",
"fontprop",
".",
"get_name",
"(",
"... | Return a wx font. Cache instances in a font dictionary for
efficiency | [
"Return",
"a",
"wx",
"font",
".",
"Cache",
"instances",
"in",
"a",
"font",
"dictionary",
"for",
"efficiency"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L411-L446 | train | 230,474 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | GraphicsContextWx.select | def select(self):
"""
Select the current bitmap into this wxDC instance
"""
if sys.platform=='win32':
self.dc.SelectObject(self.bitmap)
self.IsSelected = True | python | def select(self):
"""
Select the current bitmap into this wxDC instance
"""
if sys.platform=='win32':
self.dc.SelectObject(self.bitmap)
self.IsSelected = True | [
"def",
"select",
"(",
"self",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"self",
".",
"dc",
".",
"SelectObject",
"(",
"self",
".",
"bitmap",
")",
"self",
".",
"IsSelected",
"=",
"True"
] | Select the current bitmap into this wxDC instance | [
"Select",
"the",
"current",
"bitmap",
"into",
"this",
"wxDC",
"instance"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L505-L512 | train | 230,475 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | GraphicsContextWx.unselect | def unselect(self):
"""
Select a Null bitmasp into this wxDC instance
"""
if sys.platform=='win32':
self.dc.SelectObject(wx.NullBitmap)
self.IsSelected = False | python | def unselect(self):
"""
Select a Null bitmasp into this wxDC instance
"""
if sys.platform=='win32':
self.dc.SelectObject(wx.NullBitmap)
self.IsSelected = False | [
"def",
"unselect",
"(",
"self",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"self",
".",
"dc",
".",
"SelectObject",
"(",
"wx",
".",
"NullBitmap",
")",
"self",
".",
"IsSelected",
"=",
"False"
] | Select a Null bitmasp into this wxDC instance | [
"Select",
"a",
"Null",
"bitmasp",
"into",
"this",
"wxDC",
"instance"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L514-L520 | train | 230,476 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | GraphicsContextWx.set_linewidth | def set_linewidth(self, w):
"""
Set the line width.
"""
DEBUG_MSG("set_linewidth()", 1, self)
self.select()
if w>0 and w<1: w = 1
GraphicsContextBase.set_linewidth(self, w)
lw = int(self.renderer.points_to_pixels(self._linewidth))
if lw==0: lw = 1
self._pen.SetWidth(lw)
self.gfx_ctx.SetPen(self._pen)
self.unselect() | python | def set_linewidth(self, w):
"""
Set the line width.
"""
DEBUG_MSG("set_linewidth()", 1, self)
self.select()
if w>0 and w<1: w = 1
GraphicsContextBase.set_linewidth(self, w)
lw = int(self.renderer.points_to_pixels(self._linewidth))
if lw==0: lw = 1
self._pen.SetWidth(lw)
self.gfx_ctx.SetPen(self._pen)
self.unselect() | [
"def",
"set_linewidth",
"(",
"self",
",",
"w",
")",
":",
"DEBUG_MSG",
"(",
"\"set_linewidth()\"",
",",
"1",
",",
"self",
")",
"self",
".",
"select",
"(",
")",
"if",
"w",
">",
"0",
"and",
"w",
"<",
"1",
":",
"w",
"=",
"1",
"GraphicsContextBase",
"."... | Set the line width. | [
"Set",
"the",
"line",
"width",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L554-L566 | train | 230,477 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | GraphicsContextWx.set_linestyle | def set_linestyle(self, ls):
"""
Set the line style to be one of
"""
DEBUG_MSG("set_linestyle()", 1, self)
self.select()
GraphicsContextBase.set_linestyle(self, ls)
try:
self._style = GraphicsContextWx._dashd_wx[ls]
except KeyError:
self._style = wx.LONG_DASH# Style not used elsewhere...
# On MS Windows platform, only line width of 1 allowed for dash lines
if wx.Platform == '__WXMSW__':
self.set_linewidth(1)
self._pen.SetStyle(self._style)
self.gfx_ctx.SetPen(self._pen)
self.unselect() | python | def set_linestyle(self, ls):
"""
Set the line style to be one of
"""
DEBUG_MSG("set_linestyle()", 1, self)
self.select()
GraphicsContextBase.set_linestyle(self, ls)
try:
self._style = GraphicsContextWx._dashd_wx[ls]
except KeyError:
self._style = wx.LONG_DASH# Style not used elsewhere...
# On MS Windows platform, only line width of 1 allowed for dash lines
if wx.Platform == '__WXMSW__':
self.set_linewidth(1)
self._pen.SetStyle(self._style)
self.gfx_ctx.SetPen(self._pen)
self.unselect() | [
"def",
"set_linestyle",
"(",
"self",
",",
"ls",
")",
":",
"DEBUG_MSG",
"(",
"\"set_linestyle()\"",
",",
"1",
",",
"self",
")",
"self",
".",
"select",
"(",
")",
"GraphicsContextBase",
".",
"set_linestyle",
"(",
"self",
",",
"ls",
")",
"try",
":",
"self",
... | Set the line style to be one of | [
"Set",
"the",
"line",
"style",
"to",
"be",
"one",
"of"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L590-L608 | train | 230,478 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | GraphicsContextWx.get_wxcolour | def get_wxcolour(self, color):
"""return a wx.Colour from RGB format"""
DEBUG_MSG("get_wx_color()", 1, self)
if len(color) == 3:
r, g, b = color
r *= 255
g *= 255
b *= 255
return wx.Colour(red=int(r), green=int(g), blue=int(b))
else:
r, g, b, a = color
r *= 255
g *= 255
b *= 255
a *= 255
return wx.Colour(red=int(r), green=int(g), blue=int(b), alpha=int(a)) | python | def get_wxcolour(self, color):
"""return a wx.Colour from RGB format"""
DEBUG_MSG("get_wx_color()", 1, self)
if len(color) == 3:
r, g, b = color
r *= 255
g *= 255
b *= 255
return wx.Colour(red=int(r), green=int(g), blue=int(b))
else:
r, g, b, a = color
r *= 255
g *= 255
b *= 255
a *= 255
return wx.Colour(red=int(r), green=int(g), blue=int(b), alpha=int(a)) | [
"def",
"get_wxcolour",
"(",
"self",
",",
"color",
")",
":",
"DEBUG_MSG",
"(",
"\"get_wx_color()\"",
",",
"1",
",",
"self",
")",
"if",
"len",
"(",
"color",
")",
"==",
"3",
":",
"r",
",",
"g",
",",
"b",
"=",
"color",
"r",
"*=",
"255",
"g",
"*=",
... | return a wx.Colour from RGB format | [
"return",
"a",
"wx",
".",
"Colour",
"from",
"RGB",
"format"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L610-L625 | train | 230,479 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx.Copy_to_Clipboard | def Copy_to_Clipboard(self, event=None):
"copy bitmap of canvas to system clipboard"
bmp_obj = wx.BitmapDataObject()
bmp_obj.SetBitmap(self.bitmap)
if not wx.TheClipboard.IsOpened():
open_success = wx.TheClipboard.Open()
if open_success:
wx.TheClipboard.SetData(bmp_obj)
wx.TheClipboard.Close()
wx.TheClipboard.Flush() | python | def Copy_to_Clipboard(self, event=None):
"copy bitmap of canvas to system clipboard"
bmp_obj = wx.BitmapDataObject()
bmp_obj.SetBitmap(self.bitmap)
if not wx.TheClipboard.IsOpened():
open_success = wx.TheClipboard.Open()
if open_success:
wx.TheClipboard.SetData(bmp_obj)
wx.TheClipboard.Close()
wx.TheClipboard.Flush() | [
"def",
"Copy_to_Clipboard",
"(",
"self",
",",
"event",
"=",
"None",
")",
":",
"bmp_obj",
"=",
"wx",
".",
"BitmapDataObject",
"(",
")",
"bmp_obj",
".",
"SetBitmap",
"(",
"self",
".",
"bitmap",
")",
"if",
"not",
"wx",
".",
"TheClipboard",
".",
"IsOpened",
... | copy bitmap of canvas to system clipboard | [
"copy",
"bitmap",
"of",
"canvas",
"to",
"system",
"clipboard"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L776-L786 | train | 230,480 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx.draw_idle | def draw_idle(self):
"""
Delay rendering until the GUI is idle.
"""
DEBUG_MSG("draw_idle()", 1, self)
self._isDrawn = False # Force redraw
# Create a timer for handling draw_idle requests
# If there are events pending when the timer is
# complete, reset the timer and continue. The
# alternative approach, binding to wx.EVT_IDLE,
# doesn't behave as nicely.
if hasattr(self,'_idletimer'):
self._idletimer.Restart(IDLE_DELAY)
else:
self._idletimer = wx.FutureCall(IDLE_DELAY,self._onDrawIdle) | python | def draw_idle(self):
"""
Delay rendering until the GUI is idle.
"""
DEBUG_MSG("draw_idle()", 1, self)
self._isDrawn = False # Force redraw
# Create a timer for handling draw_idle requests
# If there are events pending when the timer is
# complete, reset the timer and continue. The
# alternative approach, binding to wx.EVT_IDLE,
# doesn't behave as nicely.
if hasattr(self,'_idletimer'):
self._idletimer.Restart(IDLE_DELAY)
else:
self._idletimer = wx.FutureCall(IDLE_DELAY,self._onDrawIdle) | [
"def",
"draw_idle",
"(",
"self",
")",
":",
"DEBUG_MSG",
"(",
"\"draw_idle()\"",
",",
"1",
",",
"self",
")",
"self",
".",
"_isDrawn",
"=",
"False",
"# Force redraw",
"# Create a timer for handling draw_idle requests",
"# If there are events pending when the timer is",
"# c... | Delay rendering until the GUI is idle. | [
"Delay",
"rendering",
"until",
"the",
"GUI",
"is",
"idle",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L788-L802 | train | 230,481 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx.draw | def draw(self, drawDC=None):
"""
Render the figure using RendererWx instance renderer, or using a
previously defined renderer if none is specified.
"""
DEBUG_MSG("draw()", 1, self)
self.renderer = RendererWx(self.bitmap, self.figure.dpi)
self.figure.draw(self.renderer)
self._isDrawn = True
self.gui_repaint(drawDC=drawDC) | python | def draw(self, drawDC=None):
"""
Render the figure using RendererWx instance renderer, or using a
previously defined renderer if none is specified.
"""
DEBUG_MSG("draw()", 1, self)
self.renderer = RendererWx(self.bitmap, self.figure.dpi)
self.figure.draw(self.renderer)
self._isDrawn = True
self.gui_repaint(drawDC=drawDC) | [
"def",
"draw",
"(",
"self",
",",
"drawDC",
"=",
"None",
")",
":",
"DEBUG_MSG",
"(",
"\"draw()\"",
",",
"1",
",",
"self",
")",
"self",
".",
"renderer",
"=",
"RendererWx",
"(",
"self",
".",
"bitmap",
",",
"self",
".",
"figure",
".",
"dpi",
")",
"self... | Render the figure using RendererWx instance renderer, or using a
previously defined renderer if none is specified. | [
"Render",
"the",
"figure",
"using",
"RendererWx",
"instance",
"renderer",
"or",
"using",
"a",
"previously",
"defined",
"renderer",
"if",
"none",
"is",
"specified",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L816-L825 | train | 230,482 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx.start_event_loop | def start_event_loop(self, timeout=0):
"""
Start an event loop. This is used to start a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events. This should not be
confused with the main GUI event loop, which is always running
and has nothing to do with this.
Call signature::
start_event_loop(self,timeout=0)
This call blocks until a callback function triggers
stop_event_loop() or *timeout* is reached. If *timeout* is
<=0, never timeout.
Raises RuntimeError if event loop is already running.
"""
if hasattr(self, '_event_loop'):
raise RuntimeError("Event loop already running")
id = wx.NewId()
timer = wx.Timer(self, id=id)
if timeout > 0:
timer.Start(timeout*1000, oneShot=True)
bind(self, wx.EVT_TIMER, self.stop_event_loop, id=id)
# Event loop handler for start/stop event loop
self._event_loop = wx.EventLoop()
self._event_loop.Run()
timer.Stop() | python | def start_event_loop(self, timeout=0):
"""
Start an event loop. This is used to start a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events. This should not be
confused with the main GUI event loop, which is always running
and has nothing to do with this.
Call signature::
start_event_loop(self,timeout=0)
This call blocks until a callback function triggers
stop_event_loop() or *timeout* is reached. If *timeout* is
<=0, never timeout.
Raises RuntimeError if event loop is already running.
"""
if hasattr(self, '_event_loop'):
raise RuntimeError("Event loop already running")
id = wx.NewId()
timer = wx.Timer(self, id=id)
if timeout > 0:
timer.Start(timeout*1000, oneShot=True)
bind(self, wx.EVT_TIMER, self.stop_event_loop, id=id)
# Event loop handler for start/stop event loop
self._event_loop = wx.EventLoop()
self._event_loop.Run()
timer.Stop() | [
"def",
"start_event_loop",
"(",
"self",
",",
"timeout",
"=",
"0",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_event_loop'",
")",
":",
"raise",
"RuntimeError",
"(",
"\"Event loop already running\"",
")",
"id",
"=",
"wx",
".",
"NewId",
"(",
")",
"timer",... | Start an event loop. This is used to start a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events. This should not be
confused with the main GUI event loop, which is always running
and has nothing to do with this.
Call signature::
start_event_loop(self,timeout=0)
This call blocks until a callback function triggers
stop_event_loop() or *timeout* is reached. If *timeout* is
<=0, never timeout.
Raises RuntimeError if event loop is already running. | [
"Start",
"an",
"event",
"loop",
".",
"This",
"is",
"used",
"to",
"start",
"a",
"blocking",
"event",
"loop",
"so",
"that",
"interactive",
"functions",
"such",
"as",
"ginput",
"and",
"waitforbuttonpress",
"can",
"wait",
"for",
"events",
".",
"This",
"should",
... | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L846-L875 | train | 230,483 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx.stop_event_loop | def stop_event_loop(self, event=None):
"""
Stop an event loop. This is used to stop a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events.
Call signature::
stop_event_loop_default(self)
"""
if hasattr(self,'_event_loop'):
if self._event_loop.IsRunning():
self._event_loop.Exit()
del self._event_loop | python | def stop_event_loop(self, event=None):
"""
Stop an event loop. This is used to stop a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events.
Call signature::
stop_event_loop_default(self)
"""
if hasattr(self,'_event_loop'):
if self._event_loop.IsRunning():
self._event_loop.Exit()
del self._event_loop | [
"def",
"stop_event_loop",
"(",
"self",
",",
"event",
"=",
"None",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'_event_loop'",
")",
":",
"if",
"self",
".",
"_event_loop",
".",
"IsRunning",
"(",
")",
":",
"self",
".",
"_event_loop",
".",
"Exit",
"(",
... | Stop an event loop. This is used to stop a blocking event
loop so that interactive functions, such as ginput and
waitforbuttonpress, can wait for events.
Call signature::
stop_event_loop_default(self) | [
"Stop",
"an",
"event",
"loop",
".",
"This",
"is",
"used",
"to",
"stop",
"a",
"blocking",
"event",
"loop",
"so",
"that",
"interactive",
"functions",
"such",
"as",
"ginput",
"and",
"waitforbuttonpress",
"can",
"wait",
"for",
"events",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L877-L890 | train | 230,484 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._get_imagesave_wildcards | def _get_imagesave_wildcards(self):
'return the wildcard string for the filesave dialog'
default_filetype = self.get_default_filetype()
filetypes = self.get_supported_filetypes_grouped()
sorted_filetypes = filetypes.items()
sorted_filetypes.sort()
wildcards = []
extensions = []
filter_index = 0
for i, (name, exts) in enumerate(sorted_filetypes):
ext_list = ';'.join(['*.%s' % ext for ext in exts])
extensions.append(exts[0])
wildcard = '%s (%s)|%s' % (name, ext_list, ext_list)
if default_filetype in exts:
filter_index = i
wildcards.append(wildcard)
wildcards = '|'.join(wildcards)
return wildcards, extensions, filter_index | python | def _get_imagesave_wildcards(self):
'return the wildcard string for the filesave dialog'
default_filetype = self.get_default_filetype()
filetypes = self.get_supported_filetypes_grouped()
sorted_filetypes = filetypes.items()
sorted_filetypes.sort()
wildcards = []
extensions = []
filter_index = 0
for i, (name, exts) in enumerate(sorted_filetypes):
ext_list = ';'.join(['*.%s' % ext for ext in exts])
extensions.append(exts[0])
wildcard = '%s (%s)|%s' % (name, ext_list, ext_list)
if default_filetype in exts:
filter_index = i
wildcards.append(wildcard)
wildcards = '|'.join(wildcards)
return wildcards, extensions, filter_index | [
"def",
"_get_imagesave_wildcards",
"(",
"self",
")",
":",
"default_filetype",
"=",
"self",
".",
"get_default_filetype",
"(",
")",
"filetypes",
"=",
"self",
".",
"get_supported_filetypes_grouped",
"(",
")",
"sorted_filetypes",
"=",
"filetypes",
".",
"items",
"(",
"... | return the wildcard string for the filesave dialog | [
"return",
"the",
"wildcard",
"string",
"for",
"the",
"filesave",
"dialog"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L893-L910 | train | 230,485 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx.gui_repaint | def gui_repaint(self, drawDC=None):
"""
Performs update of the displayed image on the GUI canvas, using the
supplied device context. If drawDC is None, a ClientDC will be used to
redraw the image.
"""
DEBUG_MSG("gui_repaint()", 1, self)
if self.IsShownOnScreen():
if drawDC is None:
drawDC=wx.ClientDC(self)
#drawDC.BeginDrawing()
drawDC.DrawBitmap(self.bitmap, 0, 0)
#drawDC.EndDrawing()
#wx.GetApp().Yield()
else:
pass | python | def gui_repaint(self, drawDC=None):
"""
Performs update of the displayed image on the GUI canvas, using the
supplied device context. If drawDC is None, a ClientDC will be used to
redraw the image.
"""
DEBUG_MSG("gui_repaint()", 1, self)
if self.IsShownOnScreen():
if drawDC is None:
drawDC=wx.ClientDC(self)
#drawDC.BeginDrawing()
drawDC.DrawBitmap(self.bitmap, 0, 0)
#drawDC.EndDrawing()
#wx.GetApp().Yield()
else:
pass | [
"def",
"gui_repaint",
"(",
"self",
",",
"drawDC",
"=",
"None",
")",
":",
"DEBUG_MSG",
"(",
"\"gui_repaint()\"",
",",
"1",
",",
"self",
")",
"if",
"self",
".",
"IsShownOnScreen",
"(",
")",
":",
"if",
"drawDC",
"is",
"None",
":",
"drawDC",
"=",
"wx",
"... | Performs update of the displayed image on the GUI canvas, using the
supplied device context. If drawDC is None, a ClientDC will be used to
redraw the image. | [
"Performs",
"update",
"of",
"the",
"displayed",
"image",
"on",
"the",
"GUI",
"canvas",
"using",
"the",
"supplied",
"device",
"context",
".",
"If",
"drawDC",
"is",
"None",
"a",
"ClientDC",
"will",
"be",
"used",
"to",
"redraw",
"the",
"image",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L912-L928 | train | 230,486 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onPaint | def _onPaint(self, evt):
"""
Called when wxPaintEvt is generated
"""
DEBUG_MSG("_onPaint()", 1, self)
drawDC = wx.PaintDC(self)
if not self._isDrawn:
self.draw(drawDC=drawDC)
else:
self.gui_repaint(drawDC=drawDC)
evt.Skip() | python | def _onPaint(self, evt):
"""
Called when wxPaintEvt is generated
"""
DEBUG_MSG("_onPaint()", 1, self)
drawDC = wx.PaintDC(self)
if not self._isDrawn:
self.draw(drawDC=drawDC)
else:
self.gui_repaint(drawDC=drawDC)
evt.Skip() | [
"def",
"_onPaint",
"(",
"self",
",",
"evt",
")",
":",
"DEBUG_MSG",
"(",
"\"_onPaint()\"",
",",
"1",
",",
"self",
")",
"drawDC",
"=",
"wx",
".",
"PaintDC",
"(",
"self",
")",
"if",
"not",
"self",
".",
"_isDrawn",
":",
"self",
".",
"draw",
"(",
"drawD... | Called when wxPaintEvt is generated | [
"Called",
"when",
"wxPaintEvt",
"is",
"generated"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1021-L1032 | train | 230,487 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onSize | def _onSize(self, evt):
"""
Called when wxEventSize is generated.
In this application we attempt to resize to fit the window, so it
is better to take the performance hit and redraw the whole window.
"""
DEBUG_MSG("_onSize()", 2, self)
# Create a new, correctly sized bitmap
self._width, self._height = self.GetClientSize()
self.bitmap =wx.EmptyBitmap(self._width, self._height)
self._isDrawn = False
if self._width <= 1 or self._height <= 1: return # Empty figure
dpival = self.figure.dpi
winch = self._width/dpival
hinch = self._height/dpival
self.figure.set_size_inches(winch, hinch)
# Rendering will happen on the associated paint event
# so no need to do anything here except to make sure
# the whole background is repainted.
self.Refresh(eraseBackground=False)
FigureCanvasBase.resize_event(self) | python | def _onSize(self, evt):
"""
Called when wxEventSize is generated.
In this application we attempt to resize to fit the window, so it
is better to take the performance hit and redraw the whole window.
"""
DEBUG_MSG("_onSize()", 2, self)
# Create a new, correctly sized bitmap
self._width, self._height = self.GetClientSize()
self.bitmap =wx.EmptyBitmap(self._width, self._height)
self._isDrawn = False
if self._width <= 1 or self._height <= 1: return # Empty figure
dpival = self.figure.dpi
winch = self._width/dpival
hinch = self._height/dpival
self.figure.set_size_inches(winch, hinch)
# Rendering will happen on the associated paint event
# so no need to do anything here except to make sure
# the whole background is repainted.
self.Refresh(eraseBackground=False)
FigureCanvasBase.resize_event(self) | [
"def",
"_onSize",
"(",
"self",
",",
"evt",
")",
":",
"DEBUG_MSG",
"(",
"\"_onSize()\"",
",",
"2",
",",
"self",
")",
"# Create a new, correctly sized bitmap",
"self",
".",
"_width",
",",
"self",
".",
"_height",
"=",
"self",
".",
"GetClientSize",
"(",
")",
"... | Called when wxEventSize is generated.
In this application we attempt to resize to fit the window, so it
is better to take the performance hit and redraw the whole window. | [
"Called",
"when",
"wxEventSize",
"is",
"generated",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1041-L1066 | train | 230,488 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onIdle | def _onIdle(self, evt):
'a GUI idle event'
evt.Skip()
FigureCanvasBase.idle_event(self, guiEvent=evt) | python | def _onIdle(self, evt):
'a GUI idle event'
evt.Skip()
FigureCanvasBase.idle_event(self, guiEvent=evt) | [
"def",
"_onIdle",
"(",
"self",
",",
"evt",
")",
":",
"evt",
".",
"Skip",
"(",
")",
"FigureCanvasBase",
".",
"idle_event",
"(",
"self",
",",
"guiEvent",
"=",
"evt",
")"
] | a GUI idle event | [
"a",
"GUI",
"idle",
"event"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1090-L1093 | train | 230,489 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onKeyDown | def _onKeyDown(self, evt):
"""Capture key press."""
key = self._get_key(evt)
evt.Skip()
FigureCanvasBase.key_press_event(self, key, guiEvent=evt) | python | def _onKeyDown(self, evt):
"""Capture key press."""
key = self._get_key(evt)
evt.Skip()
FigureCanvasBase.key_press_event(self, key, guiEvent=evt) | [
"def",
"_onKeyDown",
"(",
"self",
",",
"evt",
")",
":",
"key",
"=",
"self",
".",
"_get_key",
"(",
"evt",
")",
"evt",
".",
"Skip",
"(",
")",
"FigureCanvasBase",
".",
"key_press_event",
"(",
"self",
",",
"key",
",",
"guiEvent",
"=",
"evt",
")"
] | Capture key press. | [
"Capture",
"key",
"press",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1095-L1099 | train | 230,490 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onKeyUp | def _onKeyUp(self, evt):
"""Release key."""
key = self._get_key(evt)
#print 'release key', key
evt.Skip()
FigureCanvasBase.key_release_event(self, key, guiEvent=evt) | python | def _onKeyUp(self, evt):
"""Release key."""
key = self._get_key(evt)
#print 'release key', key
evt.Skip()
FigureCanvasBase.key_release_event(self, key, guiEvent=evt) | [
"def",
"_onKeyUp",
"(",
"self",
",",
"evt",
")",
":",
"key",
"=",
"self",
".",
"_get_key",
"(",
"evt",
")",
"#print 'release key', key",
"evt",
".",
"Skip",
"(",
")",
"FigureCanvasBase",
".",
"key_release_event",
"(",
"self",
",",
"key",
",",
"guiEvent",
... | Release key. | [
"Release",
"key",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1101-L1106 | train | 230,491 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onLeftButtonUp | def _onLeftButtonUp(self, evt):
"""End measuring on an axis."""
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
#print 'release button', 1
evt.Skip()
if self.HasCapture(): self.ReleaseMouse()
FigureCanvasBase.button_release_event(self, x, y, 1, guiEvent=evt) | python | def _onLeftButtonUp(self, evt):
"""End measuring on an axis."""
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
#print 'release button', 1
evt.Skip()
if self.HasCapture(): self.ReleaseMouse()
FigureCanvasBase.button_release_event(self, x, y, 1, guiEvent=evt) | [
"def",
"_onLeftButtonUp",
"(",
"self",
",",
"evt",
")",
":",
"x",
"=",
"evt",
".",
"GetX",
"(",
")",
"y",
"=",
"self",
".",
"figure",
".",
"bbox",
".",
"height",
"-",
"evt",
".",
"GetY",
"(",
")",
"#print 'release button', 1",
"evt",
".",
"Skip",
"... | End measuring on an axis. | [
"End",
"measuring",
"on",
"an",
"axis",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1148-L1155 | train | 230,492 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onMouseWheel | def _onMouseWheel(self, evt):
"""Translate mouse wheel events into matplotlib events"""
# Determine mouse location
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
# Convert delta/rotation/rate into a floating point step size
delta = evt.GetWheelDelta()
rotation = evt.GetWheelRotation()
rate = evt.GetLinesPerAction()
#print "delta,rotation,rate",delta,rotation,rate
step = rate*float(rotation)/delta
# Done handling event
evt.Skip()
# Mac is giving two events for every wheel event
# Need to skip every second one
if wx.Platform == '__WXMAC__':
if not hasattr(self,'_skipwheelevent'):
self._skipwheelevent = True
elif self._skipwheelevent:
self._skipwheelevent = False
return # Return without processing event
else:
self._skipwheelevent = True
# Convert to mpl event
FigureCanvasBase.scroll_event(self, x, y, step, guiEvent=evt) | python | def _onMouseWheel(self, evt):
"""Translate mouse wheel events into matplotlib events"""
# Determine mouse location
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
# Convert delta/rotation/rate into a floating point step size
delta = evt.GetWheelDelta()
rotation = evt.GetWheelRotation()
rate = evt.GetLinesPerAction()
#print "delta,rotation,rate",delta,rotation,rate
step = rate*float(rotation)/delta
# Done handling event
evt.Skip()
# Mac is giving two events for every wheel event
# Need to skip every second one
if wx.Platform == '__WXMAC__':
if not hasattr(self,'_skipwheelevent'):
self._skipwheelevent = True
elif self._skipwheelevent:
self._skipwheelevent = False
return # Return without processing event
else:
self._skipwheelevent = True
# Convert to mpl event
FigureCanvasBase.scroll_event(self, x, y, step, guiEvent=evt) | [
"def",
"_onMouseWheel",
"(",
"self",
",",
"evt",
")",
":",
"# Determine mouse location",
"x",
"=",
"evt",
".",
"GetX",
"(",
")",
"y",
"=",
"self",
".",
"figure",
".",
"bbox",
".",
"height",
"-",
"evt",
".",
"GetY",
"(",
")",
"# Convert delta/rotation/rat... | Translate mouse wheel events into matplotlib events | [
"Translate",
"mouse",
"wheel",
"events",
"into",
"matplotlib",
"events"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1183-L1212 | train | 230,493 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureCanvasWx._onLeave | def _onLeave(self, evt):
"""Mouse has left the window."""
evt.Skip()
FigureCanvasBase.leave_notify_event(self, guiEvent = evt) | python | def _onLeave(self, evt):
"""Mouse has left the window."""
evt.Skip()
FigureCanvasBase.leave_notify_event(self, guiEvent = evt) | [
"def",
"_onLeave",
"(",
"self",
",",
"evt",
")",
":",
"evt",
".",
"Skip",
"(",
")",
"FigureCanvasBase",
".",
"leave_notify_event",
"(",
"self",
",",
"guiEvent",
"=",
"evt",
")"
] | Mouse has left the window. | [
"Mouse",
"has",
"left",
"the",
"window",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1222-L1226 | train | 230,494 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | FigureManagerWx.resize | def resize(self, width, height):
'Set the canvas size in pixels'
self.canvas.SetInitialSize(wx.Size(width, height))
self.window.GetSizer().Fit(self.window) | python | def resize(self, width, height):
'Set the canvas size in pixels'
self.canvas.SetInitialSize(wx.Size(width, height))
self.window.GetSizer().Fit(self.window) | [
"def",
"resize",
"(",
"self",
",",
"width",
",",
"height",
")",
":",
"self",
".",
"canvas",
".",
"SetInitialSize",
"(",
"wx",
".",
"Size",
"(",
"width",
",",
"height",
")",
")",
"self",
".",
"window",
".",
"GetSizer",
"(",
")",
".",
"Fit",
"(",
"... | Set the canvas size in pixels | [
"Set",
"the",
"canvas",
"size",
"in",
"pixels"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1443-L1446 | train | 230,495 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | MenuButtonWx._onMenuButton | def _onMenuButton(self, evt):
"""Handle menu button pressed."""
x, y = self.GetPositionTuple()
w, h = self.GetSizeTuple()
self.PopupMenuXY(self._menu, x, y+h-4)
# When menu returned, indicate selection in button
evt.Skip() | python | def _onMenuButton(self, evt):
"""Handle menu button pressed."""
x, y = self.GetPositionTuple()
w, h = self.GetSizeTuple()
self.PopupMenuXY(self._menu, x, y+h-4)
# When menu returned, indicate selection in button
evt.Skip() | [
"def",
"_onMenuButton",
"(",
"self",
",",
"evt",
")",
":",
"x",
",",
"y",
"=",
"self",
".",
"GetPositionTuple",
"(",
")",
"w",
",",
"h",
"=",
"self",
".",
"GetSizeTuple",
"(",
")",
"self",
".",
"PopupMenuXY",
"(",
"self",
".",
"_menu",
",",
"x",
... | Handle menu button pressed. | [
"Handle",
"menu",
"button",
"pressed",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1513-L1519 | train | 230,496 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | MenuButtonWx._handleSelectAllAxes | def _handleSelectAllAxes(self, evt):
"""Called when the 'select all axes' menu item is selected."""
if len(self._axisId) == 0:
return
for i in range(len(self._axisId)):
self._menu.Check(self._axisId[i], True)
self._toolbar.set_active(self.getActiveAxes())
evt.Skip() | python | def _handleSelectAllAxes(self, evt):
"""Called when the 'select all axes' menu item is selected."""
if len(self._axisId) == 0:
return
for i in range(len(self._axisId)):
self._menu.Check(self._axisId[i], True)
self._toolbar.set_active(self.getActiveAxes())
evt.Skip() | [
"def",
"_handleSelectAllAxes",
"(",
"self",
",",
"evt",
")",
":",
"if",
"len",
"(",
"self",
".",
"_axisId",
")",
"==",
"0",
":",
"return",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"_axisId",
")",
")",
":",
"self",
".",
"_menu",
".... | Called when the 'select all axes' menu item is selected. | [
"Called",
"when",
"the",
"select",
"all",
"axes",
"menu",
"item",
"is",
"selected",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1521-L1528 | train | 230,497 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | MenuButtonWx._handleInvertAxesSelected | def _handleInvertAxesSelected(self, evt):
"""Called when the invert all menu item is selected"""
if len(self._axisId) == 0: return
for i in range(len(self._axisId)):
if self._menu.IsChecked(self._axisId[i]):
self._menu.Check(self._axisId[i], False)
else:
self._menu.Check(self._axisId[i], True)
self._toolbar.set_active(self.getActiveAxes())
evt.Skip() | python | def _handleInvertAxesSelected(self, evt):
"""Called when the invert all menu item is selected"""
if len(self._axisId) == 0: return
for i in range(len(self._axisId)):
if self._menu.IsChecked(self._axisId[i]):
self._menu.Check(self._axisId[i], False)
else:
self._menu.Check(self._axisId[i], True)
self._toolbar.set_active(self.getActiveAxes())
evt.Skip() | [
"def",
"_handleInvertAxesSelected",
"(",
"self",
",",
"evt",
")",
":",
"if",
"len",
"(",
"self",
".",
"_axisId",
")",
"==",
"0",
":",
"return",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"_axisId",
")",
")",
":",
"if",
"self",
".",
... | Called when the invert all menu item is selected | [
"Called",
"when",
"the",
"invert",
"all",
"menu",
"item",
"is",
"selected"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1530-L1539 | train | 230,498 |
ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_wx.py | MenuButtonWx._onMenuItemSelected | def _onMenuItemSelected(self, evt):
"""Called whenever one of the specific axis menu items is selected"""
current = self._menu.IsChecked(evt.GetId())
if current:
new = False
else:
new = True
self._menu.Check(evt.GetId(), new)
# Lines above would be deleted based on svn tracker ID 2841525;
# not clear whether this matters or not.
self._toolbar.set_active(self.getActiveAxes())
evt.Skip() | python | def _onMenuItemSelected(self, evt):
"""Called whenever one of the specific axis menu items is selected"""
current = self._menu.IsChecked(evt.GetId())
if current:
new = False
else:
new = True
self._menu.Check(evt.GetId(), new)
# Lines above would be deleted based on svn tracker ID 2841525;
# not clear whether this matters or not.
self._toolbar.set_active(self.getActiveAxes())
evt.Skip() | [
"def",
"_onMenuItemSelected",
"(",
"self",
",",
"evt",
")",
":",
"current",
"=",
"self",
".",
"_menu",
".",
"IsChecked",
"(",
"evt",
".",
"GetId",
"(",
")",
")",
"if",
"current",
":",
"new",
"=",
"False",
"else",
":",
"new",
"=",
"True",
"self",
".... | Called whenever one of the specific axis menu items is selected | [
"Called",
"whenever",
"one",
"of",
"the",
"specific",
"axis",
"menu",
"items",
"is",
"selected"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_wx.py#L1541-L1552 | train | 230,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.