def exit_handler(e): """When the user leaves, cancel the event.""" # We only want to cancel if the event hasn't expired already nonlocal event_id hide() if event_id is not None: TK_ROOT.after_cancel(event_id)
def exit_handler(e): """When the user leaves, cancel the event.""" # We only want to cancel if the event hasn't expired already nonlocal event_id hide() if event_id is not None: TK_ROOT.after_cancel( event_id )
def start_copying(zip_list): global copy_process copy_process = multiprocessing.Process( target=do_copy, args=(zip_list, currently_done), ) copy_process.daemon = True print(copy_process) print('Starting background process!') copy_process.start() TK_ROOT.after(UPDATE_INTERVAL, update)
def open_win(self, _=None, force_open=False): if self._readonly and not force_open: TK_ROOT.bell() return 'break' # Tell tk to stop processing this event self.win.deiconify() self.win.lift(self.parent) self.win.grab_set() self.win.focus_force() # Focus here to deselect the textbox utils.center_win(self.win, parent=self.parent) self.flow_items() self.sel_item(self.selected)
def show_prop(widget, warp_cursor=False): """Show the properties window for an item. wid should be the UI.PalItem widget that represents the item. If warp_cursor is true, the cursor will be moved relative to this window so it stays on top of the selected subitem. """ global selected_item, selected_sub_item, is_open if warp_cursor and is_open: cursor_x, cursor_y = prop_window.winfo_pointerxy() off_x = cursor_x-prop_window.winfo_rootx() off_y = cursor_y-prop_window.winfo_rooty() else: off_x, off_y = None, None prop_window.deiconify() prop_window.lift(TK_ROOT) selected_item = widget.item selected_sub_item = widget is_open = True icon_widget = wid['subitem'][pos_for_item()] # Calculate the pixel offset between the window and the subitem in # the properties dialog, and shift if needed to keep it inside the # window loc_x, loc_y = utils.adjust_inside_screen( x=( widget.winfo_rootx() + prop_window.winfo_rootx() - icon_widget.winfo_rootx() ), y=( widget.winfo_rooty() + prop_window.winfo_rooty() - icon_widget.winfo_rooty() ), win=prop_window, ) prop_window.geometry('+{x!s}+{y!s}'.format(x=loc_x, y=loc_y)) prop_window.relX = loc_x-TK_ROOT.winfo_x() prop_window.relY = loc_y-TK_ROOT.winfo_y() if off_x is not None and off_y is not None: # move the mouse cursor prop_window.event_generate('<Motion>', warp=True, x=off_x, y=off_y) load_item_data()
def show_prop(widget, warp_cursor=False): """Show the properties window for an item. wid should be the UI.PalItem widget that represents the item. If warp_cursor is true, the cursor will be moved relative to this window so it stays on top of the selected subitem. """ global selected_item, selected_sub_item, is_open if warp_cursor and is_open: cursor_x, cursor_y = prop_window.winfo_pointerxy() off_x = cursor_x - prop_window.winfo_rootx() off_y = cursor_y - prop_window.winfo_rooty() else: off_x, off_y = None, None prop_window.deiconify() prop_window.lift(TK_ROOT) selected_item = widget.item selected_sub_item = widget is_open = True icon_widget = wid['subitem'][pos_for_item()] # Calculate the pixel offset between the window and the subitem in # the properties dialog, and shift if needed to keep it inside the # window loc_x, loc_y = utils.adjust_inside_screen( x=(widget.winfo_rootx() + prop_window.winfo_rootx() - icon_widget.winfo_rootx()), y=(widget.winfo_rooty() + prop_window.winfo_rooty() - icon_widget.winfo_rooty()), win=prop_window, ) prop_window.geometry('+{x!s}+{y!s}'.format(x=loc_x, y=loc_y)) prop_window.relX = loc_x - TK_ROOT.winfo_x() prop_window.relY = loc_y - TK_ROOT.winfo_y() if off_x is not None and off_y is not None: # move the mouse cursor prop_window.event_generate('<Motion>', warp=True, x=off_x, y=off_y) load_item_data()
def enter_handler(e): """Schedule showing the tooltip.""" nonlocal event_id if targ_widget.tooltip_text: if hasattr(targ_widget, 'instate'): if not targ_widget.instate(('!disabled', )): return event_id = TK_ROOT.after( delay, after_complete, )
def enter_handler(e): """Schedule showing the tooltip.""" nonlocal event_id if targ_widget.tooltip_text: if hasattr(targ_widget, 'instate'): if not targ_widget.instate(('!disabled',)): return event_id = TK_ROOT.after( delay, after_complete, )
def show_more_info(): url = selected_item.url if url is not None: try: webbrowser.open(url, new=OPEN_IN_TAB, autoraise=True) except webbrowser.Error: if messagebox.askyesno( icon="error", title="BEE2 - Error", message='Failed to open a web browser. Do you wish for ' 'the URL to be copied to the clipboard ' 'instead?', detail='"{!s}"'.format(url), parent=prop_window): print("Saving " + url + "to clipboard!") TK_ROOT.clipboard_clear() TK_ROOT.clipboard_append(url) # Either the webbrowser or the messagebox could cause the # properties to move behind the main window, so hide it # so it doesn't appear there. hide_context(None)
def show_more_info(): url = selected_item.url if url is not None: try: webbrowser.open(url, new=OPEN_IN_TAB, autoraise=True) except webbrowser.Error: if messagebox.askyesno( icon="error", title="BEE2 - Error", message='Failed to open a web browser. Do you wish for ' 'the URL to be copied to the clipboard ' 'instead?', detail='"{!s}"'.format(url), parent=prop_window ): print("Saving " + url + "to clipboard!") TK_ROOT.clipboard_clear() TK_ROOT.clipboard_append(url) # Either the webbrowser or the messagebox could cause the # properties to move behind the main window, so hide it # so it doesn't appear there. hide_context(None)
def update(): """Check the progress of the copying until it's done. """ progress_var.set( 1000 * currently_done.value / res_count, ) export_btn_text.set( 'Extracting Resources ({!s}/{!s})...'.format( currently_done.value, res_count, ) ) if not copy_process.is_alive(): # We've finished copying export_btn_text.set( 'Export...' ) done_callback() else: # Coninuously tell TK to re-run this, so we update # without deadlocking the CPU TK_ROOT.after(UPDATE_INTERVAL, update)
break else: # Not found self.suggested = None if self.suggested is not None: self.context_menu.entryconfig( self.item_list.index(self.suggested), font=self.sugg_font) self.set_disp() # Update the textbox if needed self.flow_items() # Refresh if __name__ == '__main__': # test the window if directly executing this file from tk_root import TK_ROOT lbl = ttk.Label(TK_ROOT, text="I am a demo window.") lbl.grid() TK_ROOT.geometry("+500+500") test_list = [ Item( "SKY_BLACK", "Black", long_name="Darkness", icon="skies/black", authors=["Valve"], desc=[ ('line', 'Pure black darkness. Nothing to see here.'), ], ), Item( "SKY_BTS", "BTS",
win.after(50, reset_sfx) widgets['titleLabel'].configure(text='Settings for "' + item_name + '"') win.title('BEE2 - ' + item_name) win.transient(master=parent) win.deiconify() win.lift(parent) win.grab_set() win.geometry( '+' + str(parent.winfo_rootx() - 30) + '+' + str(parent.winfo_rooty() - win.winfo_reqheight() - 30) ) # load the window if directly executing this file if __name__ == '__main__': TK_ROOT.geometry('+250+250') def callback(vals): for key, value in sorted(vals.items()): print(key + ' = ' + repr(value)) init(callback) all_vals = { 'startup': '1', 'toplevel': '4', 'bottomlevel': '3', 'angledpanelanimation': 'ramp_45_deg_open', 'startenabled': '1', 'startreversed': '0', 'startdeployed': '1', 'startactive': '1',
def follow_main(_=None): """Move the properties window to keep a relative offset to the main window. """ prop_window.geometry('+'+str(prop_window.relX+TK_ROOT.winfo_x()) + '+'+str(prop_window.relY+TK_ROOT.winfo_y()))
def follow_main(_=None): """Move the properties window to keep a relative offset to the main window. """ prop_window.geometry('+' + str(prop_window.relX + TK_ROOT.winfo_x()) + '+' + str(prop_window.relY + TK_ROOT.winfo_y()))
block_sound = False win.after(50, reset_sfx) widgets['titleLabel'].configure(text='Settings for "' + item_name + '"') win.title('BEE2 - ' + item_name) win.transient(master=parent) win.deiconify() win.lift(parent) win.grab_set() win.geometry('+' + str(parent.winfo_rootx() - 30) + '+' + str(parent.winfo_rooty() - win.winfo_reqheight() - 30)) # load the window if directly executing this file if __name__ == '__main__': TK_ROOT.geometry('+250+250') def callback(vals): for key, value in sorted(vals.items()): print(key + ' = ' + repr(value)) init(callback) all_vals = { 'startup': '1', 'toplevel': '4', 'bottomlevel': '3', 'angledpanelanimation': 'ramp_45_deg_open', 'startenabled': '1', 'startreversed': '0', 'startdeployed': '1', 'startactive': '1',
self.suggested = item break else: # Not found self.suggested = None if self.suggested is not None: self.context_menu.entryconfig( self.item_list.index(self.suggested), font=self.sugg_font) self.set_disp() # Update the textbox if needed self.flow_items() # Refresh if __name__ == '__main__': # test the window if directly executing this file lbl = ttk.Label(TK_ROOT, text="I am a demo window.") lbl.grid() TK_ROOT.geometry("+500+500") test_list = [ Item( "SKY_BLACK", "Black", long_name="Darkness", icon="skies/black", authors=["Valve"], desc=[ ('line', 'Pure black darkness. Nothing to see here.'), ], ), Item( "SKY_BTS", "BTS",