def __init__(self, flight_gui: FlightGui, running_as_mirror: bool): """Create the sidebar caption.""" self._parent = flight_gui self._create_wtexts() self.trails_checkbox = Checkbox( self._parent.trail_checkbox_hook, DEFAULT_TRAILS, 'Trails', "Graphically intensive") self.orbits_checkbox = Checkbox( self._parent._orbits_checkbox_hook, False, 'Orbit', "Simple projection of hab around reference.") vpython.canvas.get_selected().append_to_caption("<br/>") self._create_menus() # If you change the order of these, note that the placeholder text # is set in flight_gui_footer.html self._save_box = vpython.winput( bind=self._parent._save_hook, type='string') self._save_box.disabled = True vpython.canvas.get_selected().append_to_caption("\n") self._load_box = vpython.winput( bind=self._parent._load_hook, type='string') self._load_box.disabled = True vpython.canvas.get_selected().append_to_caption("\n") vpython.canvas.get_selected().append_to_caption( "<span class='helptext'>" "Filename to save/load under data/saves/</span>") vpython.canvas.get_selected().append_to_caption("\n") vpython.canvas.get_selected().append_to_caption("<br/>") self.follow_lead_checkbox: Optional[Checkbox] if running_as_mirror: start_off_following = True self.follow_lead_checkbox = Checkbox( lambda checkbox: self._disable_inputs(checkbox.checked), start_off_following, 'Follow physics server', "Check to keep this mirror program in sync with the " "mirror://[host]:[port] OrbitX physics server specified at " "startup" ) self._disable_inputs(start_off_following) else: self.follow_lead_checkbox = None common.remove_vpython_css() common.include_vpython_footer_file( Path('orbitx', 'graphics', 'flight_gui_footer.html'))
def Reset(): vp.scene.width = 800 vp.scene.height = 800 vp.scene.range = 1.3 vp.scene.title = "ANTIKYTHERA\n" vp.button(text="display", bind=display, pos=vp.scene.title_anchor) vp.scene.append_to_title('\n') vp.button(text="display at", bind=showat, pos=vp.scene.title_anchor) vp.scene.append_to_title('\n') vp.button(text="credits", bind=credits, pos=vp.scene.title_anchor) vp.scene.append_to_title('\n') vp.winput(bind=seteclipse, pos=vp.scene.title_anchor, text = 'YEAR') vp.button(text="eclipes predictor", bind=prediction, pos=vp.scene.title_anchor) vp.scene.append_to_title('\n') current_date = datetime.datetime.today() guidate = vp.wtext(text=" ")
def __init__(self, bind: Callable, placeholder: str): global last_div_id self._winput = vpython.winput(bind=bind, type='string') last_div_id += 1 vpython.canvas.get_selected().append_to_caption(f"""<script> inp_box = document.querySelector('input[id="{last_div_id}"]'); inp_box.placeholder = "{placeholder}"; </script>""")
def __pause_time_input__(self): vp.winput(bind=self.__set_pause_time__, text=f'{self.GI.pause_time}')
def create_widgets(): Game.scene1.append_to_caption("\n\n") # ------- roughness of terrain ---------------- Game.scene1.append_to_caption("change terrain roughness to") Game.slider_roughness = v.slider(bind=func_roughness, min=0, max=1.0, step=0.01, value=Game.roughness, length=500) Game.label_roughness = v.wtext( text=f" ={Game.roughness:.2f} (0 = very smooth, 1= very rough)") Game.scene1.append_to_caption(Game.label_roughness) Game.scene1.append_to_caption( v.button(text="generate new landscape", bind=func_recalc)) Game.scene1.append_to_caption("\n\n") # ---- winputs fields: fields that accept an text entry that will be converted into a number --- Game.scene1.append_to_caption("type in values and press ENTER:\n\n ") # --------sea level--------------- Game.scene1.append_to_caption("change sea level to") #Game.input_sea_level = v.slider(bind=func_sea_level, min=0.0, max=Game.snow_level, step=0.01, value=Game.sea_level) Game.input_sea_level = v.winput(bind=func_sea_level, type="numeric", text=Game.sea_level) Game.label_sea_level = v.wtext(text=f" ={Game.sea_level:.2f} ") Game.scene1.append_to_caption(Game.label_sea_level) Game.scene1.append_to_caption(" (must be lesser than snow level)\n\n") # ------- snow level -------------- Game.scene1.append_to_caption("change snow level to") #Game.input_snow_level = v.slider(bind=func_snow_level, min=Game.sea_level, max=1.0, step=0.01, value=Game.snow_level) #Game.label_snow_level = v.wtext(text=f"{Game.snow_level*100:.0f} % of (max. height- min. height) = {Game.min_y + Game.snow_level*(Game.max_y-Game.min_y):.2f}") Game.input_snow_level = v.winput(bind=func_snow_level, type="numeric", text=Game.snow_level) Game.label_snow_level = v.wtext(text=f" ={Game.snow_level:.2f} ") Game.scene1.append_to_caption(Game.label_snow_level) Game.scene1.append_to_caption(" (must be greater than sea level)\n\n") # --------world size --------------- Game.scene1.append_to_caption("change world size to: ") #Game.input_world_size = v.slider(bind=func_world_size, min=1, max=100, step=1, # value=Game.world_size) Game.input_world_size = v.winput(bind=func_world_size, type="numeric", text=Game.world_size) Game.label_world_size = v.wtext( text=f" = {Game.world_size} x {Game.world_size} tiles") Game.scene1.append_to_caption(Game.label_world_size) Game.scene1.append_to_caption("\n\n") # -------- min height, max height -------------- Game.scene1.append_to_caption("change minimum height to:") Game.input_min_y = v.winput(bind=func_min_y, type="numeric", text=Game.min_y) Game.label_min_y = v.wtext(text=f" ={Game.min_y:.2f}") Game.scene1.append_to_caption(Game.label_min_y) Game.scene1.append_to_caption(" change maximum height to:") Game.input_max_y = v.winput(bind=func_max_y, type="numeric", text=Game.max_y) Game.label_max_y = v.wtext(text=f" ={Game.max_y:.2f}") Game.scene1.append_to_caption(Game.label_max_y) Game.scene1.append_to_caption("\n\n") # -------- Game.scene1.append_to_caption("change color of ")
vp.box() def B(b): print("The button said this: ", b.text) vp.button(bind=B, text='Click me!') # vp.scene.append_to_caption('\n\n') def T(s): print(s, type(s.number), s.number) vp.winput(bind=T) # def R(r): # print(r.checked) # alternates # # # vp.radio(bind=R, text='Run') # text to right of button # vp.scene.append_to_caption('\n\n') # # # def C(r): # print(r.checked) # alternates # # # vp.checkbox(bind=C, text='Run') # text to right of checkbox # vp.scene.append_to_caption('\n\n')
vp.scene.range = 1.3 vp.scene.title = "ANTIKYTHERA\n" #vp.scene.append_to_title('\n') vp.scene.append_to_title('\n') #vp.scene.append_to_title('\n') vp.button(text="credits", bind=credits, pos=vp.scene.title_anchor) #vp.scene.append_to_title('\n') #vp.scene.append_to_title('\n') vp.wtext(text = "--------------------------------------------------------------\n") vp.wtext(text = " SOLAR SYSTEM SIMULATOR \n") vp.wtext(text = "--------------------------------------------------------------\n") vp.wtext(text = "\nPress ") vp.button(text="Start", bind=start) vp.wtext(text = " to start the simulation\n") vp.wtext(text = "\nEnter a date in 'mm/dd/yyyy' ") vp.winput(bind=setdate, type="string") vp.wtext(text = " and press the 'Enter' key to simulate the system at that time") dateErrorText = vp.wtext(text = "\n") vp.wtext(text = "\nThis is the current date: \n") vp.wtext(text = "-----------------\n") guidate = vp.wtext(text=" ") guidate.text = "| " + guiday + "/" + guimonth + "/" + guiyear + " |\n" vp.wtext(text = "-----------------\n") vp.wtext(text = "\nControl the runtime using the buttons and slider below: \n") ################################################################################ vp.button(text="Pause", bind=Pause) vp.button(text="Play", bind=Play) vp.button(text="Reset", bind=Reset) # makes the sun shine
def __init__(self): # When the user clicks a button, this will be set. self._user_args: Optional[List[str]] = None self._program: Optional[programs.Program] = None canvas = vpython.canvas(width=1, height=1) # Some basic but nice styling. common.include_vpython_footer_file( Path('orbitx', 'graphics', 'simple_css.css')) canvas.append_to_caption("""<style> .argname { font-weight: bold; } </style>""") # Set up some buttons asking what program the user wants to run. canvas.append_to_caption("<h1>OrbitX Launcher</h1>") canvas.append_to_caption("<h2>Select a program to launch</h2>") canvas.append_to_caption( "<input type='checkbox' id='description_checkbox'>" "Show descriptions" "</input>") for program in programs.LISTING: text_fields: List[vpython.winput] = [] canvas.append_to_caption("<hr />") canvas.append_to_caption(f"<h3>{program.name}</h3>") vpython.button(text=f'Launch {program.name}!', bind=functools.partial(self._set_args, program, text_fields)) canvas.append_to_caption(f"<p>{program.description}</p>") for arg in program.argparser._actions: if '--help' in arg.option_strings: # This is the default help action, ignore it. continue canvas.append_to_caption( f"<span class='argname'>{arg.dest}:</span>") canvas.append_to_caption( f"<span class='description'> {arg.help}</span> ") arg_field = vpython.winput( # The bind is a no-op, we'll poll the .text attribute. type='string', bind=lambda _: None, text=arg.default) canvas.append_to_caption("<br />") # Monkey-patch this attribute so that we can build CLI args # properly. arg_field.arg = arg text_fields.append(arg_field) vpython_widgets.last_div_id += 1 common.remove_vpython_css() # Make clicking the per-program launch button also submit all the args # that the user has entered. canvas.append_to_caption("""<script> buttons = document.querySelectorAll("button"); for (const element of buttons) { element.addEventListener('mousedown', function(ev) { // Send an 'enter' keypress so that python code gets the // current value of each text input. inputs = document.querySelectorAll('input'); for (const input of inputs) { var ev = document.createEvent('Event'); ev.initEvent('keypress'); ev.keyCode = 13; input.dispatchEvent(ev); } }); } description_checkbox = document.querySelector( '#description_checkbox'); description_checkbox.addEventListener('change', function(event) { console.log(event); descriptions = document.getElementsByClassName("description"); for (const element of descriptions) { element.style.display = (event.target.checked ? "initial" : "none" ); } }) </script>""") # This is needed to launch vpython. vpython.sphere() vpython.canvas.get_selected().delete()
def setyear(y): year = y pause = False t = 0 day = 0 def Pause(a): global pause pause = not pause vp.scene.width = 800 vp.scene.height = 800 vp.scene.range = 1.3 vp.scene.title = "ANTIKYTHERA\n" vp.button(text="display", bind=display, pos=vp.scene.title_anchor) vp.scene.append_to_title('\n') vp.button(text="display at", bind=showat, pos=vp.scene.title_anchor) vp.scene.append_to_title('\n') vp.winput(bind=setday, pos=vp.scene.title_anchor) vp.winput(bind=setmonth, pos=vp.scene.title_anchor) vp.winput(bind=setyear, pos=vp.scene.title_anchor) vp.scene.append_to_title('\n') print("A")