Ejemplo n.º 1
0
 def _misc_command_hook(self, menu: vpython.menu):
     if menu.selected == MiscCommand.UNDOCK.value:
         self._commands.append(Request(ident=Request.UNDOCK))
     elif menu.selected == MiscCommand.DEPLOY_PARACHUTE.value:
         self._commands.append(Request(
             ident=Request.PARACHUTE,
             deploy_parachute=not self._state.parachute_deployed))
     elif menu.selected == MiscCommand.IGNITE_SRBS.value:
         self._commands.append(Request(ident=Request.IGNITE_SRBS))
     menu.selected = MiscCommand.UNSELECTED.value
Ejemplo n.º 2
0
 def _set_target(self, entity_name: str) -> None:
     try:
         self._commands.append(
             Request(ident=Request.TARGET_UPDATE, target=entity_name))
         self._3dobjs[entity_name].draw_landing_graphic(
             self._state[entity_name])
     except IndexError:
         log.error(f'Tried to set non-existent target "{entity_name}"')
Ejemplo n.º 3
0
 def _set_reference(self, entity_name: str) -> None:
     try:
         self._commands.append(Request(
             ident=Request.REFERENCE_UPDATE, reference=entity_name))
         self._landing_graphic.draw(self._3dobjs[entity_name])
         if self._show_trails:
             self._clear_trails()
     except IndexError:
         log.error(f'Tried to set non-existent reference "{entity_name}"')
Ejemplo n.º 4
0
    def _render_coolants(self):

        loops = cw.ENGLabelFrame(self.left_frame, text="", style=style)
        loops.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

        for cl in range(2):
            prefix = 'hl{}_'.format(cl + 1)
            loop = cw.ENGLabelFrame(loops,
                                    text='Coolant Loop {}'.format(cl + 1),
                                    style=style)
            loop.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)

            widgets[prefix + 'pump'] = cw.ENGLabel(loop,
                                                   text='PUMP',
                                                   value=0,
                                                   unit='%',
                                                   style=style)
            widgets[prefix + 'pump_sldr'] = cw.ENGScale(loop,
                                                        widgets[prefix +
                                                                'pump'],
                                                        style=style)

            widgets[prefix + 'temp'] = cw.ENGLabel(loop,
                                                   text='TEMP',
                                                   value=47,
                                                   unit='*C',
                                                   style=style)

            widgets[prefix + 'pump'].grid(row=0, column=0)
            widgets[prefix + 'pump_sldr'].grid(row=0,
                                               column=1,
                                               rowspan=2,
                                               columnspan=2)
            widgets[prefix + 'temp'].grid(row=1, column=0, pady=5)

            for i in range(2):
                for j in range(3):
                    indicator_num = i * 3 + j + 1
                    rad_label = f'R{indicator_num}'

                    widgets[prefix + rad_label] = cw.Indicator(
                        loop,
                        text=rad_label,
                        style=style,
                        command_on_press=Request(
                            ident=Request.TOGGLE_RADIATOR,
                            radiator_to_toggle=indicator_num - 1))
                    widgets[prefix + rad_label].grid(row=i + 2,
                                                     column=j,
                                                     sticky=tk.E)
                    widgets[prefix + rad_label].set_redrawer(
                        lambda widget, state, n=indicator_num: widget.update(
                            state.radiators[n - 1].functioning))
Ejemplo n.º 5
0
 def _load_hook(self, textbox: vpython.winput):
     full_path = common.savefile(textbox.text)
     if full_path.is_file():
         self._commands.append(Request(
             ident=Request.LOAD_SAVEFILE, loadfile=textbox.text))
         textbox.text = 'File loaded!'
         # The file we loaded will have a non-zero time acc, unpause.
         self.pause(False)
         # Re-centre on the habitat.
         self._sidebar.centre_menu._menu.selected = common.HABITAT
         self._recentre_dropdown_hook(self._sidebar.centre_menu._menu)
     else:
         log.warning(f'Ignored non-existent loadfile: {full_path}')
         textbox.text = 'File not found!'
Ejemplo n.º 6
0
    def _time_acc_dropdown_hook(self, time_acc_menu: vpython.menu):
        time_acc = STR_TO_TIME_ACC[time_acc_menu.selected]
        # Insert this TIME_ACC_SET command at the beginning of the list,
        # so that we process it as quickly as possible. This isn't necessary,
        # but can get us out of a stuck simulation faster.
        self._commands.insert(
            0, Request(ident=Request.TIME_ACC_SET, time_acc_set=time_acc))

        if self._paused and time_acc != 0:
            # We are unpausing.
            self.pause(False)
        if not self._paused and time_acc == 0:
            # We are pausing.
            self.pause(True)
Ejemplo n.º 7
0
 def _navmode_hook(self, menu: vpython.menu):
     self._commands.append(Request(
         ident=Request.NAVMODE_SET,
         navmode=Navmode[menu.selected].value))
Ejemplo n.º 8
0
 def _set_target(self, entity_name: str) -> None:
     try:
         self._commands.append(Request(
             ident=Request.TARGET_UPDATE, target=entity_name))
     except IndexError:
         log.error(f'Tried to set non-existent target "{entity_name}"')
Ejemplo n.º 9
0
    def _handle_keydown(self, evt: vpython.event_return) -> None:
        """Called in a non-main thread by vpython when it gets key input."""
        if self._paused:
            # The user could be entering in things in the text fields, so just
            # wait until they're not paused.
            return
        if self.requesting_read_from_physics_server():
            # We shouldn't be generating any commands, ignore this.
            return

        k = evt.key
        if k == 'l':
            self._show_label = not self._show_label
            for name, obj in self._3dobjs.items():
                obj._show_hide_label()
        elif k == 'a':
            self._commands.append(Request(
                ident=Request.HAB_SPIN_CHANGE,
                spin_change=common.SPIN_CHANGE))
        elif k == 'd':
            self._commands.append(Request(
                ident=Request.HAB_SPIN_CHANGE,
                spin_change=-common.SPIN_CHANGE))
        elif k == 'A':
            self._commands.append(Request(
                ident=Request.HAB_SPIN_CHANGE,
                spin_change=common.FINE_SPIN_CHANGE))
        elif k == 'D':
            self._commands.append(Request(
                ident=Request.HAB_SPIN_CHANGE,
                spin_change=-common.FINE_SPIN_CHANGE))
        elif k == 'w':
            self._commands.append(Request(
                ident=Request.HAB_THROTTLE_CHANGE,
                throttle_change=0.01))
        elif k == 's':
            self._commands.append(Request(
                ident=Request.HAB_THROTTLE_CHANGE,
                throttle_change=-0.01))
        elif k == 'W':
            self._commands.append(Request(
                ident=Request.HAB_THROTTLE_CHANGE,
                throttle_change=0.001))
        elif k == 'S':
            self._commands.append(Request(
                ident=Request.HAB_THROTTLE_CHANGE,
                throttle_change=-0.001))
        elif k == '\n':
            self._commands.append(Request(
                ident=Request.HAB_THROTTLE_SET,
                throttle_set=1.00))
        elif k == 'backspace':
            self._commands.append(Request(
                ident=Request.HAB_THROTTLE_SET,
                throttle_set=0.00))
        elif k == '.':
            try:
                self._sidebar.time_acc_menu._menu.index += 1
                self._time_acc_dropdown_hook(self._sidebar.time_acc_menu._menu)
            except IndexError:
                pass  # We're already at max time acceleration
        elif k == ',':
            if self._sidebar.time_acc_menu._menu.index != 1:
                self._sidebar.time_acc_menu._menu.index -= 1
                self._time_acc_dropdown_hook(self._sidebar.time_acc_menu._menu)
        elif k == 'p':
            # Pause
            self._sidebar.time_acc_menu._menu.index = 0
            self._time_acc_dropdown_hook(self._sidebar.time_acc_menu._menu)