|
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,60 @@ 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: WPF window instance |
| 811 | + command_name: 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 | + # Get all screen working areas |
| 824 | + all_bounds = [s.WorkingArea for s in framework.Forms.Screen.AllScreens] |
| 825 | + x, y = pos.get("Left", 0), pos.get("Top", 0) |
| 826 | + |
| 827 | + # Check if position is visible on any screen |
| 828 | + visible = any( |
| 829 | + (b.Left <= x <= b.Right and b.Top <= y <= b.Bottom) for b in all_bounds |
| 830 | + ) |
| 831 | + |
| 832 | + if visible: |
| 833 | + window.WindowStartupLocation = ( |
| 834 | + framework.Windows.WindowStartupLocation.Manual |
| 835 | + ) |
| 836 | + window.Left = x |
| 837 | + window.Top = y |
| 838 | + return True |
| 839 | + else: |
| 840 | + raise Exception("Position not visible on any screen") |
| 841 | + |
| 842 | + except Exception: |
| 843 | + window.WindowStartupLocation = ( |
| 844 | + framework.Windows.WindowStartupLocation.CenterScreen |
| 845 | + ) |
| 846 | + return False |
| 847 | + |
| 848 | + |
| 849 | +def save_window_position(window, command_name=EXEC_PARAMS.command_name): |
| 850 | + """ |
| 851 | + Save window position to persistent storage. |
| 852 | +
|
| 853 | + Args: |
| 854 | + window: WPF window instance |
| 855 | + command_name: Unique identifier for this window |
| 856 | + """ |
| 857 | + storage_key = "last_window_position_" + command_name |
| 858 | + position_data = {"Left": window.Left, "Top": window.Top} |
| 859 | + store_data(storage_key, position_data, this_project=False) |
0 commit comments