def make_component(label, values): label = wx.StaticText(self, label=f'{label}: ') pick = wx.Choice(self, -1, choices=values) # pick.SetSelection(0) # Needed on Windows FIXME controls = associate_controls(label, pick, even_split=True) add_widget(date_input_group, controls) return pick
def add_map_picker(place, kinda): def pick_map_handler(event): pick_ldl_map(place, kinda) maps_button = wx.Button(self, -1, kinda + ' maps') maps_button.Bind(wx.EVT_BUTTON, pick_map_handler) add_widget(open_map, maps_button)
def add_launch_button(parent, sizer, title, action): button = wx.Button(parent, -1, title) def make_launch_function(game_start_method): def launch_handler(event): launch_core(parent, game_start_method) return launch_handler button.Bind(wx.EVT_BUTTON, make_launch_function(action)) add_widget(sizer, button)
def __init__(self, parent): screen_width, screen_height = wx.GetDisplaySize() wx.Dialog.__init__( self, parent, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, size=(screen_width * 0.5, screen_height * 0.7), title='Key bindings') sizer = wx.BoxSizer(wx.VERTICAL) browser = wx.html2.WebView.New(self) display = format_bindings_as_html() browser.SetPage(display, "") sizer.Add(browser, 1, wx.EXPAND, 10) close = wx.Button(self, -1, 'Close') close.Bind(wx.EVT_BUTTON, lambda event: self.Destroy()) add_widget(sizer, close) self.SetSizer(sizer) doset_only(windows=lambda: windows_accessibility_fix(browser))
def __init__(self, parent): wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.VERTICAL) add_opener_buttons( self, sizer, { 'User manual': dirs.manuals / 'user-manual.html', 'Sound legend': dirs.manuals / 'sound-legend.html', }) add_widget(sizer, wx.StaticLine(self, -1)) about = wx.Button(self, -1, 'About') about.Bind(wx.EVT_BUTTON, lambda event: about_page(self)) add_widget(sizer, about) add_widget(sizer, wx.StaticLine(self, -1)) add_opener_buttons( self, sizer, { 'README': dirs.manuals / 'README.html', 'LICENCE': dirs.manuals / 'LICENCE.html', 'CHANGELOG': dirs.manuals / 'CHANGELOG.html', 'ACKNOWLEDGEMENTS': dirs.manuals / 'ACKNOWLEDGEMENTS.html' }) sizer.SetSizeHints(self) self.SetSizer(sizer)
def __init__(self, parent): wx.Dialog.__init__(self, parent, title='Date of birth') sizer = wx.BoxSizer(wx.VERTICAL) # Date input grouping date_input_group = platform_appropriate_grouping( self, 'Please input your date of birth') add_widget(date_input_group, wx.StaticText( self, -1, 'This information will not be transmitted or stored.')) def make_component(label, values): label = wx.StaticText(self, label=f'{label}: ') pick = wx.Choice(self, -1, choices=values) # pick.SetSelection(0) # Needed on Windows FIXME controls = associate_controls(label, pick, even_split=True) add_widget(date_input_group, controls) return pick self.day = make_component('Day', list(map(str, range(1, 32)))) self.month = make_component('Month', list(map(str, range(1, 13)))) self.year = make_component( 'Year', list(map(str, reversed(range(1903, 2022))))) sizer.Add(date_input_group, 1, wx.EXPAND, 10) # Done button done = wx.Button(self, -1, 'Done') done.Bind(wx.EVT_BUTTON, lambda event: self.EndModal(wx.ID_OK)) add_widget(sizer, done) # Wiring self.SetSizer(sizer) self.Fit()
def __init__(self, parent, game_controller): wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.VERTICAL) # Playing the game game_modes = { "Play Quake": game_controller.launch_quake, "Play Open Quartz": game_controller.launch_open_quartz, "Tutorial": lambda: game_controller.launch_tutorial(high_contrast=False), "Tutorial (high-contrast maps)": lambda: game_controller.launch_tutorial(high_contrast=True) } for title, action in game_modes.items(): add_launch_button(self, sizer, title, action) # Listing key bindings add_widget(sizer, wx.StaticLine(self, -1)) keys_button = wx.Button(self, -1, 'List key bindings') def show_bindings(event): bindings_html = format_bindings_as_html() modal_html_page(self, 'Key bindings', bindings_html) keys_button.Bind(wx.EVT_BUTTON, show_bindings) add_widget(sizer, keys_button) # Server stuff add_widget(sizer, wx.StaticLine(self, -1)) server_stuff = { "Dedicated server": doset( mac=start_server_mac, windows=lambda evt: start_server_windows(self), set_only=True), "Remote console": doset( mac=lambda evt: run_apple_script(dirs.gubbins / 'rcon'), windows=lambda evt: run_win_console([dirs.gubbins / 'rcon.exe']), set_only=True) } for title, action in server_stuff.items(): add_cli_tool_button(self, sizer, title, action) sizer.SetSizeHints(self) self.SetSizer(sizer)
def __init__(self, parent, game_controller): self.game_controller = game_controller wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.VERTICAL) select_qmod_button = wx.Button(self, -1, 'Play a mod') select_qmod_button.Bind(wx.EVT_BUTTON, self.play_mod_handler) add_widget(sizer, select_qmod_button) install_qmod_button = wx.Button(self, -1, 'Install a mod') install_qmod_button.Bind(wx.EVT_BUTTON, self.install_qmod_handler) add_widget(sizer, install_qmod_button) add_widget(sizer, wx.StaticLine(self, -1)) add_opener_button(self, sizer, 'Development manual', dirs.manuals / 'development-manual.html') sizer.SetSizeHints(self) self.SetSizer(sizer)
def add_cli_tool_button(parent, sizer, title, action): button = wx.Button(parent, -1, title) button.Bind(wx.EVT_BUTTON, action) add_widget(sizer, button)
def __init__(self, parent, game_controller): WILDCARD = "XML files (*.xml)|*.xml" self.game_controller = game_controller self._map_path = '' wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.VERTICAL) add_opener_button(self, sizer, 'Read the LDL tutorial', dirs.manuals / 'LDL-tutorial.html') # File picker and choosing a tutorial or example map bits open_map = platform_appropriate_grouping( self, 'Open a Level Description Language (LDL) map') def add_map_picker(place, kinda): def pick_map_handler(event): pick_ldl_map(place, kinda) maps_button = wx.Button(self, -1, kinda + ' maps') maps_button.Bind(wx.EVT_BUTTON, pick_map_handler) add_widget(open_map, maps_button) def pick_ldl_map(place, kinda): maps = find_ldl_maps(place) chooser = wx.SingleChoiceDialog(self, f'{kinda} maps:', 'Select map', list(maps.values())) if chooser.ShowModal() == wx.ID_OK: choice = chooser.GetSelection() self.map_path = str(list(maps.keys())[choice]) add_map_picker(dirs.maps_tutorial, 'Tutorial') add_map_picker(dirs.maps_example, 'Example') def pick_custom_map(event): with wx.FileDialog(self, message='Open map', wildcard=WILDCARD, style=wx.FLP_OPEN | wx.FLP_FILE_MUST_EXIST) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return self.map_path = fileDialog.GetPath() file_picker_button = wx.Button(self, -1, 'Open custom map...') file_picker_button.Bind(wx.EVT_BUTTON, pick_custom_map) add_widget(open_map, file_picker_button) chosen_label = wx.StaticText(self, -1, 'Chosen map:') self.chosen_text = wx.lib.expando.ExpandoTextCtrl(self, -1, style=wx.TE_READONLY) self.chosen_text.SetMaxHeight(1) add_widget(open_map, associate_controls(chosen_label, self.chosen_text)) add_widget(sizer, open_map) # Play and texture selection play_checkbox = wx.CheckBox(self, -1, "Play the map when built") play_checkbox.SetValue(True) add_widget(sizer, play_checkbox) texture_label = wx.StaticText(self, label='Play map with texture set:') texset_pick = wx.Choice(self, -1, choices=list(game_names.keys())) texset_pick.SetSelection(0) # Needed on Windows add_widget(sizer, associate_controls(texture_label, texset_pick)) # Let's do this! btn_build = wx.Button(self, -1, "Build the map") def check_picker_path(): filename = self.map_path if len(filename) == 0: Warn(self, 'No file chosen.') return path = Path(filename) if not path.is_file(): Error(self, "Can't find chosen file.") return return path def build_and_play_handler(event): if (path := check_picker_path()) is None: return if play_checkbox.GetValue() is True: play_wad = list( game_names.values())[texset_pick.GetSelection()] else: play_wad = None if path.name == 'tut07.xml' \ and not have_wad(WADs.QUAKE, quiet=True): Warn(self, ('Sorry, ' + path.name + ' requires the Quake data ' 'in order to run. This is a known issue.')) else: self.build_and_play(path, play_wad)
Warn(self, ('Sorry, ' + path.name + ' requires the Quake data ' 'in order to run. This is a known issue.')) else: self.build_and_play(path, play_wad) btn_build.Bind(wx.EVT_BUTTON, build_and_play_handler) add_widget(sizer, btn_build) btn_edit = wx.Button(self, -1, "Edit map (with default editor)") def edit_map_handler(event): if path := check_picker_path(): opener(path) btn_edit.Bind(wx.EVT_BUTTON, edit_map_handler) add_widget(sizer, btn_edit) # Wiring wrap-up sizer.SetSizeHints(self) self.SetSizer(sizer) # Set up LDL paths use_bins(dirs.map_tools) use_wads(dirs.map_tools, dirs.data / 'id1') def build_and_play(self, xmlfile, play_wad): for wad, destinations in wad_bspdests.items(): if wad == WADs.QUAKE and not have_wad(WADs.QUAKE, quiet=True): continue
def __init__(self, parent, game_controller): wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.VERTICAL) # Settings add_opener_buttons( self, sizer, { 'Edit autoexec.cfg (with default editor)': dirs.data / 'id1' / 'autoexec.cfg', 'Edit config.cfg (with default editor)': dirs.data / 'id1' / 'config.cfg' }) # Install registered data add_widget(sizer, wx.StaticLine(self, -1)) reg_data_button = wx.Button(self, -1, 'Install registered Quake data') reg_data_button.Bind(wx.EVT_BUTTON, self.install_data_handler) add_widget(sizer, reg_data_button) # Video mode settings add_widget(sizer, wx.StaticLine(self, -1)) add_widget( sizer, wx.StaticText(self, -1, 'Video mode settings', style=wx.ALIGN_CENTRE_HORIZONTAL)) fullscreen = wx.CheckBox(self, -1, 'Run full-screen (instead of windowed)') fullscreen.SetValue(config.fullscreen()) fullscreen.Bind(wx.EVT_CHECKBOX, lambda event: config.fullscreen(event.IsChecked())) add_widget(sizer, fullscreen) resolution_hbox = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, label='Resolution: ') pick_res = wx.Choice(self, -1, choices=RESOLUTIONS) index, _ = resolution_index_from_config() if index >= 0: pick_res.SetSelection(index) else: pick_res.Disable() pick_res.Bind( wx.EVT_CHOICE, lambda event: config.resolution(RESOLUTIONS[event.GetSelection()])) add_widget(resolution_hbox, label, border=False) add_widget(resolution_hbox, pick_res, border=False, expand=True) add_widget(sizer, resolution_hbox) doset_only(windows=lambda: add_widget( sizer, wx.StaticText(self, -1, "Some modes may not be available full-screen."))) doset_only(windows=lambda: add_widget( sizer, wx.StaticText(self, -1, "Modes may be cropped when Windows' UI is scaled."))) quick_test = wx.Button(self, -1, 'Try it out: Play tutorial') quick_test.Bind(wx.EVT_BUTTON, lambda event: game_controller.launch_tutorial()) add_widget(sizer, quick_test) def reset_to_defaults(event): fullscreen.SetValue(False) wx.PostEvent(fullscreen, wx.CommandEvent(wx.wxEVT_CHECKBOX)) pick_res.SetSelection(DEFAULT_RESOLUTION_INDEX) choice_event = wx.CommandEvent(wx.wxEVT_CHOICE) choice_event.SetInt(DEFAULT_RESOLUTION_INDEX) wx.PostEvent(pick_res, choice_event) pick_res.Enable() reset = wx.Button(self, -1, 'Reset video mode to defaults') reset.Bind(wx.EVT_BUTTON, reset_to_defaults) add_widget(sizer, reset) # Wiring sizer.SetSizeHints(self) self.SetSizer(sizer)
def __init__(self, parent, game_controller): wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.VERTICAL) resolution_strings = get_resolution_strings(RESOLUTIONS) # Settings add_opener_buttons( self, sizer, { 'Edit autoexec.cfg (with default editor)': dirs.data / 'id1' / 'autoexec.cfg', 'Edit config.cfg (with default editor)': dirs.data / 'id1' / 'config.cfg' }) # Install registered data add_widget(sizer, wx.StaticLine(self, -1)) reg_data_button = wx.Button(self, -1, 'Install registered Quake data') reg_data_button.Bind(wx.EVT_BUTTON, self.install_data_handler) add_widget(sizer, reg_data_button) # Video mode settings add_widget(sizer, wx.StaticLine(self, -1)) box = platform_appropriate_grouping(self, 'Video mode') res_label = wx.StaticText(self, label='Resolution:') res_pick = wx.Choice(self, -1, choices=resolution_strings) try: index = int(config.resolution()) except: # noqa 722 index = DEFAULT_RESOLUTION_INDEX res_pick.SetSelection(index) res_pick.Bind(wx.EVT_CHOICE, lambda event: config.resolution(event.GetSelection())) add_widget(box, associate_controls(res_label, res_pick)) doset_only(windows=lambda: add_widget( box, wx.StaticText(self, -1, "Modes may be cropped when Windows' UI is scaled."))) def mode_test(event): doset_only( windows=lambda: first_time_windows_firewall_info(parent)) if not game_flickering_check(parent): return game_controller.launch_tutorial() quick_test = wx.Button(self, -1, 'Try it out: Play tutorial') quick_test.Bind(wx.EVT_BUTTON, mode_test) add_widget(box, quick_test) def reset_to_defaults(event): res_pick.SetSelection(DEFAULT_RESOLUTION_INDEX) choice_event = wx.CommandEvent(wx.wxEVT_CHOICE) choice_event.SetInt(DEFAULT_RESOLUTION_INDEX) wx.PostEvent(res_pick, choice_event) res_pick.Enable() reset = wx.Button(self, -1, 'Reset video mode to default') reset.Bind(wx.EVT_BUTTON, reset_to_defaults) add_widget(box, reset) add_widget(sizer, box) # Wiring sizer.SetSizeHints(self) self.SetSizer(sizer)
def __init__(self, parent, game_controller): WILDCARD = "XML files (*.xml)|*.xml" self.game_controller = game_controller wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.VERTICAL) add_opener_button(self, sizer, 'Read the LDL tutorial', dirs.manuals / 'ldl-tutorial.html') # File picker and choosing a tutorial or example map bits add_widget( sizer, wx.StaticText(self, -1, 'Open a Level Description Language (LDL) map', style=wx.ALIGN_CENTRE_HORIZONTAL)) def add_map_picker(place, kinda): def pick_map_handler(event): pick_ldl_map(place, kinda) maps_button = wx.Button(self, -1, kinda + ' maps') maps_button.Bind(wx.EVT_BUTTON, pick_map_handler) add_widget(sizer, maps_button) def pick_ldl_map(place, kinda): maps = find_ldl_maps(place) chooser = wx.SingleChoiceDialog(self, f'{kinda} maps:', 'Select map', list(maps.values())) if chooser.ShowModal() == wx.ID_OK: choice = chooser.GetSelection() file_picker.SetPath(str(list(maps.keys())[choice])) add_map_picker(dirs.maps_tutorial, 'LDL tutorial') add_map_picker(dirs.maps_example, 'LDL example') file_picker = wx.FilePickerCtrl(self, -1, message="Open map", wildcard=WILDCARD) add_widget(sizer, file_picker) # Play and texture selection play_checkbox = wx.CheckBox(self, -1, "Play the map when built") play_checkbox.SetValue(True) add_widget(sizer, play_checkbox) texture_set_hbox = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, label='Play map with texture set: ') pick = wx.Choice(self, -1, choices=list(game_names.keys())) pick.SetSelection(0) # Needed on Windows add_widget(texture_set_hbox, label, border=False) add_widget(texture_set_hbox, pick, border=False, expand=True) add_widget(sizer, texture_set_hbox) # Let's do this! btn_build = wx.Button(self, -1, "Build the map") def check_picker_path(): filename = file_picker.GetPath() if len(filename) == 0: Warn(self, 'No file chosen.') return path = Path(filename) if not path.is_file(): Error(self, "Can't find chosen file.") return return path def build_and_play_handler(event): if (path := check_picker_path()) is None: return if play_checkbox.GetValue() is True: play_wad = list(game_names.values())[pick.GetSelection()] else: play_wad = None if path.name == 'tut07.xml' \ and not have_wad(WADs.QUAKE, quiet=True): Warn(self, ('Sorry, ' + path.name + ' requires the Quake data ' 'in order to run. This is a known issue.')) else: self.build_and_play(path, play_wad)