|  | 
| 24 | 24 | except ImportError: | 
| 25 | 25 |     requests = None | 
| 26 | 26 | 
 | 
| 27 |  | -CURRENT_VERSION = "v1.6.0" | 
|  | 27 | +CURRENT_VERSION = "v1.7.0" | 
| 28 | 28 | 
 | 
| 29 | 29 | def action_save_as(ui): | 
| 30 | 30 |     """ | 
| @@ -52,32 +52,124 @@ def action_save(ui): | 
| 52 | 52 |         action_save_as(ui) | 
| 53 | 53 | 
 | 
| 54 | 54 | def basic_view_enabled(ui): | 
| 55 |  | -    """ Hide specific layouts in the UI for basic view """ | 
| 56 |  | -    # Hide all widgets in the verticalLayout_config | 
| 57 |  | -    for i in range(ui.verticalLayout_config.count()): | 
| 58 |  | -        widget = ui.verticalLayout_config.itemAt(i).widget() | 
|  | 55 | +    """ Hide specific layouts in the UI for basic view and collapse the | 
|  | 56 | +    reserved space so the window side doesn't leave an empty gap. | 
|  | 57 | +
 | 
|  | 58 | +    This saves the layouts' margins/spacing and widgets' maximum heights the | 
|  | 59 | +    first time it's called, then sets margins and spacing to zero and forces | 
|  | 60 | +    widgets to zero height so the layout collapses. The values are restored | 
|  | 61 | +    by `advanced_view_enabled`. | 
|  | 62 | +    """ | 
|  | 63 | +    # Short aliases | 
|  | 64 | +    v_layout = ui.verticalLayout_config | 
|  | 65 | +    f_layout = ui.formLayout_config | 
|  | 66 | + | 
|  | 67 | +    # Save original layout settings and widget max heights once | 
|  | 68 | +    if not hasattr(ui, '_basic_view_saved'): | 
|  | 69 | +        ui._basic_view_saved = { | 
|  | 70 | +            'v_margins': v_layout.contentsMargins(), | 
|  | 71 | +            'v_spacing': v_layout.spacing(), | 
|  | 72 | +            'f_margins': f_layout.contentsMargins(), | 
|  | 73 | +            'f_spacing': f_layout.spacing(), | 
|  | 74 | +            'widgets_maxheight': {} | 
|  | 75 | +        } | 
|  | 76 | + | 
|  | 77 | +    # Collapse layout spacing and margins to remove empty space | 
|  | 78 | +    try: | 
|  | 79 | +        v_layout.setContentsMargins(0, 0, 0, 0) | 
|  | 80 | +        v_layout.setSpacing(0) | 
|  | 81 | +    except Exception: | 
|  | 82 | +        pass | 
|  | 83 | +    try: | 
|  | 84 | +        f_layout.setContentsMargins(0, 0, 0, 0) | 
|  | 85 | +        f_layout.setSpacing(0) | 
|  | 86 | +    except Exception: | 
|  | 87 | +        pass | 
|  | 88 | + | 
|  | 89 | +    # Hide and shrink widgets inside the layouts | 
|  | 90 | +    for i in range(v_layout.count()): | 
|  | 91 | +        item = v_layout.itemAt(i) | 
|  | 92 | +        widget = item.widget() if item else None | 
| 59 | 93 |         if widget: | 
|  | 94 | +            # store previous maximum height to restore later | 
|  | 95 | +            ui._basic_view_saved['widgets_maxheight'][str(id(widget))] = widget.maximumHeight() | 
|  | 96 | +            widget.setMaximumHeight(0) | 
| 60 | 97 |             widget.setVisible(False) | 
| 61 | 98 | 
 | 
| 62 |  | -    # Optionally, hide all widgets in the formLayout_config | 
| 63 |  | -    for i in range(ui.formLayout_config.count()): | 
| 64 |  | -        widget = ui.formLayout_config.itemAt(i).widget() | 
|  | 99 | +    for i in range(f_layout.count()): | 
|  | 100 | +        item = f_layout.itemAt(i) | 
|  | 101 | +        widget = item.widget() if item else None | 
| 65 | 102 |         if widget: | 
|  | 103 | +            ui._basic_view_saved['widgets_maxheight'][str(id(widget))] = widget.maximumHeight() | 
|  | 104 | +            widget.setMaximumHeight(0) | 
| 66 | 105 |             widget.setVisible(False) | 
| 67 | 106 | 
 | 
| 68 | 107 | def advanced_view_enabled(ui): | 
| 69 |  | -    """ Show specific layouts in the UI for advanced view """ | 
| 70 |  | -    # Show all widgets in the verticalLayout_config | 
| 71 |  | -    for i in range(ui.verticalLayout_config.count()): | 
| 72 |  | -        widget = ui.verticalLayout_config.itemAt(i).widget() | 
| 73 |  | -        if widget: | 
| 74 |  | -            widget.setVisible(True) | 
|  | 108 | +    """ Show specific layouts in the UI for advanced view and restore the | 
|  | 109 | +    layout margins/spacing and widgets' sizes saved by `basic_view_enabled`. | 
|  | 110 | +    """ | 
|  | 111 | +    v_layout = ui.verticalLayout_config | 
|  | 112 | +    f_layout = ui.formLayout_config | 
| 75 | 113 | 
 | 
| 76 |  | -    # Optionally, show all widgets in the formLayout_config | 
| 77 |  | -    for i in range(ui.formLayout_config.count()): | 
| 78 |  | -        widget = ui.formLayout_config.itemAt(i).widget() | 
| 79 |  | -        if widget: | 
| 80 |  | -            widget.setVisible(True) | 
|  | 114 | +    # Restore layout margins/spacing if we saved them earlier | 
|  | 115 | +    if hasattr(ui, '_basic_view_saved'): | 
|  | 116 | +        saved = ui._basic_view_saved | 
|  | 117 | +        try: | 
|  | 118 | +            m = saved.get('v_margins') | 
|  | 119 | +            if m is not None: | 
|  | 120 | +                v_layout.setContentsMargins(m.left(), m.top(), m.right(), m.bottom()) | 
|  | 121 | +            v_layout.setSpacing(saved.get('v_spacing', v_layout.spacing())) | 
|  | 122 | +        except Exception: | 
|  | 123 | +            pass | 
|  | 124 | +        try: | 
|  | 125 | +            m = saved.get('f_margins') | 
|  | 126 | +            if m is not None: | 
|  | 127 | +                f_layout.setContentsMargins(m.left(), m.top(), m.right(), m.bottom()) | 
|  | 128 | +            f_layout.setSpacing(saved.get('f_spacing', f_layout.spacing())) | 
|  | 129 | +        except Exception: | 
|  | 130 | +            pass | 
|  | 131 | + | 
|  | 132 | +        # Restore widgets' maximum heights and visibility | 
|  | 133 | +        for i in range(v_layout.count()): | 
|  | 134 | +            item = v_layout.itemAt(i) | 
|  | 135 | +            widget = item.widget() if item else None | 
|  | 136 | +            if widget: | 
|  | 137 | +                key = str(id(widget)) | 
|  | 138 | +                prev_h = saved['widgets_maxheight'].get(key) | 
|  | 139 | +                if prev_h is not None: | 
|  | 140 | +                    widget.setMaximumHeight(prev_h) | 
|  | 141 | +                else: | 
|  | 142 | +                    widget.setMaximumHeight(16777215) | 
|  | 143 | +                widget.setVisible(True) | 
|  | 144 | + | 
|  | 145 | +        for i in range(f_layout.count()): | 
|  | 146 | +            item = f_layout.itemAt(i) | 
|  | 147 | +            widget = item.widget() if item else None | 
|  | 148 | +            if widget: | 
|  | 149 | +                key = str(id(widget)) | 
|  | 150 | +                prev_h = saved['widgets_maxheight'].get(key) | 
|  | 151 | +                if prev_h is not None: | 
|  | 152 | +                    widget.setMaximumHeight(prev_h) | 
|  | 153 | +                else: | 
|  | 154 | +                    widget.setMaximumHeight(16777215) | 
|  | 155 | +                widget.setVisible(True) | 
|  | 156 | +        # clear saved state | 
|  | 157 | +        delattr(ui, '_basic_view_saved') if hasattr(ui, '_basic_view_saved') else None | 
|  | 158 | +    else: | 
|  | 159 | +        # Fallback: simply show widgets | 
|  | 160 | +        for i in range(v_layout.count()): | 
|  | 161 | +            item = v_layout.itemAt(i) | 
|  | 162 | +            widget = item.widget() if item else None | 
|  | 163 | +            if widget: | 
|  | 164 | +                widget.setVisible(True) | 
|  | 165 | +                widget.setMaximumHeight(16777215) | 
|  | 166 | + | 
|  | 167 | +        for i in range(f_layout.count()): | 
|  | 168 | +            item = f_layout.itemAt(i) | 
|  | 169 | +            widget = item.widget() if item else None | 
|  | 170 | +            if widget: | 
|  | 171 | +                widget.setVisible(True) | 
|  | 172 | +                widget.setMaximumHeight(16777215) | 
| 81 | 173 | 
 | 
| 82 | 174 | def clear_buffer(ui): | 
| 83 | 175 |     """ Clear the buffer """ | 
|  | 
0 commit comments