Appending texto to winget from 'regular' function

Hi,

This is a demo Python project using Python (of course), PyCharm and QtDesigner.

The Start button works OK but I can’t find out the proper syntax to be able to append text to the textEdit widget from the main_proc() function.

Please have a look at the notes within the code below:

import sys

from PyQt5.QtWidgets import *
from PyQt5 import uic

class PlotGUI(QMainWindow):

 def __init__(self):
     super(PlotGUI, self).__init__()
     uic.loadUi("PlotGUI.ui", self)
     self.show()

     self.pushButton_Start.clicked.connect(main_proc)

     self.textEdit_log.append("Hi!") # >>>>>>>>>>>>>>> This one works OK

def main_proc():

 print("Appended Text") # This appends text to the 'regular' text output console (ou sort of).
 # >>>>>>>>>>>>>>> I need to append text to textEdit_log from here <<<<<<<<<<<<<<<<<<<

def main():
 app = QApplication([])
 window = PlotGUI()
 app.exec_()

if __name__ == '__main__':
 main()


Could I have some help please?
I will try to upload a .rar with the all the related files, I don’t know yes if it is possible. [looks like it is not]
Thanks
H. Martins

After app.exec_() is called only code running in event handlers will be called.
That assumes you have something generating an event, like a button.

Your main_proc is not connected to anything so will never be used.

Don’t post a rar of code, many people will never open it as its a security risk.
Just make your code small enough to post here for comment.

Thank you.

main_proc runs by:

self.pushButton_Start.clicked.connect(main_proc)

and indeed it runs.

… but can’t I append text to textEdit_log from there?

Why don’t you make main_proc a method?

Well, I have lots of code already written called by main_proc and I need not only to interact reading widget contents there but also in several other functions.

The code needs to read the content of several widgets (that do not change after the Start button is pressed).

At the moment I do all that changing variable content in declaration but I would like to ‘humanise’ using, say Windows style interfacing.

This is the real main_proc:


def main_proc():

    data_out("IN; ")  # Inicializar
    data_out("DF; ")  # Default
    data_out("SP1; ")  # Select pen
    data_out("IN; ")  # Inicializar
    data_out("DF; ")  # Default
    data_out("PA; ")  # Plot absolute
    data_out("VS1; ")  # velocidade
    data_out("PU; ")  # PenUp

    path_proc()
    polygon_proc()
    circle_proc()


    data_out("SP0; ")  # Repõe caneta
    #data_out("DF; ")   # Default
    #data_out("IN; ")   # Inicializar

    print(s_filename2)
path_proc()
polygon_proc()
circle_proc()

These three functions call other etc, and they all need to read the content of the widgets and append text do textEdit_log

I need to replace many "print"s by writing in textEdit_log.

I found a solution:

class PlotGUI(QMainWindow):

    def __init__(self):
        super(PlotGUI, self).__init__()
        uic.loadUi("PlotGUI.ui", self)
        self.show()

        global txt_log                     #  <<<<<<<<<<<<<< these two lines
        txt_log = self.textEdit_log  #  <<<<<<<<<<<<<< these two lines

Then a small aggregating (append + repaint) function

def txt2log(str):
    txt_log.append(str)
    txt_log.repaint()

And finnaly,

txt2log("appending text")

placed in any other function is doing the job.

Thank you
H. Martins