def main(files: List[str]): """Run the transfer.""" if not files: LOGGER.error('No files to copy!') LOGGER.error('packages_sync: {}', __doc__) return 1 try: portal2_loc = Path(os.environ['PORTAL_2_LOC']) except KeyError: raise ValueError( 'Environment Variable $PORTAL_2_LOC not set! ' 'This should be set to Portal 2\'s directory.') from None # Load the general options in to find out where packages are. GEN_OPTS.load() # Borrow PackageLoader to do the finding and loading for us. LOGGER.info('Locating packages...') # Disable logging of package info. packages_logger.setLevel(logging.ERROR) find_packages(GEN_OPTS['Directories']['package']) packages_logger.setLevel(logging.INFO) LOGGER.info('Done!') print_package_ids() package_loc = Path('../', GEN_OPTS['Directories']['package']).resolve() file_list = [] # type: List[Path] for file in files: file_path = Path(file) if file_path.is_dir(): for sub_file in file_path.glob('**/*'): # type: Path if sub_file.is_file(): file_list.append(sub_file) else: file_list.append(file_path) files_to_check = set() for file in file_list: if file.suffix.casefold() in ('.vmx', '.log', '.bsp', '.prt', '.lin'): # Ignore these file types. continue files_to_check.add(file) if file.suffix == '.mdl': for suffix in ['.vvd', '.phy', '.dx90.vtx', '.sw.vtx']: sub_file = file.with_suffix(suffix) if sub_file.exists(): files_to_check.add(sub_file) LOGGER.info('Processing {} files...', len(files_to_check)) for file in files_to_check: check_file(file, portal2_loc, package_loc)
def on_error(exc_type, exc_value, exc_tb): """Run when the application crashes. Display to the user, log it, and quit.""" # We don't want this to fail, so import everything here, and wrap in # except Exception. import traceback # Close loading screens if they're visible.. try: import loadScreen loadScreen.close_all() except Exception: pass err = ''.join(traceback.format_exception(exc_type, exc_value, exc_tb)) # Grab and release the grab so nothing else can block the error message. try: TK_ROOT.grab_set_global() TK_ROOT.grab_release() # Append traceback to the clipboard. TK_ROOT.clipboard_append(err) except Exception: pass if not issubclass(exc_type, Exception): # It's subclassing BaseException (KeyboardInterrupt, SystemExit), # so ignore the error. return # Put it onscreen. try: from tkinter import messagebox messagebox.showinfo( title='BEE2 Error!', message='An error occurred: \n{}\n\nThis has ' 'been copied to the clipboard.'.format(err), icon=messagebox.ERROR, ) except Exception: pass try: from BEE2_config import GEN_OPTS # Try to turn on the logging window for next time.. GEN_OPTS.load() GEN_OPTS['Debug']['show_log_win'] = '1' GEN_OPTS['Debug']['window_log_level'] = 'DEBUG' GEN_OPTS.save() except Exception: # Ignore failures... pass
def on_error( exc_type: Type[BaseException], exc_value: BaseException, exc_tb: TracebackType, ) -> None: """Run when the application crashes. Display to the user, log it, and quit.""" # We don't want this to fail, so import everything here, and wrap in # except Exception. import traceback err = ''.join(traceback.format_exception(exc_type, exc_value, exc_tb)) # Grab and release the grab so nothing else can block the error message. try: TK_ROOT.grab_set_global() TK_ROOT.grab_release() # Append traceback to the clipboard. TK_ROOT.clipboard_append(err) except Exception: pass if not issubclass(exc_type, Exception): # It's subclassing BaseException (KeyboardInterrupt, SystemExit), # so ignore the error. return # Put it onscreen. try: from tkinter import messagebox from localisation import gettext messagebox.showinfo( title=gettext('BEEMOD {} Error!').format(utils.BEE_VERSION), message=gettext( 'An error occurred: \n{}\n\n' 'This has been copied to the clipboard.').format(err), icon=messagebox.ERROR, ) except Exception: pass try: from BEE2_config import GEN_OPTS # Try to turn on the logging window for next time.. GEN_OPTS.load() GEN_OPTS['Debug']['show_log_win'] = '1' GEN_OPTS['Debug']['window_log_level'] = 'DEBUG' GEN_OPTS.save() except Exception: # Ignore failures... pass
def on_error(exc_type, exc_value, exc_tb): """Run when the application crashes. Display to the user, log it, and quit.""" # We don't want this to fail, so import everything here, and wrap in # except Exception. import traceback # Close loading screens if they're visible.. try: import loadScreen loadScreen.close_all() except Exception: pass err = ''.join(traceback.format_exception(exc_type, exc_value, exc_tb)) # Grab and release the grab so nothing else can block the error message. try: TK_ROOT.grab_set_global() TK_ROOT.grab_release() # Append traceback to the clipboard. TK_ROOT.clipboard_append(err) except Exception: pass # Put it onscreen. try: from tkinter import messagebox messagebox.showinfo( title='BEE2 Error!', message='An error occurred: \n{}\n\nThis has ' 'been copied to the clipboard.'.format(err), icon=messagebox.ERROR, ) except Exception: pass try: from BEE2_config import GEN_OPTS # Try to turn on the logging window for next time.. GEN_OPTS.load() GEN_OPTS['Debug']['show_log_win'] = '1' GEN_OPTS['Debug']['window_log_level'] = 'DEBUG' GEN_OPTS.save() except Exception: # Ignore failures... pass
'log_item_fallbacks': '0', # Print message for items that have no match for a style 'log_missing_styles': '0', # Print message for items that are missing ent_count values 'log_missing_ent_count': '0', # Warn if a file is missing that a packfile refers to 'log_incorrect_packfile': '0', # Show the log window on startup 'show_log_win': '0', # The lowest level which will be shown. 'window_log_level': 'INFO', }, } GEN_OPTS.load() GEN_OPTS.set_defaults(DEFAULT_SETTINGS) LOGGER.debug('Starting loading screen...') loadScreen.main_loader.set_length('UI', 14) loadScreen.set_force_ontop(GEN_OPTS.get_bool('General', 'splash_stay_ontop')) loadScreen.show_main_loader(GEN_OPTS.get_bool('General', 'compact_splash')) # OS X starts behind other windows, fix that. if utils.MAC: TK_ROOT.lift() logWindow.init(GEN_OPTS.get_bool('Debug', 'show_log_win'), GEN_OPTS['Debug']['window_log_level']) LOGGER.debug('Loading settings...')
def _test() -> None: """Test the GUI.""" from srctools.logger import init_logging from tk_tools import TK_ROOT from BEE2_config import GEN_OPTS from packageLoader import find_packages, PACKAGE_SYS init_logging() # Setup images to read from packages. print('Loading packages for images.') GEN_OPTS.load() find_packages(GEN_OPTS['Directories']['package']) img.load_filesystems(PACKAGE_SYS.values()) print('Done.') left_frm = ttk.Frame(TK_ROOT) right_canv = tkinter.Canvas(TK_ROOT) left_frm.grid(row=0, column=0, sticky='NSEW', padx=8) right_canv.grid(row=0, column=1, sticky='NSEW', padx=8) TK_ROOT.rowconfigure(0, weight=1) TK_ROOT.columnconfigure(1, weight=1) slot_dest = [] slot_src = [] class TestItem: def __init__( self, name: str, icon: str, group: str=None, group_icon: str=None, ) -> None: self.name = name self.dnd_icon = img.png('items/clean/{}.png'.format(icon)) self.dnd_group = group if group_icon: self.dnd_group_icon = img.png('items/clean/{}.png'.format(group_icon)) def __repr__(self) -> str: return '<Item {}>'.format(self.name) manager = Manager[TestItem](TK_ROOT, config_icon=True) def func(ev): def call(slot): print('Cback: ', ev, slot) return call for event in Event: manager.reg_callback(event, func(event)) items = [ TestItem('Dropper', 'dropper'), TestItem('Entry', 'entry_door'), TestItem('Exit', 'exit_door'), TestItem('Large Obs', 'large_obs_room'), TestItem('Faith Plate', 'faithplate'), TestItem('Standard Cube', 'cube', 'ITEM_CUBE', 'cubes'), TestItem('Companion Cube', 'companion_cube', 'ITEM_CUBE', 'cubes'), TestItem('Reflection Cube', 'reflection_cube', 'ITEM_CUBE', 'cubes'), TestItem('Edgeless Cube', 'edgeless_safety_cube', 'ITEM_CUBE', 'cubes'), TestItem('Franken Cube', 'frankenturret', 'ITEM_CUBE', 'cubes'), TestItem('Repulsion Gel', 'paintsplat_bounce', 'ITEM_PAINT_SPLAT', 'paints'), TestItem('Propulsion Gel', 'paintsplat_speed', 'ITEM_PAINT_SPLAT', 'paints'), TestItem('Reflection Gel', 'paintsplat_reflection', 'ITEM_PAINT_SPLAT', 'paints'), TestItem('Conversion Gel', 'paintsplat_portal', 'ITEM_PAINT_SPLAT', 'paints'), TestItem('Cleansing Gel', 'paintsplat_water', 'ITEM_PAINT_SPLAT', 'paints'), ] for y in range(8): for x in range(4): slot = manager.slot(left_frm, source=False, label=(format(x + 4*y, '02') if y < 3 else '')) slot.grid(column=x, row=y, padx=1, pady=1) slot_dest.append(slot) for i, item in enumerate(items): slot = manager.slot(right_canv, source=True, label=format(i+1, '02')) slot_src.append(slot) slot.contents = item def configure(e): manager.flow_slots(right_canv, slot_src) configure(None) right_canv.bind('<Configure>', configure) ttk.Button( TK_ROOT, text='Debug', command=lambda: print('Dest:', [slot.contents for slot in slot_dest]) ).grid(row=2, column=0) ttk.Button( TK_ROOT, text='Debug', command=lambda: print('Source:', [slot.contents for slot in slot_src]) ).grid(row=2, column=1) name_lbl = ttk.Label(TK_ROOT, text='') name_lbl.grid(row=3, column=0) def enter(slot): if slot.contents is not None: name_lbl['text'] = 'Name: ' + slot.contents.name def exit(slot): name_lbl['text'] = '' manager.reg_callback(Event.HOVER_ENTER, enter) manager.reg_callback(Event.HOVER_EXIT, exit) manager.reg_callback(Event.CONFIG, lambda slot: messagebox.showinfo('Hello World', str(slot.contents))) TK_ROOT.deiconify() TK_ROOT.mainloop()
async def init_app(): """Initialise the application.""" GEN_OPTS.load() GEN_OPTS.set_defaults(DEFAULT_SETTINGS) # Special case, load in this early so it applies. utils.DEV_MODE = GEN_OPTS.get_bool('Debug', 'development_mode') DEV_MODE.set(utils.DEV_MODE) LOGGER.debug('Starting loading screen...') loadScreen.main_loader.set_length('UI', 16) loadScreen.set_force_ontop( GEN_OPTS.get_bool('General', 'splash_stay_ontop')) loadScreen.show_main_loader(GEN_OPTS.get_bool('General', 'compact_splash')) # OS X starts behind other windows, fix that. if utils.MAC: TK_ROOT.lift() logWindow.HANDLER.set_visible(GEN_OPTS.get_bool('Debug', 'show_log_win')) logWindow.HANDLER.setLevel(GEN_OPTS['Debug']['window_log_level']) LOGGER.debug('Loading settings...') UI.load_settings() gameMan.load() gameMan.set_game_by_name(GEN_OPTS.get_val('Last_Selected', 'Game', ''), ) gameMan.scan_music_locs() LOGGER.info('Loading Packages...') package_sys = await packages.load_packages( list(get_package_locs()), loader=loadScreen.main_loader, log_item_fallbacks=GEN_OPTS.get_bool('Debug', 'log_item_fallbacks'), log_missing_styles=GEN_OPTS.get_bool('Debug', 'log_missing_styles'), log_missing_ent_count=GEN_OPTS.get_bool('Debug', 'log_missing_ent_count'), log_incorrect_packfile=GEN_OPTS.get_bool('Debug', 'log_incorrect_packfile'), has_tag_music=gameMan.MUSIC_TAG_LOC is not None, has_mel_music=gameMan.MUSIC_MEL_VPK is not None, ) loadScreen.main_loader.step('UI', 'pre_ui') APP_NURSERY.start_soon(img.init, package_sys) APP_NURSERY.start_soon(sound.sound_task) # Load filesystems into various modules music_conf.load_filesystems(package_sys.values()) gameMan.load_filesystems(package_sys.values()) UI.load_packages() loadScreen.main_loader.step('UI', 'package_load') LOGGER.info('Done!') # Check games for Portal 2's basemodui.txt file, so we can translate items. LOGGER.info('Loading Item Translations...') for game in gameMan.all_games: game.init_trans() LOGGER.info('Initialising UI...') await UI.init_windows() # create all windows LOGGER.info('UI initialised!') loadScreen.main_loader.destroy() # Delay this until the loop has actually run. # Directly run TK_ROOT.lift() in TCL, instead # of building a callable. TK_ROOT.tk.call('after', 10, 'raise', TK_ROOT)
'log_item_fallbacks': '0', # Print message for items that have no match for a style 'log_missing_styles': '0', # Print message for items that are missing ent_count values 'log_missing_ent_count': '0', # Warn if a file is missing that a packfile refers to 'log_incorrect_packfile': '0', # Show the log window on startup 'show_log_win': '0', # The lowest level which will be shown. 'window_log_level': 'INFO', }, } GEN_OPTS.load() GEN_OPTS.set_defaults(DEFAULT_SETTINGS) loadScreen.main_loader.set_length('UI', 14) loadScreen.show_main_loader(GEN_OPTS.get_bool('General', 'compact_splash')) # OS X starts behind other windows, fix that. if utils.MAC: TK_ROOT.lift() logWindow.init( GEN_OPTS.get_bool('Debug', 'show_log_win'), GEN_OPTS['Debug']['window_log_level'] ) UI.load_settings()