Ejemplo n.º 1
0
    def menu(self):
        """
        present the menu pointed to by the current _menu_position- follow subdicts until a handler is encountered

        handlers are callable
        :return:
        """

        pointer = self._menu_position.pop(-1)

        while True:
            print('\n\n%s' % ('#' * 120))

            self._catalog.show_loaded()
            if self._current_archive is None:
                print('\nSearching all loaded archives')
            else:
                print('\nCurrent archive: %s' % self._current_archive)

            if self._selected_flowable is not None:
                print('\n Current Flowable: %.100s' % self._flowdb.flowables[self._selected_flowable])

            if self._selected_compartment is not None:
                print('\n Current Compartment: %s' % self._selected_compartment.to_list())

            if len(self.selected) == 0:
                print(' [[ No entities currently selected ]]')
            else:
                print('\n Current entity selection: ')
                for i in self.selected:
                    print('[[ %s ]]' % i)

            while isinstance(pointer, dict):
                self._menu_position.append(pointer)
                go_up = len(self._menu_position) > 1
                uchoice = menu_list(*[k for k, v in pointer.items() if v != []], go_up=go_up)
                if uchoice == -1 or uchoice is None:
                    if len(self._menu_position) == 1:
                        pointer = 1
                        break
                    self._menu_position.pop(-1)
                    pointer = self._menu_position.pop(-1)
                else:
                    pointer = pointer[uchoice]

            # pointer = 1 is the signal to quit
            if pointer == 1:
                break

            # if pointer is not a dict, it must be callable
            # and it must return a valid pointer string
            message = pointer(self)()

            if message is not True and message is not None:
                print('** %s ** ' % message)
                sleep(0.8)

            pointer = self._menu_position.pop(-1)

        self._m.save()
Ejemplo n.º 2
0
 def edit_flow(self):
     flow = pick_one(self._catalog[0].flows())
     print('Select field to edit:')
     field = menu_list(*flow.keys())
     if field == -1 or field is None:
         return True
     new = ifinput('Enter new value for %s: ' % field, flow[field])
     flow[field] = new
Ejemplo n.º 3
0
 def inspect(self):
     sel = pick_list(self.selected)
     sel.show()
     while True:
         print('** Select Inspection **')
         uchoice = menu_list(*[k for k, v in inspections[sel.entity_type].items() if v != []], go_up=True)
         if uchoice == -1 or uchoice is None:
             return True
         inspections[sel.entity_type][uchoice](self)(sel)
Ejemplo n.º 4
0
 def _edit_entity(entity):
     print('Select field to edit:')
     field = menu_list(*entity.keys())
     if field == -1 or field is None:
         return True
     new = ifinput('Enter new value for %s: ' % field, entity[field])
     if len(new) > 0:
         entity[field] = new
     else:
         print('Not updating.')
Ejemplo n.º 5
0
 def _edit_entity(entity):
     print('Select field to edit:')
     field = menu_list(*entity.keys())
     if field == -1 or field is None:
         return True
     new = ifinput('Enter new value for %s: ' % field, entity[field])
     if len(new) > 0:
         entity[field] = new
     else:
         print('Not updating.')
Ejemplo n.º 6
0
 def add_child_fragment(self):
     parent = self._selected_fragment
     k = cyoa('use (N)ew or (E)xisting flow?', 'NE', 'N')
     if k.lower() == 'e':
         print('Select Reference flow:')
         flow = pick_one(self._catalog[0].flows())
         if flow is None:
             print('Canceling child fragment flow')
             return None
     else:
         flow = self.create_flow()
     direction = menu_list('Input', 'Output')
     self._catalog[0].add_child_fragment_flow(parent, flow, direction)
Ejemplo n.º 7
0
 def create_fragment(self):
     print('Create fragment.')
     name = input('Name: ')
     k = cyoa('Reference flow: Use (F)oreground flow or (S)earch for flow?', 'FS', 'F')
     if k.lower() == 'f':
         print('Select Reference flow:')
         flow = pick_one(self._catalog[0].flows())
     else:
         self.isearch('flow')()
         flow = pick_one([f for f in self.selected if f.entity_type == 'flow'])
         self._m.add_to_foreground(flow)
         flow = flow.entity()
     print('Direction w.r.t. upstream:')
     direction = menu_list('Input', 'Output')
     print('interface\nname: %s\nflow: %s\ndirn: %s' % (name, flow, direction))
     self._catalog[0].create_fragment(flow, direction, name=name)