473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Beginner: Simple Output to a Dialog PyQt4

Hello,
I've written a script in python and put together a simple QFrame with a
QTextBrowser with Designer. I've translated the C++ into python using
puic4. The .py file is called outputWin.py. My Script and its
functions are in cnt.py. Finally, my main is in pball.py which follows
here:
import sys
from PyQt4 import Qt, QtCore
from outputWin import *
from cnt import *
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
window = Qt.QDialog()
ui = Ui_Dialog()
ui.setupUi(window)
window.show()
app.exec_()

I want to call my functions in cnt and have an output to my QDialog. Can
somebody give me a clue as to how to proceed? I can't find good an easy
tutorial for PyQt4 and I've never used Qt before.
Apr 17 '07 #1
2 4029
On Tuesday 17 April 2007 07:42, Glen wrote:
I've written a script in python and put together a simple QFrame with a
QTextBrowser with Designer. I've translated the C++ into python using
puic4.
Just to avoid any misunderstanding: the form is actually stored as XML. You
can create C++ code with uic or Python code with pyuic4.
The .py file is called outputWin.py. My Script and its
functions are in cnt.py.
OK. Ideally, your window will contain a button (or some other control) that
the user can click to execute the functions.
Finally, my main is in pball.py which follows
here:
import sys
from PyQt4 import Qt, QtCore
from outputWin import *
from cnt import *
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
window = Qt.QDialog()
ui = Ui_Dialog()
ui.setupUi(window)
window.show()
app.exec_()

I want to call my functions in cnt and have an output to my QDialog. Can
somebody give me a clue as to how to proceed? I can't find good an easy
tutorial for PyQt4 and I've never used Qt before.
If, for example, you included a push button (QPushButton) in the form you
created with Qt Designer, and called it executeButton, you could connect its
clicked() signal to a function in cnt by including the following line after
setting up the user interface:

window.connect(ui.executeButton, SIGNAL("clicked()"), cnt.myFunction)

This assumes that your function is called myFunction(), of course.
However, you wouldn't be able to get the output from this function back to
the dialog just by using a signal-slot connection like this.

One way to solve this would be to wrap the function using another function
or instance that is able to modify the contents of the dialog. Another
cleaner approach would be to subclass the user interface class (Ui_Dialog)
and implement a custom slot that can both call the function and modify the
dialog.

For example:

class Dialog(QDialog, Ui_Dialog)

def __init__(self, parent = None):

QDialog.__init__(self, parent)
self.setupUi(self)

self.connect(self.executeButton, SIGNAL("clicked()"),
self.callFunction)

def callFunction(self):

data = cnt.myFunction()
# Do something with the data.

Hope this gets you started,

David
Apr 21 '07 #2
On Sat, 21 Apr 2007 03:15:00 +0200, David Boddie wrote:
On Tuesday 17 April 2007 07:42, Glen wrote:
>
# Just to avoid any misunderstanding: the form is actually stored as XML.
# You can create C++ code with uic or Python code with pyuic4.
Right. I do remember noticing that when I opened one of the .ui files.

Thanks for the instructions. I'm tackling signals and slots next. I'll
be reading your post a few times, I'm sure. For the time being, just to
get myself off the ground and see some output, I imported my functions
from cnt.py into my main with 'from cnt import cnt'. Then I passed my
QTextEdit object into my python code and output the contents of my file
with:
f = file("filename", 'r')
for line in f:
QTxtObj.insertPlainText(line)

Maybe you could point out some problems with doing it this way, but I'm at
the point now where I have to learn how to handle signals and slots. I'm
setting up an input dialog with several options, such as download a URL,
choose an existing file.

Your information will come in handy.

Glen
>
>[quoted text muted]

OK. Ideally, your window will contain a button (or some other control)
that the user can click to execute the functions.
>[quoted text muted]

If, for example, you included a push button (QPushButton) in the form
you created with Qt Designer, and called it executeButton, you could
connect its clicked() signal to a function in cnt by including the
following line after setting up the user interface:

window.connect(ui.executeButton, SIGNAL("clicked()"), cnt.myFunction)

This assumes that your function is called myFunction(), of course.
However, you wouldn't be able to get the output from this function back
to the dialog just by using a signal-slot connection like this.

One way to solve this would be to wrap the function using another
function or instance that is able to modify the contents of the dialog.
Another cleaner approach would be to subclass the user interface class
(Ui_Dialog) and implement a custom slot that can both call the function
and modify the dialog.

For example:

class Dialog(QDialog, Ui_Dialog)

def __init__(self, parent = None):

QDialog.__init__(self, parent)
self.setupUi(self)

self.connect(self.executeButton, SIGNAL("clicked()"),
self.callFunction)

def callFunction(self):

data = cnt.myFunction()
# Do something with the data.

Hope this gets you started,

David
Apr 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Art | last post by:
NEWBIE ALERT! Esteemed List Participants and Lurkers: (System: P-II 350, 192 meg, Win98 SE, Python 2.2.3, wxPythonWIN32-2.4.1.2-Py22.exe) I'm having a lot of fun getting started with Python...
12
by: Blaze | last post by:
I am doing the first walk through on the Visual Studio .Net walkthrough book to learn a little about programming. I am having issues with the first tutorial not running correctly. It seems that...
3
by: Tina I | last post by:
I'm trying to 'convert' my self from Qt3 to Qt4 (it rocks!) and one thing seem strange: With Qt3 I usually did "from qt import *", but this does not seem to work with Qt4. I have to use "from...
25
by: Daniel Jonsson | last post by:
So, I've reached the point where my building pipeline tools actually needs to be used by other people in my company. By this reason I actually need to think about the usability, and I've come to...
5
by: Mel | last post by:
I am currently porting an SQL centered Visual Basic application to run on Linux, Python, and Qt4. Currently I am stumped on changing row colors in the QTableView widget. My test code is based on...
2
by: Pradnyesh Sawant | last post by:
Hello, I have a newly installed ubuntu 6.06 system. I am trying to install pyqt4 on it, but without success. The contents of the /etc/apt/sources.list file are:...
3
by: Marcpp | last post by:
I call a dialog from a principal program but cannot return the value of the variables (text box's). Here is a example... from ui import Agenda from dialog1 import dialogo1 from PyQt4...
6
by: Glen | last post by:
Hello again, I don't blame anyone for not answering my last post, since I obviously hadn't spent much time researching, but I've come a little ways and have another question. How can I better...
0
by: Moezzie | last post by:
So ive got a bit of a problem here. Ive been searching the net about this for quite some time now but i just cant seem to figure out how to open a dialog that ive made in QtDesigner. Of corse i...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.