|
8 | 8 | script.exit() |
9 | 9 | ``` |
10 | 10 | """ |
11 | | -#pylint: disable=consider-using-f-string |
| 11 | +# pylint: disable=consider-using-f-string |
12 | 12 |
|
13 | 13 | import sys |
14 | 14 | import os |
|
38 | 38 | # suppress any warning generated by native or third-party modules |
39 | 39 | warnings.filterwarnings("ignore") |
40 | 40 |
|
41 | | -#pylint: disable=W0703,C0302,C0103,W0614 |
| 41 | +# pylint: disable=W0703,C0302,C0103,W0614 |
42 | 42 | mlogger = logger.get_logger(__name__) |
43 | 43 |
|
44 | 44 |
|
|
48 | 48 | ICON_MEDIUM = 24 |
49 | 49 | ICON_LARGE = 32 |
50 | 50 |
|
| 51 | + |
51 | 52 | def get_info(): |
52 | 53 | """Return info on current pyRevit command. |
53 | 54 |
|
@@ -799,3 +800,66 @@ def data_exists(slot_name, this_project=True): |
799 | 800 | file_ext=DATAFEXT, |
800 | 801 | add_cmd_name=False) |
801 | 802 | return os.path.exists(data_file) |
| 803 | + |
| 804 | + |
| 805 | +def restore_window_position(window, command_name=EXEC_PARAMS.command_name): |
| 806 | + """ |
| 807 | + Restore window position from saved data. |
| 808 | +
|
| 809 | + Args: |
| 810 | + window (System.Windows.Window): WPF window instance |
| 811 | + command_name (str): Unique identifier for this window |
| 812 | +
|
| 813 | + Returns: |
| 814 | + bool: True if position was restored, False if centered to screen |
| 815 | + """ |
| 816 | + storage_key = "last_window_position_" + command_name |
| 817 | + |
| 818 | + try: |
| 819 | + pos = load_data(storage_key, this_project=False) |
| 820 | + if not pos: |
| 821 | + raise Exception("No saved position") |
| 822 | + |
| 823 | + left, top, width, height = ( |
| 824 | + pos.get("Left", 0), |
| 825 | + pos.get("Top", 0), |
| 826 | + pos.get("Width", window.Width), |
| 827 | + pos.get("Height", window.Height), |
| 828 | + ) |
| 829 | + |
| 830 | + if coreutils.is_box_visible_on_screens(left, top, width, height): |
| 831 | + window.WindowStartupLocation = ( |
| 832 | + framework.Windows.WindowStartupLocation.Manual |
| 833 | + ) |
| 834 | + window.Left = left |
| 835 | + window.Top = top |
| 836 | + window.Width = width |
| 837 | + window.Height = height |
| 838 | + return True |
| 839 | + else: |
| 840 | + raise Exception("Position not visible on any screen") |
| 841 | + |
| 842 | + except Exception as ex: |
| 843 | + mlogger.debug("Could not restore window position: %s", ex) |
| 844 | + window.WindowStartupLocation = ( |
| 845 | + framework.Windows.WindowStartupLocation.CenterScreen |
| 846 | + ) |
| 847 | + return False |
| 848 | + |
| 849 | + |
| 850 | +def save_window_position(window, command_name=EXEC_PARAMS.command_name): |
| 851 | + """ |
| 852 | + Save window position to persistent storage. |
| 853 | +
|
| 854 | + Args: |
| 855 | + window (System.Windows.Window): WPF window instance |
| 856 | + command_name (str): Unique identifier for this window |
| 857 | + """ |
| 858 | + storage_key = "last_window_position_" + command_name |
| 859 | + position_data = { |
| 860 | + "Left": window.Left, |
| 861 | + "Top": window.Top, |
| 862 | + "Width": window.ActualWidth, |
| 863 | + "Height": window.ActualHeight |
| 864 | + } |
| 865 | + store_data(storage_key, position_data, this_project=False) |
0 commit comments