<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import division <EOL> from __future__ import unicode_literals <EOL> import os <EOL> from . import st_base <EOL> from . import pyarduino <EOL> class MenuFile ( pyarduino . base . json_file . JSONFile ) : <EOL> def __init__ ( self , file_path ) : <EOL> super ( MenuFile , self ) . __init__ ( file_path ) <EOL> self . menus = [ Menu ( d ) for d in self . data ] <EOL> def get_menus ( self ) : <EOL> return self . menus <EOL> class ArduinoMenuFile ( MenuFile ) : <EOL> def __init__ ( self , preset_menu_name ) : <EOL> self . preset_menu_name = preset_menu_name <EOL> preset_path = st_base . get_preset_path ( ) <EOL> preset_file_name = '<STR_LIT>' + preset_menu_name + '<STR_LIT>' <EOL> preset_file_path = os . path . join ( preset_path , preset_file_name ) <EOL> super ( ArduinoMenuFile , self ) . __init__ ( preset_file_path ) <EOL> self . menu = self . menus [ <NUM_LIT:0> ] <EOL> self . sub_menu = self . menu . get_sub_menus ( ) [ <NUM_LIT:0> ] <EOL> def add_sub_menu ( self , sub_menu ) : <EOL> self . sub_menu . sub_menus . append ( sub_menu ) <EOL> def add_sub_menus ( self , sub_menus ) : <EOL> self . sub_menu . sub_menus += sub_menus <EOL> def write ( self ) : <EOL> menu_data = [ self . menu . get_menu_dict ( ) ] <EOL> user_menu_path = st_base . get_user_menu_path ( ) <EOL> target_menu_path = os . path . join ( user_menu_path , self . preset_menu_name ) <EOL> if not os . path . isdir ( target_menu_path ) : <EOL> os . makedirs ( target_menu_path ) <EOL> target_file_path = os . path . join ( target_menu_path , '<STR_LIT>' ) <EOL> target_file = pyarduino . base . json_file . JSONFile ( target_file_path ) <EOL> target_file . set_data ( menu_data ) <EOL> class Menu ( object ) : <EOL> def __init__ ( self , menu_dict = None ) : <EOL> self . i18n = st_base . get_i18n ( ) <EOL> self . params = menu_dict <EOL> if not self . params : <EOL> self . params = { '<STR_LIT>' : '<STR_LIT:->' } <EOL> plugin_path = st_base . get_plugin_path ( ) <EOL> dir_name = os . path . basename ( plugin_path ) <EOL> args = self . params . get ( '<STR_LIT:args>' , { } ) <EOL> if args : <EOL> for key in args : <EOL> value = args . get ( key ) <EOL> try : <EOL> value + '<STR_LIT:str>' <EOL> except TypeError : <EOL> continue <EOL> else : <EOL> if '<STR_LIT>' in value : <EOL> value = value . replace ( '<STR_LIT>' , dir_name ) <EOL> args [ key ] = value <EOL> self . params [ '<STR_LIT:args>' ] = args <EOL> self . sub_menus = [ ] <EOL> menu_dicts = self . params . get ( '<STR_LIT>' , [ ] ) <EOL> for menu_dict in menu_dicts : <EOL> sub_menu = Menu ( menu_dict ) <EOL> self . sub_menus . append ( sub_menu ) <EOL> def set ( self , key , value ) : <EOL> self . parmas [ key ] = value <EOL> def get ( self , key , default_value = None ) : <EOL> return self . params . get ( key , default_value ) <EOL> def get_sub_menus ( self ) : <EOL> return self . sub_menus <EOL> def set_sub_menus ( self , sub_menus ) : <EOL> self . sub_menus = sub_menus <EOL> def add_sub_menu ( self , sub_menu ) : <EOL> self . sub_menus . append ( sub_menu ) <EOL> def get_menu_dict ( self ) : <EOL> self . translate ( ) <EOL> if self . sub_menus : <EOL> self . params [ '<STR_LIT>' ] = [ ] <EOL> for sub_menu in self . sub_menus : <EOL> sub_menu_dict = sub_menu . get_menu_dict ( ) <EOL> self . params [ '<STR_LIT>' ] . append ( sub_menu_dict ) <EOL> else : <EOL> if '<STR_LIT>' in self . params : <EOL> self . params . pop ( '<STR_LIT>' ) <EOL> return self . params <EOL> def has_sub_menus ( self ) : <EOL> return bool ( self . sub_menus ) <EOL> def translate ( self ) : <EOL> caption = self . params . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> caption = self . i18n . translate ( caption ) <EOL> self . params [ '<STR_LIT>' ] = caption <EOL> for sub_menu in self . sub_menus : <EOL> sub_menu . translate ( ) <EOL> def load_sketchbook_menu ( sketch ) : <EOL> menu_dict = { } <EOL> sketch_name = sketch . get_name ( ) <EOL> sketch_path = sketch . get_path ( ) <EOL> sub_sketches = sketch . get_sub_sketches ( ) <EOL> menu_dict [ '<STR_LIT>' ] = sketch_name <EOL> if not sub_sketches : <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : sketch_path } <EOL> menu = Menu ( menu_dict ) <EOL> if sub_sketches : <EOL> for sub_sketch in sub_sketches : <EOL> sub_menu = load_sketchbook_menu ( sub_sketch ) <EOL> menu . add_sub_menu ( sub_menu ) <EOL> return menu <EOL> def write_menu ( preset_menu_name , sub_menus ) : <EOL> if not sub_menus : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT:None>' <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> menu = ArduinoMenuFile ( preset_menu_name ) <EOL> menu . add_sub_menus ( sub_menus ) <EOL> menu . write ( ) <EOL> def create_main_menu ( ) : <EOL> preset_path = st_base . get_preset_path ( ) <EOL> preset_file_name = '<STR_LIT>' <EOL> preset_file_path = os . path . join ( preset_path , preset_file_name ) <EOL> menu_file = MenuFile ( preset_file_path ) <EOL> menus = menu_file . get_menus ( ) <EOL> for menu in menus : <EOL> menu . translate ( ) <EOL> menu_dicts = [ menu . get_menu_dict ( ) for menu in menus ] <EOL> user_menu_path = st_base . get_stino_user_path ( ) <EOL> if not os . path . isdir ( user_menu_path ) : <EOL> os . makedirs ( user_menu_path ) <EOL> target_file_path = os . path . join ( user_menu_path , '<STR_LIT>' ) <EOL> target_file = pyarduino . base . json_file . JSONFile ( target_file_path ) <EOL> target_file . set_data ( menu_dicts ) <EOL> def create_arduino_menu ( ) : <EOL> preset_path = st_base . get_preset_path ( ) <EOL> preset_file_name = '<STR_LIT>' <EOL> preset_file_path = os . path . join ( preset_path , preset_file_name ) <EOL> menu_file = MenuFile ( preset_file_path ) <EOL> menus = menu_file . get_menus ( ) <EOL> for menu in menus : <EOL> menu . translate ( ) <EOL> menu_dicts = [ menu . get_menu_dict ( ) for menu in menus ] <EOL> user_menu_path = st_base . get_user_menu_path ( ) <EOL> menu_path = os . path . join ( user_menu_path , '<STR_LIT>' ) <EOL> if not os . path . isdir ( menu_path ) : <EOL> os . makedirs ( menu_path ) <EOL> target_file_path = os . path . join ( menu_path , '<STR_LIT>' ) <EOL> target_file = pyarduino . base . json_file . JSONFile ( target_file_path ) <EOL> target_file . set_data ( menu_dicts ) <EOL> def create_sketchbook_menu ( arduino_info ) : <EOL> sketchbook = arduino_info . get_sketchbook_dir ( ) . get_sketchbook ( ) <EOL> sub_menus = load_sketchbook_menu ( sketchbook ) . get_sub_menus ( ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) <EOL> def create_examples_menu ( arduino_info ) : <EOL> sub_menus = [ ] <EOL> for root_dir in arduino_info . get_root_dirs ( ) : <EOL> examples = root_dir . get_examples ( ) <EOL> examples_menu = load_sketchbook_menu ( examples ) <EOL> sub_menus += examples_menu . get_sub_menus ( ) <EOL> if sub_menus : <EOL> sub_menus . append ( Menu ( ) ) <EOL> libraries = root_dir . get_libraries ( ) <EOL> for library in libraries : <EOL> lib_arch = library . get_arch ( ) <EOL> caption = '<STR_LIT>' % ( library . get_name ( ) , lib_arch ) <EOL> examples = library . get_examples ( ) <EOL> examples . set_name ( caption ) <EOL> menu = load_sketchbook_menu ( examples ) <EOL> if menu . has_sub_menus ( ) : <EOL> sub_menus . append ( menu ) <EOL> if sub_menus : <EOL> sub_menus . append ( Menu ( ) ) <EOL> for package in root_dir . get_packages ( ) : <EOL> for platform in package . get_platforms ( ) : <EOL> examples = platform . get_examples ( ) <EOL> examples_menu = load_sketchbook_menu ( examples ) <EOL> libraries = platform . get_libraries ( ) <EOL> if examples_menu . get_sub_menus ( ) or libraries : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = platform . get_caption ( ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> sub_menus += examples_menu . get_sub_menus ( ) <EOL> for library in libraries : <EOL> examples = library . get_examples ( ) <EOL> menu = load_sketchbook_menu ( examples ) <EOL> if menu . has_sub_menus ( ) : <EOL> sub_menus . append ( menu ) <EOL> if sub_menus : <EOL> sub_menus . append ( Menu ( ) ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) <EOL> def create_libraries_menu ( arduino_info ) : <EOL> sub_menus = [ ] <EOL> for root_dir in arduino_info . get_root_dirs ( ) : <EOL> libraries = root_dir . get_libraries ( ) <EOL> for library in libraries : <EOL> lib_arch = library . get_arch ( ) <EOL> caption = '<STR_LIT>' % ( library . get_name ( ) , lib_arch ) <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = caption <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : library . get_path ( ) } <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> if sub_menus : <EOL> sub_menus . append ( Menu ( ) ) <EOL> for package in root_dir . get_packages ( ) : <EOL> for platform in package . get_platforms ( ) : <EOL> libraries = platform . get_libraries ( ) <EOL> if libraries : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = platform . get_caption ( ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> for library in libraries : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = library . get_name ( ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : library . get_path ( ) } <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> if sub_menus : <EOL> sub_menus . append ( Menu ( ) ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) <EOL> def create_boards_menu ( arduino_info ) : <EOL> sub_menus = [ ] <EOL> for root_dir in arduino_info . get_root_dirs ( ) : <EOL> for package in root_dir . get_packages ( ) : <EOL> for platform in package . get_platforms ( ) : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = platform . get_caption ( ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> boards = platform . get_boards ( ) <EOL> for board in boards : <EOL> menu_dict = { } <EOL> caption = board . get_caption ( ) <EOL> board_group = board . get_params ( ) . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if board_group : <EOL> caption = '<STR_LIT>' % ( board_group , caption ) <EOL> menu_dict [ '<STR_LIT>' ] = caption <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : board . get_id ( ) } <EOL> menu_dict [ '<STR_LIT>' ] = True <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> sub_menus . append ( Menu ( ) ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) <EOL> def create_board_options_menu ( arduino_info ) : <EOL> sub_menus = [ ] <EOL> target_board = arduino_info . get_target_board_info ( ) . get_target_board ( ) <EOL> if target_board : <EOL> board_options = target_board . get_options ( ) <EOL> for option_index , option in enumerate ( board_options ) : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = option . get_caption ( ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> sub_boards = option . get_items ( ) <EOL> for sub_board in sub_boards : <EOL> if sub_board . get_caption ( ) != '<STR_LIT>' : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = sub_board . get_caption ( ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : option_index , <EOL> '<STR_LIT>' : sub_board . get_id ( ) } <EOL> menu_dict [ '<STR_LIT>' ] = True <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> sub_menus . append ( Menu ( ) ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) <EOL> def create_programmers_menu ( arduino_info ) : <EOL> sub_menus = [ ] <EOL> for root_dir in arduino_info . get_root_dirs ( ) : <EOL> for package in root_dir . get_packages ( ) : <EOL> for platform in package . get_platforms ( ) : <EOL> platform_menus = [ ] <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = platform . get_caption ( ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> caption_menu = Menu ( menu_dict ) <EOL> programmers = platform . get_programmers ( ) <EOL> for programmer in programmers : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = programmer . get_params ( ) . get ( '<STR_LIT:name>' ) <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : programmer . get_id ( ) } <EOL> menu_dict [ '<STR_LIT>' ] = True <EOL> menu = Menu ( menu_dict ) <EOL> platform_menus . append ( menu ) <EOL> if platform_menus : <EOL> platform_menus . insert ( <NUM_LIT:0> , caption_menu ) <EOL> sub_menus += platform_menus <EOL> sub_menus . append ( Menu ( ) ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) <EOL> def create_serials_menu ( ) : <EOL> sub_menus = [ ] <EOL> serial_ports = pyarduino . base . serial_port . list_serial_ports ( ) <EOL> for serial_port in serial_ports : <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = serial_port <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : serial_port } <EOL> menu_dict [ '<STR_LIT>' ] = True <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) <EOL> def create_languages_menu ( ) : <EOL> sub_menus = [ ] <EOL> i18n = st_base . get_i18n ( ) <EOL> lang_ids = i18n . get_lang_ids ( ) <EOL> for lang_id in lang_ids : <EOL> lang_names = i18n . get_lang_names ( lang_id ) <EOL> caption = '<STR_LIT>' % ( lang_names [ <NUM_LIT:0> ] , lang_names [ <NUM_LIT:1> ] ) <EOL> menu_dict = { } <EOL> menu_dict [ '<STR_LIT>' ] = caption <EOL> menu_dict [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> menu_dict [ '<STR_LIT:args>' ] = { '<STR_LIT>' : lang_id } <EOL> menu_dict [ '<STR_LIT>' ] = True <EOL> menu = Menu ( menu_dict ) <EOL> sub_menus . append ( menu ) <EOL> write_menu ( '<STR_LIT>' , sub_menus ) </s>
