create the whole thing using a MenuTree which has minimal information.
 It uses a hotkey and a code only. We are supposed to resolve the display text
 and actual proc from the caller using this code.
979291
def menu_tree mt, pm = self
      mt.each_pair { |ch, code| 
        if code.is_a? Canis::MenuTree
          item = pm.add(ch, code.value, "") 
          current = PromptMenu.new @caller, code.value
          item.action = current
          menu_tree code, current
        else
          item = pm.add(ch, code.to_s, "", code) 
        end
      }
    end
821635
def main():
    

    # Parse arguments and configure application instance.
    arguments, parser = parse_arguments()

    # Start iterating
    store = RevisionStore()
    sys.stdout.write("Iterating over %d items.\n" % arguments.number)

    for i in xrange(arguments.number):
        key = chr(65 + (i % 26))
        value = [key * (i % 26), key * (i % 13), key * (i % 5)]

        store.add(key, value)

    # Wait for an enter
    if arguments.pause:
        sys.stdout.write("Done!")
        sys.stdin.readline()
1241516
def ui_main(fmt_table, node_dict):
    """"""
    cmd_funct = {"quit": False,
                 "run": node_cmd,
                 "stop": node_cmd,
                 "connect": node_cmd,
                 "details": node_cmd,
                 "update": True}
    ui_print("\033[?25l")  # cursor off
    print("{}\n".format(fmt_table))
    sys.stdout.flush()
    # refresh_main values:
    #   None = loop main-cmd, True = refresh-list, False = exit-program
    refresh_main = None
    while refresh_main is None:
        cmd_name = get_user_cmd(node_dict)
        if callable(cmd_funct[cmd_name]):
            refresh_main = cmd_funct[cmd_name](cmd_name, node_dict)
        else:
            refresh_main = cmd_funct[cmd_name]
    if cmd_name != "connect" and refresh_main:
        ui_clear(len(node_dict) + 2)
    return refresh_main
292897
function MenuCommand_createSeparator() {
                    // Make sure there's an input element
                    if (!this._element) {
                        this._element = _Global.document.createElement("hr");
                    } else {
                        // Verify the input was an hr
                        if (this._element.tagName !== "HR") {
                            throw new _ErrorFromName("WinJS.UI.MenuCommand.BadHrElement", strings.badHrElement);
                        }
                    }
                }
363093
def create_create():
    
    create = upkey("create").setResultsName("action")
    hash_key = Group(upkey("hash") + upkey("key"))
    range_key = Group(upkey("range") + upkey("key"))

    local_index = Group(
        index
        + Suppress("(")
        + primitive
        + Optional(Suppress(",") + include_vars)
        + Suppress(")")
    )
    index_type = (
        (hash_key | range_key | local_index)
        .setName("index specification")
        .setResultsName("index")
    )

    attr_declaration = (
        Group(var.setResultsName("name") + type_ + Optional(index_type))
        .setName("attr")
        .setResultsName("attr")
    )
    attrs_declaration = (
        Suppress("(")
        + Group(delimitedList(attr_declaration))
        .setName("attrs")
        .setResultsName("attrs")
        + Optional(Suppress(",") + throughput)
        + Suppress(")")
    )

    global_index = _global_index()
    global_indexes = Group(OneOrMore(global_index)).setResultsName("global_indexes")

    return (
        create
        + table_key
        + Optional(if_not_exists)
        + table
        + attrs_declaration
        + Optional(global_indexes)
    )
954979
private void menuGoToFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGoToFileActionPerformed
    final GoToFilePanel panel = new GoToFilePanel(this.explorerTree, JOptionPane.OK_OPTION);
    if (DialogProviderManager.getInstance().getDialogProvider().msgOkCancel(null, "Go To File", panel)) {
      final NodeFileOrFolder selected = panel.getSelected();
      if (selected != null) {
        final File file = selected.makeFileForNode();
        if (file != null) {
          this.focusInTree(file);
          ensureTreePanelVisible();
          SwingUtilities.invokeLater(() -> {
            explorerTree.requestFocus();
          });
        }
      }
    }
  }
631860
def generate_tree(root, paths, mock_os):
    
    tree = []
    dentries = mock_os.listdir(root)

    for d in dentries:
        full_path = mock_os.path.join(root, d)
        node = {
            'text': d,
            'href': '#%s' % d,
            'state': {
                'expanded': True
            }
        }

        if mock_os.path.isdir(full_path):
            node['nodes'] = generate_tree(full_path, paths, mock_os)
        else:
            node['icon'] = 'fa fa-file-code-o'
            node['href'] = '#'
            node['color'] = '#0088ce'
            node['dataAttr'] = {
                'toggle': 'modal',
                'target': '#file_modal',
                'load': paths[full_path] + '/'
            }
        tree.append(node)
    return tree
1028558
protected void buildTree() {
		treeGrid.setWidth100();
		treeGrid.setHeight100();
		treeGrid.setShowHeader(false);
		treeGrid.setOverflow(Overflow.AUTO);
		tree = new RefreshableTree();
		final TreeNode nodeRoot = new TreeNode("ROOT");
		tree.setRoot(nodeRoot); // invisible ROOT node (ROOT node is required)

		ClientLayerTreeInfo layerTreeInfo = (ClientLayerTreeInfo) mapModel.getMapInfo().getWidgetInfo(
				ClientLayerTreeInfo.IDENTIFIER);
		tree.setRoot(nodeRoot); // invisible ROOT node (ROOT node is required)
		if (layerTreeInfo != null) {
			for (ClientAbstractNodeInfo node : layerTreeInfo.getTreeNode().getTreeNodes()) {
				processNode(node, nodeRoot, false);
			}
		}

		treeGrid.setData(tree);
		treeGrid.addLeafClickHandler(this);
		treeGrid.addFolderClickHandler(this);

		treeGrid.addFolderClickHandler(new FolderClickHandler() {
			@Override
			public void onFolderClick(FolderClickEvent folderClickEvent) {
				folderClickEvent.getSource();
			}
		});


		treeGrid.addFolderOpenedHandler(new FolderOpenedHandler() {
			@Override
			public void onFolderOpened(FolderOpenedEvent folderOpenedEvent) {
				folderOpenedEvent.getSource();
			}
		});

		tree.openFolder(nodeRoot);
		syncNodeState(false);
	}
162328
public void createMenu(int menuId){
        mToolbar.inflateMenu(menuId);
        mMenuDataChanged = true;
        if(mAppCompatDelegate == null)
            onPrepareMenu();
    }
48076
private static void createAndShowGUI() {

    // Create and set up the window.
    JFrame frame = new JFrame("XChart Demo");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    // Add content to the window.
    frame.add(new XChartDemo());

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
1301914
protected ActionCommand createCreateCommand()
    {
        ActionCommand command = new ActionCommand(CREATE_COMMAND_ID)
        {

            @Override
            protected void doExecuteCommand()
            {
                doCreate();
            }
        };
        command.setSecurityControllerId(getId() + "." + CREATE_COMMAND_ID);
        getApplicationConfig().commandConfigurer().configure(command);
        getDetailForm().addGuarded(command, FormGuard.LIKE_COMMITCOMMAND);
        return command;
    }
992480
def create(self):
        
        self.add_handlers({'^T': self.quit, '^Q': self.quit,
                           '^V': self.toggle_view})
        self.add(npyscreen.TitleFixedText, name=self.action['title'], value='')
        response = self.action['api_action'].inventory(choices=['repos',
                                                                'tools',
                                                                'images',
                                                                'built',
                                                                'running'])
        if response[0]:
            inventory = response[1]
            if len(inventory['repos']) == 0:
                value = 'No tools were found.\n'
            else:
                value = 'Tools for all groups found:\n'
            tools = None
            if inventory['tools']:
                tools = inventory['tools']

            for repo in inventory['repos']:
                s_value = ''
                repo_name = repo.rsplit('/', 2)[1:]
                if len(repo_name) == 1:
                    repo_name = repo.split('/')
                if tools:
                    p_value = '\n  Plugin: ' + repo + '\n'
                    for tool in tools:
                        t_name = tool.split(':')
                        if (t_name[0] == repo_name[0] and
                                t_name[1] == repo_name[1]):
                            s_value += '    ' + tools[tool] + '\n      Built: '
                            s_value += inventory['built'][tool] + '\n'
                            s_value += '      Image name: '
                            s_value += inventory['images'][tool] + '\n'
                            s_value += '      Status: '
                            s_value += inventory['running'][tool] + '\n'
                if s_value:
                    value += p_value + s_value
        else:
            value = 'There was an issue with ' + self.action['name']
            value += ' retrieval:\n' + str(response[1])
            value += '\nPlease see vent.log for more details.'
        self.all_tools = value.split('\n')
        self.display_val = self.add(npyscreen.Pager, values=value.split('\n'))
144301
def do_create(self, line):
        ""
        args = self.getargs(line)
        rc = wc = 5

        name = args.pop(0)  # tablename

        if args[0] == "-c":  # capacity
            args.pop(0)  # skyp -c

            capacity = args.pop(0).strip()
            rc, _, wc = capacity.partition(",")
            rc = int(rc)
            wc = int(wc) if wc != "" else rc

        hkey, _, hkey_type = args.pop(0).partition(':')
        hkey_type = self.get_type(hkey_type or 'S')

        if args:
            rkey, _, rkey_type = args.pop(0).partition(':')
            rkey_type = self.get_type(rkey_type or 'S')
        else:
            rkey = rkey_type = None

        t = self.conn.create_table(name,
                                   self.conn.create_schema(hkey, hkey_type, rkey, rkey_type),
                                   rc, wc)
        self.pprint(self.conn.describe_table(t.name))
404782
def _create_menu(self, items):
        
        menu = Gtk.Menu()
        self._create_menu_items(menu, items)
        return menu
877470
def CreateMenuBar(self):
        """"""
        menubar = wx.MenuBar()
        menu = wx.Menu()
        menu.Append(ID_OPEN, _('&Open Profile'), _('Open a cProfile file'))
        menu.Append(ID_OPEN_MEMORY, _('Open &Memory'), _('Open a Meliae memory-dump file'))
        menu.AppendSeparator()
        menu.Append(ID_EXIT, _('&Close'), _('Close this RunSnakeRun window'))
        menubar.Append(menu, _('&File'))
        menu = wx.Menu()
#        self.packageMenuItem = menu.AppendCheckItem(
#            ID_PACKAGE_VIEW, _('&File View'),
#            _('View time spent by package/module')
#        )
        self.percentageMenuItem = menu.AppendCheckItem(
            ID_PERCENTAGE_VIEW, _('&Percentage View'),
            _('View time spent as percent of overall time')
        )
        self.rootViewItem = menu.Append(
            ID_ROOT_VIEW, _('&Root View (Home)'),
            _('View the root of the tree')
        )
        self.backViewItem = menu.Append(
            ID_BACK_VIEW, _('&Back'), _('Go back in your viewing history')
        )
        self.upViewItem = menu.Append(
            ID_UP_VIEW, _('&Up'),
            _('Go "up" to the parent of this node with the largest cumulative total')
        )
        self.moreSquareViewItem = menu.AppendCheckItem(
            ID_MORE_SQUARE, _('&Hierarchic Squares'),
            _('Toggle hierarchic squares in the square-map view')
        )

        # This stuff isn't really all that useful for profiling,
        # it's more about how to generate graphics to describe profiling...
        self.deeperViewItem = menu.Append(
            ID_DEEPER_VIEW, _('&Deeper'), _('View deeper squaremap views')
        )
        self.shallowerViewItem = menu.Append(
            ID_SHALLOWER_VIEW, _('&Shallower'), _('View shallower squaremap views')
        )
#        wx.ToolTip.Enable(True)
        menubar.Append(menu, _('&View'))
        
        self.viewTypeMenu =wx.Menu( )
        menubar.Append(self.viewTypeMenu, _('View &Type'))
        
        self.SetMenuBar(menubar)

        wx.EVT_MENU(self, ID_EXIT, lambda evt: self.Close(True))
        wx.EVT_MENU(self, ID_OPEN, self.OnOpenFile)
        wx.EVT_MENU(self, ID_OPEN_MEMORY, self.OnOpenMemory)
        
        wx.EVT_MENU(self, ID_PERCENTAGE_VIEW, self.OnPercentageView)
        wx.EVT_MENU(self, ID_UP_VIEW, self.OnUpView)
        wx.EVT_MENU(self, ID_DEEPER_VIEW, self.OnDeeperView)
        wx.EVT_MENU(self, ID_SHALLOWER_VIEW, self.OnShallowerView)
        wx.EVT_MENU(self, ID_ROOT_VIEW, self.OnRootView)
        wx.EVT_MENU(self, ID_BACK_VIEW, self.OnBackView)
        wx.EVT_MENU(self, ID_MORE_SQUARE, self.OnMoreSquareToggle)
700399
def create_menubar(MAIN):
    """"""
    actions = MAIN.action
    menubar = MAIN.menuBar()
    menubar.clear()

    """ ------ FILE ------ """
    menu_file = menubar.addMenu('File')
    menu_file.addAction(MAIN.info.action['open_dataset'])
    submenu_recent = menu_file.addMenu('Recent Datasets')
    submenu_recent.addActions(MAIN.info.action['open_recent'])
    menu_file.addAction(MAIN.info.action['export'])

    menu_file.addSeparator()
    menu_file.addAction(actions['open_settings'])
    menu_file.addSeparator()
    menu_file.addAction(actions['close_wndw'])

    """ ------ CHANNELS ------ """
    actions = MAIN.channels.action
    menu_time = menubar.addMenu('Channels')
    menu_time.addAction(actions['load_channels'])
    menu_time.addAction(actions['save_channels'])

    """ ------ NAVIGATION ------ """
    actions = MAIN.traces.action

    menu_time = menubar.addMenu('Navigation')
    menu_time.addAction(actions['step_prev'])
    menu_time.addAction(actions['step_next'])
    menu_time.addAction(actions['page_prev'])
    menu_time.addAction(actions['page_next'])
    menu_time.addSeparator()
    menu_time.addAction(actions['addtime_-6h'])
    menu_time.addAction(actions['addtime_-1h'])
    menu_time.addAction(actions['addtime_-10min'])
    menu_time.addAction(actions['addtime_10min'])
    menu_time.addAction(actions['addtime_1h'])
    menu_time.addAction(actions['addtime_6h'])
    menu_time.addSeparator()
    menu_time.addAction(actions['next_event'])
    menu_time.addAction(actions['del_and_next_event'])
    menu_time.addAction(actions['next_of_same_type'])
    menu_time.addAction(actions['centre_event'])
    menu_time.addSeparator()
    menu_time.addAction(actions['go_to_epoch'])
    menu_time.addAction(actions['line_up_with_epoch'])

    """ ------ VIEW ------ """
    actions = MAIN.traces.action

    menu_view = menubar.addMenu('View')
    submenu_ampl = menu_view.addMenu('Global Scaling')
    submenu_ampl.addAction(actions['Y_less'])
    submenu_ampl.addAction(actions['Y_more'])
    submenu_ampl.addSeparator()
    for x in sorted(MAIN.value('y_scale_presets'), reverse=True):
        act = submenu_ampl.addAction('Set to ' + str(x))
        act.triggered.connect(partial(MAIN.traces.Y_ampl, x))

    submenu_dist = menu_view.addMenu('Distance Between Traces')
    submenu_dist.addAction(actions['Y_wider'])
    submenu_dist.addAction(actions['Y_tighter'])
    submenu_dist.addSeparator()
    for x in sorted(MAIN.value('y_distance_presets'),
                    reverse=True):
        act = submenu_dist.addAction('Set to ' + str(x))
        act.triggered.connect(partial(MAIN.traces.Y_dist, x))

    submenu_length = menu_view.addMenu('Window Length')
    submenu_length.addAction(actions['X_more'])
    submenu_length.addAction(actions['X_less'])
    submenu_length.addSeparator()
    for x in sorted(MAIN.value('window_length_presets'),
                    reverse=True):
        act = submenu_length.addAction('Set to ' + str(x))
        act.triggered.connect(partial(MAIN.traces.X_length, x))

    menu_view.addAction(actions['cross_chan_mrk'])

    menu_view.addSeparator()
    menu_view.addAction(actions['export_svg'])

    """ ------ ANNOTATIONS ------ """
    actions = MAIN.notes.action

    menu_annot = menubar.addMenu('Annotations')
    menu_annot.addAction(actions['new_annot'])
    menu_annot.addAction(actions['load_annot'])
    menu_annot.addAction(actions['clear_annot'])
    menu_annot.addSeparator()

    submenu_rater = menu_annot.addMenu('Rater')
    submenu_rater.addAction(actions['new_rater'])
    submenu_rater.addAction(actions['rename_rater'])
    submenu_rater.addAction(actions['del_rater'])
    submenu_rater.addSeparator()
    if MAIN.notes.annot is not None:
        for rater in sorted(MAIN.notes.annot.raters):
            act = submenu_rater.addAction(rater)
            act.triggered.connect(partial(MAIN.notes.select_rater, rater))
    menu_annot.addSeparator()

    submenu_marker = menu_annot.addMenu('Bookmark')
    submenu_marker.addAction(actions['new_bookmark'])

    submenu_event = menu_annot.addMenu('Event')
    submenu_event.addAction(actions['new_eventtype'])
    submenu_event.addAction(actions['del_eventtype'])
    submenu_event.addAction(actions['rename_eventtype'])
    submenu_mrk2evt = submenu_event.addMenu('Markers into Events')
    submenu_mrk2evt.addAction(actions['m2e_newname'])
    submenu_mrk2evt.addAction(actions['m2e_keepname'])
    submenu_event.addAction(actions['merge_events'])
    submenu_event.addAction(MAIN.traces.action['change_event_type'])

    # these are the real QActions attached to notes
    submenu_stage = menu_annot.addMenu('Stage')
    submenu_stage.addActions(MAIN.notes.actions())

    submenu_mrkr = menu_annot.addMenu('Cycle')
    submenu_mrkr.addAction(actions['cyc_start'])
    submenu_mrkr.addAction(actions['cyc_end'])
    submenu_mrkr.addAction(actions['remove_cyc'])
    submenu_mrkr.addAction(actions['clear_cyc'])
    menu_annot.addSeparator()

    submenu_import = menu_annot.addMenu('Import Staging')
    submenu_import.addAction(actions['import_alice'])
    submenu_import.addAction(actions['import_compumedics'])
    submenu_import.addAction(actions['import_deltamed'])
    submenu_import.addAction(actions['import_domino'])
    submenu_import.addAction(actions['import_prana'])
    submenu_import.addAction(actions['import_remlogic'])
    submenu_import.addAction(actions['import_sandman'])
    submenu_import.addAction(actions['import_fasst'])

    submenu_import_qual = menu_annot.addMenu('Import Signal Quality')
    submenu_import_qual.addAction(actions['import_alice_qual'])
    submenu_import_qual.addAction(actions['import_compumedics_qual'])
    submenu_import_qual.addAction(actions['import_deltamed_qual'])
    submenu_import_qual.addAction(actions['import_domino_qual'])
    submenu_import_qual.addAction(actions['import_prana_qual'])
    submenu_import_qual.addAction(actions['import_remlogic_qual'])
    submenu_import_qual.addAction(actions['import_sandman_qual'])
    
    submenu_import_event = menu_annot.addMenu('Import Events')
    submenu_import_event.addAction(actions['import_events_wonambi'])
    submenu_import_event.addAction(actions['import_events_remlogic'])
    menu_annot.addSeparator()
    
    submenu_export_staging = menu_annot.addMenu('Export Staging')
    submenu_export_staging.addAction(actions['export_to_csv'])
    submenu_export_staging.addAction(actions['export_to_remlogic'])
    submenu_export_staging.addAction(actions['export_to_remlogic_fr'])

    menu_annot.addAction(actions['export_events'])    
    menu_annot.addSeparator()
    
    menu_annot.addAction(actions['export_sleepstats'])

    """ ------ ANALYSIS ------ """
    actions = MAIN.notes.action

    menu_analysis = menubar.addMenu('Analysis')

    submenu_detect = menu_analysis.addMenu('Detection')
    submenu_detect.addAction(actions['spindle'])
    submenu_detect.addAction(actions['slow_wave'])

    menu_analysis.addAction(actions['analyze'])


    """ ------ WINDOWS ------ """
    actions = MAIN.action

    menu_window = menubar.addMenu('Windows')
    for dockwidget_act in actions['dockwidgets']:
        menu_window.addAction(dockwidget_act)
    MAIN.menu_window = menu_window

    menu_about = menubar.addMenu('About')
    menu_about.addAction(actions['about'])
    menu_about.addAction(actions['aboutqt'])
928558
def run_treefix(input, stree_file, smap_file, a_ext=".fasta", \
                o_ext=".dnd", n_ext = ".treefix.dnd", **kwargs):
    
    cl = TreeFixCommandline(input=input, \
            stree_file=stree_file, smap_file=smap_file, a_ext=a_ext, \
            o=o_ext, n=n_ext, **kwargs)
    outtreefile = input.rsplit(o_ext, 1)[0] + n_ext
    print("TreeFix:", cl, file=sys.stderr)
    r, e = cl.run()

    if e:
        print("***TreeFix could not run", file=sys.stderr)
        return None
    else:
        logging.debug("new tree written to {0}".format(outtreefile))
        return outtreefile