Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25175 > unrolled thread
| Started by | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| First post | 2012-07-11 08:37 -0700 |
| Last post | 2012-07-13 14:12 -0700 |
| Articles | 13 — 5 participants |
Back to article view | Back to comp.lang.python
[newbie] Python and Qt4 Designer Jean Dubois <jeandubois314@gmail.com> - 2012-07-11 08:37 -0700
Re: [newbie] Python and Qt4 Designer Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2012-07-12 02:59 +0200
Re: Python and Qt4 Designer Jean Dubois <jeandubois314@gmail.com> - 2012-07-11 23:42 -0700
Re: Python and Qt4 Designer Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2012-07-13 03:52 +0200
Re: Python and Qt4 Designer Jean Dubois <jeandubois314@gmail.com> - 2012-07-13 14:12 -0700
Re: Python and Qt4 Designer Michael Torrie <torriem@gmail.com> - 2012-07-14 08:45 -0600
Re: Python and Qt4 Designer rusi <rustompmody@gmail.com> - 2012-07-14 10:13 -0700
Re: Python and Qt4 Designer Michael Torrie <torriem@gmail.com> - 2012-07-14 23:31 -0600
Re: Python and Qt4 Designer Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2012-07-15 09:58 +0200
Re: Python and Qt4 Designer Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-15 08:42 -0400
Re: Python and Qt4 Designer Michael Torrie <torriem@gmail.com> - 2012-07-16 07:56 -0600
Re: Python and Qt4 Designer Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-16 13:07 -0400
Re: Python and Qt4 Designer Jean Dubois <jeandubois314@gmail.com> - 2012-07-13 14:12 -0700
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2012-07-11 08:37 -0700 |
| Subject | [newbie] Python and Qt4 Designer |
| Message-ID | <63ac761b-a0a2-4d77-a3ca-f93069fab82a@s1g2000vbj.googlegroups.com> |
I'm trying to combine python-code made with QT4 designer with plain
python statements like
file = open("test","w")
Can anyone tell me what I have to add to the following code just to
open a file when clicking on the load-button and closing it by
clicking on the save button.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created: Wed Jul 11 17:21:35 2012
# by: PyQt4 UI code generator 4.8.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.widget = QtGui.QWidget(Form)
self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
self.widget.setObjectName(_fromUtf8("widget"))
self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.pushButton_2 = QtGui.QPushButton(self.widget)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.horizontalLayout.addWidget(self.pushButton_2)
self.pushButton = QtGui.QPushButton(self.widget)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.horizontalLayout.addWidget(self.pushButton)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form",
"Form", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.translate("Form",
"Save file", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Form",
"Load file", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
thanks in advance
jean
[toc] | [next] | [standalone]
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
|---|---|
| Date | 2012-07-12 02:59 +0200 |
| Message-ID | <mailman.2020.1342055147.4697.python-list@python.org> |
| In reply to | #25175 |
On 11/07/12 17:37, Jean Dubois wrote:
> I'm trying to combine python-code made with QT4 designer with plain
> python statements like
> file = open("test","w")
> Can anyone tell me what I have to add to the following code just to
> open a file when clicking on the load-button and closing it by
> clicking on the save button.
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> # Form implementation generated from reading ui file 'test.ui'
> #
> # Created: Wed Jul 11 17:21:35 2012
> # by: PyQt4 UI code generator 4.8.3
> #
> # WARNING! All changes made in this file will be lost!
>
> from PyQt4 import QtCore, QtGui
>
> try:
> _fromUtf8 = QtCore.QString.fromUtf8
> except AttributeError:
> _fromUtf8 = lambda s: s
>
> class Ui_Form(object):
> def setupUi(self, Form):
> Form.setObjectName(_fromUtf8("Form"))
> Form.resize(400, 300)
> self.widget = QtGui.QWidget(Form)
> self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
> self.widget.setObjectName(_fromUtf8("widget"))
> self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
> self.horizontalLayout.setMargin(0)
>
> self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
> self.pushButton_2 = QtGui.QPushButton(self.widget)
> self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
> self.horizontalLayout.addWidget(self.pushButton_2)
> self.pushButton = QtGui.QPushButton(self.widget)
> self.pushButton.setObjectName(_fromUtf8("pushButton"))
> self.horizontalLayout.addWidget(self.pushButton)
>
> self.retranslateUi(Form)
> QtCore.QMetaObject.connectSlotsByName(Form)
>
> def retranslateUi(self, Form):
> Form.setWindowTitle(QtGui.QApplication.translate("Form",
> "Form", None, QtGui.QApplication.UnicodeUTF8))
> self.pushButton_2.setText(QtGui.QApplication.translate("Form",
> "Save file", None, QtGui.QApplication.UnicodeUTF8))
> self.pushButton.setText(QtGui.QApplication.translate("Form",
> "Load file", None, QtGui.QApplication.UnicodeUTF8))
>
>
> if __name__ == "__main__":
> import sys
> app = QtGui.QApplication(sys.argv)
> Form = QtGui.QWidget()
> ui = Ui_Form()
> ui.setupUi(Form)
> Form.show()
> sys.exit(app.exec_())
>
>
> thanks in advance
> jean
Connect the signal clicked of your's buttons to your's functions.
self.pushButton.clicked.connect(self.my_func)
Here's all the truth:
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte+7
<https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2012-07-11 23:42 -0700 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <b6a17f2f-1653-4c4e-a50e-af13c1eabcd7@n16g2000vbn.googlegroups.com> |
| In reply to | #25187 |
On 12 jul, 02:59, Vincent Vande Vyvre <vincent.vandevy...@swing.be>
wrote:
> On 11/07/12 17:37, Jean Dubois wrote:
>
>
>
>
>
>
>
> > I'm trying to combine python-code made with QT4 designer with plain
> > python statements like
> > file = open("test","w")
> > Can anyone tell me what I have to add to the following code just to
> > open a file when clicking on the load-button and closing it by
> > clicking on the save button.
>
> > #!/usr/bin/env python
> > # -*- coding: utf-8 -*-
>
> > # Form implementation generated from reading ui file 'test.ui'
> > #
> > # Created: Wed Jul 11 17:21:35 2012
> > # by: PyQt4 UI code generator 4.8.3
> > #
> > # WARNING! All changes made in this file will be lost!
>
> > from PyQt4 import QtCore, QtGui
>
> > try:
> > _fromUtf8 = QtCore.QString.fromUtf8
> > except AttributeError:
> > _fromUtf8 = lambda s: s
>
> > class Ui_Form(object):
> > def setupUi(self, Form):
> > Form.setObjectName(_fromUtf8("Form"))
> > Form.resize(400, 300)
> > self.widget = QtGui.QWidget(Form)
> > self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
> > self.widget.setObjectName(_fromUtf8("widget"))
> > self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
> > self.horizontalLayout.setMargin(0)
>
> > self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
> > self.pushButton_2 = QtGui.QPushButton(self.widget)
> > self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
> > self.horizontalLayout.addWidget(self.pushButton_2)
> > self.pushButton = QtGui.QPushButton(self.widget)
> > self.pushButton.setObjectName(_fromUtf8("pushButton"))
> > self.horizontalLayout.addWidget(self.pushButton)
>
> > self.retranslateUi(Form)
> > QtCore.QMetaObject.connectSlotsByName(Form)
>
> > def retranslateUi(self, Form):
> > Form.setWindowTitle(QtGui.QApplication.translate("Form",
> > "Form", None, QtGui.QApplication.UnicodeUTF8))
> > self.pushButton_2.setText(QtGui.QApplication.translate("Form",
> > "Save file", None, QtGui.QApplication.UnicodeUTF8))
> > self.pushButton.setText(QtGui.QApplication.translate("Form",
> > "Load file", None, QtGui.QApplication.UnicodeUTF8))
>
> > if __name__ == "__main__":
> > import sys
> > app = QtGui.QApplication(sys.argv)
> > Form = QtGui.QWidget()
> > ui = Ui_Form()
> > ui.setupUi(Form)
> > Form.show()
> > sys.exit(app.exec_())
>
> > thanks in advance
> > jean
>
> Connect the signal clicked of your's buttons to your's functions.
>
> self.pushButton.clicked.connect(self.my_func)
>
> Here's all the truth:
>
> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_...
>
> --
> Vincent V.V.
> Oqapy <https://launchpad.net/oqapy> . Qarte+7
> <https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>
thanks for the reference, could you just supply a small example for
the code above to get me started?
thanks in advance
jean
[toc] | [prev] | [next] | [standalone]
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
|---|---|
| Date | 2012-07-13 03:52 +0200 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2060.1342144373.4697.python-list@python.org> |
| In reply to | #25202 |
On 12/07/12 08:42, Jean Dubois wrote:
> On 12 jul, 02:59, Vincent Vande Vyvre <vincent.vandevy...@swing.be>
> wrote:
>> On 11/07/12 17:37, Jean Dubois wrote:
>>
>>
>>
>>
>>
>>
>>
>>> I'm trying to combine python-code made with QT4 designer with plain
>>> python statements like
>>> file = open("test","w")
>>> Can anyone tell me what I have to add to the following code just to
>>> open a file when clicking on the load-button and closing it by
>>> clicking on the save button.
>>> #!/usr/bin/env python
>>> # -*- coding: utf-8 -*-
>>> # Form implementation generated from reading ui file 'test.ui'
>>> #
>>> # Created: Wed Jul 11 17:21:35 2012
>>> # by: PyQt4 UI code generator 4.8.3
>>> #
>>> # WARNING! All changes made in this file will be lost!
>>> from PyQt4 import QtCore, QtGui
>>> try:
>>> _fromUtf8 = QtCore.QString.fromUtf8
>>> except AttributeError:
>>> _fromUtf8 = lambda s: s
>>> class Ui_Form(object):
>>> def setupUi(self, Form):
>>> Form.setObjectName(_fromUtf8("Form"))
>>> Form.resize(400, 300)
>>> self.widget = QtGui.QWidget(Form)
>>> self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25))
>>> self.widget.setObjectName(_fromUtf8("widget"))
>>> self.horizontalLayout = QtGui.QHBoxLayout(self.widget)
>>> self.horizontalLayout.setMargin(0)
>>> self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
>>> self.pushButton_2 = QtGui.QPushButton(self.widget)
>>> self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
>>> self.horizontalLayout.addWidget(self.pushButton_2)
>>> self.pushButton = QtGui.QPushButton(self.widget)
>>> self.pushButton.setObjectName(_fromUtf8("pushButton"))
>>> self.horizontalLayout.addWidget(self.pushButton)
>>> self.retranslateUi(Form)
>>> QtCore.QMetaObject.connectSlotsByName(Form)
>>> def retranslateUi(self, Form):
>>> Form.setWindowTitle(QtGui.QApplication.translate("Form",
>>> "Form", None, QtGui.QApplication.UnicodeUTF8))
>>> self.pushButton_2.setText(QtGui.QApplication.translate("Form",
>>> "Save file", None, QtGui.QApplication.UnicodeUTF8))
>>> self.pushButton.setText(QtGui.QApplication.translate("Form",
>>> "Load file", None, QtGui.QApplication.UnicodeUTF8))
>>> if __name__ == "__main__":
>>> import sys
>>> app = QtGui.QApplication(sys.argv)
>>> Form = QtGui.QWidget()
>>> ui = Ui_Form()
>>> ui.setupUi(Form)
>>> Form.show()
>>> sys.exit(app.exec_())
>>> thanks in advance
>>> jean
>> Connect the signal clicked of your's buttons to your's functions.
>>
>> self.pushButton.clicked.connect(self.my_func)
>>
>> Here's all the truth:
>>
>> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_...
>>
>> --
>> Vincent V.V.
>> Oqapy <https://launchpad.net/oqapy> . Qarte+7
>> <https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>
> thanks for the reference, could you just supply a small example for
> the code above to get me started?
>
> thanks in advance
> jean
Just add the connection at the end of the Ui_Form class and, of course,
your function.
You can find numbers of examples in your PyQt4 install folder.
On my machine is located at /usr/share/doc/python-qt4-doc/examples
And, for more inspiration, have a look at this site:
http://diotavelli.net/PyQtWiki/
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2012-07-13 14:12 -0700 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <d3ed2da1-d1c5-4d1f-bd66-cceb9248bfce@googlegroups.com> |
| In reply to | #25235 |
Op vrijdag 13 juli 2012 03:52:51 UTC+2 schreef Vincent Vande Vyvre het volgende: > On 12/07/12 08:42, Jean Dubois wrote: > > On 12 jul, 02:59, Vincent Vande Vyvre <vincent.vandevy...@swing.be> > > wrote: > >> On 11/07/12 17:37, Jean Dubois wrote: > >> > >> > >> > >> > >> > >> > >> > >>> I'm trying to combine python-code made with QT4 designer with plain > >>> python statements like > >>> file = open("test","w") > >>> Can anyone tell me what I have to add to the following code just to > >>> open a file when clicking on the load-button and closing it by > >>> clicking on the save button. > >>> #!/usr/bin/env python > >>> # -*- coding: utf-8 -*- > >>> # Form implementation generated from reading ui file 'test.ui' > >>> # > >>> # Created: Wed Jul 11 17:21:35 2012 > >>> # by: PyQt4 UI code generator 4.8.3 > >>> # > >>> # WARNING! All changes made in this file will be lost! > >>> from PyQt4 import QtCore, QtGui > >>> try: > >>> _fromUtf8 = QtCore.QString.fromUtf8 > >>> except AttributeError: > >>> _fromUtf8 = lambda s: s > >>> class Ui_Form(object): > >>> def setupUi(self, Form): > >>> Form.setObjectName(_fromUtf8("Form")) > >>> Form.resize(400, 300) > >>> self.widget = QtGui.QWidget(Form) > >>> self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25)) > >>> self.widget.setObjectName(_fromUtf8("widget")) > >>> self.horizontalLayout = QtGui.QHBoxLayout(self.widget) > >>> self.horizontalLayout.setMargin(0) > >>> self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) > >>> self.pushButton_2 = QtGui.QPushButton(self.widget) > >>> self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) > >>> self.horizontalLayout.addWidget(self.pushButton_2) > >>> self.pushButton = QtGui.QPushButton(self.widget) > >>> self.pushButton.setObjectName(_fromUtf8("pushButton")) > >>> self.horizontalLayout.addWidget(self.pushButton) > >>> self.retranslateUi(Form) > >>> QtCore.QMetaObject.connectSlotsByName(Form) > >>> def retranslateUi(self, Form): > >>> Form.setWindowTitle(QtGui.QApplication.translate("Form", > >>> "Form", None, QtGui.QApplication.UnicodeUTF8)) > >>> self.pushButton_2.setText(QtGui.QApplication.translate("Form", > >>> "Save file", None, QtGui.QApplication.UnicodeUTF8)) > >>> self.pushButton.setText(QtGui.QApplication.translate("Form", > >>> "Load file", None, QtGui.QApplication.UnicodeUTF8)) > >>> if __name__ == "__main__": > >>> import sys > >>> app = QtGui.QApplication(sys.argv) > >>> Form = QtGui.QWidget() > >>> ui = Ui_Form() > >>> ui.setupUi(Form) > >>> Form.show() > >>> sys.exit(app.exec_()) > >>> thanks in advance > >>> jean > >> Connect the signal clicked of your's buttons to your's functions. > >> > >> self.pushButton.clicked.connect(self.my_func) > >> > >> Here's all the truth: > >> > >> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_... > >> > >> -- > >> Vincent V.V. > >> Oqapy <https://launchpad.net/oqapy> . Qarte+7 > >> <https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager> > > thanks for the reference, could you just supply a small example for > > the code above to get me started? > > > > thanks in advance > > jean > Just add the connection at the end of the Ui_Form class and, of course, > your function. > > You can find numbers of examples in your PyQt4 install folder. > On my machine is located at /usr/share/doc/python-qt4-doc/examples > > And, for more inspiration, have a look at this site: > http://diotavelli.net/PyQtWiki/ > > -- > Vincent V.V. > Oqapy <https://launchpad.net/oqapy> . Qarte > <https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager> Thanks for the extra docu references regards, jean
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2012-07-14 08:45 -0600 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2114.1342278483.4697.python-list@python.org> |
| In reply to | #25292 |
On 07/13/2012 03:12 PM, Jean Dubois wrote: > Thanks for the extra docu references In this day and age, I think compiling ui files to code is probably on the way out. Instead you should consider using the ui files directly in your code. This has the advantage of letting you change the gui somewhat without having to recompile all the time. Here is are some links that gives one way of loading and parsing the ui file directly: http://www.riverbankcomputing.com/pipermail/pyqt/2007-April/015902.html http://bitesofcode.blogspot.ca/2011/10/comparison-of-loading-techniques.html
[toc] | [prev] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2012-07-14 10:13 -0700 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <1bb0d4df-3937-4d5f-aedb-734e0c54eb85@f9g2000pbd.googlegroups.com> |
| In reply to | #25313 |
On Jul 14, 7:45 pm, Michael Torrie <torr...@gmail.com> wrote:
> On 07/13/2012 03:12 PM, Jean Dubois wrote:
>
> > Thanks for the extra docu references
>
> In this day and age, I think compiling ui files to code is probably on
> the way out. Instead you should consider using the ui files directly in
> your code. This has the advantage of letting you change the gui
> somewhat without having to recompile all the time.
>
> Here is are some links that gives one way of loading and parsing the ui
> file directly:
>
> http://www.riverbankcomputing.com/pipermail/pyqt/2007-April/015902.htmlhttp://bitesofcode.blogspot.ca/2011/10/comparison-of-loading-techniqu...
I looked at the second link and find code like this:
app = None
if ( not app ):
app = QtGui.QApplication([])
Maybe I'm dense but whats that if doing there?
Frankly I seem to be a bit jinxed with gui stuff. A few days ago
someone was singing the praises of some new themed tk stuff. I could
not get the first two lines -- the imports -- to work and then gave up
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2012-07-14 23:31 -0600 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2129.1342330310.4697.python-list@python.org> |
| In reply to | #25314 |
On 07/14/2012 11:13 AM, rusi wrote: > I looked at the second link and find code like this: > > app = None if ( not app ): app = QtGui.QApplication([]) > > Maybe I'm dense but whats that if doing there? > > Frankly I seem to be a bit jinxed with gui stuff. A few days ago > someone was singing the praises of some new themed tk stuff. I could > not get the first two lines -- the imports -- to work and then gave > up Since you haven't had any experience with gui development then probably loading ui files isn't the right place to start. First principles (creating gui widgets from scratch) would be it. In any case, the line in question is quite simple. It creates a QApplication object, which is basically the engine that drives all Qt applications. Once you call .run() on it, it takes over and handles all the mouse events and such for you. In fact you do not have any control over the program's execution from this point on, other than to define event call-back methods or functions that are called by the widgets when things happen, like mouse clicks. All gui toolkits operate this way. You set up the widgets, then you run the main engine or main event loop and control never returns to your main program until something triggers the end (like closing a window or the quit menu item is pressed). Probably a complete working example is what you need to see, that is documented. I primarily work with Gtk, but I'll whip up a Qt one tomorrow if I can.
[toc] | [prev] | [next] | [standalone]
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
|---|---|
| Date | 2012-07-15 09:58 +0200 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2131.1342339126.4697.python-list@python.org> |
| In reply to | #25314 |
On 15/07/12 07:31, Michael Torrie wrote:
> On 07/14/2012 11:13 AM, rusi wrote:
>> I looked at the second link and find code like this:
>>
>> app = None if ( not app ): app = QtGui.QApplication([])
>>
>> Maybe I'm dense but whats that if doing there?
>>
>> Frankly I seem to be a bit jinxed with gui stuff. A few days ago
>> someone was singing the praises of some new themed tk stuff. I could
>> not get the first two lines -- the imports -- to work and then gave
>> up
> Since you haven't had any experience with gui development then probably
> loading ui files isn't the right place to start. First principles
> (creating gui widgets from scratch) would be it.
>
> In any case, the line in question is quite simple. It creates a
> QApplication object, which is basically the engine that drives all Qt
> applications. Once you call .run() on it, it takes over and handles all
> the mouse events and such for you. In fact you do not have any control
> over the program's execution from this point on, other than to define
> event call-back methods or functions that are called by the widgets when
> things happen, like mouse clicks.
>
> All gui toolkits operate this way. You set up the widgets, then you run
> the main engine or main event loop and control never returns to your
> main program until something triggers the end (like closing a window or
> the quit menu item is pressed).
>
> Probably a complete working example is what you need to see, that is
> documented. I primarily work with Gtk, but I'll whip up a Qt one
> tomorrow if I can.
Rusi is not the op, and his question is about these lines
app = None
if ( not app ):
not this one
app = QtGui.QApplication([])
which should be written like this
app = QtGui.QApplication(sys.argv)
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-07-15 08:42 -0400 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2138.1342356136.4697.python-list@python.org> |
| In reply to | #25314 |
On Sat, 14 Jul 2012 23:31:38 -0600, Michael Torrie <torriem@gmail.com>
declaimed the following in gmane.comp.python.general:
> the mouse events and such for you. In fact you do not have any control
> over the program's execution from this point on, other than to define
> event call-back methods or functions that are called by the widgets when
> things happen, like mouse clicks.
>
Technically, those event call-backs need to already have been
defined (or will be defined within an existing call-back). <G>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2012-07-16 07:56 -0600 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2174.1342446995.4697.python-list@python.org> |
| In reply to | #25314 |
On 07/15/2012 01:58 AM, Vincent Vande Vyvre wrote: > Rusi is not the op, and his question is about these lines > > app = None > if ( not app ): Yeah that's a no-op. The original author of that code is clearly confused there. > > not this one > > app = QtGui.QApplication([]) > > which should be written like this > > app = QtGui.QApplication(sys.argv) Yeah. The QApplication not only is the main engine, but it also parses the command-line for certain flags that influence Qt's behavior, similar to gtk's main function that also parses command-line flags (specific to gtk's operation).
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-07-16 13:07 -0400 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2181.1342458489.4697.python-list@python.org> |
| In reply to | #25314 |
On Mon, 16 Jul 2012 07:56:19 -0600, Michael Torrie <torriem@gmail.com>
declaimed the following in gmane.comp.python.general:
> On 07/15/2012 01:58 AM, Vincent Vande Vyvre wrote:
> > Rusi is not the op, and his question is about these lines
> >
> > app = None
> > if ( not app ):
>
> Yeah that's a no-op. The original author of that code is clearly
> confused there.
>
I've wondered if the original sample had been much larger at one
time, and embedded in some sort of "auto-restart" loop (say, for a kiosk
application). In that situation, one would perhaps want the "app = None"
somewhere near the start to "wipe out" the previous GUI, and the "if"
was as a guard to prevent a second start-up [if there were some other
loop also in the code].
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2012-07-13 14:12 -0700 |
| Subject | Re: Python and Qt4 Designer |
| Message-ID | <mailman.2104.1342213980.4697.python-list@python.org> |
| In reply to | #25235 |
Op vrijdag 13 juli 2012 03:52:51 UTC+2 schreef Vincent Vande Vyvre het volgende: > On 12/07/12 08:42, Jean Dubois wrote: > > On 12 jul, 02:59, Vincent Vande Vyvre <vincent.vandevy...@swing.be> > > wrote: > >> On 11/07/12 17:37, Jean Dubois wrote: > >> > >> > >> > >> > >> > >> > >> > >>> I'm trying to combine python-code made with QT4 designer with plain > >>> python statements like > >>> file = open("test","w") > >>> Can anyone tell me what I have to add to the following code just to > >>> open a file when clicking on the load-button and closing it by > >>> clicking on the save button. > >>> #!/usr/bin/env python > >>> # -*- coding: utf-8 -*- > >>> # Form implementation generated from reading ui file 'test.ui' > >>> # > >>> # Created: Wed Jul 11 17:21:35 2012 > >>> # by: PyQt4 UI code generator 4.8.3 > >>> # > >>> # WARNING! All changes made in this file will be lost! > >>> from PyQt4 import QtCore, QtGui > >>> try: > >>> _fromUtf8 = QtCore.QString.fromUtf8 > >>> except AttributeError: > >>> _fromUtf8 = lambda s: s > >>> class Ui_Form(object): > >>> def setupUi(self, Form): > >>> Form.setObjectName(_fromUtf8("Form")) > >>> Form.resize(400, 300) > >>> self.widget = QtGui.QWidget(Form) > >>> self.widget.setGeometry(QtCore.QRect(10, 20, 146, 25)) > >>> self.widget.setObjectName(_fromUtf8("widget")) > >>> self.horizontalLayout = QtGui.QHBoxLayout(self.widget) > >>> self.horizontalLayout.setMargin(0) > >>> self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) > >>> self.pushButton_2 = QtGui.QPushButton(self.widget) > >>> self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")) > >>> self.horizontalLayout.addWidget(self.pushButton_2) > >>> self.pushButton = QtGui.QPushButton(self.widget) > >>> self.pushButton.setObjectName(_fromUtf8("pushButton")) > >>> self.horizontalLayout.addWidget(self.pushButton) > >>> self.retranslateUi(Form) > >>> QtCore.QMetaObject.connectSlotsByName(Form) > >>> def retranslateUi(self, Form): > >>> Form.setWindowTitle(QtGui.QApplication.translate("Form", > >>> "Form", None, QtGui.QApplication.UnicodeUTF8)) > >>> self.pushButton_2.setText(QtGui.QApplication.translate("Form", > >>> "Save file", None, QtGui.QApplication.UnicodeUTF8)) > >>> self.pushButton.setText(QtGui.QApplication.translate("Form", > >>> "Load file", None, QtGui.QApplication.UnicodeUTF8)) > >>> if __name__ == "__main__": > >>> import sys > >>> app = QtGui.QApplication(sys.argv) > >>> Form = QtGui.QWidget() > >>> ui = Ui_Form() > >>> ui.setupUi(Form) > >>> Form.show() > >>> sys.exit(app.exec_()) > >>> thanks in advance > >>> jean > >> Connect the signal clicked of your's buttons to your's functions. > >> > >> self.pushButton.clicked.connect(self.my_func) > >> > >> Here's all the truth: > >> > >> http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_... > >> > >> -- > >> Vincent V.V. > >> Oqapy <https://launchpad.net/oqapy> . Qarte+7 > >> <https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager> > > thanks for the reference, could you just supply a small example for > > the code above to get me started? > > > > thanks in advance > > jean > Just add the connection at the end of the Ui_Form class and, of course, > your function. > > You can find numbers of examples in your PyQt4 install folder. > On my machine is located at /usr/share/doc/python-qt4-doc/examples > > And, for more inspiration, have a look at this site: > http://diotavelli.net/PyQtWiki/ > > -- > Vincent V.V. > Oqapy <https://launchpad.net/oqapy> . Qarte > <https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager> Thanks for the extra docu references regards, jean
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web