Python Forum
Python C++ Template Equivalent
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python C++ Template Equivalent
#3
I tried a mixin. It works, but the mixin provides only half the additional functionality because it really needs to act like a QWidget to get the show/close events.
class BaseView():
    """Abstract base class for views"""
    def __init__(self):
       self.update_list = UpdateList(1.0)

    def upload(self):
        """Forward update message to all ValueControl objects"""
        if self.isVisible():
            for child in self.children():
                if isinstance(child, ValueControl):
                    child.update_value()


class View(QtWidgets.QWidget, BaseView):
    """Add upload and update loop to QWidget"""

    def __init__(self, *args, **kwargs):
        QtWidgets.QWidget.__init__(self, *args, **kwargs)
        BaseView.__init__(self)

    def showEvent(self, event):
        """Start update loop when window is shown"""
        self.upload()
        self.update_list.start()
        event.accept()

    def closeEvent(self, event):
        """Stop update loop when window is closed"""
        self.update_list.stop()
        event.accept()
A benefit of this approach is giving View and GroupView a common superclass makes them easier to find using methods like QtWidget.findChildren(BaseView).
Reply


Messages In This Thread
Python C++ Template Equivalent - by deanhystad - May-03-2021, 02:30 PM
RE: Python C++ Template Equivalent - by Gribouillis - May-03-2021, 04:04 PM
RE: Python C++ Template Equivalent - by deanhystad - May-03-2021, 08:32 PM
RE: Python C++ Template Equivalent - by Gribouillis - May-03-2021, 09:05 PM
RE: Python C++ Template Equivalent - by deanhystad - May-03-2021, 09:30 PM
RE: Python C++ Template Equivalent - by deanhystad - May-04-2021, 04:41 PM
RE: Python C++ Template Equivalent - by Gribouillis - May-04-2021, 05:04 PM
RE: Python C++ Template Equivalent - by deanhystad - May-04-2021, 07:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Equivalent Python code from VBA Mishal0488 4 1,242 May-02-2024, 10:17 PM
Last Post: DeaD_EyE
  What is bug template using python Anldra12 0 1,019 Nov-02-2021, 11:36 AM
Last Post: Anldra12
  Erreur de code python sur un template rpm de zabbix samba 0 2,024 Apr-02-2021, 09:43 AM
Last Post: samba
  Hi Guys, please help me to write SAS macro parameter equivalent code in Python Manohar9589 2 2,739 Jun-14-2020, 05:07 PM
Last Post: Larz60+
  python equivalent to MATLAB xcov chai0404 2 4,041 Apr-02-2020, 10:29 PM
Last Post: chai0404
  Python equivalent of Matlab code kwokmaster 1 3,606 Mar-25-2020, 10:14 PM
Last Post: j.crater
  Equivalent of 'bwareafilt' for Python Mighty 1 3,754 Feb-05-2020, 10:32 PM
Last Post: Marbelous
  Convert a mongo db scrip to python equivalent Herath 1 2,312 Aug-20-2019, 02:28 PM
Last Post: fishhook
  SAS Equivalent of Macro variable in Python AI_ML_Neophyte 4 12,000 Mar-29-2019, 08:14 AM
Last Post: FelixS
  Python equivalent to sed [solved] cygnus_X1 2 11,619 Sep-24-2018, 10:13 PM
Last Post: cygnus_X1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020