summaryrefslogtreecommitdiffstats
path: root/examples/richtext.py
blob: 2e6abac02cbe25d6ff28f02a9229db88e9a7e7ef (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python

"""**************************************************************************
** $Id: richtext.py,v 1.1 2003/07/01 14:18:37 phil Exp $
**
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
***************************************************************************"""

import sys
from python_tqt.qt import *

sayings = [
    "<b>Saying 1:</b><br>"
    "<hr><br><br>"
    "<big>Evil is that which one believes of others.  It is a sin to believe evil "
    "of others, but it is seldom a mistake.</big><br><br>"
    "<center><i>-- H.L. Mencken</i></center>",

    "<b>Saying 2:</b><br>"
    "<hr><br><br>"
    "<big>A well-used door needs no oil on its hinges.<br>"
    "A swift-flowing steam does not grow stagnant.<br>"
    "Neither sound nor thoughts can travel through a vacuum.<br>"
    "Software rots if not used.<br><br>"
    "These are great mysteries.</big><br><br>"
    "<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>",

    "<b>Saying 3:</b><br>"
    "<hr><br><br>"
    "<big>Show business is just like high school, except you get paid.</big><br><br>"
    "<center><i>-- Martin Mull</i></center>",

    "<b>Saying 4:</b><br>"
    "<hr><br><br>"
    "<big><b>The Least Successful Executions</b><br>"
    "<twocolumn><p>      History has furnished us with two executioners worthy of attention. "
    "The first performed in Sydney in Australia.  In 1803 three attempts were "
    "made to hang a Mr. Joseph Samuels.  On the first two of these the rope "
    "snapped, while on the third Mr. Samuels just hung there peacefully until he "
    "and everyone else got bored.  Since he had proved unsusceptible to capital "
    "punishment, he was reprieved.</p>"
    "<p>        The most important British executioner was Mr. James Berry who "
    "tried three times in 1885 to hang Mr. John Lee at Exeter Jail, but on each "
    "occasion failed to get the trap door open.<!p>"
    "<p>        In recognition of this achievement, the Home Secretary commuted "
    "Lee's sentence to \"life\" imprisonment.  He was released in 1917, emigrated "
    "to America and lived until 1933.</p></twocolumn></big><br><br>"
    "<center><i>-- Stephen Pile, \"The Book of Heroic Failures\"</i></center>",

    "<b>Saying 5:</b><br>"
    "<hr><br><br>"
    "<big>If you can, help others.  If you can't, at least don't hurt others.</big><br><br>"
    "<center><i>-- the Dalai Lama</i></center>",

    "<b>Saying 6:</b><br>"
    "<hr><br><br>"
    "<big>Television has brought back murder into the home -- where it belongs.</big><br><br>"
    "<center><i>-- Alfred Hitchcock</i></center>",

    "<b>Saying 7:</b><br>"
    "<hr><br><br>"
    "<big>I don't know who my grandfather was; I am much more concerned to know "
    "what his grandson will be.</big><br><br>"
    "<center><i>-- Abraham Lincoln</i></center>",

    0
]

class MyRichText( TQVBox ):
    def __init__( self, parent = None, name = None ):
        TQVBox.__init__( self, parent, name )
    
        self.setMargin( 5 )

        self.view = TQTextView( self )
        #self.view.setText( "This is a <b>Test</b> with <i>italic</i> <u>stuff</u>" )
        paper = TQBrush()
        paper.setPixmap( TQPixmap( "marble.png" ) )
        if paper.pixmap() != 0 :
            self.view.setPaper( paper )
        else :
            self.view.setPaper( white )

        self.view.setText( sayings[0] )
        self.view.setMinimumSize( 450, 250 )

        buttons = TQHBox( self )
        buttons.setMargin( 5 )

        self.bClose = TQPushButton( "&Close",   buttons )
        self.bPrev  = TQPushButton( "<< &Prev", buttons )
        self.bNext  = TQPushButton( "&Next >>", buttons )

        self.bPrev.setEnabled( False )

        self.connect( self.bClose, SIGNAL("clicked()"), tqApp, SLOT("quit()") )
        self.connect( self.bPrev,  SIGNAL("clicked()"), self.prev )
        self.connect( self.bNext,  SIGNAL("clicked()"), self.__next__ )

        self.num = 0
    
    def prev( self ):
        if self.num <= 0 :
            return
        self.num -= 1
        self.view.setText( sayings[self.num] )
        if self.num == 0 :
            self.bPrev.setEnabled( False )
        self.bNext.setEnabled( True )

    def __next__( self ):
        self.num += 1
        if not sayings[self.num]:
            return
        self.view.setText( sayings[self.num] )
        if not sayings[self.num + 1]:
            self.bNext.setEnabled( False )
        self.bPrev.setEnabled( True )

def main( args ):
    a = TQApplication(sys.argv)          # application object
    
    richtext = MyRichText()
    richtext.resize( 450, 350 );
    richtext.setCaption( "TQt Example - Richtext" )
    a.setMainWidget( richtext )
    richtext.show()
    
    a.exec_loop()
    
if __name__=="__main__":
    main(sys.argv)