def check_vanilla_raws(): """Validates status of vanilla raws are ready.""" if not download.get_queue('baselines').empty(): return False raw_status = baselines.find_vanilla_raws() if raw_status is None: messagebox.showerror( message='Your Dwarf Fortress version could not be detected ' 'accurately, which is necessary to process this request.' '\n\nYou will need to restore the file "release notes.txt" in ' 'order to use this launcher feature.', title='Cannot continue') return False if raw_status is False: if lnp.userconfig.get_bool('downloadBaselines'): messagebox.showinfo( message='A copy of Dwarf Fortress needs to be ' 'downloaded in order to use this. The download is ' 'currently in progress.\n\nPlease note: You ' 'will need to retry the action after the download ' 'completes.', title='Download required') return False return True
def __init__(self): """ Constructor for TkGui. Params: lnp A PyLNP instance to perform actual work. """ self.root = root = Tk() self.updateDays = IntVar() self.downloadBaselines = BooleanVar() self.show_scrollbars = BooleanVar() self.autoclose = BooleanVar() self.do_reload = False controls.init(self) binding.init(lnp) if not self.ensure_df(): return root.option_add('*tearOff', FALSE) windowing = root.tk.call('tk', 'windowingsystem') if windowing == "win32": root.tk.call( 'wm', 'iconbitmap', root, "-default", get_resource('LNP.ico')) elif windowing == "x11": root.tk.call( 'wm', 'iconphoto', root, "-default", get_image(get_resource('LNP'))) elif windowing == "aqua": # OS X has no window icons pass root.title("PyLNP") self.vcmd = (root.register(validate_number), '%P') main = Frame(root) self.logo = logo = get_image(get_resource('LNPSMALL')) Label(root, image=logo, anchor=CENTER).pack(fill=X) main.pack(side=TOP, fill=BOTH, expand=Y) self.download_panel = controls.create_control_group( main, 'Download status') self.download_text = StringVar() self.download_status = Label( self.download_panel, textvariable=self.download_text) self.download_panel.pack(fill=X, expand=N, side=BOTTOM) self.download_status.pack(side=BOTTOM) self.n = n = Notebook(main) self.create_tab(OptionsTab, 'Options') self.create_tab(GraphicsTab, 'Graphics') self.create_tab(UtilitiesTab, 'Utilities') self.create_tab(AdvancedTab, 'Advanced') if 'dfhack' in lnp.df_info.variations: self.create_tab(DFHackTab, 'DFHack') if mods.read_mods(): self.create_tab(ModsTab, 'Mods') n.enable_traversal() n.pack(fill=BOTH, expand=Y, padx=2, pady=3) play_font = tkFont.Font(font='TkDefaultFont') play_font.config(weight=tkFont.BOLD, size=int(play_font['size'] * 1.5)) Style().configure('Big.TButton', font=play_font) play_button = controls.create_trigger_button( main, 'Play Dwarf Fortress!', 'Play the game!', launcher.run_df) play_button.configure(style='Big.TButton') play_button.pack(side=BOTTOM, fill=X, padx=(1, 3), pady=(0, 3)) self.menubar = self.create_menu(root) self.save_size = None root.update() height = root.winfo_height() if windowing == "x11": # On Linux, the menu bar height isn't being calculated correctly # for minsize height += self.menubar.winfo_reqheight() root.minsize(width=root.winfo_width(), height=height) self.download_panel.pack_forget() root.geometry('{}x{}'.format( lnp.userconfig.get_number('tkgui_width'), lnp.userconfig.get_number('tkgui_height'))) root.bind("<Configure>", lambda e: self.on_resize()) root.update() queue = download.get_queue('baselines') queue.register_start_queue(self.start_download_queue) queue.register_begin_download(self.start_download) queue.register_progress(self.download_progress) queue.register_end_download(self.end_download) queue.register_end_queue(self.end_download_queue) binding.update() root.bind('<<UpdateAvailable>>', lambda e: UpdateWindow(self.root)) # Used for cross-thread signaling and communication during downloads self.update_pending = Semaphore(1) self.queue = Queue.Queue() self.cross_thread_data = None self.reply_semaphore = Semaphore(0) self.download_text_string = '' root.bind('<<ConfirmDownloads>>', lambda e: self.confirm_downloading()) root.bind('<<ForceUpdate>>', lambda e: self.update_download_text()) root.bind('<<ShowDLPanel>>', lambda e: self.download_panel.pack( fill=X, expand=N, side=BOTTOM)) root.bind( '<<HideDLPanel>>', lambda e: self.download_panel.pack_forget()) self.cross_thread_timer = self.root.after(100, self.check_cross_thread)
def __init__(self): """ Constructor for TkGui. Args: lnp: A PyLNP instance to perform actual work. """ self.root = root = Tk() self.updateDays = IntVar() self.downloadBaselines = BooleanVar() self.show_scrollbars = BooleanVar() self.autoclose = BooleanVar() self.do_reload = False controls.init(self) binding.init(lnp, self) if not self.ensure_df(): return if sys.version_info[0] == 3: Style().map('Treeview', foreground=fixed_map('foreground'), background=fixed_map('background')) if lnp.os == 'linux' and not terminal.terminal_configured(): self.root.withdraw() messagebox.showinfo( 'PyLNP', 'You need to configure a terminal to allow things like DFHack ' 'to work correctly. Press OK to do this now.') self.configure_terminal(True) self.root.deiconify() root.option_add('*tearOff', FALSE) windowing = root.tk.call('tk', 'windowingsystem') if windowing == "win32": root.tk.call('wm', 'iconbitmap', root, "-default", get_resource('LNP.ico')) elif windowing == "x11": root.tk.call('wm', 'iconphoto', root, "-default", get_image(get_resource('LNP'))) elif windowing == "aqua": # OS X has no window icons pass root.title("PyLNP") self.vcmd = (root.register(validate_number), '%P') main = Frame(root) self.logo = logo = get_image(get_resource('LNPSMALL')) Label(root, image=logo, anchor=CENTER).pack(fill=X) main.pack(side=TOP, fill=BOTH, expand=Y) self.download_panel = controls.create_control_group( main, 'Download status') self.download_text = StringVar() self.download_status = Label(self.download_panel, textvariable=self.download_text) self.download_panel.pack(fill=X, expand=N, side=BOTTOM) self.download_status.pack(side=BOTTOM) self.n = n = Notebook(main) self.create_tab(OptionsTab, 'Options') self.create_tab(GraphicsTab, 'Graphics') self.create_tab(UtilitiesTab, 'Utilities') self.create_tab(AdvancedTab, 'Advanced') if 'dfhack' in lnp.df_info.variations: self.create_tab(DFHackTab, 'DFHack') if mods.read_mods(): self.create_tab(ModsTab, 'Mods') n.enable_traversal() n.pack(fill=BOTH, expand=Y, padx=2, pady=3) play_font = tkFont.Font(font='TkDefaultFont') play_font.config(weight=tkFont.BOLD, size=int(play_font['size'] * 1.5)) Style().configure('Big.TButton', font=play_font) play_button = controls.create_trigger_button(main, 'Play Dwarf Fortress!', 'Play the game!', self.run_df) if sys.platform != 'darwin': play_button.configure(style='Big.TButton') play_button.pack(side=BOTTOM, fill=X, padx=(1, 3), pady=(0, 3)) else: play_button.pack(side=BOTTOM, fill=X, padx=(30, 30), pady=(0, 3)) self.menubar = self.create_menu(root) self.save_size = None root.update() height = root.winfo_height() if windowing == "x11": # On Linux, the menu bar height isn't being calculated correctly # for minsize height += self.menubar.winfo_reqheight() root.minsize(width=root.winfo_width(), height=height) self.download_panel.pack_forget() root.geometry('{}x{}'.format( lnp.userconfig.get_number('tkgui_width'), lnp.userconfig.get_number('tkgui_height'))) root.bind("<Configure>", lambda e: self.on_resize()) root.update() queue = download.get_queue('baselines') queue.register_start_queue(self.start_download_queue) queue.register_begin_download(self.start_download) queue.register_progress(self.download_progress) queue.register_end_download(self.end_download) queue.register_end_queue(self.end_download_queue) binding.update() root.bind('<<UpdateAvailable>>', lambda e: UpdateWindow(self.root)) # Used for cross-thread signaling and communication during downloads self.update_pending = Semaphore(1) self.queue = Queue.Queue() self.cross_thread_data = None self.reply_semaphore = Semaphore(0) self.download_text_string = '' root.bind('<<ConfirmDownloads>>', lambda e: self.confirm_downloading()) root.bind('<<ForceUpdate>>', lambda e: self.update_download_text()) root.bind( '<<ShowDLPanel>>', lambda e: self.download_panel.pack(fill=X, expand=N, side=BOTTOM)) root.bind('<<HideDLPanel>>', lambda e: self.download_panel.pack_forget()) self.cross_thread_timer = self.root.after(100, self.check_cross_thread)