summaryrefslogtreecommitdiff
path: root/examples/python/simple.py
blob: 44fcae7a23ab4bacedd1036cc3c923b65ac9b35e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env pyquicklauncher
# -*- coding: iso8859-15 -*-
#--------------------------------------------------------------------------------------------------#
"""           =.             This file is part of the PyQt examples collection
            .=l.             Copyright (C) 2004 Michael Lauer <mickey@Vanille.de>
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the
  -_. . .   )=.  =           GNU General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.
"""
#--------------------------------------------------------------------------------------------------#

#--------------------------------------------------------------------------------------------------#
__version__ = "1.0.0"
__author__ = "Michael 'Mickey' Lauer <mickey@Vanille.de>"
__license__ = "GPL"
#--------------------------------------------------------------------------------------------------#

import sys
from qt import *
from qtpe import *

#--------------------------------------------------------------------------------------------------#
class SimpleWidget( QWidget ):
    """A simple main widget with a label and a push button."""

    def __init__( self, parent, name = "SimpleWidget" ):
        """Construct me."""
        QWidget.__init__( self, parent, name )

        #
        # Set the caption of this toplevel widget.
        # Encapsulate all user visible strings into self.tr to prepare for localization
        #
        self.setCaption( self.tr( "Simple Example Application" ) )

        #
        # A simple vertical layout.
        # Either call layout.setAutoAdd( True ) or use layout.addWidget( wid ) to manually add widgets
        #
        layout = QVBoxLayout( self )
        layout.setSpacing( 8 )
        layout.setMargin( 11 )

        #
        # Create a label as child of this widget (self) and add it to the layout.
        # A Qt object will be deleted when its parent is being deleted, hence it is not
        # necessary to keep the reference for this widget except you want to change some
        # of its attributes later, i.e. set a different text later on
        # via label.setText( self.tr( "newText" ) )
        #
        label = QLabel( self.tr( "Click on the Button and watch what happens!" ), self )
        layout.addWidget( label )

        #
        # Add a push button as child of this widget and add it to the layout.
        #
        button = QPushButton( self.tr( "Quit!" ), self )
        layout.addWidget( button )

        #
        # Define what happens, when the user clicks on the button.
        # This is being done by a signal-slot connection using QObject.connect.
        # We could also have connected a SIGNAL to a SIGNAL or directly to the
        # the application object slot quit().
        #
        QObject.connect( button, SIGNAL( "clicked()" ), self.slotQuitAppRequested )

    def slotQuitAppRequested( self ):
        """Leave the application when a user clicks on the button."""
        #
        # Leave the main loop by calling the quit() method of the application object
        #
        qApp.quit()

#--------------------------------------------------------------------------------------------------#

#
# Create the one and only application object.
# For plain Qt applications, use QApplication, for Qtopia/Opie applications, use QPEApplication
#
app = QPEApplication( sys.argv[1:] )
#
# Construct an instance of our main widget. Since it is the top level widget, is has no parent (None).
#
mw = SimpleWidget( None )
#
# Show the main widget. For plain Qt applications you should use app.setMainWidget( mw ) and mw.show()
#
app.showMainWidget( mw )
#
# Enter the event processing by calling the event loop which is implemented in the application object.
#
app.exec_loop()