idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
229,500 | def handle_menu_event ( self , obj ) : 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 ( ) | handle a popup menu event from the map | 454 | 8 |
229,501 | def map_callback ( self , obj ) : 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 ( ) | called when an event happens on the slipmap | 579 | 9 |
229,502 | 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 ) self . draw_callback = None self . map . add_object ( mp_slipmap . SlipDefaultPopup ( self . default_popup , combine = True ) ) self . map . add_object ( mp_slipmap . SlipClearLayer ( 'Drawing' ) ) | end line drawing | 110 | 3 |
229,503 | def draw_lines ( self , callback ) : from MAVProxy . modules . mavproxy_map import mp_slipmap self . draw_callback = callback self . draw_line = [ ] self . map . add_object ( mp_slipmap . SlipDefaultPopup ( None ) ) | draw a series of connected lines on the map calling callback when done | 65 | 13 |
229,504 | def cmd_set_originpos ( self , args ) : ( 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 ) | called when user selects Set Origin on map | 99 | 8 |
229,505 | def cmd_center ( self , args ) : if len ( args ) < 3 : print ( "map center LAT LON" ) return lat = float ( args [ 1 ] ) lon = float ( args [ 2 ] ) self . map . set_center ( lat , lon ) | control center of view | 61 | 4 |
229,506 | def cmd_follow ( self , args ) : if len ( args ) < 2 : print ( "map follow 0|1" ) return follow = int ( args [ 1 ] ) self . map . set_follow ( follow ) | control following of vehicle | 48 | 4 |
229,507 | def set_secondary_vehicle_position ( self , m ) : 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 ) ) | show 2nd vehicle on map | 234 | 6 |
229,508 | 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 [ 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 | control kml reading | 249 | 4 |
229,509 | def cmd_snap_wp ( self , args ) : 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 ( ) | snap waypoints to KML | 340 | 6 |
229,510 | def cmd_snap_fence ( self , args ) : 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 ( ) | snap fence to KML | 305 | 5 |
229,511 | def fencekml ( self , layername ) : #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 ( ) | set a layer as the geofence | 249 | 8 |
229,512 | def togglekml ( self , layername ) : #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 | toggle the display of a kml | 273 | 7 |
229,513 | 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 . curtextlayers : self . mpstate . map . remove_object ( layer ) self . allayers = [ ] self . curlayers = [ ] self . alltextlayers = [ ] self . curtextlayers = [ ] self . menu_needs_refreshing = True | Clear the kmls from the map | 105 | 8 |
229,514 | 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 : 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 | Load a kml from file and put it on the map | 478 | 12 |
229,515 | 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_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 | handle GUI elements | 490 | 3 |
229,516 | def readkmz ( self , filename ) : #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 | reads in a kmz file and returns xml nodes | 211 | 10 |
229,517 | def cmd_asterix ( self , args ) : 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 ) | asterix command parser | 158 | 4 |
229,518 | def start_listener ( self ) : 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 ) | start listening for packets | 132 | 4 |
229,519 | def stop_listener ( self ) : if self . sock is not None : self . sock . close ( ) self . sock = None self . tracks = { } | stop listening for packets | 35 | 4 |
229,520 | def set_secondary_vehicle_position ( self , m ) : 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 ) | store second vehicle position for filtering purposes | 118 | 7 |
229,521 | 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 * 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 | return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds | 169 | 20 |
229,522 | 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 . 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 | return true if vehicle could come within filter_dist_z meters of adsb vehicle in timeout seconds | 221 | 20 |
229,523 | def mavlink_packet ( self , m ) : if m . get_type ( ) == 'GLOBAL_POSITION_INT' : if abs ( m . lat ) < 1000 and abs ( m . lon ) < 1000 : return self . vehicle_pos = VehiclePos ( m ) | get time from mavlink ATTITUDE | 65 | 10 |
229,524 | 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 | 43 | 5 |
229,525 | def complete_links ( self , text ) : 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 ) ) | return list of links | 94 | 4 |
229,526 | def cmd_link_attributes ( self , args ) : link = args [ 0 ] attributes = args [ 1 ] print ( "Setting link %s attributes (%s)" % ( link , attributes ) ) self . link_attributes ( link , attributes ) | change optional link attributes | 54 | 4 |
229,527 | def find_link ( self , device ) : 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 | find a device based on number name or label | 77 | 9 |
229,528 | def cmd_link_remove ( self , args ) : 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 | remove an link | 217 | 3 |
229,529 | def master_send_callback ( self , m , master ) : 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 ( ) ) ) | called on sending a message | 177 | 5 |
229,530 | 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 + 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 | special handling for MAVLink packets with a time_boot_ms field | 230 | 15 |
229,531 | def report_altitude ( self , 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' ) | possibly report a new altitude | 313 | 5 |
229,532 | def cmd_vehicle ( self , args ) : 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 ) ) | handle vehicle commands | 290 | 3 |
229,533 | 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 = 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 | read from device | 158 | 3 |
229,534 | 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 = 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 | write to a device | 216 | 4 |
229,535 | def get_absolute ( self , points ) : # 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 | Given a set of points geo referenced to this instance return the points as absolute values . | 208 | 17 |
229,536 | def cmd_cameraview ( self , args ) : 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' ) | camera view commands | 87 | 3 |
229,537 | 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 . 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 | scale a PWM value | 165 | 5 |
229,538 | 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 | 41 | 13 |
229,539 | def _create_wx_app ( ) : 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 | Creates a wx . App instance if it has not been created sofar . | 87 | 17 |
229,540 | def draw_if_interactive ( ) : DEBUG_MSG ( "draw_if_interactive()" , 1 , None ) if matplotlib . is_interactive ( ) : figManager = Gcf . get_active ( ) if figManager is not None : figManager . canvas . draw_idle ( ) | This should be overriden in a windowing environment if drawing should be done in interactive python mode | 70 | 20 |
229,541 | def new_gc ( self ) : DEBUG_MSG ( 'new_gc()' , 2 , self ) self . gc = GraphicsContextWx ( self . bitmap , self ) self . gc . select ( ) self . gc . unselect ( ) return self . gc | Return an instance of a GraphicsContextWx and sets the current gc copy | 63 | 16 |
229,542 | def get_wx_font ( self , s , prop ) : 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 | Return a wx font . Cache instances in a font dictionary for efficiency | 268 | 14 |
229,543 | def select ( self ) : if sys . platform == 'win32' : self . dc . SelectObject ( self . bitmap ) self . IsSelected = True | Select the current bitmap into this wxDC instance | 35 | 11 |
229,544 | def unselect ( self ) : if sys . platform == 'win32' : self . dc . SelectObject ( wx . NullBitmap ) self . IsSelected = False | Select a Null bitmasp into this wxDC instance | 38 | 12 |
229,545 | def set_linewidth ( self , w ) : 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 ( ) | Set the line width . | 128 | 5 |
229,546 | def set_linestyle ( self , ls ) : 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 ( ) | Set the line style to be one of | 162 | 8 |
229,547 | def get_wxcolour ( self , color ) : 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 ) ) | return a wx . Colour from RGB format | 144 | 9 |
229,548 | def Copy_to_Clipboard ( self , event = None ) : 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 ( ) | copy bitmap of canvas to system clipboard | 119 | 8 |
229,549 | 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 # 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 ) | Delay rendering until the GUI is idle . | 152 | 9 |
229,550 | def draw ( self , drawDC = None ) : 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 ) | Render the figure using RendererWx instance renderer or using a previously defined renderer if none is specified . | 79 | 23 |
229,551 | def start_event_loop ( self , timeout = 0 ) : 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 ( ) | 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 . | 145 | 55 |
229,552 | def stop_event_loop ( self , event = None ) : if hasattr ( self , '_event_loop' ) : if self . _event_loop . IsRunning ( ) : self . _event_loop . Exit ( ) del self . _event_loop | 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 . | 58 | 32 |
229,553 | def _get_imagesave_wildcards ( self ) : 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 | return the wildcard string for the filesave dialog | 198 | 10 |
229,554 | def gui_repaint ( self , drawDC = None ) : 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 | 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 . | 103 | 34 |
229,555 | def _onPaint ( self , evt ) : 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 ( ) | Called when wxPaintEvt is generated | 79 | 11 |
229,556 | def _onSize ( self , evt ) : 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 ) | Called when wxEventSize is generated . | 199 | 10 |
229,557 | def _onIdle ( self , evt ) : evt . Skip ( ) FigureCanvasBase . idle_event ( self , guiEvent = evt ) | a GUI idle event | 35 | 4 |
229,558 | def _onKeyDown ( self , evt ) : key = self . _get_key ( evt ) evt . Skip ( ) FigureCanvasBase . key_press_event ( self , key , guiEvent = evt ) | Capture key press . | 51 | 4 |
229,559 | def _onKeyUp ( self , evt ) : key = self . _get_key ( evt ) #print 'release key', key evt . Skip ( ) FigureCanvasBase . key_release_event ( self , key , guiEvent = evt ) | Release key . | 58 | 3 |
229,560 | def _onLeftButtonUp ( self , evt ) : 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 ) | End measuring on an axis . | 92 | 6 |
229,561 | def _onMouseWheel ( self , evt ) : # 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 ) | Translate mouse wheel events into matplotlib events | 250 | 10 |
229,562 | def _onLeave ( self , evt ) : evt . Skip ( ) FigureCanvasBase . leave_notify_event ( self , guiEvent = evt ) | Mouse has left the window . | 37 | 6 |
229,563 | def resize ( self , width , height ) : self . canvas . SetInitialSize ( wx . Size ( width , height ) ) self . window . GetSizer ( ) . Fit ( self . window ) | Set the canvas size in pixels | 44 | 6 |
229,564 | def _onMenuButton ( self , evt ) : 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 ( ) | Handle menu button pressed . | 71 | 5 |
229,565 | def _handleSelectAllAxes ( self , evt ) : 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 ( ) | Called when the select all axes menu item is selected . | 85 | 12 |
229,566 | def _handleInvertAxesSelected ( self , evt ) : 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 ( ) | Called when the invert all menu item is selected | 127 | 11 |
229,567 | def _onMenuItemSelected ( self , evt ) : 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 ( ) | Called whenever one of the specific axis menu items is selected | 111 | 12 |
229,568 | def getActiveAxes ( self ) : active = [ ] for i in range ( len ( self . _axisId ) ) : if self . _menu . IsChecked ( self . _axisId [ i ] ) : active . append ( i ) return active | Return a list of the selected axes . | 56 | 8 |
229,569 | def updateButtonText ( self , lst ) : axis_txt = '' for e in lst : axis_txt += '%d,' % ( e + 1 ) # remove trailing ',' and add to button string self . SetLabel ( "Axes: %s" % axis_txt [ : - 1 ] ) | Update the list of selected axes in the menu button | 68 | 10 |
229,570 | def _create_menu ( self ) : DEBUG_MSG ( "_create_menu()" , 1 , self ) self . _menu = MenuButtonWx ( self ) self . AddControl ( self . _menu ) self . AddSeparator ( ) | Creates the menu - implemented as a button which opens a pop - up menu since wxPython does not allow a menu as a control | 55 | 28 |
229,571 | def _create_controls ( self , can_kill ) : DEBUG_MSG ( "_create_controls()" , 1 , self ) # Need the following line as Windows toolbars default to 15x16 self . SetToolBitmapSize ( wx . Size ( 16 , 16 ) ) self . AddSimpleTool ( _NTB_X_PAN_LEFT , _load_bitmap ( 'stock_left.xpm' ) , 'Left' , 'Scroll left' ) self . AddSimpleTool ( _NTB_X_PAN_RIGHT , _load_bitmap ( 'stock_right.xpm' ) , 'Right' , 'Scroll right' ) self . AddSimpleTool ( _NTB_X_ZOOMIN , _load_bitmap ( 'stock_zoom-in.xpm' ) , 'Zoom in' , 'Increase X axis magnification' ) self . AddSimpleTool ( _NTB_X_ZOOMOUT , _load_bitmap ( 'stock_zoom-out.xpm' ) , 'Zoom out' , 'Decrease X axis magnification' ) self . AddSeparator ( ) self . AddSimpleTool ( _NTB_Y_PAN_UP , _load_bitmap ( 'stock_up.xpm' ) , 'Up' , 'Scroll up' ) self . AddSimpleTool ( _NTB_Y_PAN_DOWN , _load_bitmap ( 'stock_down.xpm' ) , 'Down' , 'Scroll down' ) self . AddSimpleTool ( _NTB_Y_ZOOMIN , _load_bitmap ( 'stock_zoom-in.xpm' ) , 'Zoom in' , 'Increase Y axis magnification' ) self . AddSimpleTool ( _NTB_Y_ZOOMOUT , _load_bitmap ( 'stock_zoom-out.xpm' ) , 'Zoom out' , 'Decrease Y axis magnification' ) self . AddSeparator ( ) self . AddSimpleTool ( _NTB_SAVE , _load_bitmap ( 'stock_save_as.xpm' ) , 'Save' , 'Save plot contents as images' ) self . AddSeparator ( ) bind ( self , wx . EVT_TOOL , self . _onLeftScroll , id = _NTB_X_PAN_LEFT ) bind ( self , wx . EVT_TOOL , self . _onRightScroll , id = _NTB_X_PAN_RIGHT ) bind ( self , wx . EVT_TOOL , self . _onXZoomIn , id = _NTB_X_ZOOMIN ) bind ( self , wx . EVT_TOOL , self . _onXZoomOut , id = _NTB_X_ZOOMOUT ) bind ( self , wx . EVT_TOOL , self . _onUpScroll , id = _NTB_Y_PAN_UP ) bind ( self , wx . EVT_TOOL , self . _onDownScroll , id = _NTB_Y_PAN_DOWN ) bind ( self , wx . EVT_TOOL , self . _onYZoomIn , id = _NTB_Y_ZOOMIN ) bind ( self , wx . EVT_TOOL , self . _onYZoomOut , id = _NTB_Y_ZOOMOUT ) bind ( self , wx . EVT_TOOL , self . _onSave , id = _NTB_SAVE ) bind ( self , wx . EVT_TOOL_ENTER , self . _onEnterTool , id = self . GetId ( ) ) if can_kill : bind ( self , wx . EVT_TOOL , self . _onClose , id = _NTB_CLOSE ) bind ( self , wx . EVT_MOUSEWHEEL , self . _onMouseWheel ) | Creates the button controls and links them to event handlers | 888 | 11 |
229,572 | def set_active ( self , ind ) : DEBUG_MSG ( "set_active()" , 1 , self ) self . _ind = ind if ind != None : self . _active = [ self . _axes [ i ] for i in self . _ind ] else : self . _active = [ ] # Now update button text wit active axes self . _menu . updateButtonText ( ind ) | ind is a list of index numbers for the axes which are to be made active | 87 | 16 |
229,573 | def getURIWithRedirect ( self , url ) : tries = 0 while tries < 5 : conn = httplib . HTTPConnection ( self . server ) conn . request ( "GET" , url ) r1 = conn . getresponse ( ) if r1 . status in [ 301 , 302 , 303 , 307 ] : location = r1 . getheader ( 'Location' ) if self . debug : print ( "redirect from %s to %s" % ( url , location ) ) url = location conn . close ( ) tries += 1 continue data = r1 . read ( ) conn . close ( ) if sys . version_info . major < 3 : return data else : encoding = r1 . headers . get_content_charset ( default ) return data . decode ( encoding ) return None | fetch a URL with redirect handling | 170 | 7 |
229,574 | def cmd_rc ( self , args ) : if len ( args ) != 2 : print ( "Usage: rc <channel|all> <pwmvalue>" ) return value = int ( args [ 1 ] ) if value > 65535 or value < - 1 : raise ValueError ( "PWM value must be a positive integer between 0 and 65535" ) if value == - 1 : value = 65535 channels = self . override if args [ 0 ] == 'all' : for i in range ( 16 ) : channels [ i ] = value else : channel = int ( args [ 0 ] ) if channel < 1 or channel > 16 : print ( "Channel must be between 1 and 8 or 'all'" ) return channels [ channel - 1 ] = value self . set_override ( channels ) | handle RC value override | 168 | 4 |
229,575 | def complete_variable ( text ) : if text == '' : return list ( rline_mpstate . status . msgs . keys ( ) ) if text . endswith ( ":2" ) : suffix = ":2" text = text [ : - 2 ] else : suffix = '' try : if mavutil . evaluate_expression ( text , rline_mpstate . status . msgs ) is not None : return [ text + suffix ] except Exception as ex : pass try : m1 = re . match ( "^(.*?)([A-Z0-9][A-Z0-9_]*)[.]([A-Za-z0-9_]*)$" , text ) except Exception as ex : return [ ] if m1 is not None : prefix = m1 . group ( 1 ) mtype = m1 . group ( 2 ) fname = m1 . group ( 3 ) if mtype in rline_mpstate . status . msgs : ret = [ ] for f in rline_mpstate . status . msgs [ mtype ] . get_fieldnames ( ) : if f . startswith ( fname ) : ret . append ( prefix + mtype + '.' + f + suffix ) return ret return [ ] try : m2 = re . match ( "^(.*?)([A-Z0-9][A-Z0-9_]*)$" , text ) except Exception as ex : return [ ] prefix = m2 . group ( 1 ) mtype = m2 . group ( 2 ) ret = [ ] for k in list ( rline_mpstate . status . msgs . keys ( ) ) : if k . startswith ( mtype ) : ret . append ( prefix + k + suffix ) return ret | complete a MAVLink variable or expression | 387 | 8 |
229,576 | def complete_rule ( rule , cmd ) : global rline_mpstate rule_components = rule . split ( ' ' ) # complete the empty string (e.g "graph <TAB><TAB>") if len ( cmd ) == 0 : return rule_expand ( rule_components [ 0 ] , "" ) # check it matches so far for i in range ( len ( cmd ) - 1 ) : if not rule_match ( rule_components [ i ] , cmd [ i ] ) : return [ ] # expand the next rule component expanded = rule_expand ( rule_components [ len ( cmd ) - 1 ] , cmd [ - 1 ] ) return expanded | complete using one rule | 147 | 4 |
229,577 | def createPlotPanel ( self ) : self . figure = Figure ( ) self . axes = self . figure . add_subplot ( 111 ) self . canvas = FigureCanvas ( self , - 1 , self . figure ) self . canvas . SetSize ( wx . Size ( 300 , 300 ) ) self . axes . axis ( 'off' ) self . figure . subplots_adjust ( left = 0 , right = 1 , top = 1 , bottom = 0 ) self . sizer = wx . BoxSizer ( wx . VERTICAL ) self . sizer . Add ( self . canvas , 1 , wx . EXPAND , wx . ALL ) self . SetSizerAndFit ( self . sizer ) self . Fit ( ) | Creates the figure and axes for the plotting panel . | 161 | 11 |
229,578 | def rescaleX ( self ) : self . ratio = self . figure . get_size_inches ( ) [ 0 ] / float ( self . figure . get_size_inches ( ) [ 1 ] ) self . axes . set_xlim ( - self . ratio , self . ratio ) self . axes . set_ylim ( - 1 , 1 ) | Rescales the horizontal axes to make the lengthscales equal . | 76 | 14 |
229,579 | def calcFontScaling ( self ) : self . ypx = self . figure . get_size_inches ( ) [ 1 ] * self . figure . dpi self . xpx = self . figure . get_size_inches ( ) [ 0 ] * self . figure . dpi self . fontSize = self . vertSize * ( self . ypx / 2.0 ) self . leftPos = self . axes . get_xlim ( ) [ 0 ] self . rightPos = self . axes . get_xlim ( ) [ 1 ] | Calculates the current font size and left position for the current window . | 117 | 15 |
229,580 | def checkReszie ( self ) : if not self . resized : oldypx = self . ypx oldxpx = self . xpx self . ypx = self . figure . get_size_inches ( ) [ 1 ] * self . figure . dpi self . xpx = self . figure . get_size_inches ( ) [ 0 ] * self . figure . dpi if ( oldypx != self . ypx ) or ( oldxpx != self . xpx ) : self . resized = True else : self . resized = False | Checks if the window was resized . | 120 | 9 |
229,581 | def createHeadingPointer ( self ) : self . headingTri = patches . RegularPolygon ( ( 0.0 , 0.80 ) , 3 , 0.05 , color = 'k' , zorder = 4 ) self . axes . add_patch ( self . headingTri ) self . headingText = self . axes . text ( 0.0 , 0.675 , '0' , color = 'k' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' , zorder = 4 ) | Creates the pointer for the current heading . | 118 | 9 |
229,582 | def adjustHeadingPointer ( self ) : self . headingText . set_text ( str ( self . heading ) ) self . headingText . set_size ( self . fontSize ) | Adjust the value of the heading pointer . | 40 | 8 |
229,583 | def createNorthPointer ( self ) : self . headingNorthTri = patches . RegularPolygon ( ( 0.0 , 0.80 ) , 3 , 0.05 , color = 'k' , zorder = 4 ) self . axes . add_patch ( self . headingNorthTri ) self . headingNorthText = self . axes . text ( 0.0 , 0.675 , 'N' , color = 'k' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' , zorder = 4 ) | Creates the north pointer relative to current heading . | 120 | 10 |
229,584 | def adjustNorthPointer ( self ) : self . headingNorthText . set_size ( self . fontSize ) headingRotate = mpl . transforms . Affine2D ( ) . rotate_deg_around ( 0.0 , 0.0 , self . heading ) + self . axes . transData self . headingNorthText . set_transform ( headingRotate ) if ( self . heading > 90 ) and ( self . heading < 270 ) : headRot = self . heading - 180 else : headRot = self . heading self . headingNorthText . set_rotation ( headRot ) self . headingNorthTri . set_transform ( headingRotate ) # Adjust if overlapping with heading pointer if ( self . heading <= 10.0 ) or ( self . heading >= 350.0 ) : self . headingNorthText . set_text ( '' ) else : self . headingNorthText . set_text ( 'N' ) | Adjust the position and orientation of the north pointer . | 196 | 10 |
229,585 | def createRPYText ( self ) : self . rollText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) , 'Roll: %.2f' % self . roll , color = 'w' , size = self . fontSize ) self . pitchText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) , 'Pitch: %.2f' % self . pitch , color = 'w' , size = self . fontSize ) self . yawText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 , 'Yaw: %.2f' % self . yaw , color = 'w' , size = self . fontSize ) self . rollText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . pitchText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . yawText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) | Creates the text for roll pitch and yaw . | 330 | 11 |
229,586 | def updateRPYLocations ( self ) : # Locations self . rollText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) ) ) self . pitchText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) ) ) self . yawText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , - 0.97 ) ) # Font Size self . rollText . set_size ( self . fontSize ) self . pitchText . set_size ( self . fontSize ) self . yawText . set_size ( self . fontSize ) | Update the locations of roll pitch yaw text . | 194 | 10 |
229,587 | def updateRPYText ( self ) : self . rollText . set_text ( 'Roll: %.2f' % self . roll ) self . pitchText . set_text ( 'Pitch: %.2f' % self . pitch ) self . yawText . set_text ( 'Yaw: %.2f' % self . yaw ) | Updates the displayed Roll Pitch Yaw Text | 79 | 9 |
229,588 | def createCenterPointMarker ( self ) : self . axes . add_patch ( patches . Rectangle ( ( - 0.75 , - self . thick ) , 0.5 , 2.0 * self . thick , facecolor = 'orange' , zorder = 3 ) ) self . axes . add_patch ( patches . Rectangle ( ( 0.25 , - self . thick ) , 0.5 , 2.0 * self . thick , facecolor = 'orange' , zorder = 3 ) ) self . axes . add_patch ( patches . Circle ( ( 0 , 0 ) , radius = self . thick , facecolor = 'orange' , edgecolor = 'none' , zorder = 3 ) ) | Creates the center pointer in the middle of the screen . | 153 | 12 |
229,589 | def createHorizonPolygons ( self ) : # Sky Polygon vertsTop = [ [ - 1 , 0 ] , [ - 1 , 1 ] , [ 1 , 1 ] , [ 1 , 0 ] , [ - 1 , 0 ] ] self . topPolygon = Polygon ( vertsTop , facecolor = 'dodgerblue' , edgecolor = 'none' ) self . axes . add_patch ( self . topPolygon ) # Ground Polygon vertsBot = [ [ - 1 , 0 ] , [ - 1 , - 1 ] , [ 1 , - 1 ] , [ 1 , 0 ] , [ - 1 , 0 ] ] self . botPolygon = Polygon ( vertsBot , facecolor = 'brown' , edgecolor = 'none' ) self . axes . add_patch ( self . botPolygon ) | Creates the two polygons to show the sky and ground . | 182 | 13 |
229,590 | def calcHorizonPoints ( self ) : ydiff = math . tan ( math . radians ( - self . roll ) ) * float ( self . ratio ) pitchdiff = self . dist10deg * ( self . pitch / 10.0 ) # Sky Polygon vertsTop = [ ( - self . ratio , ydiff - pitchdiff ) , ( - self . ratio , 1 ) , ( self . ratio , 1 ) , ( self . ratio , - ydiff - pitchdiff ) , ( - self . ratio , ydiff - pitchdiff ) ] self . topPolygon . set_xy ( vertsTop ) # Ground Polygon vertsBot = [ ( - self . ratio , ydiff - pitchdiff ) , ( - self . ratio , - 1 ) , ( self . ratio , - 1 ) , ( self . ratio , - ydiff - pitchdiff ) , ( - self . ratio , ydiff - pitchdiff ) ] self . botPolygon . set_xy ( vertsBot ) | Updates the verticies of the patches for the ground and sky . | 212 | 15 |
229,591 | def createPitchMarkers ( self ) : self . pitchPatches = [ ] # Major Lines (multiple of 10 deg) for i in [ - 9 , - 8 , - 7 , - 6 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] : width = self . calcPitchMarkerWidth ( i ) currPatch = patches . Rectangle ( ( - width / 2.0 , self . dist10deg * i - ( self . thick / 2.0 ) ) , width , self . thick , facecolor = 'w' , edgecolor = 'none' ) self . axes . add_patch ( currPatch ) self . pitchPatches . append ( currPatch ) # Add Label for +-30 deg self . vertSize = 0.09 self . pitchLabelsLeft = [ ] self . pitchLabelsRight = [ ] i = 0 for j in [ - 90 , - 60 , - 30 , 30 , 60 , 90 ] : self . pitchLabelsLeft . append ( self . axes . text ( - 0.55 , ( j / 10.0 ) * self . dist10deg , str ( j ) , color = 'w' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' ) ) self . pitchLabelsLeft [ i ] . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . pitchLabelsRight . append ( self . axes . text ( 0.55 , ( j / 10.0 ) * self . dist10deg , str ( j ) , color = 'w' , size = self . fontSize , horizontalalignment = 'center' , verticalalignment = 'center' ) ) self . pitchLabelsRight [ i ] . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) i += 1 | Creates the rectangle patches for the pitch indicators . | 447 | 10 |
229,592 | def adjustPitchmarkers ( self ) : pitchdiff = self . dist10deg * ( self . pitch / 10.0 ) rollRotate = mpl . transforms . Affine2D ( ) . rotate_deg_around ( 0.0 , - pitchdiff , self . roll ) + self . axes . transData j = 0 for i in [ - 9 , - 8 , - 7 , - 6 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] : width = self . calcPitchMarkerWidth ( i ) self . pitchPatches [ j ] . set_xy ( ( - width / 2.0 , self . dist10deg * i - ( self . thick / 2.0 ) - pitchdiff ) ) self . pitchPatches [ j ] . set_transform ( rollRotate ) j += 1 # Adjust Text Size and rotation i = 0 for j in [ - 9 , - 6 , - 3 , 3 , 6 , 9 ] : self . pitchLabelsLeft [ i ] . set_y ( j * self . dist10deg - pitchdiff ) self . pitchLabelsRight [ i ] . set_y ( j * self . dist10deg - pitchdiff ) self . pitchLabelsLeft [ i ] . set_size ( self . fontSize ) self . pitchLabelsRight [ i ] . set_size ( self . fontSize ) self . pitchLabelsLeft [ i ] . set_rotation ( self . roll ) self . pitchLabelsRight [ i ] . set_rotation ( self . roll ) self . pitchLabelsLeft [ i ] . set_transform ( rollRotate ) self . pitchLabelsRight [ i ] . set_transform ( rollRotate ) i += 1 | Adjusts the location and orientation of pitch markers . | 394 | 10 |
229,593 | def createAARText ( self ) : self . airspeedText = self . axes . text ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) , 'AS: %.1f m/s' % self . airspeed , color = 'w' , size = self . fontSize , ha = 'right' ) self . altitudeText = self . axes . text ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) , 'ALT: %.1f m ' % self . relAlt , color = 'w' , size = self . fontSize , ha = 'right' ) self . climbRateText = self . axes . text ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 , 'CR: %.1f m/s' % self . climbRate , color = 'w' , size = self . fontSize , ha = 'right' ) self . airspeedText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . altitudeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . climbRateText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) | Creates the text for airspeed altitude and climb rate . | 357 | 12 |
229,594 | def updateAARLocations ( self ) : # Locations self . airspeedText . set_position ( ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + ( 2 * self . vertSize ) - ( self . vertSize / 10.0 ) ) ) self . altitudeText . set_position ( ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 + self . vertSize - ( 0.5 * self . vertSize / 10.0 ) ) ) self . climbRateText . set_position ( ( self . rightPos - ( self . vertSize / 10.0 ) , - 0.97 ) ) # Font Size self . airspeedText . set_size ( self . fontSize ) self . altitudeText . set_size ( self . fontSize ) self . climbRateText . set_size ( self . fontSize ) | Update the locations of airspeed altitude and Climb rate . | 197 | 12 |
229,595 | def updateAARText ( self ) : self . airspeedText . set_text ( 'AR: %.1f m/s' % self . airspeed ) self . altitudeText . set_text ( 'ALT: %.1f m ' % self . relAlt ) self . climbRateText . set_text ( 'CR: %.1f m/s' % self . climbRate ) | Updates the displayed airspeed altitude climb rate Text | 87 | 10 |
229,596 | def createBatteryBar ( self ) : self . batOutRec = patches . Rectangle ( ( self . rightPos - ( 1.3 + self . rOffset ) * self . batWidth , 1.0 - ( 0.1 + 1.0 + ( 2 * 0.075 ) ) * self . batHeight ) , self . batWidth * 1.3 , self . batHeight * 1.15 , facecolor = 'darkgrey' , edgecolor = 'none' ) self . batInRec = patches . Rectangle ( ( self . rightPos - ( self . rOffset + 1 + 0.15 ) * self . batWidth , 1.0 - ( 0.1 + 1 + 0.075 ) * self . batHeight ) , self . batWidth , self . batHeight , facecolor = 'lawngreen' , edgecolor = 'none' ) self . batPerText = self . axes . text ( self . rightPos - ( self . rOffset + 0.65 ) * self . batWidth , 1 - ( 0.1 + 1 + ( 0.075 + 0.15 ) ) * self . batHeight , '%.f' % self . batRemain , color = 'w' , size = self . fontSize , ha = 'center' , va = 'top' ) self . batPerText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . voltsText = self . axes . text ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - ( 0.1 + 0.05 + 0.075 ) * self . batHeight , '%.1f V' % self . voltage , color = 'w' , size = self . fontSize , ha = 'right' , va = 'top' ) self . ampsText = self . axes . text ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - self . vertSize - ( 0.1 + 0.05 + 0.1 + 0.075 ) * self . batHeight , '%.1f A' % self . current , color = 'w' , size = self . fontSize , ha = 'right' , va = 'top' ) self . voltsText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . ampsText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'k' ) ] ) self . axes . add_patch ( self . batOutRec ) self . axes . add_patch ( self . batInRec ) | Creates the bar to display current battery percentage . | 605 | 10 |
229,597 | def updateBatteryBar ( self ) : # Bar self . batOutRec . set_xy ( ( self . rightPos - ( 1.3 + self . rOffset ) * self . batWidth , 1.0 - ( 0.1 + 1.0 + ( 2 * 0.075 ) ) * self . batHeight ) ) self . batInRec . set_xy ( ( self . rightPos - ( self . rOffset + 1 + 0.15 ) * self . batWidth , 1.0 - ( 0.1 + 1 + 0.075 ) * self . batHeight ) ) self . batPerText . set_position ( ( self . rightPos - ( self . rOffset + 0.65 ) * self . batWidth , 1 - ( 0.1 + 1 + ( 0.075 + 0.15 ) ) * self . batHeight ) ) self . batPerText . set_fontsize ( self . fontSize ) self . voltsText . set_text ( '%.1f V' % self . voltage ) self . ampsText . set_text ( '%.1f A' % self . current ) self . voltsText . set_position ( ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - ( 0.1 + 0.05 ) * self . batHeight ) ) self . ampsText . set_position ( ( self . rightPos - ( self . rOffset + 1.3 + 0.2 ) * self . batWidth , 1 - self . vertSize - ( 0.1 + 0.05 + 0.1 ) * self . batHeight ) ) self . voltsText . set_fontsize ( self . fontSize ) self . ampsText . set_fontsize ( self . fontSize ) if self . batRemain >= 0 : self . batPerText . set_text ( int ( self . batRemain ) ) self . batInRec . set_height ( self . batRemain * self . batHeight / 100.0 ) if self . batRemain / 100.0 > 0.5 : self . batInRec . set_facecolor ( 'lawngreen' ) elif self . batRemain / 100.0 <= 0.5 and self . batRemain / 100.0 > 0.2 : self . batInRec . set_facecolor ( 'yellow' ) elif self . batRemain / 100.0 <= 0.2 and self . batRemain >= 0.0 : self . batInRec . set_facecolor ( 'r' ) elif self . batRemain == - 1 : self . batInRec . set_height ( self . batHeight ) self . batInRec . set_facecolor ( 'k' ) | Updates the position and values of the battery bar . | 597 | 11 |
229,598 | def createStateText ( self ) : self . modeText = self . axes . text ( self . leftPos + ( self . vertSize / 10.0 ) , 0.97 , 'UNKNOWN' , color = 'grey' , size = 1.5 * self . fontSize , ha = 'left' , va = 'top' ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = self . fontSize / 10.0 , foreground = 'black' ) ] ) | Creates the mode and arm state text . | 114 | 9 |
229,599 | def updateStateText ( self ) : self . modeText . set_position ( ( self . leftPos + ( self . vertSize / 10.0 ) , 0.97 ) ) self . modeText . set_text ( self . mode ) self . modeText . set_size ( 1.5 * self . fontSize ) if self . armed : self . modeText . set_color ( 'red' ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = self . fontSize / 10.0 , foreground = 'yellow' ) ] ) elif ( self . armed == False ) : self . modeText . set_color ( 'lightgreen' ) self . modeText . set_bbox ( None ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = 1 , foreground = 'black' ) ] ) else : # Fall back if unknown self . modeText . set_color ( 'grey' ) self . modeText . set_bbox ( None ) self . modeText . set_path_effects ( [ PathEffects . withStroke ( linewidth = self . fontSize / 10.0 , foreground = 'black' ) ] ) | Updates the mode and colours red or green depending on arm state . | 272 | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.