473,657 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(wind ow)
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 4040
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 misunderstandin g: 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(wind ow)
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.executeButto n, 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(se lf)

self.connect(se lf.executeButto n, SIGNAL("clicked ()"),
self.callFuncti on)

def callFunction(se lf):

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 misunderstandin g: 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.insertP lainText(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.executeButto n, 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(se lf)

self.connect(se lf.executeButto n, SIGNAL("clicked ()"),
self.callFuncti on)

def callFunction(se lf):

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
2868
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 ... it is the most elegant and graceful language I have ever used (Fortran, Cobol, Basic, many assemblers, Forth, C, VB, etc.). I don't have the resources or the
12
1882
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 the build fails with what the book tells me to do. Specifically, I am doing this: public authors1 GetAuthors() { authors1 authors = new Authors1();
3
2083
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 PyQt4 import QtGui , QtCore" and also have to use "QtCore.something". Like when connecting a button: self.connect(self.ui.testButton, QtCore.SIGNAL("clicked()"), self.doSomething)
25
2676
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 the conclusion that I need a GUI. So, which of the two packages should I learn, and which one is easier to pick up? Thanks in advance! Daniel
5
11684
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 code from the PyQt4 examples and looks like this: *** Start Code *** import sys from PyQt4 import QtCore, QtGui, QtSql
2
2948
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: ******************************************************************************** deb http://in.archive.ubuntu.com/ubuntu/ dapper main restricted universe deb http://in.archive.ubuntu.com/ubuntu/ dapper-backports main restricted universe multiverse deb...
3
6151
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 import * import dbm
6
3834
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 format text output to a QTextEdit object? I'm inserting 5 columns into each row. When I write the info to a file, it looks like the following: 42: 115 26: 114 35: 112 19: 108 16: 107 45: 107 40: 106 5: 105 41: 104 ...
0
1831
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 used pyuic4 to make it into python code. This is the code for my dialog window(it contains just a TextEdit and a LineEdit): from PyQt4 import QtCore, QtGui class Ui_Dialog(object): def setupUi(self, Dialog): ...
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8312
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.