def _show_skin_in_model_viewer(self, row): skin_name = self.proxy.data(self.proxy.index(row, 0)) ac_name = self.proxy.data(self.proxy.index(row, 1)) mv_autoexec_cfg = Path(self._active_dcs_install.install_path).joinpath( 'Config', 'ModelViewer', 'autoexec.lua') mv_exe = Path(self._active_dcs_install.install_path).joinpath( 'bin', 'ModelViewer.exe') for f in mv_autoexec_cfg, mv_exe: if not f.exists(): logger.error('file not found: {}'.format(f.abspath())) return mount_lines = set() if self._active_dcs_install.autoexec_cfg: for vfs_path in self._active_dcs_install.autoexec_cfg.mounted_vfs_paths: mount_lines.add( 'mount_vfs_texture_path("{}")\n'.format(vfs_path)) backup_path = mv_autoexec_cfg.dirname().joinpath( 'autoexec.lua_EMFT_BACKUP') if not backup_path.exists(): logger.info('backing up "{}" -> "{}"'.format( mv_autoexec_cfg.abspath(), backup_path.abspath())) mv_autoexec_cfg.copy2(backup_path.abspath()) orig_lines = mv_autoexec_cfg.lines() lines = [] for line in orig_lines: if Config().allow_mv_autoexec_changes: if RE_MOUNT_LINE.match(line): # print('skipping', line) continue if RE_LOAD_MODEL_LINE.match(line): # print('skipping', line) continue if RE_LOAD_LIVERY_LINE.match(line): # print('skipping', line) continue lines.append(line) # model_path = 'LoadModel("Bazar/World/Shapes/{}.edm")'.format(self._active_dcs_install.get_object_model(ac_name)) lines.insert( 0, 'LoadLivery("{ac_name}","{skin_name}")'.format(**locals())) lines.insert( 0, 'LoadModel("Bazar/World/Shapes/{ac_name}.edm")'.format(**locals())) if Config().allow_mv_autoexec_changes: for line in mount_lines: lines.insert(0, line) mv_autoexec_cfg.write_lines(lines) os.startfile(mv_exe.abspath())
def __init__(self, parent=None): iTab.__init__(self, parent=parent) logging.Handler.__init__(self) self.levels = { 'NOTSET': dict(level=0, color='#808080'), 'DEBUG': dict(level=10, color='#808080'), 'INFO': dict(level=20, color='#000000'), 'WARNING': dict(level=30, color='#FF5500'), 'ERROR': dict(level=40, color='#FF0000'), 'CRITICAL': dict(level=50, color='#FF0000'), } self.records = [] self.setLevel(logging.DEBUG) self.setFormatter( logging.Formatter( '%(asctime)s: %(levelname)s: %(module)s.%(funcName)s - %(message)s', '%H:%M:%S')) self.combo = Combo(on_change=self.combo_changed, choices=['DEBUG', 'INFO', 'WARNING', 'ERROR']) self.filter_line_edit_msg = LineEdit('', self._filter_updated, clear_btn_enabled=True) self.filter_line_edit_module = LineEdit('', self._filter_updated, clear_btn_enabled=True) self.log_text = PlainTextEdit(read_only=True) self._min_lvl = self.levels[Config().log_level]['level'] self.combo.set_index_from_text(Config().log_level) self.clear_btn = PushButton('Clear log', self._clean) self.send_btn = PushButton('Send log', self._send) self.setLayout( VLayout([ HLayout([ (self.combo, dict(stretch=1)), 20, (self.clear_btn, dict(stretch=0)), (self.send_btn, dict(stretch=0)), ]), GridLayout([ [Label('Filter message'), self.filter_line_edit_msg], [Label('Filter module'), self.filter_line_edit_module], ]), self.log_text, ])) logger = logging.getLogger('__main__') logger.addHandler(self) self._clean()
def _check_for_new_version(self): if hasattr(self, 'install_new_version_btn'): self.install_new_version_btn.setVisible(False) updater.get_latest_release( channel=Config().update_channel, branch=Version(global_.APP_VERSION), success_callback=I.update_config_tab, )
def update_config_tab(self, latest_release: AVRelease): self.remote_version.set_text_color('black') for x in ['stable', 'beta', 'alpha']: dcs_install = getattr(dcs_installs, x) if dcs_install: getattr(self, '{}_install'.format(x)).setText(dcs_install.install_path) getattr(self, '{}_variant'.format(x)).setText(dcs_install.saved_games) getattr(self, '{}_version'.format(x)).setText(dcs_install.version) else: getattr(self, '{}_install'.format(x)).setText('not found') self.update_channel_combo.set_index_from_text(Config().update_channel) if latest_release: app_version = Version(global_.APP_VERSION) self.latest_release = latest_release self.remote_version.setText(latest_release.version.version_str) if app_version < self.latest_release.version: self.remote_version.set_text_color('green') if app_version != self.latest_release.version: self.install_new_version_btn.setVisible(True)
def start_ui(test=False): from PyQt5.QtWidgets import QApplication import sys from src.ui.tab_reorder import TabReorder from src.ui.tab_log import TabLog from src.ui.tab_config import TabConfig from src.ui.tab_skins import TabSkins logger.debug('starting QtApp object') global_.QT_APP = QApplication([]) global_.MAIN_UI = MainUi() global_.MAIN_UI.add_tab(TabLog(), helpers={'write_log': 'write'}) global_.MAIN_UI.add_tab(TabReorder(), helpers={ 'tab_reorder_update_view_after_remote_scan': 'tab_reorder_update_view_after_remote_scan' }) from src.misc import dcs_installs dcs_installs.discover_dcs_installations() global_.MAIN_UI.add_tab(TabSkins(), helpers={}) global_.MAIN_UI.add_tab(TabConfig(), helpers={'update_config_tab': 'update_config_tab'}) global_.MAIN_UI.show() def pre_update_hook(): if not hasattr(sys, 'frozen'): logger.warning('skipping update on script run') return False else: I.hide() return True def cancel_update_hook(): I.show() from utils import Progress # noinspection PyTypeChecker Progress.register_adapter(I) from src.updater import updater updater.find_and_install_latest_release( current_version=global_.APP_VERSION, executable_path='emft.exe', channel=Config().update_channel, cancel_update_hook=cancel_update_hook, pre_update_hook=pre_update_hook, ) global_.MAIN_UI.update_config_tab() if test: logger.critical('RUNNING IN TEST MODE') import time from utils import ThreadPool, nice_exit def test_hook(): time.sleep(10) nice_exit() pool = ThreadPool(1, 'test') pool.queue_task(test_hook) sys.exit(global_.QT_APP.exec())
def __init__(self, parent=None): iTab.__init__(self, parent=parent) self.sg = LineEdit(Config().saved_games_path or '', self._on_change_sg, read_only=True) self.update_channel_combo = Combo(self._on_change_update_channel, [ 'stable', 'rc', 'dev', 'beta', 'alpha' ]) self.latest_release = None self.remote_version = Label('') self.update_channel_combo.set_index_from_text(Config().update_channel) self.update_scan_btn = PushButton('Check for new version', self._check_for_new_version) self.install_new_version_btn = PushButton('Install this version', self._install_latest_version) updater_layout = GroupBox( 'Auto-update', VLayout( [ Label('During the initial testing phase of this application, auto-update cannot be turned off.\n' 'You can, however, elect to participate in early testing, or stick to the most stable' ' versions only.'), 10, GridLayout( [ [ Label('Active update channel'), HLayout( [ self.update_channel_combo, self.update_scan_btn, HSpacer() ] ), ], [10], [ Label('Current version'), Label(__version__), ], [ Label('Remote version'), HLayout([self.remote_version, self.install_new_version_btn, HSpacer()]), ], # [ # Label('GUID'), # Label(__guid__), # ], ], [0, 1] ) ] ) ) sg_path_layout = GroupBox( 'Saved Games directory', GridLayout( [ [ self.sg, PushButton('Browse', self._sg_browse), PushButton('Scan', self._sg_scan), PushButton('Open', self._sg_open), ] ], [1], False ) ) dcs_installations = [] for x in ['stable', 'beta', 'alpha']: setattr(self, '{}_group'.format(x), GroupBox('DCS {} installation'.format(x))) setattr(self, '{}_install'.format(x), Label('')) setattr(self, '{}_variant'.format(x), Label('')) setattr(self, '{}_version'.format(x), Label('')) getattr(self, '{}_group'.format(x)).setLayout( GridLayout( [ [Label('Installation'), getattr(self, '{}_install'.format(x)), ], [Label('Variant'), getattr(self, '{}_variant'.format(x))], [Label('Version'), getattr(self, '{}_version'.format(x))], ], [0, 1] ) ) dcs_installations.append(getattr(self, '{}_group'.format(x))) dcs_installations = VLayout( [ *dcs_installations ] ) self.setLayout( VLayout( [ updater_layout, VSpacer(), sg_path_layout, VSpacer(), dcs_installations, VSpacer(), ] ) ) self.install_new_version_btn.setVisible(False)
def _on_change_update_channel(self, *_): Config().update_channel = self.update_channel_combo.currentText() self.remote_version.setText('') self._check_for_new_version()
def _on_change_sg(self, *_): Config().saved_games_path = str(Path(self.sg.text()).abspath())
def __init__(self): super(TabSkins, self).__init__() self.no_install_label = Label( 'No DSC installation found on this system') self.no_install_label.set_text_color('red') self.no_install_label.setVisible( len(list(dcs_installs.present_dcs_installations)) == 0) self.allow_mv_autoexec_changes = Checkbox( 'Allow EMFT to edit the "autoexec.cfg" of DCS ModelViewer to inject required VFS textures paths', self._on_allow_mv_autoexec_changes, ) self.allow_mv_autoexec_changes.setChecked( Config().allow_mv_autoexec_changes) def _make_filter(): return LineEdit('', on_text_changed=self._apply_filter, clear_btn_enabled=True) self.filter_skin_name = _make_filter() self.filter_ac_name = _make_filter() self.filter_folder = _make_filter() self.combo_active_dcs_installation = Combo( self._on_active_dcs_installation_change, list(x.label for x in dcs_installs.present_dcs_installations), ) if Config().skins_active_dcs_installation: try: self.combo_active_dcs_installation.set_index_from_text( Config().skins_active_dcs_installation) except ValueError: pass data = [] header_data = ['Skin name', 'Aircraft', 'Containing folder'] self._menu = Menu('Title') # self._menu.add_action('Test menu', self._test_menu) self._menu.add_action('Open skin folder', self._context_open_folder) # self._menu.add_action('Show skin in model viewer', self._show_skin_in_model_viewer) self.table = TableViewWithSingleRowMenu(self._menu) self.table.setSelectionMode(self.table.SingleSelection) # noinspection PyUnresolvedReferences self.table.doubleClicked.connect(self._table_double_clicked) self.model = TableModel(data, header_data) self.proxy = TableProxy() self.proxy.setSourceModel(self.model) # noinspection PyUnresolvedReferences self.model.modelReset.connect(self.proxy.default_sort) self.table.setModel(self.proxy) self.setLayout( VLayout( [ # self.allow_mv_autoexec_changes, HLayout([ Label('Active DCS installation:'), self.combo_active_dcs_installation, self.no_install_label, HSpacer(), ]), GroupBox( 'Filters', GridLayout([ [ Label('Skin name:'), self.filter_skin_name, ], [ Label('Aircraft:'), self.filter_ac_name, ], [ Label('Folder:'), self.filter_folder, ], ]), ), (self.table, dict(stretch=1)), ], )) self._display_list_of_skins_for_currently_selected_install()
def _on_allow_mv_autoexec_changes(self): Config( ).allow_mv_autoexec_changes = self.allow_mv_autoexec_changes.isChecked( )
def _on_active_dcs_installation_change(self): Config( ).skins_active_dcs_installation = self.combo_active_dcs_installation.currentText( ) self._display_list_of_skins_for_currently_selected_install()
def combo_changed(self, new_value): Config().log_level = new_value self._set_log_level(new_value)