slaclab / pydm

Python Display Manager
http://slaclab.github.io/pydm/
Other
113 stars 77 forks source link

Stretchable layout with MEDM-style widgets #857

Open prjemian opened 2 years ago

prjemian commented 2 years ago

What's the problem this feature will solve? MEDM widgets are placed by absolute positioning. MEDM users are accustomed to changing the screen size and the widgets will stretch accordingly. In Qt, the stretchable feature is provided by a layout manager which re-positions its widgets as the layout changes size.

The widgets from the adl2pydm converter are not stretchable and this is a popular feature that is missed in MEDM screens converted for use in PyDM.

Describe the solution you'd like Internal widgets proportionally should stretch as the window changes size. (note: These example screens are rendered with caQtDM, a C++/Qt application, showing the idea is possible in Qt.)

original size as-drawn

stretched stretched

Additional context After some research, it seems a good candidate case for a Qt Custom Layout Manager. The new custom layout would accept widgets placed in absolute coordinates and then adjust the geometry (x,y,h,w) of each to fit the containing QFrame.

The PyDM project already has an existing custom layout manager (FlowLayout()) that would be a good example for a new layout manager for this feature: https://github.com/slaclab/pydm/blob/5740b1a57c9c7870df26f2d5b898e345a104f423/pydm/widgets/template_repeater.py#L17-L112

The adl2pydm converter would use this new layout for each of the MEDM screens it converts.

prjemian commented 2 years ago

Looking at the the caQtDM repository does not reveal any Qt custom layout manager. Instead, the application likely responds to resize events of the windows directly.

To co-exist with use of the standard Qt layout managers, a custom layout manager seems the right way to proceed.

prjemian commented 2 years ago

A basic version of the new custom layout (name to be adjusted per agreement):

class MedmLayout(QLayout):
    """
    Layout Manager for MEDM widgets.

    Widgets are added to this layout with absolute coordinates (x,y,height,width).
    When the layout is resized, the manager will resize each of the
    widgets in the layout.
    """

shows up in designer by following the patterns in qtplugins.py:

MedmLayoutPlugin = qtplugin_factory(MedmLayout,
                                    group='PyDM Layouts',
                                    is_container=True,
                                    extensions=BASE_EXTENSIONS)

but there are problems:

(dev-pydm) zorinvm@zorin22:~/.../slaclab/pydm$ designer
Loading PyDM Widgets
Exception occurred while running Qt Designer.
Traceback (most recent call last):
  File "/home/zorinvm/Documents/projects/slaclab/pydm/pydm/widgets/qtplugin_base.py", line 119, in createWidget
    w = self.cls(parent=parent)
TypeError: 'parent' is an unknown keyword argument

Designer: The custom widget factory registered for widgets of class MedmLayout returned 0.
** WARNING Factory failed to create  "MedmLayout"

https://stackoverflow.com/questions/5659875/custom-layout-in-qt-designer

Advice is to write a custom container (QWidget, QFrame, ...) which can be interfaced as a designer plugin. Then call the custom layout from the custom container.

prjemian commented 2 years ago

Now called AbsoluteGeometryLayout

prjemian commented 2 years ago

QFrame is a subclass of QWidget Clipboard01

The additional attributes provided by QFrame are not expected. The AbsoluteGeometryWidget will subclass from QWidget and call AbsoluteGeometryLayout which will have zeroes for all the margins by default: Clipboard01

prjemian commented 2 years ago

Drat!. Even with the custom layout called from the custom widget, the custom widget is not designable in the sense that child widgets can be dragged into it. Unless the window is based on the custom widget. In either case, widgets added will not be part of the custom layout.

Rethink it

A QWidget can have widget children. It can manipulate the geometry of each child during a resizeEvent(). One way for that to be successful is to keep the original widget size and then compute the horizontal and vertical scale factors with each new resizeEvent.