PyQt UI event control segregation

2024/9/20 13:52:57

I am a beginner in python but my OOPS concept from Java and Android are strong enough to motivate me in making some tool in python. I am using PyQt for developing the application. In my application there are lot of QTabWidget used and has lot of UI controls in each TAB widget. Please see the screenshot for the same. enter image description here

All of the event control of entire tool i have kept in one single file but now i want to segregate it based on one individual python file per QTab for event control inside the Tab.

My project file architecture looks like :

enter image description here

I know this would be some really easy thing but considering my experience with Python i am finding it difficult. I would really appreciate example with code snippet. Since i am able to control real complicated QThread from seperate files but not able get how to do it for Ui controls.

I tried making a file for it like i made for Thread classes but end up with argument passing expection to super

from generated.MainGUI import Ui_MainWindow
class SemiAuto_Create_Load(QtGui.QMainWindow):def __init__(self,parent=none):super(SemiAuto_Create_Load, self).__init__()self.ui = Ui_MainWindowself.ui.setupUi(self)self.connectControlEvents()

Tried : self.sacl = SemiAuto_Create_Load()

Exception :

TypeError: init() takes exactly 3 arguments (1 given)

Answer

Okay i got this working with changes in

Mainwindow.py

class MainWindow(QtGui.QMainWindow):def __init__(self, parent = None):super(MainWindow, self).__init__(parent)Profile().notify(None)self.ui = Ui_MainWindow()self.ui.setupUi(self)self.connectButtons()SemiAuto_Create_Load(self, self.ui)

And

SemiAuto_Create_Load

class SemiAuto_Create_Load(QtGui.QMainWindow):def __init__(self, parent, ui):super(SemiAuto_Create_Load, self).__init__(parent)self.ui = uiself.connectControlEvents()def connectControlEvents(self):self.ui.load_vsa_radio.clicked.connect(self.onLoad_vsa_radio)self.ui.create_vsa_radio.clicked.connect(self.onCreate_vsa_radio)

Problem was passing the parameter with parent in init() and trying to get the object of MainGUI directly instead of as a parameter from MainWindow

https://en.xdnf.cn/q/119497.html

Related Q&A

How to re-run process Linux after crash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.This question does not appear to be about a specific programming problem, a software algorithm, or s…

Number of pairs

I am trying to write a code that takes m. a, a list of integers n. b, an integer and returns the number of pairs (m,n) with m,n in a such that |m-n|<=b. So far, Ive got this def nearest_pairs(a, b):…

xml.etree.ElementTree.ParseError: not well-formed

I have the following code:from xml.etree import ElementTreefile_path = some_file_pathdocument = ElementTree.parse(file_path, ElementTree.XMLParser(encoding=utf-8))If my XML looks like the following it …

Convert nested XML content into CSV using xml tree in python

Im very new to python and please treat me as same. When i tried to convert the XML content into List of Dictionaries Im getting output but not as expected and tried a lot playing around.XML Content<…

How to decode binary file with for index, line in enumerate(file)?

I am opening up an extremely large binary file I am opening in Python 3.5 in file1.py:with open(pathname, rb) as file:for i, line in enumerate(file):# parsing hereHowever, I naturally get an error beca…

how to install pyshpgeocode from git [duplicate]

This question already has answers here:The unauthenticated git protocol on port 9418 is no longer supported(10 answers)Closed 2 years ago.I would like to install the following from Git https://github.c…

How to export dictionary as CSV using Python?

I am having problems exporting certain items in a dictionary to CSV. I can export name but not images (the image URL).This is an example of part of my dictionary: new = [{ "name" : "pete…

Passing values to a function from within a function in python

I need to pass values from one function to the next from within the function.For example (my IRC bot programmed to respond to commands in the channel):def check_perms(nick,chan,cmd):sql = "SELECT …

How to make Stop button to terminate start function already running in Tkinter (Python)

I am making a GUI using Tkinter with two main buttons: "Start" and "Stop". Could you, please, advise on how to make the "Stop" button to terminate the already running func…

adding language to markdown codeblock in bulk

My Problem is to add to every single block of code a language in my markdown files. Ive hundreds of files in nested directories. The files have this form: ```language a ```Normal text``` b ```Normal te…