Build files for pyuic2 have been removed along with the examples for version 2 of Qt and the build/configure scripts have been amended accordingly. The "examples3" directory has been renamed to just "examples". Signed-off-by: aneejit1 <aneejit1@gmail.com>pull/10/head
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 355 B After Width: | Height: | Size: 355 B |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
@ -1,11 +0,0 @@
|
||||
To run these examples, make sure you have your PYTHONPATH environment variable
|
||||
set if needed and explicitly set the path to python at the top of each script
|
||||
if you don't have /usr/bin/env.
|
||||
|
||||
The examples are written for TQt v2.x.
|
||||
|
||||
A much better source of information about using PyTQt is Boudewijn Rempt's
|
||||
book at http://stage.linuxports.com/projects/pyqt/.
|
||||
|
||||
Phil Thompson
|
||||
phil@riverbankcomputing.co.uk
|
@ -1,277 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# A simple application.
|
||||
|
||||
|
||||
import sys, string
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
fileopen = [
|
||||
'16 13 5 1',
|
||||
'. c #040404',
|
||||
'# c #808304',
|
||||
'a c None',
|
||||
'b c #f3f704',
|
||||
'c c #f3f7f3',
|
||||
'aaaaaaaaa...aaaa',
|
||||
'aaaaaaaa.aaa.a.a',
|
||||
'aaaaaaaaaaaaa..a',
|
||||
'a...aaaaaaaa...a',
|
||||
'.bcb.......aaaaa',
|
||||
'.cbcbcbcbc.aaaaa',
|
||||
'.bcbcbcbcb.aaaaa',
|
||||
'.cbcb...........',
|
||||
'.bcb.#########.a',
|
||||
'.cb.#########.aa',
|
||||
'.b.#########.aaa',
|
||||
'..#########.aaaa',
|
||||
'...........aaaaa'
|
||||
]
|
||||
|
||||
filesave = [
|
||||
'14 14 4 1',
|
||||
'. c #040404',
|
||||
'# c #808304',
|
||||
'a c #bfc2bf',
|
||||
'b c None',
|
||||
'..............',
|
||||
'.#.aaaaaaaa.a.',
|
||||
'.#.aaaaaaaa...',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.##........##.',
|
||||
'.############.',
|
||||
'.##.........#.',
|
||||
'.##......aa.#.',
|
||||
'.##......aa.#.',
|
||||
'.##......aa.#.',
|
||||
'b.............'
|
||||
]
|
||||
|
||||
fileprint = [
|
||||
'16 14 6 1',
|
||||
'. c #000000',
|
||||
'# c #848284',
|
||||
'a c #c6c3c6',
|
||||
'b c #ffff00',
|
||||
'c c #ffffff',
|
||||
'd c None',
|
||||
'ddddd.........dd',
|
||||
'dddd.cccccccc.dd',
|
||||
'dddd.c.....c.ddd',
|
||||
'ddd.cccccccc.ddd',
|
||||
'ddd.c.....c....d',
|
||||
'dd.cccccccc.a.a.',
|
||||
'd..........a.a..',
|
||||
'.aaaaaaaaaa.a.a.',
|
||||
'.............aa.',
|
||||
'.aaaaaa###aa.a.d',
|
||||
'.aaaaaabbbaa...d',
|
||||
'.............a.d',
|
||||
'd.aaaaaaaaa.a.dd',
|
||||
'dd...........ddd'
|
||||
]
|
||||
|
||||
|
||||
fileOpenText = \
|
||||
'''<img source="fileopen">
|
||||
Click this button to open a <em>new file</em>.<br><br>
|
||||
You can also select the <b>Open</b> command from the <b>File</b> menu.'''
|
||||
|
||||
fileSaveText = \
|
||||
'''Click this button to save the file you are editing.<br><br>
|
||||
You will be prompted for a filename.<br><br>
|
||||
You can also select the <b>Save</b> command from the <b>File</b> menu.'''
|
||||
|
||||
filePrintText = \
|
||||
'''Click this button to print the file you are editing.<br><br>
|
||||
You can also select the <b>Print</b> command from the <b>File</b> menu.'''
|
||||
|
||||
|
||||
editorList = []
|
||||
|
||||
|
||||
class ApplicationWindow(TQMainWindow):
|
||||
def __init__(self):
|
||||
TQMainWindow.__init__(self,None,'example application main window',TQt.WDestructiveClose)
|
||||
|
||||
self.filename = TQString.null
|
||||
self.printer = TQPrinter()
|
||||
|
||||
self.fileTools = TQToolBar(self,'file operations')
|
||||
|
||||
openIcon = TQPixmap(fileopen)
|
||||
self.fileOpen = TQToolButton(TQIconSet(openIcon),'Open File',TQString.null,self.load,self.fileTools,'open file')
|
||||
|
||||
saveIcon = TQPixmap(filesave)
|
||||
self.fileSave = TQToolButton(TQIconSet(saveIcon),'Save File',TQString.null,self.save,self.fileTools,'save file')
|
||||
|
||||
printIcon = TQPixmap(fileprint)
|
||||
self.filePrint = TQToolButton(TQIconSet(printIcon),'Print File',TQString.null,self.printDoc,self.fileTools,'print file')
|
||||
|
||||
TQWhatsThis.whatsThisButton(self.fileTools)
|
||||
|
||||
TQWhatsThis.add(self.fileOpen,fileOpenText)
|
||||
TQMimeSourceFactory.defaultFactory().setPixmap('fileopen',openIcon)
|
||||
TQWhatsThis.add(self.fileSave,fileSaveText)
|
||||
TQWhatsThis.add(self.filePrint,filePrintText)
|
||||
|
||||
self.file = TQPopupMenu(self)
|
||||
self.menuBar().insertItem('&File',self.file)
|
||||
|
||||
self.file.insertItem('&New',self.newDoc,TQt.CTRL + TQt.Key_N)
|
||||
|
||||
id = self.file.insertItem(TQIconSet(openIcon),'&Open',self.load,TQt.CTRL + TQt.Key_O)
|
||||
self.file.setWhatsThis(id,fileOpenText)
|
||||
|
||||
id = self.file.insertItem(TQIconSet(saveIcon),'&Save',self.save,TQt.CTRL + TQt.Key_S)
|
||||
self.file.setWhatsThis(id,fileSaveText)
|
||||
|
||||
id = self.file.insertItem('Save &as',self.saveAs)
|
||||
self.file.setWhatsThis(id,fileSaveText)
|
||||
|
||||
self.file.insertSeparator()
|
||||
|
||||
id = self.file.insertItem(TQIconSet(printIcon),'&Print',self.printDoc,TQt.CTRL + TQt.Key_P)
|
||||
self.file.setWhatsThis(id,filePrintText)
|
||||
|
||||
self.file.insertSeparator()
|
||||
|
||||
self.file.insertItem('&Close',self,SLOT('close()'),TQt.CTRL + TQt.Key_W)
|
||||
self.file.insertItem('&Quit',tqApp,SLOT('closeAllWindows()'),TQt.CTRL + TQt.Key_Q)
|
||||
|
||||
self.help = TQPopupMenu(self)
|
||||
self.menuBar().insertSeparator()
|
||||
self.menuBar().insertItem('&Help',self.help)
|
||||
|
||||
self.help.insertItem('&About',self.about,TQt.Key_F1)
|
||||
self.help.insertItem('About &TQt',self.aboutTQt)
|
||||
|
||||
self.e = TQMultiLineEdit(self,'editor')
|
||||
self.e.setFocus()
|
||||
self.setCentralWidget(self.e)
|
||||
|
||||
self.statusBar().message('Ready',2000)
|
||||
self.resize(450,600)
|
||||
|
||||
def newDoc(self):
|
||||
ed = ApplicationWindow()
|
||||
ed.show()
|
||||
editorList.append(ed)
|
||||
|
||||
def load(self):
|
||||
fn = TQFileDialog.getOpenFileName(TQString.null,TQString.null,self)
|
||||
if fn.isEmpty():
|
||||
self.statusBar().message('Loading aborted',2000)
|
||||
return
|
||||
|
||||
fileName = str(fn)
|
||||
|
||||
self.e.setAutoUpdate(0)
|
||||
self.e.clear()
|
||||
|
||||
try:
|
||||
f = open(fileName,'r')
|
||||
except:
|
||||
return
|
||||
|
||||
for l in f.readlines():
|
||||
self.e.append(l.rstrip())
|
||||
|
||||
f.close()
|
||||
|
||||
self.e.setAutoUpdate(1)
|
||||
self.e.repaint()
|
||||
self.e.setEdited(0)
|
||||
self.setCaption(fileName)
|
||||
self.statusBar().message('Loaded document %s' % (fileName),2000)
|
||||
|
||||
def save(self):
|
||||
if self.filename.isEmpty():
|
||||
self.saveAs()
|
||||
return
|
||||
|
||||
try:
|
||||
f = open(str(self.filename),'w+')
|
||||
except:
|
||||
self.statusBar().message('Could not write to %s' % (self.filename),2000)
|
||||
return
|
||||
|
||||
f.write(str(self.e.text()))
|
||||
f.close()
|
||||
|
||||
self.e.setEdited(0)
|
||||
self.setCaption(self.filename)
|
||||
self.statusBar().message('File %s saved' % (self.filename),2000)
|
||||
|
||||
def saveAs(self):
|
||||
fn = TQFileDialog.getSaveFileName(TQString.null,TQString.null,self)
|
||||
if not fn.isEmpty():
|
||||
self.filename = fn
|
||||
self.save()
|
||||
else:
|
||||
self.statusBar().message('Saving aborted',2000)
|
||||
|
||||
def printDoc(self):
|
||||
Margin = 10
|
||||
pageNo = 1
|
||||
|
||||
if self.printer.setup(self):
|
||||
self.statusBar().message('Printing...')
|
||||
|
||||
p = TQPainter()
|
||||
p.begin(self.printer)
|
||||
p.setFont(self.e.font())
|
||||
yPos = 0
|
||||
fm = p.fontMetrics()
|
||||
metrics = TQPaintDeviceMetrics(self.printer)
|
||||
|
||||
for i in range(self.e.numLines):
|
||||
if Margin + yPos > metrics.height() - Margin:
|
||||
pageNo = pageNo + 1
|
||||
self.statusBar().message('Printing (page %d)...' % (pageNo))
|
||||
self.printer.newPage()
|
||||
yPos = 0
|
||||
|
||||
p.drawText(Margin,Margin + yPos,metrics.width(),fm.lineSpacing(),TQt.ExpandTabs | TQt.DontClip,self.e.textLine(i))
|
||||
yPos = yPos + fm.lineSpacing()
|
||||
|
||||
p.end()
|
||||
self.statusBar().message('Printing completed',2000)
|
||||
else:
|
||||
self.statusBar().message('Printing aborted',2000)
|
||||
|
||||
def closeEvent(self,ce):
|
||||
if not self.e.edited():
|
||||
ce.accept()
|
||||
return
|
||||
|
||||
rc = TQMessageBox.information(self,'TQt Application Example',
|
||||
'The document has been changed since the last save.',
|
||||
'Save Now','Cancel','Leave Anyway',0,1)
|
||||
|
||||
if rc == 0:
|
||||
self.save()
|
||||
ce.accept()
|
||||
elif rc == 2:
|
||||
ce.accept()
|
||||
else:
|
||||
ce.ignore()
|
||||
|
||||
def about(self):
|
||||
TQMessageBox.about(self,'TQt Application Example',
|
||||
'This example demonstrates simple use of TQMainWindow,\nTQMenuBar and TQToolBar.')
|
||||
|
||||
def aboutTQt(self):
|
||||
TQMessageBox.aboutTQt(self,'TQt Application Example')
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
mw = ApplicationWindow()
|
||||
mw.setCaption('Document 1')
|
||||
mw.show()
|
||||
a.connect(a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()'))
|
||||
a.exec_loop()
|
@ -1,113 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#/****************************************************************************
|
||||
#** $Id: buttongroups.py,v 1.1.1.1 2002/06/04 23:04:42 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 *
|
||||
|
||||
TRUE = 1
|
||||
FALSE = 0
|
||||
|
||||
##
|
||||
# Creates all child widgets of the ButtonGroups window
|
||||
##
|
||||
|
||||
class ButtonsGroups( TQWidget ):
|
||||
def __init__( self, *args ):
|
||||
TQWidget.__init__(*(self,) + args)
|
||||
|
||||
# Create Widgets which allow easy layouting
|
||||
self.vbox = TQVBoxLayout( self )
|
||||
self.box1 = TQHBoxLayout( self.vbox )
|
||||
self.box2 = TQHBoxLayout( self.vbox )
|
||||
|
||||
# ------- first group
|
||||
|
||||
# Create an exclusive button group
|
||||
self.grp1 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Button Group 1 (exclusive)", self )
|
||||
self.box1.addWidget( self.grp1 )
|
||||
self.grp1.setExclusive( TRUE )
|
||||
|
||||
# insert 3 radiobuttons
|
||||
self.rb11 = TQRadioButton( "&Radiobutton 1", self.grp1 )
|
||||
self.rb11.setChecked( TRUE )
|
||||
TQRadioButton( "R&adiobutton 2", self.grp1 )
|
||||
TQRadioButton( "Ra&diobutton 3", self.grp1 )
|
||||
|
||||
# ------- second group
|
||||
|
||||
# Create a non-exclusive buttongroup
|
||||
self.grp2 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Button Group 2 (non-exclusive)", self )
|
||||
self.box1.addWidget( self.grp2 )
|
||||
self.grp2.setExclusive( FALSE )
|
||||
|
||||
# insert 3 checkboxes
|
||||
TQCheckBox( "&Checkbox 1", self.grp2 )
|
||||
self.cb12 = TQCheckBox( "C&heckbox 2", self.grp2 )
|
||||
self.cb12.setChecked( TRUE )
|
||||
self.cb13 = TQCheckBox( "Triple &State Button", self.grp2 )
|
||||
self.cb13.setTristate( TRUE )
|
||||
self.cb13.setChecked( TRUE )
|
||||
|
||||
# ------------ third group
|
||||
|
||||
# create a buttongroup which is exclusive for radiobuttons and non-exclusive for all other buttons
|
||||
self.grp3 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Button Group 3 (Radiobutton-exclusive)", self )
|
||||
self.box2.addWidget( self.grp3 )
|
||||
self.grp3.setRadioButtonExclusive( TRUE )
|
||||
|
||||
# insert three radiobuttons
|
||||
self.rb21 = TQRadioButton( "Rad&iobutton 1", self.grp3 )
|
||||
self.rb22 = TQRadioButton( "Radi&obutton 2", self.grp3 )
|
||||
self.rb23 = TQRadioButton( "Radio&button 3", self.grp3 )
|
||||
self.rb23.setChecked( TRUE )
|
||||
|
||||
# insert a checkbox...
|
||||
self.state = TQCheckBox( "E&nable Radiobuttons", self.grp3 )
|
||||
self.state.setChecked( TRUE )
|
||||
# ...and connect its SIGNAL clicked() with the SLOT slotChangeGrp3State()
|
||||
self.connect( self.state, SIGNAL( "clicked()" ), self.slotChangeGrp3State )
|
||||
|
||||
# ------------ fourth group
|
||||
|
||||
# create a groupbox which layouts its childs in a columns
|
||||
self.grp4 = TQButtonGroup( 1, TQGroupBox.Horizontal, "Groupbox with normal buttons", self )
|
||||
self.box2.addWidget( self.grp4 )
|
||||
|
||||
# insert two pushbuttons...
|
||||
TQPushButton( "&Push Button", self.grp4 )
|
||||
self.tb = TQPushButton( "&Toggle Button", self.grp4 )
|
||||
|
||||
# ... and make the second one a toggle button
|
||||
self.tb.setToggleButton( TRUE )
|
||||
self.tb.setOn( TRUE )
|
||||
|
||||
|
||||
#
|
||||
# SLOT slotChangeGrp3State()
|
||||
# enables/disables the radiobuttons of the third buttongroup
|
||||
#
|
||||
|
||||
def slotChangeGrp3State( self ):
|
||||
self.rb21.setEnabled( self.state.isChecked() )
|
||||
self.rb22.setEnabled( self.state.isChecked() )
|
||||
self.rb23.setEnabled( self.state.isChecked() )
|
||||
|
||||
|
||||
## main program
|
||||
a = TQApplication( sys.argv )
|
||||
|
||||
buttonsgroups = ButtonsGroups()
|
||||
buttonsgroups.resize( 500, 250 )
|
||||
buttonsgroups.setCaption( "Examples for Buttons and Groups" )
|
||||
a.setMainWidget( buttonsgroups )
|
||||
buttonsgroups.show()
|
||||
|
||||
a.exec_loop()
|
@ -1,219 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
seed = 0.353535353535
|
||||
KINDA_RAND_MAX = 32767
|
||||
|
||||
def kindaRand():
|
||||
global seed
|
||||
seed = seed * 147
|
||||
seed = seed - int(seed)
|
||||
return int(seed*(KINDA_RAND_MAX + 1))
|
||||
|
||||
velmax = 15
|
||||
velmin = 4
|
||||
|
||||
def velocity(i):
|
||||
if i == 1 or i == 2:
|
||||
i = (kindaRand()&0x7fff % velmax)/3 + velmin
|
||||
else:
|
||||
i = (kindaRand()&0x7fff % velmax) + velmin
|
||||
|
||||
maxpoints = 5
|
||||
maxcurves = 8
|
||||
|
||||
def poly():
|
||||
d = TQApplication.desktop()
|
||||
d.setPaletteBackgroundColor(white)
|
||||
xvel = [ 0 ] * 8
|
||||
yvel = [ 0 ] * 8
|
||||
head = 0
|
||||
tail = -maxcurves + 2
|
||||
a = TQPointArray() * maxcurves
|
||||
r = d.rect()
|
||||
for i in range(maxcurves):
|
||||
a[i].resize(maxpoints)
|
||||
p = a[0]
|
||||
for i in range(maxpoints):
|
||||
p.setPoint(i, (kindaRand()&0x7fff) % r.width(),
|
||||
(kindaRand()&0x7fff) % r.height() )
|
||||
xvel[i] = velocity(i)
|
||||
yvel[i] = velocity(i)
|
||||
|
||||
paint = TQPainter()
|
||||
paint.begin(d)
|
||||
|
||||
for ntimes in range(2000):
|
||||
paint.setBrush(TQColor(kindaRand()%360,180,255, TQColor.Hsv))
|
||||
paint.drawPolygon(a[head])
|
||||
tail = tail + 1
|
||||
if tail >= maxcurves:
|
||||
tail = 0
|
||||
minx = r.left()
|
||||
maxx = r.right()
|
||||
miny = r.top()
|
||||
maxy = r.bottom()
|
||||
p = a[head]
|
||||
head = head + 1
|
||||
if head >= maxcurves:
|
||||
head = 0
|
||||
for i in range(maxpoints):
|
||||
x, y = p.point(i)
|
||||
x = x + xvel[i]
|
||||
y = y + yvel[i]
|
||||
if x >= maxx:
|
||||
x = maxx - (x - maxx + 1)
|
||||
xvel[i] = -velocity(i)
|
||||
if x <= minx:
|
||||
x = minx + (minx - x + 1)
|
||||
xvel[i] = velocity(i)
|
||||
if y >= maxy:
|
||||
y = maxy - (y - maxy + 1)
|
||||
yvel[i] = -velocity(i)
|
||||
if y <= miny:
|
||||
y = miny + (miny - y + 1)
|
||||
yvel[i] = velocity(i)
|
||||
a[head].setPoint(i, x, y)
|
||||
paint.end()
|
||||
|
||||
def rotate():
|
||||
w = 64
|
||||
h = 64
|
||||
image = TQImage(w, h, 8, 128)
|
||||
for i in range(128):
|
||||
image.setColor(i, tqRgb(i,0,0))
|
||||
for y in range(h):
|
||||
for x in range(w):
|
||||
image.setPixel(x,y,(x+y)%128)
|
||||
|
||||
pm = TQPixmap()
|
||||
pm.convertFromImage(image)
|
||||
#pm.optimize(1)
|
||||
|
||||
d = TQApplication.desktop()
|
||||
|
||||
for i in range(0,361,2):
|
||||
m = TQWMatrix()
|
||||
m.rotate(i)
|
||||
rpm = pm.xForm(m)
|
||||
d.setPaletteBackgroundPixmap(rpm)
|
||||
d.update()
|
||||
|
||||
def generateStone(pm, c1, c2, c3):
|
||||
p = TQPainter()
|
||||
p1 = TQPen(c1, 0)
|
||||
p2 = TQPen(c2, 0)
|
||||
p3 = TQPen(c3, 0)
|
||||
|
||||
p.begin(pm)
|
||||
for i in range(pm.width()):
|
||||
for j in range(pm.height()):
|
||||
r = kindaRand()
|
||||
if r < KINDA_RAND_MAX / 3:
|
||||
p.setPen(p1)
|
||||
elif r < KINDA_RAND_MAX / 3 * 2:
|
||||
p.setPen(p2)
|
||||
else:
|
||||
p.setPen(p3)
|
||||
p.drawPoint(i, j)
|
||||
p.end()
|
||||
|
||||
def drawShadeText(p, x, y, text, topColor, bottomColor, sw=2):
|
||||
if not p.isActive():
|
||||
return
|
||||
|
||||
p.setPen(bottomColor)
|
||||
p.drawText(x+sw, y+sw, text)
|
||||
p.setPen(topColor)
|
||||
p.drawText(x, y, text)
|
||||
|
||||
class DesktopWidget(TQWidget):
|
||||
def __init__(self, s, parent=None, name=''):
|
||||
TQWidget.__init__(self, parent, name, WType_Desktop | WPaintDesktop)
|
||||
self.text = s
|
||||
self.pm = None
|
||||
|
||||
def paintEvent(self, pe):
|
||||
c1 = self.backgroundColor()
|
||||
c2 = c1.light(104)
|
||||
c3 = c1.dark(106)
|
||||
if not self.pm:
|
||||
self.pm = TQPixmap(64, 64)
|
||||
generateStone(self.pm, c1, c2, c3)
|
||||
self.setPaletteBackgroundPixmap(self.pm)
|
||||
self.update()
|
||||
br = self.fontMetrics().boundingRect(self.text)
|
||||
offscreen = TQPixmap(br.width(), br.height())
|
||||
x = self.width()/2 - br.width()/2
|
||||
y = self.height()/2 - br.height()/2
|
||||
offscreen.fill(self, x, y)
|
||||
p = TQPainter()
|
||||
p.begin(offscreen)
|
||||
drawShadeText(p, -br.x(), -br.y(), self.text, c2, c3, 3)
|
||||
p.end()
|
||||
bitBlt(self, x, y, offscreen)
|
||||
|
||||
def desktopWidget(s='Troll Tech'):
|
||||
t = DesktopWidget(s)
|
||||
t.update()
|
||||
tqApp.exec_loop()
|
||||
|
||||
def desktopText(s='Troll Tech'):
|
||||
border = 20
|
||||
|
||||
c1 = tqApp.palette().normal().background()
|
||||
c2 = c1.light(104)
|
||||
c3 = c1.dark(106)
|
||||
|
||||
pm = TQPixmap(10, 10)
|
||||
p = TQPainter()
|
||||
p.begin(pm)
|
||||
r = p.fontMetrics().boundingRect(s)
|
||||
p.end()
|
||||
|
||||
appWidth = tqApp.desktop().width()
|
||||
appHeight = tqApp.desktop().height()
|
||||
if r.width() > appWidth - border*2:
|
||||
r.setWidth(appWidth - border*2)
|
||||
if r.height() > appHeight - border*2:
|
||||
r.setHeight(appHeight - border*2)
|
||||
|
||||
pm.resize(r.size().width()+border*2,r.size().height()+border*2)
|
||||
generateStone(pm, c1, c2, c3)
|
||||
p.begin(pm)
|
||||
drawShadeText(p, -r.x()+border, -r.y()+border, s, c2, c3)
|
||||
p.end()
|
||||
|
||||
tqApp.desktop().setPaletteBackgroundPixmap(pm)
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
if len(sys.argv) > 1:
|
||||
f = TQFont('charter', 96, TQFont.Weight.Black)
|
||||
f.setStyleHint(TQFont.StyleHint.Times)
|
||||
a.setFont(f)
|
||||
validOptions = 0
|
||||
if len(sys.argv) == 2:
|
||||
validOptions = 1
|
||||
if sys.argv[1] == '-poly':
|
||||
poly()
|
||||
elif sys.argv[1] == '-rotate':
|
||||
rotate()
|
||||
elif sys.argv[1] == '-troll':
|
||||
desktopText()
|
||||
elif sys.argv[1] == '-trollwidget':
|
||||
desktopWidget()
|
||||
else:
|
||||
validOptions = 0
|
||||
if len(sys.argv) == 3:
|
||||
validOptions = 1
|
||||
if sys.argv[1] == '-shadetext':
|
||||
desktopText(sys.argv[2])
|
||||
elif sys.argv[1] == '-shadewidget':
|
||||
desktopWidget(sys.argv[2])
|
||||
else:
|
||||
validOptions = 0
|
||||
|
||||
if not validOptions:
|
||||
rotate()
|
@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
class Directory(TQListViewItem):
|
||||
def __init__(self, parent, name=None):
|
||||
TQListViewItem.__init__(*(self,parent))
|
||||
if isinstance(parent, TQListView):
|
||||
self.p = None
|
||||
self.f = '/'
|
||||
else:
|
||||
self.p = parent
|
||||
self.f = name
|
||||
self.c = []
|
||||
self.readable = 1
|
||||
|
||||
def setOpen(self, o):
|
||||
if o and not self.childCount():
|
||||
s = self.fullName()
|
||||
thisDir = TQDir(s)
|
||||
if not thisDir.isReadable():
|
||||
self.readable = 0
|
||||
return
|
||||
|
||||
files = thisDir.entryInfoList()
|
||||
if files:
|
||||
for f in files:
|
||||
fileName = str(f.fileName())
|
||||
if fileName == '.' or fileName == '..':
|
||||
continue
|
||||
elif f.isSymLink():
|
||||
d = TQListViewItem(self, fileName, 'Symbolic Link')
|
||||
elif f.isDir():
|
||||
d = Directory(self, fileName)
|
||||
else:
|
||||
if f.isFile():
|
||||
s = 'File'
|
||||
else:
|
||||
s = 'Special'
|
||||
d = TQListViewItem(self, fileName, s)
|
||||
self.c.append(d)
|
||||
|
||||
TQListViewItem.setOpen(self, o)
|
||||
|
||||
def setup(self):
|
||||
self.setExpandable(1)
|
||||
TQListViewItem.setup(self)
|
||||
|
||||
def fullName(self):
|
||||
if self.p:
|
||||
s = self.p.fullName() + self.f + '/'
|
||||
else:
|
||||
s = '/'
|
||||
return s
|
||||
|
||||
def text(self, column):
|
||||
if column == 0:
|
||||
return self.f
|
||||
elif self.readable:
|
||||
return 'Directory'
|
||||
else:
|
||||
return 'Unreadable Directory'
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
mw = TQListView()
|
||||
a.setMainWidget(mw)
|
||||
mw.setCaption('Directory Browser')
|
||||
mw.addColumn('Name')
|
||||
mw.addColumn('Type')
|
||||
mw.resize(400, 400)
|
||||
mw.setTreeStepSize(20)
|
||||
root = Directory(mw)
|
||||
root.setOpen(1)
|
||||
mw.show()
|
||||
a.exec_loop()
|
@ -1,96 +0,0 @@
|
||||
# This is part of the dragdrop example.
|
||||
|
||||
|
||||
from python_tqt.qt import *
|
||||
|
||||
import secret
|
||||
|
||||
|
||||
class DropSite(TQLabel):
|
||||
def __init__(self, parent=None, name=None):
|
||||
TQLabel.__init__( self, parent, name )
|
||||
self.setAcceptDrops(1)
|
||||
|
||||
# this is a normal event
|
||||
def mousePressEvent( self, e ):
|
||||
if ( self.pixmap() ) :
|
||||
drobj = TQImageDrag( self.pixmap().convertToImage(), self )
|
||||
pm = TQPixmap()
|
||||
pm.convertFromImage(self.pixmap().convertToImage().smoothScale(
|
||||
self.pixmap().width()/3,self.pixmap().height()/3))
|
||||
drobj.setPixmap(pm,TQPoint(-5,-7))
|
||||
else :
|
||||
drobj = TQTextDrag( self.text(), self )
|
||||
drobj.dragCopy()
|
||||
|
||||
def backgroundColorChange( self, qcolor ):
|
||||
# Reduce flicker by using repaint() rather than update()
|
||||
self.repaint()
|
||||
|
||||
def dragMoveEvent( self, e ):
|
||||
# Check if you want the drag at e.pos()...
|
||||
# Give the user some feedback...
|
||||
pass
|
||||
|
||||
def dragEnterEvent( self, e ):
|
||||
# Check if you want the drag...
|
||||
if (secret.canDecode( e ) or
|
||||
TQTextDrag.canDecode( e ) or
|
||||
TQImageDrag.canDecode( e ) or
|
||||
TQUriDrag.canDecode( e )):
|
||||
e.accept()
|
||||
|
||||
# Give the user some feedback...
|
||||
t = ''
|
||||
i = 0
|
||||
while e.format( i ):
|
||||
if ( t != '' ):
|
||||
t += "\n"
|
||||
t += str(e.format( i ))
|
||||
i += 1
|
||||
self.emit(PYSIGNAL('message(TQString &)'), (TQString(t),))
|
||||
self.setPaletteBackgroundColor(TQt.white)
|
||||
|
||||
def dragLeaveEvent( self, TQDragLeaveEvent ):
|
||||
# Give the user some feedback...
|
||||
self.emit(PYSIGNAL('message(TQString &)'), (TQString(''),))
|
||||
self.setPaletteBackgroundColor(TQt.lightGray)
|
||||
|
||||
def dropEvent( self, e ):
|
||||
self.setPaletteBackgroundColor(TQt.lightGray)
|
||||
# Try to decode to the data you understand...
|
||||
str = TQString()
|
||||
if ( TQTextDrag.decode( e, str ) ) :
|
||||
self.setText( str )
|
||||
self.setMinimumSize( self.minimumSize().expandedTo(self.sizeHint()) )
|
||||
return
|
||||
|
||||
pm = TQPixmap()
|
||||
if ( TQImageDrag.decode( e, pm ) ) :
|
||||
self.setPixmap( pm )
|
||||
self.setMinimumSize(self.minimumSize().expandedTo(self.sizeHint()))
|
||||
return
|
||||
|
||||
# TQStrList strings
|
||||
#strings = TQStrList()
|
||||
strings = []
|
||||
if ( TQUriDrag.decode( e, strings ) ) :
|
||||
m = TQString("Full URLs:\n")
|
||||
for u in strings:
|
||||
m = m + " " + u + '\n'
|
||||
# TQStringList files
|
||||
files = []
|
||||
if ( TQUriDrag.decodeLocalFiles( e, files ) ) :
|
||||
m += "Files:\n"
|
||||
# for (TQStringList.Iterator i=files.begin() i!=files.end() ++i)
|
||||
for i in files:
|
||||
m = m + " " + i + '\n'
|
||||
self.setText( m )
|
||||
self.setMinimumSize(self.minimumSize().expandedTo(self.sizeHint()))
|
||||
return
|
||||
|
||||
str = secret.decode( e )
|
||||
if str:
|
||||
self.setText( str )
|
||||
self.setMinimumSize(self.minimumSize().expandedTo(self.sizeHint()))
|
||||
return
|
@ -1,235 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import sys
|
||||
import math
|
||||
from python_tqt.qt import *
|
||||
from python_tqt.qtgl import *
|
||||
from OpenGL.GL import *
|
||||
|
||||
def gear(inner_radius,outer_radius,width,teeth,tooth_depth):
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth/2.0;
|
||||
r2 = outer_radius + tooth_depth/2.0;
|
||||
|
||||
da = 2.0*math.pi/teeth/4.0;
|
||||
|
||||
glShadeModel(GL_FLAT)
|
||||
|
||||
glNormal3f(0.0,0.0,1.0)
|
||||
|
||||
# draw front face
|
||||
|
||||
glBegin(GL_QUAD_STRIP)
|
||||
|
||||
for i in range(teeth+1):
|
||||
angle = i * 2.0*math.pi/teeth;
|
||||
glVertex3f(r0*math.cos(angle), r0*math.sin(angle), width*0.5 )
|
||||
glVertex3f(r1*math.cos(angle), r1*math.sin(angle), width*0.5 )
|
||||
glVertex3f(r0*math.cos(angle), r0*math.sin(angle), width*0.5 )
|
||||
glVertex3f(r1*math.cos(angle+3*da), r1*math.sin(angle+3*da), width*0.5 )
|
||||
|
||||
glEnd()
|
||||
|
||||
# draw front sides of teeth
|
||||
|
||||
da = 2.0*math.pi/teeth/4.0;
|
||||
|
||||
glBegin(GL_QUADS)
|
||||
|
||||
for i in range(teeth):
|
||||
angle = i*2.0*math.pi/teeth
|
||||
|
||||
glVertex3f( r1*math.cos(angle), r1*math.sin(angle), width*0.5 )
|
||||
glVertex3f( r2*math.cos(angle+da), r2*math.sin(angle+da), width*0.5 )
|
||||
glVertex3f( r2*math.cos(angle+2*da), r2*math.sin(angle+2*da), width*0.5 )
|
||||
glVertex3f( r1*math.cos(angle+3*da), r1*math.sin(angle+3*da), width*0.5 )
|
||||
|
||||
glEnd()
|
||||
|
||||
|
||||
glNormal3f( 0.0, 0.0, -1.0 )
|
||||
|
||||
# draw back face
|
||||
|
||||
glBegin( GL_QUAD_STRIP );
|
||||
|
||||
for i in range(teeth+1):
|
||||
angle = i*2.0*math.pi/teeth;
|
||||
|
||||
glVertex3f( r1*math.cos(angle), r1*math.sin(angle), -width*0.5 )
|
||||
glVertex3f( r0*math.cos(angle), r0*math.sin(angle), -width*0.5 )
|
||||
glVertex3f( r1*math.cos(angle+3*da), r1*math.sin(angle+3*da), -width*0.5 )
|
||||
glVertex3f( r0*math.cos(angle), r0*math.sin(angle), -width*0.5 )
|
||||
|
||||
glEnd()
|
||||
|
||||
# draw back sides of teeth
|
||||
|
||||
da = 2.0*math.pi/teeth/4.0
|
||||
|
||||
glBegin( GL_QUADS )
|
||||
|
||||
for i in range(teeth):
|
||||
angle = i*2.0*math.pi/teeth
|
||||
|
||||
glVertex3f( r1*math.cos(angle+3*da), r1*math.sin(angle+3*da), -width*0.5 )
|
||||
glVertex3f( r2*math.cos(angle+2*da), r2*math.sin(angle+2*da), -width*0.5 )
|
||||
glVertex3f( r2*math.cos(angle+da), r2*math.sin(angle+da), -width*0.5 )
|
||||
glVertex3f( r1*math.cos(angle), r1*math.sin(angle), -width*0.5 )
|
||||
|
||||
glEnd()
|
||||
|
||||
# draw outward faces of teeth
|
||||
|
||||
glBegin( GL_QUAD_STRIP )
|
||||
|
||||
for i in range(teeth):
|
||||
angle = i*2.0*math.pi/teeth
|
||||
|
||||
glVertex3f( r1*math.cos(angle), r1*math.sin(angle), width*0.5 )
|
||||
glVertex3f( r1*math.cos(angle), r1*math.sin(angle), -width*0.5 )
|
||||
|
||||
u = r2*math.cos(angle+da) - r1*math.cos(angle)
|
||||
v = r2*math.sin(angle+da) - r1*math.sin(angle)
|
||||
|
||||
len = math.sqrt( u*u + v*v )
|
||||
u /= len
|
||||
v /= len
|
||||
glNormal3f( v, -u, 0.0 )
|
||||
glVertex3f( r2*math.cos(angle+da), r2*math.sin(angle+da), width*0.5 )
|
||||
glVertex3f( r2*math.cos(angle+da), r2*math.sin(angle+da), -width*0.5 )
|
||||
glNormal3f( math.cos(angle), math.sin(angle), 0.0 )
|
||||
glVertex3f( r2*math.cos(angle+2*da), r2*math.sin(angle+2*da), width*0.5 )
|
||||
glVertex3f( r2*math.cos(angle+2*da), r2*math.sin(angle+2*da), -width*0.5 )
|
||||
u = r1*math.cos(angle+3*da) - r2*math.cos(angle+2*da)
|
||||
v = r1*math.sin(angle+3*da) - r2*math.sin(angle+2*da)
|
||||
glNormal3f( v, -u, 0.0 )
|
||||
glVertex3f( r1*math.cos(angle+3*da), r1*math.sin(angle+3*da), width*0.5 )
|
||||
glVertex3f( r1*math.cos(angle+3*da), r1*math.sin(angle+3*da), -width*0.5 )
|
||||
glNormal3f( math.cos(angle), math.sin(angle), 0.0 )
|
||||
|
||||
glVertex3f( r1*math.cos(0.0), r1*math.sin(0.0), width*0.5 )
|
||||
glVertex3f( r1*math.cos(0.0), r1*math.sin(0.0), -width*0.5 )
|
||||
|
||||
glEnd()
|
||||
|
||||
glShadeModel (GL_SMOOTH)
|
||||
|
||||
# draw inside radius cylinder
|
||||
|
||||
glBegin( GL_QUAD_STRIP )
|
||||
|
||||
for i in range(teeth+1):
|
||||
angle = i * 2.0*math.pi / teeth;
|
||||
glNormal3f( -math.cos(angle), -math.sin(angle), 0.0 );
|
||||
glVertex3f( r0*math.cos(angle), r0*math.sin(angle), -width*0.5 );
|
||||
glVertex3f( r0*math.cos(angle), r0*math.sin(angle), width*0.5 );
|
||||
|
||||
glEnd()
|
||||
|
||||
##############################################################################
|
||||
class GearWidget(TQGLWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQGLWidget.__init__(self,parent,name)
|
||||
|
||||
self.angle=0.0
|
||||
self.view_rotx=0.0
|
||||
self.view_roty=0.0
|
||||
self.view_rotz=0.0
|
||||
|
||||
self.startTimer(10)
|
||||
|
||||
def timerEvent(self,event):
|
||||
self.updateGL()
|
||||
|
||||
def paintGL(self):
|
||||
self.angle = self.angle + 2.0
|
||||
self.view_rotx = self.view_rotx + 1.0
|
||||
self.view_roty = self.view_roty + 3.0
|
||||
self.view_rotz = self.view_rotz + 2.0
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
|
||||
|
||||
glPushMatrix()
|
||||
glRotatef( self.view_rotx, 1.0, 0.0, 0.0 )
|
||||
glRotatef( self.view_roty, 0.0, 1.0, 0.0 )
|
||||
glRotatef( self.view_rotz, 0.0, 0.0, 1.0 )
|
||||
|
||||
glPushMatrix()
|
||||
glTranslatef( -3.0, -2.0, 0.0 )
|
||||
glRotatef( self.angle, 0.0, 0.0, 1.0 )
|
||||
glCallList(self.gear1)
|
||||
glPopMatrix()
|
||||
|
||||
glPushMatrix()
|
||||
glTranslatef( 3.1, -2.0, 0.0 )
|
||||
glRotatef( -2.0*self.angle-9.0, 0.0, 0.0, 1.0 )
|
||||
glCallList(self.gear2)
|
||||
glPopMatrix()
|
||||
|
||||
glPushMatrix()
|
||||
glTranslatef( -3.1, 2.2, -1.8 )
|
||||
glRotatef( 90.0, 1.0, 0.0, 0.0 )
|
||||
glRotatef( 2.0*self.angle-2.0, 0.0, 0.0, 1.0 )
|
||||
glCallList(self.gear3)
|
||||
glPopMatrix()
|
||||
|
||||
glPopMatrix()
|
||||
|
||||
def resizeGL(self,width,height):
|
||||
w = width / float(height)
|
||||
h = 1.0
|
||||
|
||||
glViewport( 0, 0, width, height )
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
glLoadIdentity()
|
||||
glFrustum( -w, w, -h, h, 5.0, 60.0 )
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
glLoadIdentity()
|
||||
glTranslatef( 0.0, 0.0, -40.0 )
|
||||
|
||||
def initializeGL(self):
|
||||
pos=(5.0, 5.0, 10.0, 1.0 )
|
||||
ared=(0.8, 0.1, 0.0, 1.0 )
|
||||
agreen=(0.0, 0.8, 0.2, 1.0 )
|
||||
ablue=(0.2, 0.2, 1.0, 1.0 )
|
||||
|
||||
glLightfv(GL_LIGHT0,GL_POSITION,pos)
|
||||
glEnable(GL_CULL_FACE)
|
||||
glEnable(GL_LIGHTING)
|
||||
glEnable(GL_LIGHT0)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
|
||||
self.gear1=glGenLists(1)
|
||||
glNewList(self.gear1,GL_COMPILE)
|
||||
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ared)
|
||||
gear(1.0,4.0,1.0,20,0.7)
|
||||
glEndList()
|
||||
|
||||
self.gear2=glGenLists(1)
|
||||
glNewList(self.gear2,GL_COMPILE)
|
||||
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,agreen)
|
||||
gear(0.5,2.0,2.0,10,0.7)
|
||||
glEndList()
|
||||
|
||||
self.gear3=glGenLists(1)
|
||||
glNewList(self.gear3,GL_COMPILE)
|
||||
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ablue)
|
||||
gear(1.3,2.0,0.5,10,0.7)
|
||||
glEndList()
|
||||
|
||||
glEnable(GL_NORMALIZE)
|
||||
|
||||
##############################################################################
|
||||
if __name__=='__main__':
|
||||
TQApplication.setColorSpec(TQApplication.CustomColor)
|
||||
app=TQApplication(sys.argv)
|
||||
|
||||
if not TQGLFormat.hasOpenGL():
|
||||
raise Exception('No TQt OpenGL support.')
|
||||
|
||||
widget=GearWidget()
|
||||
app.setMainWidget(widget)
|
||||
widget.show()
|
||||
app.exec_loop()
|
@ -1,301 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
#****************************************************************************
|
||||
#** $Id: menu.py,v 1.1.1.1 2002/06/04 23:04:42 phil Exp $
|
||||
#**
|
||||
#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved.
|
||||
#**
|
||||
#** This file is part of an example program for PyTQt. This example
|
||||
#** program may be used, distributed and modified without limitation.
|
||||
#**
|
||||
#*****************************************************************************/
|
||||
|
||||
import sys, string
|
||||
from python_tqt.qt import *
|
||||
|
||||
TRUE = 1
|
||||
FALSE = 0
|
||||
|
||||
# XPM
|
||||
p1_xpm = [
|
||||
"16 16 3 1",
|
||||
" c None",
|
||||
". c #000000000000",
|
||||
"X c #FFFFFFFF0000",
|
||||
" ",
|
||||
" ",
|
||||
" .... ",
|
||||
" .XXXX. ",
|
||||
" .............. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .XXXXXXXXXXXX. ",
|
||||
" .............. ",
|
||||
" "
|
||||
]
|
||||
|
||||
# XPM
|
||||
p2_xpm = [
|
||||
"16 16 3 1",
|
||||
" c None",
|
||||
". c #000000000000",
|
||||
"X c #FFFFFFFFFFFF",
|
||||
" ",
|
||||
" ...... ",
|
||||
" .XXX.X. ",
|
||||
" .XXX.XX. ",
|
||||
" .XXX.XXX. ",
|
||||
" .XXX..... ",
|
||||
" .XXXXXXX. ",
|
||||
" .XXXXXXX. ",
|
||||
" .XXXXXXX. ",
|
||||
" .XXXXXXX. ",
|
||||
" .XXXXXXX. ",
|
||||
" .XXXXXXX. ",
|
||||
" .XXXXXXX. ",
|
||||
" ......... ",
|
||||
" ",
|
||||
" "
|
||||
]
|
||||
|
||||
# XPM
|
||||
p3_xpm = [
|
||||
"16 16 3 1",
|
||||
" c None",
|
||||
". c #000000000000",
|
||||
"X c #FFFFFFFFFFFF",
|
||||
" ",
|
||||
" ",
|
||||
" ......... ",
|
||||
" ........... ",
|
||||
" ........ .. ",
|
||||
" ........... ",
|
||||
" ........... ",
|
||||
" ........... ",
|
||||
" ........... ",
|
||||
" ...XXXXX... ",
|
||||
" ...XXXXX... ",
|
||||
" ...XXXXX... ",
|
||||
" ...XXXXX... ",
|
||||
" ......... ",
|
||||
" ",
|
||||
" "
|
||||
]
|
||||
|
||||
p4_xpm = [
|
||||
' 16 14 5 1',
|
||||
'. c #000000',
|
||||
'# c #848284',
|
||||
'a c #c6c3c6',
|
||||
'b c #ffff00',
|
||||
'c c #ffffff',
|
||||
'aaaaa.........aa',
|
||||
'aaaa.cccccccc.aa',
|
||||
'aaaa.c.....c.aaa',
|
||||
'aaa.cccccccc.aaa',
|
||||
'aaa.c.....c....a',
|
||||
'aa.cccccccc.a.a.',
|
||||
'a..........a.a..',
|
||||
'.aaaaaaaaaa.a.a.',
|
||||
'.............aa.',
|
||||
'.aaaaaa###aa.a.a',
|
||||
'.aaaaaabbbaa...a',
|
||||
'.............a.a',
|
||||
'a.aaaaaaaaa.a.aa',
|
||||
'aa...........aaa'
|
||||
]
|
||||
|
||||
# Auxiliary class to provide fancy menu items with different fonts.
|
||||
# Used for the "bold" and "underline" menu items in the options menu.
|
||||
|
||||
#class MyMenuItem( TQCustomMenuItem ):
|
||||
# def __init__( self, s=None, f=None ):
|
||||
# apply( TQCustomMenuItem.__init__,( self, s, f ) )
|
||||
# string = TQString( s )
|
||||
# font = TQFont( f )
|
||||
|
||||
# def paint( self, p, TRUE, FALSE, x, y, w, h ) :
|
||||
# p.setFont ( font )
|
||||
# p.drawText( x, y, w, h, TQt.AlignLeft | TQt.AlignVCenter | TQt.ShowPrefix | TQt.DontClip, string )
|
||||
# def sizeHint( self ):
|
||||
# return TQFontMetrics( font ).size( TQt.AlignLeft | TQt.AlignVCenter | TQt.ShowPrefix | TQt.DontClip, string )
|
||||
|
||||
|
||||
#
|
||||
### Implementation of MenuExample class
|
||||
#
|
||||
|
||||
class MenuExample( TQWidget ):
|
||||
def __init__( self, parent=None, name=None ):
|
||||
TQWidget.__init__(*(self, parent, name))
|
||||
self.p1 = TQIconSet( TQPixmap ( p1_xpm ) )
|
||||
self.p2 = TQIconSet( TQPixmap ( p2_xpm ) )
|
||||
self.p3 = TQIconSet( TQPixmap ( p3_xpm ) )
|
||||
self.p4 = TQIconSet( TQPixmap ( p4_xpm ) )
|
||||
#openIcon = TQPixmap()
|
||||
#saveIcon = TQPixmap()
|
||||
#printIcon = TQPixmap()
|
||||
|
||||
self.printer = TQPopupMenu( self )
|
||||
#TQ_CHECK_PTR( self.printer )
|
||||
self.printer.insertTearOffHandle()
|
||||
self.printer.insertItem( "&Print to printer", self.printDoc )
|
||||
self.printer.insertItem( "Print to &file", self.file )
|
||||
self.printer.insertItem( "Print to fa&x", self.fax )
|
||||
self.printer.insertSeparator()
|
||||
self.printer.insertItem( "Printer &Setup", self.printerSetup )
|
||||
|
||||
self.file = TQPopupMenu( self )
|
||||
#TQ_CHECK_PTR( self.file );
|
||||
self.file.insertItem( self.p1, "&Open", self.open, TQt.CTRL+TQt.Key_O )
|
||||
self.file.insertItem( self.p2, "&New", self.news, TQt.CTRL+TQt.Key_N )
|
||||
self.file.insertItem( self.p3, "&Save", self.save, TQt.CTRL+TQt.Key_S )
|
||||
self.file.insertItem( "&Close", self.closeDoc, TQt.CTRL+TQt.Key_W )
|
||||
self.file.insertSeparator()
|
||||
self.file.insertItem( self.p4, "&Print", self.printer, TQt.CTRL+TQt.Key_P )
|
||||
self.file.insertSeparator()
|
||||
self.file.insertItem( "E&xit", tqApp, SLOT( "quit()" ), TQt.CTRL+TQt.Key_Q )
|
||||
|
||||
self.edit = TQPopupMenu( self )
|
||||
#TQ_CHECK_PTR( self.edit )
|
||||
undoID = self.edit.insertItem( "&Undo", self.undo )
|
||||
redoID = self.edit.insertItem( "&Redo", self.redo )
|
||||
self.edit.setItemEnabled( undoID, TRUE )
|
||||
self.edit.setItemEnabled( redoID, FALSE )
|
||||
|
||||
self.options = TQPopupMenu( self )
|
||||
#TQ_CHECK_PTR( self.options )
|
||||
self.options.insertTearOffHandle()
|
||||
self.options.setCaption( 'Options' )
|
||||
self.options.insertItem( "&Normal Font", self.normal )
|
||||
self.options.insertSeparator()
|
||||
|
||||
self.options.polish() # adjust system settings
|
||||
self.f = TQFont( self.options.font() )
|
||||
self.f.setBold( TRUE )
|
||||
self.boldID = self.options.insertItem( "&Bold" )
|
||||
self.options.setAccel( TQt.CTRL+TQt.Key_B, self.boldID )
|
||||
self.options.connectItem( self.boldID, self.bold )
|
||||
|
||||
self.f = TQFont( self.options.font() )
|
||||
self.f.setUnderline( TRUE )
|
||||
self.underlineID = self.options.insertItem( "&Underline" )
|
||||
self.options.setAccel( TQt.CTRL+TQt.Key_U, self.underlineID )
|
||||
self.options.connectItem( self.underlineID, self.underline )
|
||||
|
||||
self.isBold = FALSE
|
||||
self.isUnderline = FALSE
|
||||
self.options.setCheckable( TRUE )
|
||||
|
||||
self.options = TQPopupMenu()
|
||||
#TQ_CHECK_PTR( self.options )
|
||||
self.options.insertItem( "&Normal Font", self.normal )
|
||||
self.options.insertSeparator()
|
||||
self.boldID = self.options.insertItem( "&Bold", self.bold )
|
||||
self.underlineID = self.options.insertItem( "&Underline", self.underline )
|
||||
|
||||
self.isBold = FALSE
|
||||
self.isUnderline = FALSE
|
||||
self.options.setCheckable( TRUE )
|
||||
|
||||
self.help = TQPopupMenu( self )
|
||||
#TQ_CHECK_PTR( self.help )
|
||||
self.help.insertItem( "&About", self.about, TQt.CTRL+TQt.Key_H )
|
||||
self.help.insertItem( "About &TQt", self.aboutTQt )
|
||||
|
||||
self.menu = TQMenuBar( self )
|
||||
#TQ_CHECK_PTR( self.menu );
|
||||
self.menu.insertItem( "&File", self.file )
|
||||
self.menu.insertItem( "&Edit", self.edit )
|
||||
self.menu.insertItem( "&Options", self.options )
|
||||
self.menu.insertSeparator()
|
||||
self.menu.insertItem( "&Help", self.help )
|
||||
self.menu.setSeparator( TQMenuBar.InWindowsStyle )
|
||||
|
||||
self.label = TQLabel( self )
|
||||
#TQ_CHECK_PTR( self.label )
|
||||
self.label.setGeometry( 20, self.rect().center().y()-20, self.width()-40, 40 )
|
||||
self.label.setFrameStyle( TQFrame.Box | TQFrame.Raised )
|
||||
self.label.setLineWidth( 1 )
|
||||
self.label.setAlignment( TQt.AlignCenter )
|
||||
|
||||
self.label.setFont( TQFont( "times", 12, TQFont.Bold ) )
|
||||
self.connect( self, PYSIGNAL( "explain" ), self.label.setText )
|
||||
#self.connect( self, PYSIGNAL( "explain(const char *)" ),
|
||||
# self.label, SLOT( "setText(const char *)" ) )
|
||||
|
||||
self.setMinimumSize( 100, 80 )
|
||||
|
||||
def open( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/Open selected", ) )
|
||||
|
||||
def news( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/New selected", ) )
|
||||
|
||||
def save( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/Save selected", ) )
|
||||
|
||||
def closeDoc( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/Close selected", ) )
|
||||
|
||||
def undo( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "Edit/Undo selected", ) )
|
||||
|
||||
def redo( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "Edit/Redo selected", ) )
|
||||
|
||||
def normal( self ):
|
||||
self.isBold = FALSE
|
||||
self.isUnderline = FALSE
|
||||
self.options.setItemChecked( self.boldID, self.isBold )
|
||||
self.options.setItemChecked( self.underlineID, self.isUnderline )
|
||||
self.emit(PYSIGNAL("explain"), ("Options/Normal selected",))
|
||||
|
||||
def bold( self ):
|
||||
self.isBold = not self.isBold
|
||||
self.options.setItemChecked( self.boldID, self.isBold )
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "Options/Bold selected", ) )
|
||||
|
||||
def underline( self ):
|
||||
self.isUnderline = not self.isUnderline
|
||||
self.options.setItemChecked( self.underlineID, self.isUnderline )
|
||||
self.emit(PYSIGNAL("explain"), ("Options/Underline selected",))
|
||||
|
||||
def about( self ):
|
||||
TQMessageBox.about( self, "TQt Menu Example",
|
||||
"This example demonstrates simple use of TQt menus.\n"
|
||||
"You can cut and paste lines from it to your own\n"
|
||||
"programs." )
|
||||
|
||||
def aboutTQt( self ):
|
||||
TQMessageBox.aboutTQt( self, "TQt Menu Example" )
|
||||
|
||||
def printDoc( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/Printer/Print selected", ) )
|
||||
|
||||
def file( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/Printer/Print To File selected", ) )
|
||||
|
||||
def fax( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/Printer/Print To Fax selected", ) )
|
||||
|
||||
def printerSetup( self ):
|
||||
self.emit ( PYSIGNAL( "explain" ), ( "File/Printer/Printer Setup selected", ) )
|
||||
|
||||
def resizeEvent( self, ev ):
|
||||
self.label.setGeometry( 20, self.rect().center().y()-20, self.width()-40, 40 )
|
||||
|
||||
a = TQApplication( sys.argv )
|
||||
m = MenuExample()
|
||||
|
||||
a.setMainWidget( m )
|
||||
m.setCaption( 'MenuExample' )
|
||||
m.show()
|
||||
#a.connect( a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()') )
|
||||
a.exec_loop()
|
Before Width: | Height: | Size: 3.6 KiB |
@ -1,65 +0,0 @@
|
||||
# This is part of the dragdrop example.
|
||||
|
||||
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
def canDecode(e):
|
||||
return e.provides( "secret/magic" )
|
||||
|
||||
|
||||
def decode(e):
|
||||
payload = str(e.data( "secret/magic" ))
|
||||
if ( str(payload) != '' ):
|
||||
e.accept()
|
||||
return TQString("The secret number is "+str(ord(payload)) )
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class SecretDrag(TQStoredDrag):
|
||||
def __init__(self, secret, parent=None, name=None):
|
||||
TQStoredDrag.__init__(self, 'secret/magic', parent, name)
|
||||
data = TQByteArray(chr(secret))
|
||||
self.setEncodedData( data )
|
||||
|
||||
|
||||
# XPM
|
||||
picture_xpm = [
|
||||
"16 16 3 1",
|
||||
" c None",
|
||||
". c #000000",
|
||||
"X c #FFFF00",
|
||||
" ..... ",
|
||||
" ..XXXXX.. ",
|
||||
" .XXXXXXXXX. ",
|
||||
" .XXXXXXXXXXX. ",
|
||||
" .XX..XXX..XX. ",
|
||||
".XXXXXXXXXXXXX. ",
|
||||
".XX...XXX...XX. ",
|
||||
".XXX..XXX..XXX. ",
|
||||
".XXXXXXXXXXXXX. ",
|
||||
".XXXXXX.XXXXXX. ",
|
||||
" .XX.XX.XX.XX. ",
|
||||
" .XXX..X..XXX. ",
|
||||
" .XXXXXXXXX. ",
|
||||
" ..XXXXX.. ",
|
||||
" ..... ",
|
||||
" "
|
||||
]
|
||||
|
||||
|
||||
class SecretSource(TQLabel):
|
||||
def __init__(self, secret, parent=None, name=None):
|
||||
TQLabel.__init__(self, "Secret", parent, name)
|
||||
self.setPaletteBackgroundColor( TQt.blue.light() )
|
||||
self.setFrameStyle( TQLabel.Box | TQLabel.Sunken )
|
||||
self.setMinimumHeight( self.sizeHint().height()*2 )
|
||||
self.setAlignment( TQLabel.AlignCenter )
|
||||
self.mySecret = secret
|
||||
|
||||
def mousePressEvent(self, e):
|
||||
sd = SecretDrag( self.mySecret, self )
|
||||
sd.setPixmap(TQPixmap(picture_xpm),TQPoint(8,8))
|
||||
sd.dragCopy()
|
||||
self.mySecret = self.mySecret + 1
|
@ -1,203 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# A port of the semaphore example from TQt.
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
# Check if thread support was enabled.
|
||||
try:
|
||||
from python_tqt.qt import TQThread
|
||||
except:
|
||||
print("Thread support not enabled")
|
||||
sys.exit(1)
|
||||
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
# The semaphore instances.
|
||||
yellowSem = None
|
||||
greenSem = None
|
||||
|
||||
|
||||
class YellowThread(TQThread):
|
||||
def __init__(self,o):
|
||||
TQThread.__init__(self)
|
||||
|
||||
self.receiver = o
|
||||
self.stopped = 0
|
||||
self.mutex = TQMutex()
|
||||
|
||||
def run(self):
|
||||
global yellowSem, greenSem
|
||||
|
||||
for i in range(20):
|
||||
yellowSem += 1
|
||||
|
||||
event = TQCustomEvent(12345)
|
||||
event.setData(TQString("Yellow!"))
|
||||
TQThread.postEvent(self.receiver,event)
|
||||
self.msleep(200);
|
||||
|
||||
greenSem -= 1
|
||||
|
||||
self.mutex.lock()
|
||||
if self.stopped:
|
||||
self.stopped = 0
|
||||
self.mutex.unlock()
|
||||
break
|
||||
|
||||
self.mutex.unlock()
|
||||
|
||||
yellowSem += 1
|
||||
|
||||
event = TQCustomEvent(12346)
|
||||
event.setData(TQString("Yellow!"))
|
||||
TQThread.postEvent(self.receiver,event)
|
||||
|
||||
greenSem -= 1
|
||||
|
||||
def stop(self):
|
||||
self.mutex.lock()
|
||||
self.stopped = 1
|
||||
self.mutex.unlock()
|
||||
|
||||
|
||||
class GreenThread(TQThread):
|
||||
def __init__(self,o):
|
||||
TQThread.__init__(self)
|
||||
|
||||
self.receiver = o
|
||||
self.stopped = 0
|
||||
self.mutex = TQMutex()
|
||||
|
||||
def run(self):
|
||||
global yellowSem, greenSem
|
||||
|
||||
for i in range(20):
|
||||
greenSem += 1
|
||||
|
||||
event = TQCustomEvent(12345)
|
||||
event.setData(TQString("Green!"))
|
||||
TQThread.postEvent(self.receiver,event)
|
||||
self.msleep(200)
|
||||
|
||||
yellowSem -= 1
|
||||
|
||||
self.mutex.lock()
|
||||
if self.stopped:
|
||||
self.stopped = 0
|
||||
self.mutex.unlock()
|
||||
break
|
||||
|
||||
self.mutex.unlock()
|
||||
|
||||
greenSem += 1
|
||||
|
||||
event = TQCustomEvent(12346)
|
||||
event.setData(TQString("Green!"))
|
||||
TQThread.postEvent(self.receiver,event)
|
||||
self.msleep(10)
|
||||
|
||||
yellowSem -= 1
|
||||
|
||||
def stop(self):
|
||||
self.mutex.lock()
|
||||
self.stopped = 1
|
||||
self.mutex.unlock()
|
||||
|
||||
|
||||
class SemaphoreExample(TQWidget):
|
||||
def __init__(self):
|
||||
TQWidget.__init__(self)
|
||||
|
||||
self.yellowThread = YellowThread(self)
|
||||
self.greenThread = GreenThread(self)
|
||||
|
||||
global yellowSem, greenSem
|
||||
yellowSem = TQSemaphore(1)
|
||||
greenSem = TQSemaphore(1)
|
||||
|
||||
self.button = TQPushButton("&Ignition!",self)
|
||||
self.connect(self.button,SIGNAL("clicked()"),self.startExample)
|
||||
|
||||
self.mlineedit = TQMultiLineEdit(self)
|
||||
self.label = TQLabel(self)
|
||||
|
||||
vbox = TQVBoxLayout(self,5)
|
||||
vbox.addWidget(self.button)
|
||||
vbox.addWidget(self.mlineedit)
|
||||
vbox.addWidget(self.label)
|
||||
|
||||
def __del__(self):
|
||||
stopYellow = self.yellowThread.running()
|
||||
stopGreen = self.greenThread.running()
|
||||
|
||||
if stopYellow:
|
||||
self.yellowThread.stop()
|
||||
|
||||
if self.greenThread.running():
|
||||
self.greenThread.stop()
|
||||
|
||||
if stopYellow:
|
||||
self.yellowThread.wait()
|
||||
|
||||
if stopGreen:
|
||||
self.greenThread.wait()
|
||||
|
||||
global yellowSem, greenSem
|
||||
yellowSem = None
|
||||
greenSem = None
|
||||
|
||||
def startExample(self):
|
||||
if self.yellowThread.running() or self.greenThread.running():
|
||||
TQMessageBox.information(self,"Sorry",
|
||||
"The threads have not completed yet, and must finish before "
|
||||
"they can be started again.")
|
||||
|
||||
return
|
||||
|
||||
self.mlineedit.clear()
|
||||
|
||||
global yellowSem
|
||||
|
||||
while yellowSem.available() < yellowSem.total():
|
||||
yellowSem -= 1
|
||||
|
||||
yellowSem += 1
|
||||
|
||||
self.yellowThread.start()
|
||||
self.greenThread.start()
|
||||
|
||||
def customEvent(self,event):
|
||||
if event.type() == 12345:
|
||||
s = event.data()
|
||||
|
||||
self.mlineedit.append(s)
|
||||
|
||||
if s.latin1() == "Green!":
|
||||
self.label.setPaletteBackgroundColor(TQt.green)
|
||||
else:
|
||||
self.label.setPaletteBackgroundColor(TQt.yellow)
|
||||
|
||||
self.label.setText(s)
|
||||
|
||||
del s
|
||||
elif event.type() == 12346:
|
||||
s = event.data()
|
||||
|
||||
TQMessageBox.information(self,s.latin1() + " - Finished",
|
||||
"The thread creating the \"" + s.latin1() +
|
||||
"\" events has finished.")
|
||||
|
||||
del s
|
||||
else:
|
||||
print("Unknown custom event type:", event.type())
|
||||
|
||||
|
||||
app = TQApplication(sys.argv)
|
||||
se = SemaphoreExample()
|
||||
app.setMainWidget(se)
|
||||
se.show()
|
||||
|
||||
sys.exit(app.exec_loop())
|
@ -1,65 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
class Test(TQWidget):
|
||||
def __init__(self, parent=None, name='Test', f=0):
|
||||
TQWidget.__init__(self, parent, name, f)
|
||||
|
||||
def paintEvent(self, e):
|
||||
p = TQPainter(self)
|
||||
p.setClipRect(e.rect())
|
||||
d = 1000
|
||||
x1 = 0
|
||||
x2 = self.width() - 1
|
||||
y1 = 0
|
||||
y2 = self.height() - 1
|
||||
|
||||
x = int((x1+x2)/2)
|
||||
p.drawLine(x, y1, x+d, y1+d)
|
||||
p.drawLine(x, y1, x-d, y1+d)
|
||||
p.drawLine(x, y2, x+d, y2-d)
|
||||
p.drawLine(x, y2, x-d, y2-d)
|
||||
|
||||
y = int((y1+y2)/2)
|
||||
p.drawLine(x1, y, x1+d, y+d)
|
||||
p.drawLine(x1, y, x1+d, y-d)
|
||||
p.drawLine(x2, y, x2-d, y+d)
|
||||
p.drawLine(x2, y, x2-d, y-d)
|
||||
|
||||
|
||||
if __name__=="__main__":
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
s1 = TQSplitter(TQt.Vertical, None, "main")
|
||||
s2 = TQSplitter(TQt.Horizontal, s1, "top")
|
||||
|
||||
t1 = Test(s2)
|
||||
t1.setPaletteBackgroundColor(TQt.blue.light(180))
|
||||
t1.setMinimumSize(50,0)
|
||||
|
||||
t2 = Test(s2)
|
||||
t2.setPaletteBackgroundColor(TQt.green.light(180))
|
||||
s2.setResizeMode(t2, TQSplitter.KeepSize)
|
||||
s2.moveToFirst(t2)
|
||||
|
||||
s3 = TQSplitter(TQt.Horizontal, s1, "bottom")
|
||||
|
||||
t3 = Test(s3)
|
||||
t3.setPaletteBackgroundColor(TQt.red)
|
||||
t4 = Test(s3)
|
||||
t4.setPaletteBackgroundColor(TQt.white)
|
||||
|
||||
t5 = Test(s3)
|
||||
t5.setMaximumHeight(250)
|
||||
t5.setMinimumSize(80,50)
|
||||
t5.setPaletteBackgroundColor(TQt.yellow)
|
||||
|
||||
s1.setOpaqueResize(1)
|
||||
s2.setOpaqueResize(1)
|
||||
s3.setOpaqueResize(1)
|
||||
|
||||
a.setMainWidget(s1)
|
||||
s1.show()
|
||||
a.exec_loop()
|
@ -1,115 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
class Table(TQTableView):
|
||||
def __init__(self, numRows, numCols, parent=None, name=''):
|
||||
TQTableView.__init__(self, parent, name)
|
||||
self.curRow = self.curCol = 0
|
||||
self.setFocusPolicy(TQWidget.StrongFocus)
|
||||
self.setBackgroundMode(TQWidget.PaletteBase)
|
||||
self.setNumCols(numCols)
|
||||
self.setNumRows(numRows)
|
||||
self.setCellWidth(100)
|
||||
self.setCellHeight(30)
|
||||
self.setTableFlags(Tbl_vScrollBar |
|
||||
Tbl_hScrollBar |
|
||||
Tbl_clipCellPainting)
|
||||
self.resize(400,200)
|
||||
self.contents = [''] * (numRows * numCols)
|
||||
|
||||
def cellContent(self, row, col):
|
||||
return self.contents[self.indexOf(row,col)]
|
||||
|
||||
def setCellContent(self, row, col, c):
|
||||
self.contents[self.indexOf(row,col)] = c
|
||||
self.updateCell(row, col)
|
||||
|
||||
def paintCell(self, p, row, col):
|
||||
w = self.cellWidth(col)
|
||||
h = self.cellHeight(row)
|
||||
x2 = w-1
|
||||
y2 = h-1
|
||||
|
||||
p.drawLine(x2,0,x2,y2)
|
||||
p.drawLine(0,y2,x2,y2)
|
||||
|
||||
if row == self.curRow and col == self.curCol:
|
||||
if self.hasFocus():
|
||||
p.drawRect(0, 0, x2, y2)
|
||||
else:
|
||||
p.setPen(TQt.DotLine)
|
||||
p.drawRect(0, 0, x2, y2)
|
||||
p.setPen(TQt.SolidLine)
|
||||
|
||||
p.drawText(0,0,w,h,TQt.AlignCenter,self.contents[self.indexOf(row,col)])
|
||||
|
||||
def mousePressEvent(self, me):
|
||||
oldRow = self.curRow
|
||||
oldCol = self.curCol
|
||||
clickedPos = me.pos()
|
||||
self.curRow = self.findRow(clickedPos.y())
|
||||
self.curCol = self.findCol(clickedPos.x())
|
||||
if self.curRow != oldRow or \
|
||||
self.curCol != oldCol:
|
||||
self.updateCell(oldRow, oldCol)
|
||||
self.updateCell(self.curRow, self.curCol)
|
||||
|
||||
def keyPressEvent(self, ke):
|
||||
oldRow = self.curRow
|
||||
oldCol = self.curCol
|
||||
edge = 0
|
||||
key = ke.key()
|
||||
if key == Key_Left:
|
||||
if self.curCol > 0:
|
||||
self.curCol = self.curCol - 1
|
||||
edge = self.leftCell()
|
||||
if self.curCol < edge:
|
||||
self.setLeftCell(edge-1)
|
||||
elif key == Key_Right:
|
||||
if self.curCol < self.numCols()-1:
|
||||
self.curCol = self.curCol + 1
|
||||
edge = self.lastColVisible()
|
||||
if self.curCol >= edge:
|
||||
self.setLeftCell(self.leftCell()+1)
|
||||
elif key == Key_Up:
|
||||
if self.curRow > 0:
|
||||
self.curRow = self.curRow - 1
|
||||
edge = self.topCell()
|
||||
if self.curRow < edge:
|
||||
self.setTopCell(edge-1)
|
||||
elif key == Key_Down:
|
||||
if self.curRow < self.numRows()-1:
|
||||
self.curRow = self.curRow + 1
|
||||
edge = self.lastRowVisible()
|
||||
if self.curRow >= edge:
|
||||
self.setTopCell(self.topCell()+1)
|
||||
else:
|
||||
ke.ignore()
|
||||
return
|
||||
|
||||
if self.curRow != oldRow or \
|
||||
self.curCol != oldCol:
|
||||
self.updateCell(oldRow, oldCol)
|
||||
self.updateCell(self.curRow, self.curCol)
|
||||
|
||||
def focusInEvnet(self, fie):
|
||||
self.updateCell(self.curRow, self.curCol)
|
||||
|
||||
def focusOutEvent(self, foe):
|
||||
self.updateCell(self.curRow, self.curCol)
|
||||
|
||||
def indexOf(self, row, col):
|
||||
return (row * self.numCols()) + col
|
||||
|
||||
numRows = 20
|
||||
numCols = 20
|
||||
a = TQApplication(sys.argv)
|
||||
v = Table(numRows, numCols)
|
||||
for i in range(numRows):
|
||||
for j in range(numCols):
|
||||
v.setCellContent(i,j,'%d %c' % (j, 65+(i%26)))
|
||||
a.setMainWidget(v)
|
||||
v.show()
|
||||
a.exec_loop()
|
@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 1.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
hello = TQPushButton("Hello world!",None)
|
||||
hello.resize(100,30)
|
||||
|
||||
a.setMainWidget(hello)
|
||||
hello.show()
|
||||
a.exec_loop()
|
@ -1,145 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 10.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
self.setFocusProxy(self.slider)
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
def setRange(self,minVal,maxVal):
|
||||
if minVal < 0 or maxVal > 99 or minVal > maxVal:
|
||||
raise ValueError('LCDRange.setRange(): invalid range')
|
||||
self.slider.setRange(minVal,maxVal)
|
||||
|
||||
|
||||
class CannonField(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.ang = 45
|
||||
self.f = 0
|
||||
self.setPalette(TQPalette(TQColor(250,250,200)))
|
||||
|
||||
def angle(self):
|
||||
return self.ang
|
||||
|
||||
def setAngle(self,degrees):
|
||||
if degrees < 5:
|
||||
degrees = 5
|
||||
if degrees > 70:
|
||||
degrees = 70
|
||||
if self.ang == degrees:
|
||||
return
|
||||
self.ang = degrees
|
||||
self.repaint(self.cannonRect(),0)
|
||||
self.emit(PYSIGNAL('angleChanged(int)'),(self.ang,))
|
||||
|
||||
def force(self):
|
||||
return self.f
|
||||
|
||||
def setForce(self,newton):
|
||||
if newton < 0:
|
||||
newton = 0
|
||||
if self.f == newton:
|
||||
return
|
||||
self.f = newton
|
||||
self.emit(PYSIGNAL('forceChanged(int)'),(self.f,))
|
||||
|
||||
def paintEvent(self,ev):
|
||||
if not ev.rect().intersects(self.cannonRect()):
|
||||
return
|
||||
|
||||
cr = self.cannonRect()
|
||||
pix = TQPixmap(cr.size())
|
||||
pix.fill(self,cr.topLeft())
|
||||
|
||||
p = TQPainter(pix)
|
||||
|
||||
p.setBrush(TQt.blue)
|
||||
p.setPen(TQt.NoPen)
|
||||
|
||||
p.translate(0,pix.height() - 1)
|
||||
p.drawPie(TQRect(-35,-35,70,70),0,90 * 16)
|
||||
p.rotate(-self.ang)
|
||||
p.drawRect(TQRect(33,-4,15,8))
|
||||
p.end()
|
||||
|
||||
p.begin(self)
|
||||
p.drawPixmap(cr.topLeft(),pix)
|
||||
|
||||
def cannonRect(self):
|
||||
r = TQRect(0,0,50,50)
|
||||
r.moveBottomLeft(self.rect().bottomLeft())
|
||||
return r
|
||||
|
||||
def sizePolicy(self):
|
||||
return TQSizePolicy(TQSizePolicy.Expanding,TQSizePolicy.Expanding)
|
||||
|
||||
|
||||
class MyWidget(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton('&Quit',self,'quit')
|
||||
quit.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(quit,SIGNAL('clicked()'),tqApp,SLOT('quit()'))
|
||||
|
||||
self.angle = LCDRange(self,'angle')
|
||||
self.angle.setRange(5,70)
|
||||
|
||||
self.force = LCDRange(self,'force')
|
||||
self.force.setRange(10,50)
|
||||
|
||||
self.cannonField = CannonField(self,'cannonField')
|
||||
|
||||
self.connect(self.angle,PYSIGNAL('valueChanged(int)'),self.cannonField.setAngle)
|
||||
self.connect(self.cannonField,PYSIGNAL('angleChanged(int)'),self.angle.setValue)
|
||||
|
||||
self.connect(self.force,PYSIGNAL('valueChanged(int)'),self.cannonField.setForce)
|
||||
self.connect(self.cannonField,PYSIGNAL('forceChanged(int)'),self.force.setValue)
|
||||
|
||||
grid = TQGridLayout(self,2,2,10)
|
||||
|
||||
grid.addWidget(quit,0,0)
|
||||
grid.addWidget(self.cannonField,1,1)
|
||||
grid.setColStretch(1,10)
|
||||
|
||||
leftBox = TQVBoxLayout()
|
||||
|
||||
grid.addLayout(leftBox,1,0)
|
||||
|
||||
leftBox.addWidget(self.angle)
|
||||
leftBox.addWidget(self.force)
|
||||
|
||||
self.angle.setValue(60)
|
||||
self.force.setValue(25)
|
||||
self.angle.setFocus()
|
||||
|
||||
|
||||
TQApplication.setColorSpec(TQApplication.CustomColor)
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
w.setGeometry(100,100,500,355)
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,213 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 11.
|
||||
|
||||
import sys
|
||||
import math
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
self.setFocusProxy(self.slider)
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
def setRange(self,minVal,maxVal):
|
||||
if minVal < 0 or maxVal > 99 or minVal > maxVal:
|
||||
raise ValueError('LCDRange.setRange(): invalid range')
|
||||
self.slider.setRange(minVal,maxVal)
|
||||
|
||||
|
||||
class CannonField(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.ang = 45
|
||||
self.f = 0
|
||||
self.timerCount = 0
|
||||
|
||||
self.autoShootTimer = TQTimer(self,'movement handler')
|
||||
self.connect(self.autoShootTimer,SIGNAL('timeout()'),self.moveShot)
|
||||
|
||||
self.shoot_ang = 0
|
||||
self.shoot_f = 0
|
||||
|
||||
self.setPalette(TQPalette(TQColor(250,250,200)))
|
||||
|
||||
self.barrelRect = TQRect(33,-4,15,8)
|
||||
|
||||
def angle(self):
|
||||
return self.ang
|
||||
|
||||
def setAngle(self,degrees):
|
||||
if degrees < 5:
|
||||
degrees = 5
|
||||
if degrees > 70:
|
||||
degrees = 70
|
||||
if self.ang == degrees:
|
||||
return
|
||||
self.ang = degrees
|
||||
self.repaint(self.cannonRect(),0)
|
||||
self.emit(PYSIGNAL('angleChanged(int)'),(self.ang,))
|
||||
|
||||
def force(self):
|
||||
return self.f
|
||||
|
||||
def setForce(self,newton):
|
||||
if newton < 0:
|
||||
newton = 0
|
||||
if self.f == newton:
|
||||
return
|
||||
self.f = newton
|
||||
self.emit(PYSIGNAL('forceChanged(int)'),(self.f,))
|
||||
|
||||
def shoot(self):
|
||||
if self.autoShootTimer.isActive():
|
||||
return
|
||||
|
||||
self.timerCount = 0
|
||||
self.shoot_ang = self.ang
|
||||
self.shoot_f = self.f
|
||||
self.autoShootTimer.start(50)
|
||||
|
||||
def moveShot(self):
|
||||
r = TQRegion(self.shotRect())
|
||||
self.timerCount = self.timerCount + 1
|
||||
|
||||
shotR = self.shotRect()
|
||||
|
||||
if shotR.x() > self.width() or shotR.y() > self.height():
|
||||
self.autoShootTimer.stop()
|
||||
else:
|
||||
r = r.unite(TQRegion(shotR))
|
||||
|
||||
self.repaint(r)
|
||||
|
||||
def paintEvent(self,ev):
|
||||
updateR = ev.rect()
|
||||
p = TQPainter(self)
|
||||
|
||||
if updateR.intersects(self.cannonRect()):
|
||||
self.paintCannon(p)
|
||||
|
||||
if self.autoShootTimer.isActive() and updateR.intersects(self.shotRect()):
|
||||
self.paintShot(p)
|
||||
|
||||
def paintShot(self,p):
|
||||
p.setBrush(TQt.black)
|
||||
p.setPen(TQt.NoPen)
|
||||
p.drawRect(self.shotRect())
|
||||
|
||||
def paintCannon(self,p):
|
||||
cr = self.cannonRect()
|
||||
pix = TQPixmap(cr.size())
|
||||
pix.fill(self,cr.topLeft())
|
||||
|
||||
tmp = TQPainter(pix)
|
||||
tmp.setBrush(TQt.blue)
|
||||
tmp.setPen(TQt.NoPen)
|
||||
|
||||
tmp.translate(0,pix.height() - 1)
|
||||
tmp.drawPie(TQRect(-35,-35,70,70),0,90 * 16)
|
||||
tmp.rotate(-self.ang)
|
||||
tmp.drawRect(self.barrelRect)
|
||||
tmp.end()
|
||||
|
||||
p.drawPixmap(cr.topLeft(),pix)
|
||||
|
||||
def cannonRect(self):
|
||||
r = TQRect(0,0,50,50)
|
||||
r.moveBottomLeft(self.rect().bottomLeft())
|
||||
return r
|
||||
|
||||
def shotRect(self):
|
||||
gravity = 4.0
|
||||
|
||||
time = self.timerCount / 4.0
|
||||
velocity = self.shoot_f
|
||||
radians = self.shoot_ang * 3.14159265 / 180
|
||||
|
||||
velx = velocity * math.cos(radians)
|
||||
vely = velocity * math.sin(radians)
|
||||
x0 = (self.barrelRect.right() + 5) * math.cos(radians)
|
||||
y0 = (self.barrelRect.right() + 5) * math.sin(radians)
|
||||
x = x0 + velx * time
|
||||
y = y0 + vely * time - 0.5 * gravity * time * time
|
||||
|
||||
r = TQRect(0,0,6,6)
|
||||
r.moveCenter(TQPoint(int(x),int(self.height() - 1 - y))))
|
||||
return r
|
||||
|
||||
def sizePolicy(self):
|
||||
return TQSizePolicy(TQSizePolicy.Expanding,TQSizePolicy.Expanding)
|
||||
|
||||
|
||||
class MyWidget(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton('&Quit',self,'quit')
|
||||
quit.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(quit,SIGNAL('clicked()'),tqApp,SLOT('quit()'))
|
||||
|
||||
self.angle = LCDRange(self,'angle')
|
||||
self.angle.setRange(5,70)
|
||||
|
||||
self.force = LCDRange(self,'force')
|
||||
self.force.setRange(10,50)
|
||||
|
||||
self.cannonField = CannonField(self,'cannonField')
|
||||
|
||||
self.connect(self.angle,PYSIGNAL('valueChanged(int)'),self.cannonField.setAngle)
|
||||
self.connect(self.cannonField,PYSIGNAL('angleChanged(int)'),self.angle.setValue)
|
||||
|
||||
self.connect(self.force,PYSIGNAL('valueChanged(int)'),self.cannonField.setForce)
|
||||
self.connect(self.cannonField,PYSIGNAL('forceChanged(int)'),self.force.setValue)
|
||||
|
||||
shoot = TQPushButton('&Shoot',self,'shoot')
|
||||
shoot.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(shoot,SIGNAL('clicked()'),self.cannonField.shoot)
|
||||
|
||||
grid = TQGridLayout(self,2,2,10)
|
||||
|
||||
grid.addWidget(quit,0,0)
|
||||
grid.addWidget(self.cannonField,1,1)
|
||||
grid.setColStretch(1,10)
|
||||
|
||||
leftBox = TQVBoxLayout()
|
||||
grid.addLayout(leftBox,1,0)
|
||||
leftBox.addWidget(self.angle)
|
||||
leftBox.addWidget(self.force)
|
||||
|
||||
topBox = TQHBoxLayout()
|
||||
grid.addLayout(topBox,0,1)
|
||||
topBox.addWidget(shoot)
|
||||
topBox.addStretch(1)
|
||||
|
||||
self.angle.setValue(60)
|
||||
self.force.setValue(25)
|
||||
self.angle.setFocus()
|
||||
|
||||
|
||||
TQApplication.setColorSpec(TQApplication.CustomColor)
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
w.setGeometry(100,100,500,355)
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,252 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 12.
|
||||
|
||||
import sys
|
||||
import math
|
||||
import random
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQVBox):
|
||||
def __init__(self,s=None,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
|
||||
self.label = TQLabel(' ',self,'label')
|
||||
self.label.setAlignment(TQt.AlignCenter)
|
||||
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
self.setFocusProxy(self.slider)
|
||||
|
||||
if s is not None:
|
||||
self.setText(s)
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
def setRange(self,minVal,maxVal):
|
||||
if minVal < 0 or maxVal > 99 or minVal > maxVal:
|
||||
raise ValueError('LCDRange.setRange(): invalid range')
|
||||
self.slider.setRange(minVal,maxVal)
|
||||
|
||||
def text(self):
|
||||
return self.label.text()
|
||||
|
||||
def setText(self,s):
|
||||
self.label.setText(s)
|
||||
|
||||
|
||||
class CannonField(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.ang = 45
|
||||
self.f = 0
|
||||
self.timerCount = 0
|
||||
|
||||
self.autoShootTimer = TQTimer(self,'movement handler')
|
||||
self.connect(self.autoShootTimer,SIGNAL('timeout()'),self.moveShot)
|
||||
|
||||
self.shoot_ang = 0
|
||||
self.shoot_f = 0
|
||||
self.target = TQPoint(0,0)
|
||||
|
||||
self.setPalette(TQPalette(TQColor(250,250,200)))
|
||||
|
||||
self.barrelRect = TQRect(33,-4,15,8)
|
||||
|
||||
self.newTarget()
|
||||
|
||||
def angle(self):
|
||||
return self.ang
|
||||
|
||||
def setAngle(self,degrees):
|
||||
if degrees < 5:
|
||||
degrees = 5
|
||||
if degrees > 70:
|
||||
degrees = 70
|
||||
if self.ang == degrees:
|
||||
return
|
||||
self.ang = degrees
|
||||
self.repaint(self.cannonRect(),0)
|
||||
self.emit(PYSIGNAL('angleChanged(int)'),(self.ang,))
|
||||
|
||||
def force(self):
|
||||
return self.f
|
||||
|
||||
def setForce(self,newton):
|
||||
if newton < 0:
|
||||
newton = 0
|
||||
if self.f == newton:
|
||||
return
|
||||
self.f = newton
|
||||
self.emit(PYSIGNAL('forceChanged(int)'),(self.f,))
|
||||
|
||||
def shoot(self):
|
||||
if self.autoShootTimer.isActive():
|
||||
return
|
||||
|
||||
self.timerCount = 0
|
||||
self.shoot_ang = self.ang
|
||||
self.shoot_f = self.f
|
||||
self.autoShootTimer.start(50)
|
||||
|
||||
def newTarget(self):
|
||||
r = TQRegion(self.targetRect())
|
||||
self.target = TQPoint(random.randint(200,390),random.randint(10,265))
|
||||
self.repaint(r.unite(TQRegion(self.targetRect())))
|
||||
|
||||
def moveShot(self):
|
||||
r = TQRegion(self.shotRect())
|
||||
self.timerCount = self.timerCount + 1
|
||||
|
||||
shotR = self.shotRect()
|
||||
|
||||
if shotR.intersects(self.targetRect()):
|
||||
self.autoShootTimer.stop()
|
||||
self.emit(PYSIGNAL('hit()'),())
|
||||
elif shotR.x() > self.width() or shotR.y() > self.height():
|
||||
self.autoShootTimer.stop()
|
||||
self.emit(PYSIGNAL('missed()'),())
|
||||
else:
|
||||
r = r.unite(TQRegion(shotR))
|
||||
|
||||
self.repaint(r)
|
||||
|
||||
def paintEvent(self,ev):
|
||||
updateR = ev.rect()
|
||||
p = TQPainter(self)
|
||||
|
||||
if updateR.intersects(self.cannonRect()):
|
||||
self.paintCannon(p)
|
||||
|
||||
if self.autoShootTimer.isActive() and updateR.intersects(self.shotRect()):
|
||||
self.paintShot(p)
|
||||
|
||||
if updateR.intersects(self.targetRect()):
|
||||
self.paintTarget(p)
|
||||
|
||||
def paintShot(self,p):
|
||||
p.setBrush(TQt.black)
|
||||
p.setPen(TQt.NoPen)
|
||||
p.drawRect(self.shotRect())
|
||||
|
||||
def paintTarget(self,p):
|
||||
p.setBrush(TQt.red)
|
||||
p.setPen(TQt.black)
|
||||
p.drawRect(self.targetRect())
|
||||
|
||||
def paintCannon(self,p):
|
||||
cr = self.cannonRect()
|
||||
pix = TQPixmap(cr.size())
|
||||
pix.fill(self,cr.topLeft())
|
||||
|
||||
tmp = TQPainter(pix)
|
||||
tmp.setBrush(TQt.blue)
|
||||
tmp.setPen(TQt.NoPen)
|
||||
|
||||
tmp.translate(0,pix.height() - 1)
|
||||
tmp.drawPie(TQRect(-35,-35,70,70),0,90 * 16)
|
||||
tmp.rotate(-self.ang)
|
||||
tmp.drawRect(self.barrelRect)
|
||||
tmp.end()
|
||||
|
||||
p.drawPixmap(cr.topLeft(),pix)
|
||||
|
||||
def cannonRect(self):
|
||||
r = TQRect(0,0,50,50)
|
||||
r.moveBottomLeft(self.rect().bottomLeft())
|
||||
return r
|
||||
|
||||
def shotRect(self):
|
||||
gravity = 4.0
|
||||
|
||||
time = self.timerCount / 4.0
|
||||
velocity = self.shoot_f
|
||||
radians = self.shoot_ang * 3.14159265 / 180
|
||||
|
||||
velx = velocity * math.cos(radians)
|
||||
vely = velocity * math.sin(radians)
|
||||
x0 = (self.barrelRect.right() + 5) * math.cos(radians)
|
||||
y0 = (self.barrelRect.right() + 5) * math.sin(radians)
|
||||
x = x0 + velx * time
|
||||
y = y0 + vely * time - 0.5 * gravity * time * time
|
||||
|
||||
r = TQRect(0,0,6,6)
|
||||
r.moveCenter(TQPoint(int(x),int(self.height() - 1 - y)))
|
||||
return r
|
||||
|
||||
def targetRect(self):
|
||||
r = TQRect(0,0,20,10)
|
||||
r.moveCenter(TQPoint(self.target.x(),self.height() - 1 - self.target.y()))
|
||||
return r
|
||||
|
||||
def sizePolicy(self):
|
||||
return TQSizePolicy(TQSizePolicy.Expanding,TQSizePolicy.Expanding)
|
||||
|
||||
|
||||
class MyWidget(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton('&Quit',self,'quit')
|
||||
quit.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(quit,SIGNAL('clicked()'),tqApp,SLOT('quit()'))
|
||||
|
||||
self.angle = LCDRange('ANGLE',self,'angle')
|
||||
self.angle.setRange(5,70)
|
||||
|
||||
self.force = LCDRange('FORCE',self,'force')
|
||||
self.force.setRange(10,50)
|
||||
|
||||
self.cannonField = CannonField(self,'cannonField')
|
||||
|
||||
self.connect(self.angle,PYSIGNAL('valueChanged(int)'),self.cannonField.setAngle)
|
||||
self.connect(self.cannonField,PYSIGNAL('angleChanged(int)'),self.angle.setValue)
|
||||
|
||||
self.connect(self.force,PYSIGNAL('valueChanged(int)'),self.cannonField.setForce)
|
||||
self.connect(self.cannonField,PYSIGNAL('forceChanged(int)'),self.force.setValue)
|
||||
|
||||
shoot = TQPushButton('&Shoot',self,'shoot')
|
||||
shoot.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(shoot,SIGNAL('clicked()'),self.cannonField.shoot)
|
||||
|
||||
grid = TQGridLayout(self,2,2,10)
|
||||
|
||||
grid.addWidget(quit,0,0)
|
||||
grid.addWidget(self.cannonField,1,1)
|
||||
grid.setColStretch(1,10)
|
||||
|
||||
leftBox = TQVBoxLayout()
|
||||
grid.addLayout(leftBox,1,0)
|
||||
leftBox.addWidget(self.angle)
|
||||
leftBox.addWidget(self.force)
|
||||
|
||||
topBox = TQHBoxLayout()
|
||||
grid.addLayout(topBox,0,1)
|
||||
topBox.addWidget(shoot)
|
||||
topBox.addStretch(1)
|
||||
|
||||
self.angle.setValue(60)
|
||||
self.force.setValue(25)
|
||||
self.angle.setFocus()
|
||||
|
||||
|
||||
TQApplication.setColorSpec(TQApplication.CustomColor)
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
w.setGeometry(100,100,500,355)
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,329 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 13.
|
||||
|
||||
import sys
|
||||
import math
|
||||
import random
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQWidget):
|
||||
def __init__(self,s=None,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
|
||||
self.label = TQLabel(' ',self,'label')
|
||||
self.label.setAlignment(TQt.AlignCenter)
|
||||
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
self.setFocusProxy(self.slider)
|
||||
|
||||
l = TQVBoxLayout(self)
|
||||
l.addWidget(lcd,1)
|
||||
l.addWidget(self.slider)
|
||||
l.addWidget(self.label)
|
||||
|
||||
if s is not None:
|
||||
self.setText(s)
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
def setRange(self,minVal,maxVal):
|
||||
if minVal < 0 or maxVal > 99 or minVal > maxVal:
|
||||
raise ValueError('LCDRange.setRange(): invalid range')
|
||||
self.slider.setRange(minVal,maxVal)
|
||||
|
||||
def text(self):
|
||||
return self.label.text()
|
||||
|
||||
def setText(self,s):
|
||||
self.label.setText(s)
|
||||
|
||||
|
||||
class CannonField(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.ang = 45
|
||||
self.f = 0
|
||||
self.timerCount = 0
|
||||
|
||||
self.autoShootTimer = TQTimer(self,'movement handler')
|
||||
self.connect(self.autoShootTimer,SIGNAL('timeout()'),self.moveShot)
|
||||
|
||||
self.shoot_ang = 0
|
||||
self.shoot_f = 0
|
||||
self.target = TQPoint(0,0)
|
||||
self.gameEnded = 0
|
||||
|
||||
self.setPalette(TQPalette(TQColor(250,250,200)))
|
||||
|
||||
self.barrelRect = TQRect(33,-4,15,8)
|
||||
|
||||
self.newTarget()
|
||||
|
||||
def angle(self):
|
||||
return self.ang
|
||||
|
||||
def setAngle(self,degrees):
|
||||
if degrees < 5:
|
||||
degrees = 5
|
||||
if degrees > 70:
|
||||
degrees = 70
|
||||
if self.ang == degrees:
|
||||
return
|
||||
self.ang = degrees
|
||||
self.repaint(self.cannonRect(),0)
|
||||
self.emit(PYSIGNAL('angleChanged(int)'),(self.ang,))
|
||||
|
||||
def force(self):
|
||||
return self.f
|
||||
|
||||
def setForce(self,newton):
|
||||
if newton < 0:
|
||||
newton = 0
|
||||
if self.f == newton:
|
||||
return
|
||||
self.f = newton
|
||||
self.emit(PYSIGNAL('forceChanged(int)'),(self.f,))
|
||||
|
||||
def shoot(self):
|
||||
if self.isShooting():
|
||||
return
|
||||
|
||||
self.timerCount = 0
|
||||
self.shoot_ang = self.ang
|
||||
self.shoot_f = self.f
|
||||
self.autoShootTimer.start(50)
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(0,))
|
||||
|
||||
def newTarget(self):
|
||||
r = TQRegion(self.targetRect())
|
||||
self.target = TQPoint(random.randint(200,390),random.randint(10,265))
|
||||
self.repaint(r.unite(TQRegion(self.targetRect())))
|
||||
|
||||
def gameOver(self):
|
||||
return self.gameEnded
|
||||
|
||||
def setGameOver(self):
|
||||
if self.gameEnded:
|
||||
return
|
||||
if self.isShooting():
|
||||
self.autoShootTime.stop()
|
||||
self.gameEnded = 1
|
||||
self.repaint()
|
||||
|
||||
def restartGame(self):
|
||||
if self.isShooting():
|
||||
self.autoShootTime.stop()
|
||||
self.gameEnded = 0
|
||||
self.repaint()
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(1,))
|
||||
|
||||
def moveShot(self):
|
||||
r = TQRegion(self.shotRect())
|
||||
self.timerCount = self.timerCount + 1
|
||||
|
||||
shotR = self.shotRect()
|
||||
|
||||
if shotR.intersects(self.targetRect()):
|
||||
self.autoShootTimer.stop()
|
||||
self.emit(PYSIGNAL('hit()'),())
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(1,))
|
||||
elif shotR.x() > self.width() or shotR.y() > self.height():
|
||||
self.autoShootTimer.stop()
|
||||
self.emit(PYSIGNAL('missed()'),())
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(1,))
|
||||
else:
|
||||
r = r.unite(TQRegion(shotR))
|
||||
|
||||
self.repaint(r)
|
||||
|
||||
def paintEvent(self,ev):
|
||||
updateR = ev.rect()
|
||||
p = TQPainter(self)
|
||||
|
||||
if self.gameEnded:
|
||||
p.setPen(TQt.black)
|
||||
p.setFont(TQFont('Courier',48,TQFont.Bold))
|
||||
p.drawText(self.rect(),TQt.AlignCenter,'Game Over')
|
||||
|
||||
if updateR.intersects(self.cannonRect()):
|
||||
self.paintCannon(p)
|
||||
|
||||
if self.isShooting() and updateR.intersects(self.shotRect()):
|
||||
self.paintShot(p)
|
||||
|
||||
if not self.gameEnded and updateR.intersects(self.targetRect()):
|
||||
self.paintTarget(p)
|
||||
|
||||
def paintShot(self,p):
|
||||
p.setBrush(TQt.black)
|
||||
p.setPen(TQt.NoPen)
|
||||
p.drawRect(self.shotRect())
|
||||
|
||||
def paintTarget(self,p):
|
||||
p.setBrush(TQt.red)
|
||||
p.setPen(TQt.black)
|
||||
p.drawRect(self.targetRect())
|
||||
|
||||
def paintCannon(self,p):
|
||||
cr = self.cannonRect()
|
||||
pix = TQPixmap(cr.size())
|
||||
pix.fill(self,cr.topLeft())
|
||||
|
||||
tmp = TQPainter(pix)
|
||||
tmp.setBrush(TQt.blue)
|
||||
tmp.setPen(TQt.NoPen)
|
||||
|
||||
tmp.translate(0,pix.height() - 1)
|
||||
tmp.drawPie(TQRect(-35,-35,70,70),0,90 * 16)
|
||||
tmp.rotate(-self.ang)
|
||||
tmp.drawRect(self.barrelRect)
|
||||
tmp.end()
|
||||
|
||||
p.drawPixmap(cr.topLeft(),pix)
|
||||
|
||||
def cannonRect(self):
|
||||
r = TQRect(0,0,50,50)
|
||||
r.moveBottomLeft(self.rect().bottomLeft())
|
||||
return r
|
||||
|
||||
def shotRect(self):
|
||||
gravity = 4.0
|
||||
|
||||
time = self.timerCount / 4.0
|
||||
velocity = self.shoot_f
|
||||
radians = self.shoot_ang * 3.14159265 / 180
|
||||
|
||||
velx = velocity * math.cos(radians)
|
||||
vely = velocity * math.sin(radians)
|
||||
x0 = (self.barrelRect.right() + 5) * math.cos(radians)
|
||||
y0 = (self.barrelRect.right() + 5) * math.sin(radians)
|
||||
x = x0 + velx * time
|
||||
y = y0 + vely * time - 0.5 * gravity * time * time
|
||||
|
||||
r = TQRect(0,0,6,6)
|
||||
r.moveCenter(TQPoint(int(x),int(self.height() - 1 - y)))
|
||||
return r
|
||||
|
||||
def targetRect(self):
|
||||
r = TQRect(0,0,20,10)
|
||||
r.moveCenter(TQPoint(self.target.x(),self.height() - 1 - self.target.y()))
|
||||
return r
|
||||
|
||||
def isShooting(self):
|
||||
return self.autoShootTimer.isActive()
|
||||
|
||||
def sizePolicy(self):
|
||||
return TQSizePolicy(TQSizePolicy.Expanding,TQSizePolicy.Expanding)
|
||||
|
||||
|
||||
class GameBoard(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton('&Quit',self,'quit')
|
||||
quit.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(quit,SIGNAL('clicked()'),tqApp,SLOT('quit()'))
|
||||
|
||||
self.angle = LCDRange('ANGLE',self,'angle')
|
||||
self.angle.setRange(5,70)
|
||||
|
||||
self.force = LCDRange('FORCE',self,'force')
|
||||
self.force.setRange(10,50)
|
||||
|
||||
self.cannonField = CannonField(self,'cannonField')
|
||||
|
||||
self.connect(self.angle,PYSIGNAL('valueChanged(int)'),self.cannonField.setAngle)
|
||||
self.connect(self.cannonField,PYSIGNAL('angleChanged(int)'),self.angle.setValue)
|
||||
|
||||
self.connect(self.force,PYSIGNAL('valueChanged(int)'),self.cannonField.setForce)
|
||||
self.connect(self.cannonField,PYSIGNAL('forceChanged(int)'),self.force.setValue)
|
||||
|
||||
self.connect(self.cannonField,PYSIGNAL('hit()'),self.hit)
|
||||
self.connect(self.cannonField,PYSIGNAL('missed()'),self.missed)
|
||||
|
||||
self.shoot = TQPushButton('&Shoot',self,'shoot')
|
||||
self.shoot.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(self.shoot,SIGNAL('clicked()'),self.fire)
|
||||
self.connect(self.cannonField,PYSIGNAL('canShoot(bool)'),self.shoot,SLOT('setEnabled(bool)'))
|
||||
|
||||
restart = TQPushButton('&New Game',self,'newgame')
|
||||
restart.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(restart,SIGNAL('clicked()'),self.newGame)
|
||||
|
||||
self.hits = TQLCDNumber(2,self,'hits')
|
||||
self.shotsLeft = TQLCDNumber(2,self,'shotsleft')
|
||||
hitsL = TQLabel('HITS',self,'hitsLabel')
|
||||
shotsLeftL = TQLabel('SHOTS LEFT',self,'shotsleftLabel')
|
||||
|
||||
grid = TQGridLayout(self,2,2,10)
|
||||
grid.addWidget(quit,0,0)
|
||||
grid.addWidget(self.cannonField,1,1)
|
||||
grid.setColStretch(1,10)
|
||||
|
||||
leftBox = TQVBoxLayout()
|
||||
grid.addLayout(leftBox,1,0)
|
||||
leftBox.addWidget(self.angle)
|
||||
leftBox.addWidget(self.force)
|
||||
|
||||
topBox = TQHBoxLayout()
|
||||
grid.addLayout(topBox,0,1)
|
||||
topBox.addWidget(self.shoot)
|
||||
topBox.addWidget(self.hits)
|
||||
topBox.addWidget(hitsL)
|
||||
topBox.addWidget(self.shotsLeft)
|
||||
topBox.addWidget(shotsLeftL)
|
||||
topBox.addStretch(1)
|
||||
topBox.addWidget(restart)
|
||||
|
||||
self.angle.setValue(60)
|
||||
self.force.setValue(25)
|
||||
self.angle.setFocus()
|
||||
|
||||
self.newGame()
|
||||
|
||||
def fire(self):
|
||||
if self.cannonField.gameOver() or self.cannonField.isShooting():
|
||||
return
|
||||
self.shotsLeft.display(self.shotsLeft.intValue() - 1)
|
||||
self.cannonField.shoot()
|
||||
|
||||
def hit(self):
|
||||
self.hits.display(self.hits.intValue() + 1)
|
||||
if self.shotsLeft.intValue() == 0:
|
||||
self.cannonField.setGameOver()
|
||||
else:
|
||||
self.cannonField.newTarget()
|
||||
|
||||
def missed(self):
|
||||
if self.shotsLeft.intValue() == 0:
|
||||
self.cannonField.setGameOver()
|
||||
|
||||
def newGame(self):
|
||||
self.shotsLeft.display(15)
|
||||
self.hits.display(0)
|
||||
self.cannonField.restartGame()
|
||||
self.cannonField.newTarget()
|
||||
|
||||
|
||||
TQApplication.setColorSpec(TQApplication.CustomColor)
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
gb = GameBoard()
|
||||
gb.setGeometry(100,100,500,355)
|
||||
a.setMainWidget(gb)
|
||||
gb.show()
|
||||
a.exec_loop()
|
@ -1,377 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 14.
|
||||
|
||||
import sys
|
||||
import math
|
||||
import random
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQWidget):
|
||||
def __init__(self,s=None,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
|
||||
self.label = TQLabel(' ',self,'label')
|
||||
self.label.setAlignment(TQt.AlignCenter)
|
||||
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
self.setFocusProxy(self.slider)
|
||||
|
||||
l = TQVBoxLayout(self)
|
||||
l.addWidget(lcd,1)
|
||||
l.addWidget(self.slider)
|
||||
l.addWidget(self.label)
|
||||
|
||||
if s is not None:
|
||||
self.setText(s)
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
def setRange(self,minVal,maxVal):
|
||||
if minVal < 0 or maxVal > 99 or minVal > maxVal:
|
||||
raise ValueError('LCDRange.setRange(): invalid range')
|
||||
self.slider.setRange(minVal,maxVal)
|
||||
|
||||
def text(self):
|
||||
return self.label.text()
|
||||
|
||||
def setText(self,s):
|
||||
self.label.setText(s)
|
||||
|
||||
|
||||
class CannonField(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.ang = 45
|
||||
self.f = 0
|
||||
self.timerCount = 0
|
||||
|
||||
self.autoShootTimer = TQTimer(self,'movement handler')
|
||||
self.connect(self.autoShootTimer,SIGNAL('timeout()'),self.moveShot)
|
||||
|
||||
self.shoot_ang = 0
|
||||
self.shoot_f = 0
|
||||
self.target = TQPoint(0,0)
|
||||
self.gameEnded = 0
|
||||
self.barrelPressed = 0
|
||||
|
||||
self.setPalette(TQPalette(TQColor(250,250,200)))
|
||||
|
||||
self.barrelRect = TQRect(33,-4,15,8)
|
||||
|
||||
self.newTarget()
|
||||
|
||||
def angle(self):
|
||||
return self.ang
|
||||
|
||||
def setAngle(self,degrees):
|
||||
if degrees < 5:
|
||||
degrees = 5
|
||||
if degrees > 70:
|
||||
degrees = 70
|
||||
if self.ang == degrees:
|
||||
return
|
||||
self.ang = degrees
|
||||
self.repaint(self.cannonRect(),0)
|
||||
self.emit(PYSIGNAL('angleChanged(int)'),(self.ang,))
|
||||
|
||||
def force(self):
|
||||
return self.f
|
||||
|
||||
def setForce(self,newton):
|
||||
if newton < 0:
|
||||
newton = 0
|
||||
if self.f == newton:
|
||||
return
|
||||
self.f = newton
|
||||
self.emit(PYSIGNAL('forceChanged(int)'),(self.f,))
|
||||
|
||||
def shoot(self):
|
||||
if self.isShooting():
|
||||
return
|
||||
|
||||
self.timerCount = 0
|
||||
self.shoot_ang = self.ang
|
||||
self.shoot_f = self.f
|
||||
self.autoShootTimer.start(50)
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(0,))
|
||||
|
||||
def newTarget(self):
|
||||
r = TQRegion(self.targetRect())
|
||||
self.target = TQPoint(random.randint(200,390),random.randint(10,265))
|
||||
self.repaint(r.unite(TQRegion(self.targetRect())))
|
||||
|
||||
def gameOver(self):
|
||||
return self.gameEnded
|
||||
|
||||
def setGameOver(self):
|
||||
if self.gameEnded:
|
||||
return
|
||||
if self.isShooting():
|
||||
self.autoShootTime.stop()
|
||||
self.gameEnded = 1
|
||||
self.repaint()
|
||||
|
||||
def restartGame(self):
|
||||
if self.isShooting():
|
||||
self.autoShootTime.stop()
|
||||
self.gameEnded = 0
|
||||
self.repaint()
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(1,))
|
||||
|
||||
def moveShot(self):
|
||||
r = TQRegion(self.shotRect())
|
||||
self.timerCount = self.timerCount + 1
|
||||
|
||||
shotR = self.shotRect()
|
||||
|
||||
if shotR.intersects(self.targetRect()):
|
||||
self.autoShootTimer.stop()
|
||||
self.emit(PYSIGNAL('hit()'),())
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(1,))
|
||||
elif shotR.x() > self.width() or shotR.y() > self.height() or shotR.intersects(self.barrierRect()):
|
||||
self.autoShootTimer.stop()
|
||||
self.emit(PYSIGNAL('missed()'),())
|
||||
self.emit(PYSIGNAL('canShoot(bool)'),(1,))
|
||||
else:
|
||||
r = r.unite(TQRegion(shotR))
|
||||
|
||||
self.repaint(r)
|
||||
|
||||
def mousePressEvent(self,ev):
|
||||
if ev.button() != TQt.LeftButton:
|
||||
return
|
||||
if self.barrelHit(ev.pos()):
|
||||
self.barrelPressed = 1
|
||||
|
||||
def mouseMoveEvent(self,ev):
|
||||
if not self.barrelPressed:
|
||||
return
|
||||
pnt = ev.pos()
|
||||
if pnt.x() <= 0:
|
||||
pnt.setX(1)
|
||||
if pnt.y() >= self.height():
|
||||
pnt.setY(self.height() - 1)
|
||||
rad = math.atan(float(self.rect().bottom() - pnt.y()) / pnt.x())
|
||||
self.setAngle(int(round(rad * 180 / math.pi)))
|
||||
|
||||
def mouseReleaseEvent(self,ev):
|
||||
if ev.button() == TQt.LeftButton:
|
||||
self.barrelPressed = 0
|
||||
|
||||
def paintEvent(self,ev):
|
||||
updateR = ev.rect()
|
||||
p = TQPainter(self)
|
||||
|
||||
if self.gameEnded:
|
||||
p.setPen(TQt.black)
|
||||
p.setFont(TQFont('Courier',48,TQFont.Bold))
|
||||
p.drawText(self.rect(),TQt.AlignCenter,'Game Over')
|
||||
|
||||
if updateR.intersects(self.cannonRect()):
|
||||
self.paintCannon(p)
|
||||
|
||||
if updateR.intersects(self.barrierRect()):
|
||||
self.paintBarrier(p)
|
||||
|
||||
if self.isShooting() and updateR.intersects(self.shotRect()):
|
||||
self.paintShot(p)
|
||||
|
||||
if not self.gameEnded and updateR.intersects(self.targetRect()):
|
||||
self.paintTarget(p)
|
||||
|
||||
def paintShot(self,p):
|
||||
p.setBrush(TQt.black)
|
||||
p.setPen(TQt.NoPen)
|
||||
p.drawRect(self.shotRect())
|
||||
|
||||
def paintTarget(self,p):
|
||||
p.setBrush(TQt.red)
|
||||
p.setPen(TQt.black)
|
||||
p.drawRect(self.targetRect())
|
||||
|
||||
def paintBarrier(self,p):
|
||||
p.setBrush(TQt.yellow)
|
||||
p.setPen(TQt.black)
|
||||
p.drawRect(self.barrierRect())
|
||||
|
||||
def paintCannon(self,p):
|
||||
cr = self.cannonRect()
|
||||
pix = TQPixmap(cr.size())
|
||||
pix.fill(self,cr.topLeft())
|
||||
|
||||
tmp = TQPainter(pix)
|
||||
tmp.setBrush(TQt.blue)
|
||||
tmp.setPen(TQt.NoPen)
|
||||
|
||||
tmp.translate(0,pix.height() - 1)
|
||||
tmp.drawPie(TQRect(-35,-35,70,70),0,90 * 16)
|
||||
tmp.rotate(-self.ang)
|
||||
tmp.drawRect(self.barrelRect)
|
||||
tmp.end()
|
||||
|
||||
p.drawPixmap(cr.topLeft(),pix)
|
||||
|
||||
def cannonRect(self):
|
||||
r = TQRect(0,0,50,50)
|
||||
r.moveBottomLeft(self.rect().bottomLeft())
|
||||
return r
|
||||
|
||||
def shotRect(self):
|
||||
gravity = 4.0
|
||||
|
||||
time = self.timerCount / 4.0
|
||||
velocity = self.shoot_f
|
||||
radians = self.shoot_ang * math.pi / 180
|
||||
|
||||
velx = velocity * math.cos(radians)
|
||||
vely = velocity * math.sin(radians)
|
||||
x0 = (self.barrelRect.right() + 5) * math.cos(radians)
|
||||
y0 = (self.barrelRect.right() + 5) * math.sin(radians)
|
||||
x = x0 + velx * time
|
||||
y = y0 + vely * time - 0.5 * gravity * time * time
|
||||
|
||||
r = TQRect(0,0,6,6)
|
||||
r.moveCenter(TQPoint(int(x),int(self.height() - 1 - y)))
|
||||
return r
|
||||
|
||||
def targetRect(self):
|
||||
r = TQRect(0,0,20,10)
|
||||
r.moveCenter(TQPoint(self.target.x(),self.height() - 1 - self.target.y()))
|
||||
return r
|
||||
|
||||
def barrierRect(self):
|
||||
return TQRect(145,self.height() - 100,15,100)
|
||||
|
||||
def barrelHit(self,p):
|
||||
mtx = TQWMatrix()
|
||||
mtx.translate(0,self.height() - 1)
|
||||
mtx.rotate(-self.ang)
|
||||
(mtx, invertable) = mtx.invert()
|
||||
return self.barrelRect.contains(mtx.map(p))
|
||||
|
||||
def isShooting(self):
|
||||
return self.autoShootTimer.isActive()
|
||||
|
||||
def sizePolicy(self):
|
||||
return TQSizePolicy(TQSizePolicy.Expanding,TQSizePolicy.Expanding)
|
||||
|
||||
|
||||
class GameBoard(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton('&Quit',self,'quit')
|
||||
quit.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(quit,SIGNAL('clicked()'),tqApp,SLOT('quit()'))
|
||||
|
||||
self.angle = LCDRange('ANGLE',self,'angle')
|
||||
self.angle.setRange(5,70)
|
||||
|
||||
self.force = LCDRange('FORCE',self,'force')
|
||||
self.force.setRange(10,50)
|
||||
|
||||
box = TQVBox(self,'cannonFrame')
|
||||
box.setFrameStyle(TQFrame.WinPanel | TQFrame.Sunken)
|
||||
|
||||
self.cannonField = CannonField(box,'cannonField')
|
||||
|
||||
self.connect(self.angle,PYSIGNAL('valueChanged(int)'),self.cannonField.setAngle)
|
||||
self.connect(self.cannonField,PYSIGNAL('angleChanged(int)'),self.angle.setValue)
|
||||
|
||||
self.connect(self.force,PYSIGNAL('valueChanged(int)'),self.cannonField.setForce)
|
||||
self.connect(self.cannonField,PYSIGNAL('forceChanged(int)'),self.force.setValue)
|
||||
|
||||
self.connect(self.cannonField,PYSIGNAL('hit()'),self.hit)
|
||||
self.connect(self.cannonField,PYSIGNAL('missed()'),self.missed)
|
||||
|
||||
self.shoot = TQPushButton('&Shoot',self,'shoot')
|
||||
self.shoot.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(self.shoot,SIGNAL('clicked()'),self.fire)
|
||||
self.connect(self.cannonField,PYSIGNAL('canShoot(bool)'),self.shoot,SLOT('setEnabled(bool)'))
|
||||
|
||||
restart = TQPushButton('&New Game',self,'newgame')
|
||||
restart.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(restart,SIGNAL('clicked()'),self.newGame)
|
||||
|
||||
self.hits = TQLCDNumber(2,self,'hits')
|
||||
self.shotsLeft = TQLCDNumber(2,self,'shotsleft')
|
||||
hitsL = TQLabel('HITS',self,'hitsLabel')
|
||||
shotsLeftL = TQLabel('SHOTS LEFT',self,'shotsleftLabel')
|
||||
|
||||
accel = TQAccel(self)
|
||||
accel.connectItem(accel.insertItem(TQt.Key_Enter),self.fire)
|
||||
accel.connectItem(accel.insertItem(TQt.Key_Return),self.fire)
|
||||
accel.connectItem(accel.insertItem(TQt.CTRL + TQt.Key_Q),tqApp,SLOT('quit()'))
|
||||
|
||||
grid = TQGridLayout(self,2,2,10)
|
||||
grid.addWidget(quit,0,0)
|
||||
grid.addWidget(box,1,1)
|
||||
grid.setColStretch(1,10)
|
||||
|
||||
leftBox = TQVBoxLayout()
|
||||
grid.addLayout(leftBox,1,0)
|
||||
leftBox.addWidget(self.angle)
|
||||
leftBox.addWidget(self.force)
|
||||
|
||||
topBox = TQHBoxLayout()
|
||||
grid.addLayout(topBox,0,1)
|
||||
topBox.addWidget(self.shoot)
|
||||
topBox.addWidget(self.hits)
|
||||
topBox.addWidget(hitsL)
|
||||
topBox.addWidget(self.shotsLeft)
|
||||
topBox.addWidget(shotsLeftL)
|
||||
topBox.addStretch(1)
|
||||
topBox.addWidget(restart)
|
||||
|
||||
self.angle.setValue(60)
|
||||
self.force.setValue(25)
|
||||
self.angle.setFocus()
|
||||
|
||||
self.newGame()
|
||||
|
||||
def fire(self):
|
||||
if self.cannonField.gameOver() or self.cannonField.isShooting():
|
||||
return
|
||||
self.shotsLeft.display(self.shotsLeft.intValue() - 1)
|
||||
self.cannonField.shoot()
|
||||
|
||||
def hit(self):
|
||||
self.hits.display(self.hits.intValue() + 1)
|
||||
if self.shotsLeft.intValue() == 0:
|
||||
self.cannonField.setGameOver()
|
||||
else:
|
||||
self.cannonField.newTarget()
|
||||
|
||||
def missed(self):
|
||||
if self.shotsLeft.intValue() == 0:
|
||||
self.cannonField.setGameOver()
|
||||
|
||||
def newGame(self):
|
||||
self.shotsLeft.display(15)
|
||||
self.hits.display(0)
|
||||
self.cannonField.restartGame()
|
||||
self.cannonField.newTarget()
|
||||
|
||||
|
||||
TQApplication.setColorSpec(TQApplication.CustomColor)
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
gb = GameBoard()
|
||||
gb.setGeometry(100,100,500,355)
|
||||
a.setMainWidget(gb)
|
||||
gb.show()
|
||||
a.exec_loop()
|
@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 2.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
quit = TQPushButton("Quit",None)
|
||||
quit.resize(75,30)
|
||||
quit.setFont(TQFont("Times",18,TQFont.Bold))
|
||||
|
||||
TQObject.connect(quit,SIGNAL("clicked()"),a,SLOT("quit()"))
|
||||
|
||||
a.setMainWidget(quit)
|
||||
quit.show()
|
||||
a.exec_loop()
|
@ -1,20 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 3.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
box = TQVBox()
|
||||
box.resize(200,120)
|
||||
|
||||
quit = TQPushButton("Quit",box)
|
||||
quit.setFont(TQFont("Times",18,TQFont.Bold))
|
||||
|
||||
TQObject.connect(quit,SIGNAL("clicked()"),a,SLOT("quit()"))
|
||||
|
||||
a.setMainWidget(box)
|
||||
box.show()
|
||||
a.exec_loop()
|
@ -1,29 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 4.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class MyWidget(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.setMinimumSize(200,120)
|
||||
self.setMaximumSize(200,120)
|
||||
|
||||
quit = TQPushButton("Quit",self,"quit")
|
||||
quit.setGeometry(62,40,75,30)
|
||||
quit.setFont(TQFont("Times",18,TQFont.Bold))
|
||||
|
||||
self.connect(quit,SIGNAL("clicked()"),tqApp,SLOT("quit()"))
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
w.setGeometry(100,100,200,120)
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 5.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class MyWidget(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton("Quit",self,"quit")
|
||||
quit.setFont(TQFont("Times",18,TQFont.Bold))
|
||||
|
||||
self.connect(quit,SIGNAL("clicked()"),tqApp,SLOT("quit()"))
|
||||
|
||||
lcd = TQLCDNumber(2,self,"lcd")
|
||||
|
||||
slider = TQSlider(TQt.Horizontal,self,"slider")
|
||||
slider.setRange(0,99)
|
||||
slider.setValue(0)
|
||||
|
||||
self.connect(slider,SIGNAL("valueChanged(int)"),lcd,SLOT("display(int)"))
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,41 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 6.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,"lcd")
|
||||
slider = TQSlider(TQt.Horizontal,self,"slider")
|
||||
slider.setRange(0,99)
|
||||
slider.setValue(0)
|
||||
self.connect(slider,SIGNAL("valueChanged(int)"),lcd,SLOT("display(int)"))
|
||||
|
||||
|
||||
class MyWidget(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton("Quit",self,"quit")
|
||||
quit.setFont(TQFont("Times",18,TQFont.Bold))
|
||||
|
||||
self.connect(quit,SIGNAL("clicked()"),tqApp,SLOT("quit()"))
|
||||
|
||||
grid = TQGrid(4,self)
|
||||
|
||||
for c in range(4):
|
||||
for r in range(4):
|
||||
LCDRange(grid)
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 7.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
|
||||
class MyWidget(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton("Quit",self,"quit")
|
||||
quit.setFont(TQFont("Times",18,TQFont.Bold))
|
||||
|
||||
self.connect(quit,SIGNAL("clicked()"),tqApp,SLOT("quit()"))
|
||||
|
||||
grid = TQGrid(4,self)
|
||||
|
||||
self.lcdlist = []
|
||||
previous = None
|
||||
|
||||
for r in range(4):
|
||||
for c in range(4):
|
||||
lr = LCDRange(grid)
|
||||
|
||||
if previous is not None:
|
||||
self.connect(lr,PYSIGNAL("valueChanged(int)"),previous.setValue)
|
||||
|
||||
previous = lr
|
||||
self.lcdlist.append(lr)
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,96 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 8.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
self.setFocusProxy(self.slider)
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
def setRange(self,minVal,maxVal):
|
||||
if minVal < 0 or maxVal > 99 or minVal > maxVal:
|
||||
raise ValueError('LCDRange.setRange(): invalid range')
|
||||
self.slider.setRange(minVal,maxVal)
|
||||
|
||||
|
||||
class CannonField(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.ang = 45
|
||||
self.setPalette(TQPalette(TQColor(250,250,200)))
|
||||
|
||||
def angle(self):
|
||||
return self.ang
|
||||
|
||||
def setAngle(self,degrees):
|
||||
if degrees < 5:
|
||||
degrees = 5
|
||||
if degrees > 70:
|
||||
degrees = 70
|
||||
if self.ang == degrees:
|
||||
return
|
||||
self.ang = degrees
|
||||
self.repaint()
|
||||
self.emit(PYSIGNAL('angleChanged(int)'),(self.ang,))
|
||||
|
||||
def paintEvent(self,ev):
|
||||
p = TQPainter(self)
|
||||
p.drawText(200,200,'Angle = %d' % (self.ang))
|
||||
|
||||
def sizePolicy(self):
|
||||
return TQSizePolicy(TQSizePolicy.Expanding,TQSizePolicy.Expanding)
|
||||
|
||||
|
||||
class MyWidget(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton('Quit',self,'quit')
|
||||
quit.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(quit,SIGNAL('clicked()'),tqApp,SLOT('quit()'))
|
||||
|
||||
self.angle = LCDRange(self,'angle')
|
||||
self.angle.setRange(5,70)
|
||||
|
||||
self.cannonField = CannonField(self,'cannonField')
|
||||
|
||||
self.connect(self.angle,PYSIGNAL('valueChanged(int)'),self.cannonField.setAngle)
|
||||
self.connect(self.cannonField,PYSIGNAL('angleChanged(int)'),self.angle.setValue)
|
||||
|
||||
grid = TQGridLayout(self,2,2,10)
|
||||
|
||||
grid.addWidget(quit,0,0)
|
||||
grid.addWidget(self.angle,1,0,TQt.AlignTop)
|
||||
grid.addWidget(self.cannonField,1,1)
|
||||
grid.setColStretch(1,10)
|
||||
|
||||
self.angle.setValue(60)
|
||||
self.angle.setFocus()
|
||||
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
w.setGeometry(100,100,500,355)
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,104 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# TQt tutorial 9.
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class LCDRange(TQVBox):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQVBox.__init__(self,parent,name)
|
||||
|
||||
lcd = TQLCDNumber(2,self,'lcd')
|
||||
self.slider = TQSlider(TQt.Horizontal,self,'slider')
|
||||
self.slider.setRange(0,99)
|
||||
self.slider.setValue(0)
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),lcd,SLOT('display(int)'))
|
||||
self.connect(self.slider,SIGNAL('valueChanged(int)'),self,PYSIGNAL('valueChanged(int)'))
|
||||
|
||||
self.setFocusProxy(self.slider)
|
||||
|
||||
def value(self):
|
||||
return self.slider.value()
|
||||
|
||||
def setValue(self,value):
|
||||
self.slider.setValue(value)
|
||||
|
||||
def setRange(self,minVal,maxVal):
|
||||
if minVal < 0 or maxVal > 99 or minVal > maxVal:
|
||||
raise ValueError('LCDRange.setRange(): invalid range')
|
||||
self.slider.setRange(minVal,maxVal)
|
||||
|
||||
|
||||
class CannonField(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
self.ang = 45
|
||||
self.setPalette(TQPalette(TQColor(250,250,200)))
|
||||
|
||||
def angle(self):
|
||||
return self.ang
|
||||
|
||||
def setAngle(self,degrees):
|
||||
if degrees < 5:
|
||||
degrees = 5
|
||||
if degrees > 70:
|
||||
degrees = 70
|
||||
if self.ang == degrees:
|
||||
return
|
||||
self.ang = degrees
|
||||
self.repaint()
|
||||
self.emit(PYSIGNAL('angleChanged(int)'),(self.ang,))
|
||||
|
||||
def paintEvent(self,ev):
|
||||
p = TQPainter(self)
|
||||
|
||||
p.setBrush(TQt.blue)
|
||||
p.setPen(TQt.NoPen)
|
||||
|
||||
p.translate(0,self.rect().bottom())
|
||||
p.drawPie(TQRect(-35,-35,70,70),0,90 * 16)
|
||||
p.rotate(-self.ang)
|
||||
p.drawRect(TQRect(33,-4,15,8))
|
||||
|
||||
def sizePolicy(self):
|
||||
return TQSizePolicy(TQSizePolicy.Expanding,TQSizePolicy.Expanding)
|
||||
|
||||
|
||||
class MyWidget(TQWidget):
|
||||
def __init__(self,parent=None,name=None):
|
||||
TQWidget.__init__(self,parent,name)
|
||||
|
||||
quit = TQPushButton('&Quit',self,'quit')
|
||||
quit.setFont(TQFont('Times',18,TQFont.Bold))
|
||||
self.connect(quit,SIGNAL('clicked()'),tqApp,SLOT('quit()'))
|
||||
|
||||
self.angle = LCDRange(self,'angle')
|
||||
self.angle.setRange(5,70)
|
||||
|
||||
self.cannonField = CannonField(self,'cannonField')
|
||||
|
||||
self.connect(self.angle,PYSIGNAL('valueChanged(int)'),self.cannonField.setAngle)
|
||||
self.connect(self.cannonField,PYSIGNAL('angleChanged(int)'),self.angle.setValue)
|
||||
|
||||
grid = TQGridLayout(self,2,2,10)
|
||||
|
||||
grid.addWidget(quit,0,0)
|
||||
grid.addWidget(self.angle,1,0,TQt.AlignTop)
|
||||
grid.addWidget(self.cannonField,1,1)
|
||||
grid.setColStretch(1,10)
|
||||
|
||||
self.angle.setValue(60)
|
||||
self.angle.setFocus()
|
||||
|
||||
|
||||
TQApplication.setColorSpec(TQApplication.CustomColor)
|
||||
a = TQApplication(sys.argv)
|
||||
|
||||
w = MyWidget()
|
||||
w.setGeometry(100,100,500,355)
|
||||
a.setMainWidget(w)
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,512 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import sys, string
|
||||
from python_tqt.qt import *
|
||||
|
||||
#
|
||||
## Constructs an analog clock widget that uses an internal TQTimer.
|
||||
#
|
||||
def TQMIN( x, y ):
|
||||
if y > x:
|
||||
return y
|
||||
return x
|
||||
|
||||
#
|
||||
## Constructs an analog clock widget that uses an internal TQTimer.
|
||||
#
|
||||
|
||||
class AnalogClock( TQWidget ):
|
||||
def __init__( self, *args ):
|
||||
TQWidget.__init__(*(self,) + args)
|
||||
self.time = TQTime.currentTime() # get current time
|
||||
internalTimer = TQTimer( self ) # create internal timer
|
||||
self.connect( internalTimer, SIGNAL("timeout()"), self.timeout )
|
||||
internalTimer.start( 5000 ) # emit signal every 5 seconds
|
||||
|
||||
#
|
||||
## The TQTimer::timeout() signal is received by this slot.
|
||||
#
|
||||
|
||||
def timeout( self ):
|
||||
new_time = TQTime.currentTime() # get the current time
|
||||
if new_time.minute() != self.time.minute(): # minute has changed
|
||||
self.update()
|
||||
|
||||
#
|
||||
## The clock is painted using a 1000x1000 square coordinate system.
|
||||
#
|
||||
def paintEvent( self, qe ): # paint clock
|
||||
if not self.isVisible(): # is is invisible
|
||||
return
|
||||
self.time = TQTime.currentTime() # save current time
|
||||
|
||||
pts = TQPointArray()
|
||||
paint = TQPainter( self )
|
||||
paint.setBrush( self.foregroundColor() ) # fill with foreground color
|
||||
|
||||
cp = TQPoint( self.rect().center() ) # widget center point
|
||||
d = TQMIN( self.width(), self.height() ) # we want a circular clock
|
||||
|
||||
matrix = TQWMatrix() # setup transformation matrix
|
||||
matrix.translate( cp.x(), cp.y() ) # origin at widget center
|
||||
matrix.scale( d / 1000.0, d / 1000.0 ) # scale coordinate system
|
||||
|
||||
h_angle = 30 * ( self.time.hour() % 12 - 3 ) + self.time.minute() / 2
|
||||
matrix.rotate( h_angle ) # rotate to draw hour hand
|
||||
paint.setWorldMatrix( matrix )
|
||||
pts.setPoints( [ -20,0, 0,-20, 300,0, 0,20 ] )
|
||||
paint.drawPolygon( pts ) # draw hour hand
|
||||
matrix.rotate( -h_angle ) # rotate back to zero
|
||||
|
||||
m_angle = ( self.time.minute() - 15 ) * 6
|
||||
matrix.rotate( m_angle ) # rotate to draw minute hand
|
||||
paint.setWorldMatrix( matrix )
|
||||
pts.setPoints( [ -10,0, 0,-10, 400,0, 0,10 ] )
|
||||
paint.drawPolygon( pts ) # draw minute hand
|
||||
matrix.rotate( -m_angle ) # rotate back to zero
|
||||
|
||||
for i in range( 0, 12 ): # draw hour lines
|
||||
paint.setWorldMatrix( matrix )
|
||||
paint.drawLine( 450,0, 500,0 )
|
||||
matrix.rotate( 30 )
|
||||
|
||||
|
||||
class DigitalClock( TQLCDNumber ):
|
||||
def __init__( self, *args ):
|
||||
TQLCDNumber.__init__(*(self,) + args)
|
||||
self.showingColon = 0
|
||||
self.setFrameStyle(TQFrame.Panel | TQFrame.Raised)
|
||||
self.setLineWidth( 2 )
|
||||
self.showTime()
|
||||
self.normalTimer = self.startTimer( 500 )
|
||||
self.showDateTimer = -1
|
||||
|
||||
def timerEvent( self, e ):
|
||||
if e.timerId() == self.showDateTimer:
|
||||
self.stopDate()
|
||||
else:
|
||||
if self.showDateTimer == -1:
|
||||
self.showTime()
|
||||
|
||||
def mousePressEvent( self, e ):
|
||||
if e.button() == TQt.LeftButton:
|
||||
self.showDate()
|
||||
|
||||
def showDate( self ):
|
||||
if self.showDateTimer != -1:
|
||||
return
|
||||
d = TQDate.currentDate()
|
||||
self.display('%2d %2d' % (d.month(), d.day()))
|
||||
self.showDateTimer = self.startTimer(2000)
|
||||
|
||||
def stopDate( self ):
|
||||
self.killTimer(self.showDateTimer)
|
||||
self.showDateTimer = -1
|
||||
self.showTime()
|
||||
|
||||
def showTime( self ):
|
||||
self.showingColon = not self.showingColon
|
||||
s = list(str(TQTime.currentTime().toString())[:5]) #.left(5)
|
||||
if not self.showingColon:
|
||||
s[2] = ' '
|
||||
if s[0] == '0':
|
||||
s[0] = ' '
|
||||
s = ''.join(s)
|
||||
self.display( s )
|
||||
|
||||
def TQMIN( x, y ):
|
||||
if y > x:
|
||||
return y
|
||||
return x
|
||||
|
||||
TRUE = 1
|
||||
FALSE = 0
|
||||
MOVIEFILENAME = "trolltech.gif"
|
||||
|
||||
#
|
||||
# WidgetView contains lots of TQt widgets.
|
||||
#
|
||||
|
||||
class WidgetView ( TQWidget ):
|
||||
def __init__( self, *args ):
|
||||
TQWidget.__init__(*(self,) + args)
|
||||
|
||||
# Set the window caption/title
|
||||
self.setCaption( "TQt Widgets Demo Application" )
|
||||
|
||||
# Install an application-global event filter
|
||||
tqApp.installEventFilter( self )
|
||||
|
||||
# Create a layout to position the widgets
|
||||
self.topLayout = TQVBoxLayout( self, 10 )
|
||||
|
||||
# Create a grid layout to hold most of the widgets
|
||||
self.grid = TQGridLayout( 6, 3 )
|
||||
|
||||
# This layout will get all of the stretch
|
||||
self.topLayout.addLayout( self.grid, 10 )
|
||||
|
||||
# Create a menubar
|
||||
self.menubar = TQMenuBar( self )
|
||||
#self.menubar.setSeparator( TQMenuBar.InWindowsStyle )
|
||||
self.menubar.setSeparator( 1 )
|
||||
|
||||
# Create an easter egg
|
||||
TQToolTip.add( self.menubar, TQRect( 0, 0, 2, 2 ), "easter egg" )
|
||||
|
||||
self.popup = TQPopupMenu()
|
||||
self.id = self.popup.insertItem( "&New" )
|
||||
self.popup.setItemEnabled( self.id, FALSE )
|
||||
self.id = self.popup.insertItem( "&Open" )
|
||||
self.popup.setItemEnabled( self.id, FALSE )
|
||||
self.popup.insertSeparator()
|
||||
self.popup.insertItem( "&Quit", tqApp, SLOT("quit()"), TQt.CTRL+TQt.Key_Q )
|
||||
|
||||
self.menubar.insertItem( "&File", self.popup )
|
||||
|
||||
# Must tell the layout about a menubar in a widget
|
||||
self.topLayout.setMenuBar( self.menubar )
|
||||
|
||||
# Create an analog and a digital clock
|
||||
self.aclock = AnalogClock( self )
|
||||
self.aclock.resize( 50, 50 )
|
||||
self.dclock = DigitalClock( self )
|
||||
self.dclock.setMaximumWidth( 200 )
|
||||
self.grid.addWidget( self.aclock, 0, 2 )
|
||||
self.grid.addWidget( self.dclock, 1, 2 )
|
||||
|
||||
# Give the dclock widget a blue palette
|
||||
col = TQColor()
|
||||
col.setRgb( 0xaa, 0xbe, 0xff )
|
||||
self.dclock.setPalette( TQPalette( col ) )
|
||||
|
||||
# make tool tips for both of them
|
||||
TQToolTip.add( self.aclock, "custom widget: analog clock" )
|
||||
TQToolTip.add( self.dclock, "custom widget: digital clock" )
|
||||
|
||||
# Create a push button.
|
||||
self.pb = TQPushButton( self, "button1" ) # create button 1
|
||||
self.pb.setText( "Push button 1" )
|
||||
self.pb.setFixedHeight( self.pb.sizeHint().height() )
|
||||
self.grid.addWidget( self.pb, 0, 0, TQt.AlignVCenter )
|
||||
self.connect( self.pb, SIGNAL("clicked()"), self.button1Clicked )
|
||||
TQToolTip.add( self.pb, "push button 1" )
|
||||
self.pm = TQPixmap()
|
||||
self.pix = self.pm.load( "qt.png" ) # load pixmap for button 2
|
||||
if not self.pix:
|
||||
TQMessageBox.information( None, "TQt Widgets Example",
|
||||
"Could not load the file \"qt.png\", which\n"
|
||||
"contains an icon used...\n\n"
|
||||
"The text \"line 42\" will be substituted.",
|
||||
TQMessageBox.Ok + TQMessageBox.Default )
|
||||
|
||||
# Create a label containing a TQMovie
|
||||
self.movielabel = TQLabel( self, "label0" )
|
||||
self.movie = TQMovie( MOVIEFILENAME )
|
||||
self.movie.connectStatus( self.movieStatus )
|
||||
self.movie.connectUpdate( self.movieUpdate )
|
||||
self.movielabel.setFrameStyle( TQFrame.Box | TQFrame.Plain )
|
||||
self.movielabel.setMovie( self.movie )
|
||||
self.movielabel.setMargin( 0 )
|
||||
self.movielabel.setFixedSize( 128 + self.movielabel.frameWidth() * 2,
|
||||
64 + self.movielabel.frameWidth() * 2 )
|
||||
self.grid.addWidget( self.movielabel, 0, 1, TQt.AlignCenter )
|
||||
TQToolTip.add( self.movielabel, "movie" )
|
||||
|
||||
# Create a group of check boxes
|
||||
self.bg = TQButtonGroup( self, "checkGroup" )
|
||||
self.bg.setTitle( "Check Boxes" )
|
||||
self.grid.addWidget( self.bg, 1, 0 )
|
||||
|
||||
# Create a layout for the check boxes
|
||||
self.vbox = TQVBoxLayout(self.bg, 10)
|
||||
|
||||
self.vbox.addSpacing( self.bg.fontMetrics().height() )
|
||||
|
||||
self.cb = list(range(3))
|
||||
self.cb[0] = TQCheckBox( self.bg )
|
||||
self.cb[0].setText( "Read" )
|
||||
self.vbox.addWidget( self.cb[0] )
|
||||
self.cb[0].setMinimumSize( self.cb[0].sizeHint() )
|
||||
self.cb[1] = TQCheckBox( self.bg )
|
||||
self.cb[1].setText( "Write" )
|
||||
self.vbox.addWidget( self.cb[1] )
|
||||
self.cb[1].setMinimumSize( self.cb[1].sizeHint() )
|
||||
self.cb[2] = TQCheckBox( self.bg )
|
||||
self.cb[2].setText( "Execute" )
|
||||
self.cb[2].setMinimumSize( self.cb[2].sizeHint() )
|
||||
self.vbox.addWidget( self.cb[2] )
|
||||
self.bg.setMinimumSize( self.bg.childrenRect().size() )
|
||||
self.vbox.activate()
|
||||
|
||||
self.connect( self.bg, SIGNAL("clicked(int)"), self.checkBoxClicked )
|
||||
|
||||
TQToolTip.add( self.cb[0], "check box 1" )
|
||||
TQToolTip.add( self.cb[1], "check box 2" )
|
||||
TQToolTip.add( self.cb[2], "check box 3" )
|
||||
|
||||
# Create a group of radio buttons
|
||||
self.bg = TQButtonGroup( self, "radioGroup" )
|
||||
self.bg.setTitle( "Radio buttons" )
|
||||
|
||||
self.grid.addWidget( self.bg, 1, 1 )
|
||||
|
||||
# Create a layout for the radio buttons
|
||||
self.vbox = TQVBoxLayout( self.bg, 10 )
|
||||
|
||||
self.vbox.addSpacing( self.bg.fontMetrics().height() )
|
||||
self.rb = TQRadioButton( self.bg )
|
||||
self.rb.setText( "&AM" )
|
||||
self.rb.setChecked( TRUE )
|
||||
self.vbox.addWidget( self.rb )
|
||||
self.rb.setMinimumSize( self.rb.sizeHint() )
|
||||
TQToolTip.add( self.rb, "radio button 1" )
|
||||
self.rb = TQRadioButton( self.bg )
|
||||
self.rb.setText( "&FM" )
|
||||
self.vbox.addWidget( self.rb )
|
||||
self.rb.setMinimumSize( self.rb.sizeHint() )
|
||||
TQToolTip.add( self.rb, "radio button 2" )
|
||||
self.rb = TQRadioButton( self.bg )
|
||||
self.rb.setText( "&Short Wave" )
|
||||
self.vbox.addWidget( self.rb )
|
||||
self.rb.setMinimumSize( self.rb.sizeHint() )
|
||||
self.vbox.activate()
|
||||
|
||||
self.connect( self.bg, SIGNAL("clicked(int)"), self.radioButtonClicked )
|
||||
TQToolTip.add( self.rb, "radio button 3" )
|
||||
|
||||
# Create a list box
|
||||
self.lb = TQListBox( self, "listBox" )
|
||||
for i in range( 0, 100, 1 ): # fill list box
|
||||
txt = TQString()
|
||||
txt = "line %d" % i
|
||||
if i == 42 and self.pix:
|
||||
self.lb.insertItem( self.pm )
|
||||
else:
|
||||
self.lb.insertItem( txt )
|
||||
|
||||
self.grid.addMultiCellWidget( self.lb, 2, 4, 0, 0 )
|
||||
self.connect( self.lb, SIGNAL("selected(int)"), self.listBoxItemSelected )
|
||||
TQToolTip.add( self.lb, "list box" )
|
||||
|
||||
self.vbox = TQVBoxLayout( 8 )
|
||||
self.grid.addLayout( self.vbox, 2, 1 )
|
||||
|
||||
# Create a slider
|
||||
self.sb = TQSlider( 0, 300, 1, 100, TQSlider.Horizontal, self, "Slider" )
|
||||
#self.sb.setTickmarks( TQSlider.Below )
|
||||
self.sb.setTickmarks( 1 )
|
||||
self.sb.setTickInterval( 10 )
|
||||
#self.sb.setFocusPolicy( TQWidget.TabFocus )
|
||||
self.sb.setFocusPolicy( 1 )
|
||||
self.sb.setFixedHeight( self.sb.sizeHint().height() )
|
||||
self.vbox.addWidget( self.sb )
|
||||
|
||||
self.connect( self.sb, SIGNAL("valueChanged(int)"), self.sliderValueChanged )
|
||||
TQToolTip.add( self.sb, "slider" )
|
||||
|
||||
# Create a combo box
|
||||
self.combo = TQComboBox( FALSE, self, "comboBox" )
|
||||
self.combo.insertItem( "darkBlue" )
|
||||
self.combo.insertItem( "darkRed" )
|
||||
self.combo.insertItem( "darkGreen" )
|
||||
self.combo.insertItem( "blue" )
|
||||
self.combo.insertItem( "red" )
|
||||
self.combo.setFixedHeight( self.combo.sizeHint().height() )
|
||||
self.vbox.addWidget( self.combo )
|
||||
self.connect( self.combo, SIGNAL("activated(int)"), self.comboBoxItemActivated )
|
||||
TQToolTip.add( self.combo, "read-only combo box" )
|
||||
|
||||
# Create an editable combo box
|
||||
self.edCombo = TQComboBox( TRUE, self, "edComboBox" )
|
||||
self.edCombo.insertItem( "Permutable" )
|
||||
self.edCombo.insertItem( "Malleable" )
|
||||
self.edCombo.insertItem( "Adaptable" )
|
||||
self.edCombo.insertItem( "Alterable" )
|
||||
self.edCombo.insertItem( "Inconstant" )
|
||||
self.edCombo.setFixedHeight( self.edCombo.sizeHint().height() )
|
||||
self.vbox.addWidget( self.edCombo )
|
||||
self.connect( self.edCombo, SIGNAL("activated(const TQString &)"), self.edComboBoxItemActivated)
|
||||
TQToolTip.add( self.edCombo, "editable combo box" )
|
||||
|
||||
self.edCombo.setAutoCompletion( TRUE )
|
||||
|
||||
self.vbox.addStretch( 1 )
|
||||
|
||||
self.vbox = TQVBoxLayout( 8 )
|
||||
self.grid.addLayout( self.vbox, 2, 2 )
|
||||
|
||||
# Create a spin box
|
||||
self.spin = TQSpinBox( 0, 10, 1, self, "spin" )
|
||||
self.spin.setSuffix( " mm" )
|
||||
self.spin.setSpecialValueText( "Auto" )
|
||||
self.spin.setMinimumSize( self.spin.sizeHint() )
|
||||
self.connect( self.spin, SIGNAL( "valueChanged(const TQString &)" ), self.spinBoxValueChanged )
|
||||
TQToolTip.add( self.spin, "spin box" )
|
||||
self.vbox.addWidget( self.spin )
|
||||
|
||||
self.vbox.addStretch( 1 )
|
||||
|
||||
# Create a multi line edit
|
||||
self.mle = TQMultiLineEdit( self, "multiLineEdit" )
|
||||
|
||||
self.grid.addMultiCellWidget( self.mle, 3, 3, 1, 2 )
|
||||
self.mle.setMinimumHeight( self.mle.fontMetrics().height() * 3 )
|
||||
self.mle.setText("This is a TQMultiLineEdit widget,\n"
|
||||
"useful for small multi-line\n"
|
||||
"input fields.")
|
||||
TQToolTip.add( self.mle, "multi line editor" )
|
||||
|
||||
# Create a single line edit
|
||||
self.le = TQLineEdit( self, "lineEdit" )
|
||||
self.grid.addMultiCellWidget( self.le, 4, 4, 1, 2 )
|
||||
self.le.setFixedHeight( self.le.sizeHint().height() )
|
||||
self.connect( self.le, SIGNAL("textChanged(const TQString &)"), self.lineEditTextChanged )
|
||||
TQToolTip.add( self.le, "single line editor" )
|
||||
|
||||
# Create a horizontal line (sort of TQFrame) above the message line
|
||||
self.separator = TQFrame( self, "separatorLine" )
|
||||
self.separator.setFrameStyle( TQFrame.HLine | TQFrame.Sunken )
|
||||
self.separator.setFixedHeight( self.separator.sizeHint().height() )
|
||||
self.grid.addMultiCellWidget( self.separator, 5, 5, 0, 2 )
|
||||
TQToolTip.add( self.separator, "tool tips on a separator! wow!" )
|
||||
|
||||
self.grid.setRowStretch( 0, 0 )
|
||||
self.grid.setRowStretch( 1, 0 )
|
||||
self.grid.setRowStretch( 2, 0 )
|
||||
self.grid.setRowStretch( 3, 1 )
|
||||
self.grid.setRowStretch( 4, 1 )
|
||||
self.grid.setRowStretch( 5, 0 )
|
||||
|
||||
self.grid.setColStretch( 0, 1 )
|
||||
self.grid.setColStretch( 1, 1 )
|
||||
self.grid.setColStretch( 2, 1 )
|
||||
|
||||
# Create an label and a message in a plain widget
|
||||
# The message is updated when buttons are clicked etc.
|
||||
|
||||
self.hbox = TQHBoxLayout()
|
||||
self.topLayout.addLayout( self.hbox )
|
||||
self.msgLabel = TQLabel( self, "msgLabel" )
|
||||
self.msgLabel.setText( "Message:" )
|
||||
self.msgLabel.setAlignment( TQt.AlignHCenter | TQt.AlignVCenter )
|
||||
self.msgLabel.setFixedSize( self.msgLabel.sizeHint() )
|
||||
self.hbox.addWidget( self.msgLabel )
|
||||
TQToolTip.add( self.msgLabel, "label 1" )
|
||||
|
||||
self.msg = TQLabel( self, "message" )
|
||||
self.msg.setFrameStyle( TQFrame.Panel | TQFrame.Sunken )
|
||||
self.msg.setAlignment( TQt.AlignCenter )
|
||||
self.msg.setFont( TQFont( "times", 12, TQFont.Bold ) )
|
||||
self.msg.setText( "Message" )
|
||||
self.msg.setFixedHeight( self.msg.sizeHint().height() )
|
||||
self.msg.setText( "" )
|
||||
self.hbox.addWidget( self.msg, 5 )
|
||||
TQToolTip.add( self.msg, "label 2" )
|
||||
|
||||
self.topLayout.activate()
|
||||
|
||||
def setStatus(self, text):
|
||||
self.msg.setText( text )
|
||||
|
||||
def movieUpdate( self, r ):
|
||||
# Uncomment this to test animated icons on your window manager
|
||||
self.setIcon( self.movie.framePixmap() )
|
||||
|
||||
def movieStatus( self, s ):
|
||||
if s == TQMovie.SourceEmpty or s == TQMovie.UnrecognizedFormat:
|
||||
pm = TQPixmap('tt-logo.png')
|
||||
self.movielabel.setPixmap(pm)
|
||||
self.movielabel.setFixedSize(pm.size())
|
||||
else:
|
||||
if ( self.movielabel.movie() ): # for flicker-free animation:
|
||||
self.movielabel.setBackgroundMode( TQWidget.NoBackground )
|
||||
|
||||
def button1Clicked( self ):
|
||||
self.msg.setText( "The first push button was clicked" )
|
||||
|
||||
def checkBoxClicked( self, id ):
|
||||
txt = TQString()
|
||||
txt = "Check box %s clicked : " % str(id)
|
||||
chk = ["-","-","-"]
|
||||
if self.cb[0].isChecked():
|
||||
chk[0] = "r"
|
||||
if self.cb[1].isChecked():
|
||||
chk[1] = "w"
|
||||
if self.cb[2].isChecked():
|
||||
chk[2] = "x"
|
||||
txt = txt + str(chk[0]+chk[1]+chk[2])
|
||||
self.msg.setText( txt )
|
||||
|
||||
def edComboBoxItemActivated( self, text):
|
||||
txt = TQString()
|
||||
txt = "Editable Combo Box set to %s" % text
|
||||
self.msg.setText( txt )
|
||||
|
||||
def radioButtonClicked( self, id ):
|
||||
txt = TQString()
|
||||
txt = "Radio button #%d clicked" % id
|
||||
self.msg.setText( txt )
|
||||
|
||||
def listBoxItemSelected( self, index ):
|
||||
txt = TQString()
|
||||
txt = "List box item %d selected" % index
|
||||
self.msg.setText( txt )
|
||||
|
||||
def sliderValueChanged( self, value ):
|
||||
txt = TQString()
|
||||
txt = "Movie set to %d%% of normal speed" % value
|
||||
self.msg.setText( txt )
|
||||
self.movie.setSpeed( value )
|
||||
|
||||
def comboBoxItemActivated( self, index ):
|
||||
txt = TQString()
|
||||
txt = "Comboxo box item %d activated" % index
|
||||
self.msg.setText( txt )
|
||||
if index == 0:
|
||||
TQApplication.setWinStyleHighlightColor( TQt.darkBlue )
|
||||
elif index == 1:
|
||||
TQApplication.setWinStyleHighlightColor( TQt.darkRed )
|
||||
elif index == 2:
|
||||
TQApplication.setWinStyleHighlightColor( TQt.darkGreen )
|
||||
elif index == 3:
|
||||
TQApplication.setWinStyleHighlightColor( TQt.blue )
|
||||
elif index == 4:
|
||||
TQApplication.setWinStyleHighlightColor( TQt.red )
|
||||
|
||||
def lineEditTextChanged( self, newText ):
|
||||
self.msg.setText("Line edit text: " + str(newText))
|
||||
|
||||
def spinBoxValueChanged( self, valueText ):
|
||||
self.msg.setText("Spin box value: " + str(valueText))
|
||||
|
||||
# All application events are passed throught this event filter.
|
||||
# We're using it to display some information about a clicked
|
||||
# widget (right mouse button + CTRL).
|
||||
#def eventFilter( self, event ):
|
||||
# identify_now = TRUE
|
||||
# if event.type() == Event_MouseButtonPress and identify_now:
|
||||
# e = TQMouseEvent( event )
|
||||
# if (e.button() == TQt.RightButton) and (e.state() & TQt.ControlButton) != 0:
|
||||
# txt = TQString( "The clicked widget is a\n" )
|
||||
# txt = txt + TQObect.className()
|
||||
# txt = txt + "\nThe widget's name is\n"
|
||||
# if TQObject.name():
|
||||
# txt = txt + TQObject.name()
|
||||
# else:
|
||||
# txt = txt + "<no name>"
|
||||
# identify_now = FALSE # don't do it in message box
|
||||
# TQMessageBox.message( "Identify Widget", txt, 0, TQObject )
|
||||
# identify_now = TRUE; # allow it again
|
||||
# return FALSE # don't eat event
|
||||
|
||||
################################################################################################
|
||||
|
||||
#TQApplication.setColourSpec( TQApplication.CustomColor )
|
||||
a = TQApplication( sys.argv )
|
||||
|
||||
w = WidgetView()
|
||||
a.setMainWidget( w )
|
||||
w.show()
|
||||
a.exec_loop()
|
@ -1,61 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
def TQMIN(x, y):
|
||||
if y > x: return y
|
||||
return x
|
||||
class AnalogClock(TQWidget):
|
||||
def __init__(self, *args):
|
||||
TQWidget.__init__(*(self,) + args)
|
||||
self.time = TQTime.currentTime()
|
||||
internalTimer = TQTimer(self)
|
||||
self.connect(internalTimer, SIGNAL("timeout()"), self.timeout)
|
||||
internalTimer.start(5000)
|
||||
|
||||
def timeout(self):
|
||||
new_time = TQTime.currentTime()
|
||||
if new_time.minute() != self.time.minute():
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, qe):
|
||||
if not self.isVisible():
|
||||
return
|
||||
self.time = TQTime.currentTime()
|
||||
|
||||
pts = TQPointArray()
|
||||
paint = TQPainter(self)
|
||||
paint.setBrush(self.foregroundColor())
|
||||
|
||||
cp = TQPoint(self.rect().center())
|
||||
d = TQMIN(self.width(), self.height())
|
||||
matrix = TQWMatrix()
|
||||
matrix.translate(cp.x(), cp.y())
|
||||
matrix.scale(d/1000.0, d/1000.0)
|
||||
|
||||
h_angle = 30*(self.time.hour()%12 - 3) + self.time.minute()/2
|
||||
matrix.rotate(h_angle)
|
||||
paint.setWorldMatrix(matrix)
|
||||
pts.setPoints([-20,0,0,-20,300,0,0,20])
|
||||
paint.drawPolygon(pts)
|
||||
matrix.rotate(-h_angle)
|
||||
|
||||
m_angle = (self.time.minute()-15)*6
|
||||
matrix.rotate(m_angle)
|
||||
paint.setWorldMatrix(matrix)
|
||||
pts.setPoints([-10,0,0,-10,400,0,0,10])
|
||||
paint.drawPolygon(pts)
|
||||
matrix.rotate(-m_angle)
|
||||
|
||||
for i in range(0,12):
|
||||
paint.setWorldMatrix(matrix)
|
||||
paint.drawLine(450,0, 500,0)
|
||||
matrix.rotate(30)
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
clock = AnalogClock()
|
||||
clock.resize(100,100)
|
||||
a.setMainWidget(clock)
|
||||
clock.show()
|
||||
a.exec_loop()
|
@ -1,457 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# A port to PyTQt of the application example from TQt v2.x.
|
||||
|
||||
|
||||
import sys, string
|
||||
from python_tqt.qt import *
|
||||
|
||||
TRUE = 1
|
||||
FALSE = 0
|
||||
fileopen = [
|
||||
' 16 13 5 1',
|
||||
'. c #040404',
|
||||
'# c #808304',
|
||||
'a c None',
|
||||
'b c #f3f704',
|
||||
'c c #f3f7f3',
|
||||
'aaaaaaaaa...aaaa',
|
||||
'aaaaaaaa.aaa.a.a',
|
||||
'aaaaaaaaaaaaa..a',
|
||||
'a...aaaaaaaa...a',
|
||||
'.bcb.......aaaaa',
|
||||
'.cbcbcbcbc.aaaaa',
|
||||
'.bcbcbcbcb.aaaaa',
|
||||
'.cbcb...........',
|
||||
'.bcb.#########.a',
|
||||
'.cb.#########.aa',
|
||||
'.b.#########.aaa',
|
||||
'..#########.aaaa',
|
||||
'...........aaaaa'
|
||||
]
|
||||
|
||||
filesave = [
|
||||
' 14 14 4 1',
|
||||
'. c #040404',
|
||||
'# c #808304',
|
||||
'a c #bfc2bf',
|
||||
'b c None',
|
||||
'..............',
|
||||
'.#.aaaaaaaa.a.',
|
||||
'.#.aaaaaaaa...',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.#.aaaaaaaa.#.',
|
||||
'.##........##.',
|
||||
'.############.',
|
||||
'.##.........#.',
|
||||
'.##......aa.#.',
|
||||
'.##......aa.#.',
|
||||
'.##......aa.#.',
|
||||
'b.............'
|
||||
]
|
||||
|
||||
fileprint = [
|
||||
' 16 14 6 1',
|
||||
'. c #000000',
|
||||
'# c #848284',
|
||||
'a c #c6c3c6',
|
||||
'b c #ffff00',
|
||||
'c c #ffffff',
|
||||
'd c None',
|
||||
'ddddd.........dd',
|
||||
'dddd.cccccccc.dd',
|
||||
'dddd.c.....c.ddd',
|
||||
'ddd.cccccccc.ddd',
|
||||
'ddd.c.....c....d',
|
||||
'dd.cccccccc.a.a.',
|
||||
'd..........a.a..',
|
||||
'.aaaaaaaaaa.a.a.',
|
||||
'.............aa.',
|
||||
'.aaaaaa###aa.a.d',
|
||||
'.aaaaaabbbaa...d',
|
||||
'.............a.d',
|
||||
'd.aaaaaaaaa.a.dd',
|
||||
'dd...........ddd'
|
||||
]
|
||||
|
||||
class ABCentralWidget( TQWidget ):
|
||||
def __init__( self, *args ):
|
||||
TQWidget.__init__(*(self, ) + args)
|
||||
self.mainGrid = TQGridLayout( self, 2, 1, 5, 5 )
|
||||
|
||||
self.setupTabWidget()
|
||||
self.setupListView()
|
||||
|
||||
self.mainGrid.setRowStretch( 0, 0 )
|
||||
self.mainGrid.setRowStretch( 1, 1 )
|
||||
|
||||
def save( self, filename ):
|
||||
if not self.listView.firstChild():
|
||||
return
|
||||
|
||||
f = TQFile( filename )
|
||||
if not f.open( IO_WriteOnly ):
|
||||
return
|
||||
|
||||
t = TQTextStream( f )
|
||||
|
||||
#it = TQListViewItemIterator( self.listView )
|
||||
|
||||
while not t.eof():
|
||||
item = TQListViewItem( self.listView )
|
||||
for i in range (0, 4):
|
||||
t << item.text( i ) << '\n'
|
||||
#for it in it.current():
|
||||
#for i in range (0, 4):
|
||||
#t << it.current().text[ i ] << "\n"
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
def load( self, filename ):
|
||||
self.listView.clear()
|
||||
|
||||
f = TQFile( filename )
|
||||
if not f.open( IO_ReadOnly ):
|
||||
return
|
||||
|
||||
t = TQTextStream( f )
|
||||
|
||||
while not t.eof():
|
||||
item = TQListViewItem( self.listView )
|
||||
for i in range (0, 4):
|
||||
item.setText( i, t.readLine() )
|
||||
|
||||
f.close();
|
||||
|
||||
|
||||
def setupTabWidget( self ):
|
||||
self.tabWidget = TQTabWidget( self )
|
||||
|
||||
self.input = TQWidget( self.tabWidget )
|
||||
self.grid1 = TQGridLayout( self.input, 2, 5, 5, 5 )
|
||||
|
||||
self.liFirstName = TQLabel( 'First &Name', self.input )
|
||||
self.liFirstName.resize( self.liFirstName.sizeHint() )
|
||||
self.grid1.addWidget( self.liFirstName, 0, 0 )
|
||||
|
||||
self.liLastName = TQLabel( '&Last Name', self.input )
|
||||
self.liLastName.resize( self.liLastName.sizeHint() )
|
||||
self.grid1.addWidget( self.liLastName, 0, 1 )
|
||||
|
||||
self.liAddress = TQLabel( '&Address', self.input )
|
||||
self.liAddress.resize( self.liAddress.sizeHint() )
|
||||
self.grid1.addWidget( self.liAddress, 0, 2 )
|
||||
|
||||
self.liEMail = TQLabel( '&E-Mail', self.input )
|
||||
self.liEMail.resize( self.liEMail.sizeHint() )
|
||||
self.grid1.addWidget( self.liEMail, 0, 3 )
|
||||
|
||||
self.add = TQPushButton( '&Add', self.input )
|
||||
self.add.resize( self.add.sizeHint() )
|
||||
self.grid1.addWidget( self.add, 0, 4 )
|
||||
self.connect( self.add, SIGNAL( 'clicked()' ), self.addEntry )
|
||||
|
||||
self.iFirstName = TQLineEdit( self.input )
|
||||
self.iFirstName.resize( self.iFirstName.sizeHint() )
|
||||
self.grid1.addWidget( self.iFirstName, 1, 0 )
|
||||
self.liFirstName.setBuddy( self.iFirstName )
|
||||
|
||||
self.iLastName = TQLineEdit( self.input )
|
||||
self.iLastName.resize( self.iLastName.sizeHint() )
|
||||
self.grid1.addWidget( self.iLastName, 1, 1 )
|
||||
self.liLastName.setBuddy( self.iLastName )
|
||||
|
||||
self.iAddress = TQLineEdit( self.input )
|
||||
self.iAddress.resize( self.iAddress.sizeHint() )
|
||||
self.grid1.addWidget( self.iAddress, 1, 2 )
|
||||
self.liAddress.setBuddy( self.iAddress )
|
||||
|
||||
self.iEMail = TQLineEdit( self.input )
|
||||
self.iEMail.resize( self.iEMail.sizeHint() )
|
||||
self.grid1.addWidget( self.iEMail, 1, 3 )
|
||||
self.liEMail.setBuddy( self.iEMail )
|
||||
|
||||
self.change = TQPushButton( '&Change', self.input )
|
||||
self.change.resize( self.change.sizeHint() )
|
||||
self.grid1.addWidget( self.change, 1, 4 )
|
||||
self.connect( self.change, SIGNAL( 'clicked()' ), self.changeEntry )
|
||||
|
||||
self.tabWidget.addTab( self.input, '&Add/Change Entry' )
|
||||
|
||||
# --------------------------------------
|
||||
|
||||
self.search = TQWidget( self )
|
||||
self.grid2 = TQGridLayout( self.search, 2, 5, 5, 5 )
|
||||
|
||||
self.cFirstName = TQCheckBox( 'First &Name', self.search )
|
||||
self.cFirstName.resize( self.cFirstName.sizeHint() )
|
||||
self.grid2.addWidget( self.cFirstName, 0, 0 )
|
||||
self.connect( self.cFirstName, SIGNAL( 'clicked()' ), self.toggleFirstName )
|
||||
|
||||
self.cLastName = TQCheckBox( '&Last Name', self.search )
|
||||
self.cLastName.resize( self.cLastName.sizeHint() )
|
||||
self.grid2.addWidget( self.cLastName, 0, 1 )
|
||||
self.connect( self.cLastName, SIGNAL( 'clicked()' ), self.toggleLastName )
|
||||
|
||||
self.cAddress = TQCheckBox( '&Address', self.search )
|
||||
self.cAddress.resize( self.cAddress.sizeHint() )
|
||||
self.grid2.addWidget( self.cAddress, 0, 2 )
|
||||
self.connect( self.cAddress, SIGNAL( 'clicked()' ), self.toggleAddress )
|
||||
|
||||
self.cEMail = TQCheckBox( '&E-Mail', self.search )
|
||||
self.cEMail.resize( self.cEMail.sizeHint() )
|
||||
self.grid2.addWidget( self.cEMail, 0, 3 )
|
||||
self.connect( self.cEMail, SIGNAL( 'clicked()' ), self.toggleEMail )
|
||||
|
||||
self.sFirstName = TQLineEdit( self.search )
|
||||
self.sFirstName.resize( self.sFirstName.sizeHint() )
|
||||
self.grid2.addWidget( self.sFirstName, 1, 0 )
|
||||
|
||||
self.sLastName = TQLineEdit( self.search )
|
||||
self.sLastName.resize( self.sLastName.sizeHint() )
|
||||
self.grid2.addWidget( self.sLastName, 1, 1 )
|
||||
|
||||
self.sAddress = TQLineEdit( self.search )
|
||||
self.sAddress.resize( self.sAddress.sizeHint() )
|
||||
self.grid2.addWidget( self.sAddress, 1, 2 )
|
||||
|
||||
self.sEMail = TQLineEdit( self.search )
|
||||
self.sEMail.resize( self.sEMail.sizeHint() )
|
||||
self.grid2.addWidget( self.sEMail, 1, 3 )
|
||||
|
||||
self.find = TQPushButton( '&Find', self.search )
|
||||
self.find.resize( self.find.sizeHint() )
|
||||
self.grid2.addWidget( self.find, 1, 4 )
|
||||
self.connect( self.find, SIGNAL( 'clicked()' ), self.findEntries )
|
||||
|
||||
self.cFirstName.setChecked( TRUE )
|
||||
self.sFirstName.setEnabled( TRUE )
|
||||
self.sLastName.setEnabled( FALSE )
|
||||
self.sAddress.setEnabled( FALSE )
|
||||
self.sEMail.setEnabled( FALSE )
|
||||
|
||||
self.tabWidget.addTab( self.search, "&Search" )
|
||||
|
||||
self.mainGrid.addWidget( self.tabWidget, 0, 0 )
|
||||
|
||||
def setupListView( self ):
|
||||
self.listView = TQListView( self )
|
||||
self.listView.addColumn( 'First Name' )
|
||||
self.listView.addColumn( 'Last Name' )
|
||||
self.listView.addColumn( 'Address' )
|
||||
self.listView.addColumn( 'E-Mail' )
|
||||
|
||||
self.listView.setSelectionMode( TQListView.Extended )
|
||||
|
||||
self.connect( self.listView, SIGNAL( 'clicked( TQListViewItem* )' ), self.itemSelected )
|
||||
|
||||
self.mainGrid.addWidget( self.listView, 1, 0 )
|
||||
self.listView.setAllColumnsShowFocus( TRUE )
|
||||
|
||||
|
||||
def addEntry( self ):
|
||||
if not self.iFirstName.text().isEmpty() or not self.iLastName.text().isEmpty() or \
|
||||
not self.iAddress.text().isEmpty() or not self.iEMail.text().isEmpty() :
|
||||
self.item = TQListViewItem( self.listView )
|
||||
self.item.setText( 0, self.iFirstName.text() )
|
||||
self.item.setText( 1, self.iLastName.text() )
|
||||
self.item.setText( 2, self.iAddress.text() )
|
||||
self.item.setText( 3, self.iEMail.text() )
|
||||
|
||||
self.iFirstName.setText( '' )
|
||||
self.iLastName.setText( '' )
|
||||
self.iAddress.setText( '' )
|
||||
self.iEMail.setText( '' )
|
||||
|
||||
def changeEntry( self ):
|
||||
self.item = self.listView.currentItem()
|
||||
if self.item and ( not self.iFirstName.text().isEmpty() or not self.iLastName.text().isEmpty() or \
|
||||
not self.iAddress.text().isEmpty() or not self.iEMail.text().isEmpty() ) :
|
||||
self.item.setText( 0, self.iFirstName.text() )
|
||||
self.item.setText( 1, self.iLastName.text() )
|
||||
self.item.setText( 2, self.iAddress.text() )
|
||||
self.item.setText( 3, self.iEMail.text() )
|
||||
|
||||
def selectionChanged( self ):
|
||||
self.iFirstName.setText( '' )
|
||||
self.iLastName.setText( '' )
|
||||
self.iAddress.setText( '' )
|
||||
self.iEMail.setText( '' )
|
||||
|
||||
def itemSelected( self, item ):
|
||||
self.item.setSelected( TRUE )
|
||||
self.item.repaint()
|
||||
|
||||
self.iFirstName.setText( item.text( 0 ) )
|
||||
self.iLastName.setText( item.text( 1 ) )
|
||||
self.iAddress.setText( item.text( 2 ) )
|
||||
self.iEMail.setText( item.text( 3 ) )
|
||||
|
||||
def toggleFirstName( self ):
|
||||
self.sFirstName.setText( '' )
|
||||
if self.cFirstName.isChecked():
|
||||
self.sFirstName.setEnabled( TRUE )
|
||||
self.sFirstName.setFocus()
|
||||
else:
|
||||
self.sFirstName.setEnabled( FALSE )
|
||||
|
||||
def toggleLastName( self ):
|
||||
self.sLastName.setText( '' )
|
||||
if self.cLastName.isChecked():
|
||||
self.sLastName.setEnabled( TRUE )
|
||||
self.sLastName.setFocus()
|
||||
else:
|
||||
self.sLastName.setEnabled( FALSE )
|
||||
|
||||
|
||||
def toggleAddress( self ):
|
||||
self.sAddress.setText( '' )
|
||||
if self.cAddress.isChecked():
|
||||
self.sAddress.setEnabled( TRUE )
|
||||
self.sAddress.setFocus()
|
||||
else:
|
||||
self.sAddress.setEnabled( FALSE )
|
||||
|
||||
|
||||
def toggleEMail( self ):
|
||||
self.sEMail.setText( '' )
|
||||
if self.cEMail.isChecked():
|
||||
self.sEMail.setEnabled( TRUE )
|
||||
self.sEMail.setFocus()
|
||||
|
||||
else:
|
||||
self.sEMail.setEnabled( FALSE )
|
||||
|
||||
|
||||
def findEntries( self ):
|
||||
if not self.cFirstName.isChecked() and not self.cLastName.isChecked() and \
|
||||
not self.cAddress.isChecked() and not self.cEMail.isChecked():
|
||||
self.listView.clearSelection()
|
||||
return
|
||||
|
||||
it = TQListViewItemIterator( self.listView )
|
||||
|
||||
for it in it.current() :
|
||||
select = TRUE
|
||||
|
||||
if self.cFirstName.isChecked():
|
||||
if select and it.current().text( 0 ).contains( self.sFirstName.text() ):
|
||||
select = TRUE
|
||||
else:
|
||||
select = FALSE
|
||||
|
||||
if self.cLastName.isChecked():
|
||||
if select and it.current().text( 1 ).contains( self.sLastName.text() ):
|
||||
select = TRUE
|
||||
else:
|
||||
select = FALSE
|
||||
|
||||
if self.cAddress.isChecked():
|
||||
if select and it.current().text( 2 ).contains( self.sAddress.text() ):
|
||||
select = TRUE
|
||||
else:
|
||||
select = FALSE
|
||||
|
||||
if self.cEMail.isChecked():
|
||||
if select and it.current().text( 3 ).contains( self.sEMail.text() ):
|
||||
select = TRUE
|
||||
else:
|
||||
select = FALSE
|
||||
|
||||
|
||||
if select:
|
||||
it.current().setSelected( TRUE )
|
||||
else:
|
||||
it.current().setSelected( FALSE )
|
||||
it.current().repaint()
|
||||
|
||||
|
||||
class ABMainWindow(TQMainWindow):
|
||||
def __init__( self ):
|
||||
TQMainWindow.__init__( self, None, 'example addressbook application' )
|
||||
|
||||
self.filename = TQString.null
|
||||
self.setupMenuBar()
|
||||
self.setupFileTools()
|
||||
self.setupStatusBar()
|
||||
self.setupCentralWidget()
|
||||
|
||||
def setupMenuBar( self ):
|
||||
self.file = TQPopupMenu( self )
|
||||
self.menuBar().insertItem( '&File', self.file )
|
||||
|
||||
openIcon = TQIconSet( TQPixmap( fileopen ) )
|
||||
self.file.insertItem( 'New', self.fileNew, TQt.CTRL + TQt.Key_N )
|
||||
self.file.insertItem( openIcon, 'Open', self.fileOpen, TQt.CTRL + TQt.Key_O )
|
||||
self.file.insertSeparator()
|
||||
saveIcon = TQIconSet( TQPixmap( filesave ) )
|
||||
self.file.insertItem( saveIcon, 'Save', self.fileSave, TQt.CTRL + TQt.Key_S )
|
||||
self.file.insertItem( 'Save As...', self.fileSaveAs )
|
||||
self.file.insertSeparator()
|
||||
printIcon = TQIconSet( TQPixmap( fileprint ) )
|
||||
self.file.insertItem( printIcon, 'Print...', self.filePrint, TQt.CTRL + TQt.Key_P )
|
||||
self.file.insertSeparator()
|
||||
#self.file.insertItem( 'Close', self.closeWindow, TQt.CTRL + TQt.Key_W )
|
||||
self.file.insertItem('Close', self, SLOT('close()'), TQt.CTRL+TQt.Key_W)
|
||||
self.file.insertItem( 'Quit', tqApp, SLOT( 'quit()' ), TQt.CTRL + TQt.Key_Q )
|
||||
|
||||
def setupFileTools( self ):
|
||||
pass
|
||||
#self.fileTools = TQToolBar( self, 'file operations' )
|
||||
|
||||
def setupStatusBar( self ):
|
||||
self.statusBar().message( "Ready", 2000 )
|
||||
|
||||
def setupCentralWidget( self ):
|
||||
self.view = ABCentralWidget( self )
|
||||
#self.view.show()
|
||||
self.setCentralWidget( self.view )
|
||||
|
||||
def closeWindow( self ):
|
||||
close()
|
||||
|
||||
|
||||
def fileNew( self ):
|
||||
pass
|
||||
|
||||
def fileOpen( self ):
|
||||
fn = TQFileDialog.getOpenFileName( TQString.null, TQString.null, self )
|
||||
if not fn.isEmpty():
|
||||
self.filename = fn
|
||||
self.view.load( self.filename )
|
||||
|
||||
def fileSave( self ):
|
||||
if self.filename.isEmpty():
|
||||
self.fileSaveAs()
|
||||
return
|
||||
|
||||
self.view.save( self.filename )
|
||||
|
||||
def fileSaveAs( self ):
|
||||
fn = TQFileDialog.getSaveFileName( TQString.null, TQString.null, self )
|
||||
if not fn.isEmpty():
|
||||
self.filename = fn
|
||||
self.fileSave
|
||||
|
||||
def filePrint( self ):
|
||||
pass
|
||||
|
||||
|
||||
a = TQApplication( sys.argv )
|
||||
|
||||
mw = ABMainWindow()
|
||||
#mw.setupMenuBar()
|
||||
#mw.setupFileTools
|
||||
#mw.setupStatusBar
|
||||
#mw.setupCentralWidget
|
||||
#view = ABCentralWidget()
|
||||
#mw.setCentralWidget( view )
|
||||
mw.setCaption( 'Addressbook 1' )
|
||||
a.setMainWidget( mw )
|
||||
mw.show()
|
||||
|
||||
a.connect( a, SIGNAL( 'lastWindowClosed()' ), a, SLOT( 'quit()' ) )
|
||||
a.exec_loop()
|
@ -1,58 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# A port to PyTQt of the dclock example from TQt v2.x.
|
||||
|
||||
|
||||
import sys, string
|
||||
from python_tqt.qt import *
|
||||
|
||||
|
||||
class DigitalClock(TQLCDNumber):
|
||||
def __init__(self, parent=None, name=None):
|
||||
TQLCDNumber.__init__(self, parent, name)
|
||||
self.showingColon = 0
|
||||
self.setFrameStyle(TQFrame.Panel | TQFrame.Raised)
|
||||
self.setLineWidth(2)
|
||||
self.showTime()
|
||||
self.normalTimer = self.startTimer(500)
|
||||
self.showDateTimer = -1
|
||||
|
||||
def timerEvent(self, e):
|
||||
if e.timerId() == self.showDateTimer:
|
||||
self.stopDate()
|
||||
else:
|
||||
if self.showDateTimer == -1:
|
||||
self.showTime()
|
||||
|
||||
def mousePressEvent(self, e):
|
||||
if e.button() == TQt.LeftButton:
|
||||
self.showDate()
|
||||
|
||||
def showDate(self):
|
||||
if self.showDateTimer != -1:
|
||||
return
|
||||
d = TQDate.currentDate()
|
||||
self.display('%2d %2d' % (d.month(), d.day()))
|
||||
self.showDateTimer = self.startTimer(2000)
|
||||
|
||||
def stopDate(self):
|
||||
self.killTimer(self.showDateTimer)
|
||||
self.showDateTimer = -1
|
||||
self.showTime()
|
||||
|
||||
def showTime(self):
|
||||
self.showingColon = not self.showingColon
|
||||
s = list(str(TQTime.currentTime().toString())[:5]) #.left(5)
|
||||
if not self.showingColon:
|
||||
s[2] = ' '
|
||||
if s[0] == '0':
|
||||
s[0] = ' '
|
||||
s = ''.join(s)
|
||||
self.display(s)
|
||||
|
||||
a = TQApplication(sys.argv)
|
||||
clock = DigitalClock()
|
||||
clock.resize(170,80)
|
||||
a.setMainWidget(clock)
|
||||
clock.show()
|
||||
a.exec_loop()
|
@ -1,57 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Ported to PyTQt by Issac Trotts on Jan 1, 2002
|
||||
|
||||
import sys
|
||||
from python_tqt.qt import *
|
||||
|
||||
import dropsite, secret
|
||||
|
||||
|
||||
def addStuff( parent, yn_image, yn_secret = 0 ):
|
||||
tll = TQVBoxLayout( parent, 10 )
|
||||
d = dropsite.DropSite( parent, 'dropsite' )
|
||||
d.setFrameStyle( TQFrame.Sunken + TQFrame.WinPanel )
|
||||
tll.addWidget( d )
|
||||
if yn_image:
|
||||
stuff = TQPixmap()
|
||||
if not stuff.load( "trolltech.bmp" ):
|
||||
stuff = TQPixmap(20,20)
|
||||
stuff.fill(TQt.green)
|
||||
d.setPixmap( stuff )
|
||||
else:
|
||||
d.setText("Drag and Drop")
|
||||
d.setFont(TQFont("Helvetica",18))
|
||||
if secret:
|
||||
s = secret.SecretSource( 42, parent )
|
||||
tll.addWidget( s )
|
||||
|
||||
format = TQLabel( "\n\n\n\nNone\n\n\n\n", parent )
|
||||
tll.addWidget( format )
|
||||
tll.activate()
|
||||
parent.resize( parent.sizeHint() )
|
||||
|
||||
TQObject.connect( d, PYSIGNAL('message(TQString &)'),
|
||||
format, SLOT('setText(TQString &)') )
|
||||
|
||||
|
||||
app = TQApplication( sys.argv )
|
||||
|
||||
mw = TQWidget()
|
||||
addStuff( mw, 1 )
|
||||
mw.setCaption( "TQt Example - Drag and Drop" )
|
||||
mw.show()
|
||||
|
||||
mw2 = TQWidget()
|
||||
addStuff( mw2, 0 )
|
||||
mw2.setCaption( "TQt Example - Drag and Drop" )
|
||||
mw2.show()
|
||||
|
||||
mw3 = TQWidget()
|
||||
addStuff( mw3, 1, 1 )
|
||||
mw3.setCaption( "TQt Example - Drag and Drop" )
|
||||
mw3.show()
|
||||
|
||||
TQObject.connect(tqApp,SIGNAL('lastWindowClosed()'),tqApp,SLOT('quit()'))
|
||||
|
||||
app.exec_loop()
|
Before Width: | Height: | Size: 355 B |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 3.1 KiB |
@ -1,260 +0,0 @@
|
||||
/**********************************************************************
|
||||
** Copyright (C) 2000 Trolltech AS. All rights reserved.
|
||||
** Copyright (C) 2000, 2001 Phil Thompson <phil@river-bank.demon.co.uk>
|
||||
**
|
||||
** This file is part of TQt Designer.
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
||||
**
|
||||
** Contact info@trolltech.com if any conditions of this licensing are
|
||||
** not clear to you.
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#include "domtool.h"
|
||||
|
||||
#include <tqsizepolicy.h>
|
||||
#include <tqpalette.h>
|
||||
#include <tqcursor.h>
|
||||
#include <tqrect.h>
|
||||
#include <tqsize.h>
|
||||
#include <tqfont.h>
|
||||
|
||||
|
||||
/*!
|
||||
\class DomTool domtool.h
|
||||
\brief Tools for the dom
|
||||
|
||||
A collection of static functions used by Resource (part of the
|
||||
designer) and Uic.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
Returns the contents of property \a name of object \a e as
|
||||
variant or the variant passed as \a defValue if the property does
|
||||
not exist.
|
||||
|
||||
\sa hasProperty()
|
||||
*/
|
||||
TQVariant DomTool::readProperty( const TQDomElement& e, const TQString& name, const TQVariant& defValue )
|
||||
{
|
||||
TQDomElement n;
|
||||
for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
||||
if ( n.tagName() == "property" ) {
|
||||
TQDomElement n2 = n.firstChild().toElement();
|
||||
if ( n2.tagName() == "name" ) {
|
||||
TQString prop = n2.firstChild().toText().data();
|
||||
if ( prop == name )
|
||||
return elementToVariant( n2.nextSibling().toElement(), defValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns wheter object \a e defines property \a name or not.
|
||||
|
||||
\sa readProperty()
|
||||
*/
|
||||
bool DomTool::hasProperty( const TQDomElement& e, const TQString& name )
|
||||
{
|
||||
TQDomElement n;
|
||||
for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
||||
if ( n.tagName() == "property" ) {
|
||||
TQDomElement n2 = n.firstChild().toElement();
|
||||
if ( n2.tagName() == "name" ) {
|
||||
TQString prop = n2.firstChild().toText().data();
|
||||
if ( prop == name )
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
TQVariant DomTool::elementToVariant( const TQDomElement& e, const TQVariant& defValue )
|
||||
{
|
||||
TQString dummy;
|
||||
return elementToVariant( e, defValue, dummy );
|
||||
}
|
||||
|
||||
/*!
|
||||
Interprets element \a e as variant and returns the result of the interpretation.
|
||||
*/
|
||||
TQVariant DomTool::elementToVariant( const TQDomElement& e, const TQVariant& defValue, TQString &comment )
|
||||
{
|
||||
TQVariant v;
|
||||
if ( e.tagName() == "rect" ) {
|
||||
TQDomElement n3 = e.firstChild().toElement();
|
||||
int x = 0, y = 0, w = 0, h = 0;
|
||||
while ( !n3.isNull() ) {
|
||||
if ( n3.tagName() == "x" )
|
||||
x = n3.firstChild().toText().data().toInt();
|
||||
else if ( n3.tagName() == "y" )
|
||||
y = n3.firstChild().toText().data().toInt();
|
||||
else if ( n3.tagName() == "width" )
|
||||
w = n3.firstChild().toText().data().toInt();
|
||||
else if ( n3.tagName() == "height" )
|
||||
h = n3.firstChild().toText().data().toInt();
|
||||
n3 = n3.nextSibling().toElement();
|
||||
}
|
||||
v = TQVariant( TQRect( x, y, w, h ) );
|
||||
} else if ( e.tagName() == "point" ) {
|
||||
TQDomElement n3 = e.firstChild().toElement();
|
||||
int x = 0, y = 0;
|
||||
while ( !n3.isNull() ) {
|
||||
if ( n3.tagName() == "x" )
|
||||
x = n3.firstChild().toText().data().toInt();
|
||||
else if ( n3.tagName() == "y" )
|
||||
y = n3.firstChild().toText().data().toInt();
|
||||
n3 = n3.nextSibling().toElement();
|
||||
}
|
||||
v = TQVariant( TQPoint( x, y ) );
|
||||
} else if ( e.tagName() == "size" ) {
|
||||
TQDomElement n3 = e.firstChild().toElement();
|
||||
int w = 0, h = 0;
|
||||
while ( !n3.isNull() ) {
|
||||
if ( n3.tagName() == "width" )
|
||||
w = n3.firstChild().toText().data().toInt();
|
||||
else if ( n3.tagName() == "height" )
|
||||
h = n3.firstChild().toText().data().toInt();
|
||||
n3 = n3.nextSibling().toElement();
|
||||
}
|
||||
v = TQVariant( TQSize( w, h ) );
|
||||
} else if ( e.tagName() == "color" ) {
|
||||
v = TQVariant( readColor( e ) );
|
||||
} else if ( e.tagName() == "font" ) {
|
||||
TQDomElement n3 = e.firstChild().toElement();
|
||||
TQFont f( defValue.toFont() );
|
||||
while ( !n3.isNull() ) {
|
||||
if ( n3.tagName() == "family" )
|
||||
f.setFamily( n3.firstChild().toText().data() );
|
||||
else if ( n3.tagName() == "pointsize" )
|
||||
f.setPointSize( n3.firstChild().toText().data().toInt() );
|
||||
else if ( n3.tagName() == "bold" )
|
||||
f.setBold( n3.firstChild().toText().data().toInt() );
|
||||
else if ( n3.tagName() == "italic" )
|
||||
f.setItalic( n3.firstChild().toText().data().toInt() );
|
||||
else if ( n3.tagName() == "underline" )
|
||||
f.setUnderline( n3.firstChild().toText().data().toInt() );
|
||||
else if ( n3.tagName() == "strikeout" )
|
||||
f.setStrikeOut( n3.firstChild().toText().data().toInt() );
|
||||
n3 = n3.nextSibling().toElement();
|
||||
}
|
||||
v = TQVariant( f );
|
||||
} else if ( e.tagName() == "string" ) {
|
||||
v = TQVariant( e.firstChild().toText().data() );
|
||||
TQDomElement n = e;
|
||||
n = n.nextSibling().toElement();
|
||||
if ( n.tagName() == "comment" )
|
||||
comment = n.firstChild().toText().data();
|
||||
} else if ( e.tagName() == "cstring" ) {
|
||||
v = TQVariant( TQCString( e.firstChild().toText().data() ) );
|
||||
} else if ( e.tagName() == "number" ) {
|
||||
v = TQVariant( e.firstChild().toText().data().toInt() );
|
||||
} else if ( e.tagName() == "bool" ) {
|
||||
TQString t = e.firstChild().toText().data();
|
||||
v = TQVariant( t == "true" || t == "1" );
|
||||
} else if ( e.tagName() == "pixmap" ) {
|
||||
v = TQVariant( e.firstChild().toText().data() );
|
||||
} else if ( e.tagName() == "iconset" ) {
|
||||
v = TQVariant( e.firstChild().toText().data() );
|
||||
} else if ( e.tagName() == "image" ) {
|
||||
v = TQVariant( e.firstChild().toText().data() );
|
||||
} else if ( e.tagName() == "enum" ) {
|
||||
v = TQVariant( e.firstChild().toText().data() );
|
||||
} else if ( e.tagName() == "set" ) {
|
||||
v = TQVariant( e.firstChild().toText().data() );
|
||||
} else if ( e.tagName() == "sizepolicy" ) {
|
||||
TQDomElement n3 = e.firstChild().toElement();
|
||||
TQSizePolicy sp;
|
||||
while ( !n3.isNull() ) {
|
||||
if ( n3.tagName() == "hsizetype" )
|
||||
sp.setHorData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
|
||||
else if ( n3.tagName() == "vsizetype" )
|
||||
sp.setVerData( (TQSizePolicy::SizeType)n3.firstChild().toText().data().toInt() );
|
||||
n3 = n3.nextSibling().toElement();
|
||||
}
|
||||
v = TQVariant( sp );
|
||||
} else if ( e.tagName() == "cursor" ) {
|
||||
v = TQVariant( TQCursor( e.firstChild().toText().data().toInt() ) );
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
/*! Returns the color which is returned in the dom element \a e.
|
||||
*/
|
||||
|
||||
TQColor DomTool::readColor( const TQDomElement &e )
|
||||
{
|
||||
TQDomElement n = e.firstChild().toElement();
|
||||
int r= 0, g = 0, b = 0;
|
||||
while ( !n.isNull() ) {
|
||||
if ( n.tagName() == "red" )
|
||||
r = n.firstChild().toText().data().toInt();
|
||||
else if ( n.tagName() == "green" )
|
||||
g = n.firstChild().toText().data().toInt();
|
||||
else if ( n.tagName() == "blue" )
|
||||
b = n.firstChild().toText().data().toInt();
|
||||
n = n.nextSibling().toElement();
|
||||
}
|
||||
|
||||
return TQColor( r, g, b );
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the contents of attribute \a name of object \a e as
|
||||
variant or the variant passed as \a defValue if the attribute does
|
||||
not exist.
|
||||
|
||||
\sa hasAttribute()
|
||||
*/
|
||||
TQVariant DomTool::readAttribute( const TQDomElement& e, const TQString& name, const TQVariant& defValue )
|
||||
{
|
||||
TQDomElement n;
|
||||
for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
||||
if ( n.tagName() == "attribute" ) {
|
||||
TQDomElement n2 = n.firstChild().toElement();
|
||||
if ( n2.tagName() == "name" ) {
|
||||
TQString prop = n2.firstChild().toText().data();
|
||||
if ( prop == name )
|
||||
return elementToVariant( n2.nextSibling().toElement(), defValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns wheter object \a e defines attribute \a name or not.
|
||||
|
||||
\sa readAttribute()
|
||||
*/
|
||||
bool DomTool::hasAttribute( const TQDomElement& e, const TQString& name )
|
||||
{
|
||||
TQDomElement n;
|
||||
for ( n = e.firstChild().toElement(); !n.isNull(); n = n.nextSibling().toElement() ) {
|
||||
if ( n.tagName() == "attribute" ) {
|
||||
TQDomElement n2 = n.firstChild().toElement();
|
||||
if ( n2.tagName() == "name" ) {
|
||||
TQString prop = n2.firstChild().toText().data();
|
||||
if ( prop == name )
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/**********************************************************************
|
||||
** Copyright (C) 2000 Troll Tech AS. All rights reserved.
|
||||
** Copyright (C) 2000, 2001 Phil Thompson <phil@river-bank.demon.co.uk>
|
||||
**
|
||||
** This file is part of TQt GUI Designer.
|
||||
**
|
||||
** This file may be distributed under the terms of the GNU General
|
||||
** Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file COPYING included in the
|
||||
** packaging of this file. If you did not get the file, send email
|
||||
** to info@trolltech.com
|
||||
**
|
||||
** The file is provided AS IS with NO WARRANTY OF ANY KIND,
|
||||
** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE.
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef DOMTOOL_H
|
||||
#define DOMTOOL_H
|
||||
|
||||
#include <tqnamespace.h>
|
||||
#include <tqvariant.h>
|
||||
#include <tqdom.h>
|
||||
|
||||
|
||||
class DomTool : public TQt
|
||||
{
|
||||
public:
|
||||
static TQVariant readProperty( const TQDomElement& e, const TQString& name, const TQVariant& defValue );
|
||||
static bool hasProperty( const TQDomElement& e, const TQString& name );
|
||||
static TQVariant elementToVariant( const TQDomElement& e, const TQVariant& defValue );
|
||||
static TQVariant elementToVariant( const TQDomElement& e, const TQVariant& defValue, TQString &comment );
|
||||
static TQVariant readAttribute( const TQDomElement& e, const TQString& name, const TQVariant& defValue );
|
||||
static bool hasAttribute( const TQDomElement& e, const TQString& name );
|
||||
static TQColor readColor( const TQDomElement &e );
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // DOMTOOL_H
|
@ -1,33 +0,0 @@
|
||||
/**********************************************************************
|
||||
** Copyright (C) 2000 Trolltech AS. All rights reserved.
|
||||
**
|
||||
** This file is part of TQt Designer.
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
||||
**
|
||||
** Contact info@trolltech.com if any conditions of this licensing are
|
||||
** not clear to you.
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef GLOBALDEFS_H
|
||||
#define GLOBALDEFS_H
|
||||
|
||||
#include <tqcolor.h>
|
||||
|
||||
#define BOXLAYOUT_DEFAULT_MARGIN 11
|
||||
#define BOXLAYOUT_DEFAULT_SPACING 6
|
||||
|
||||
static TQColor backColor1( 226, 244, 216 );
|
||||
static TQColor backColor2( 235, 235, 235 );
|
||||
static TQColor selectedBack( 192, 192, 192 );
|
||||
|
||||
#endif
|
@ -1,24 +0,0 @@
|
||||
# Copyright (c) 2000, 2001
|
||||
# Phil Thompson <phil@river-bank.demon.co.uk>
|
||||
# Copyright (c) 2002, 2003
|
||||
# Riverbank Computing Limited <info@riverbankcomputing.co.uk>
|
||||
#
|
||||
# The project file for pyuic for TQt v2.
|
||||
|
||||
|
||||
TEMPLATE = app
|
||||
CONFIG = qt console warn_on release
|
||||
INCLUDEPATH = @BLX_INCLUDEPATH@ $(TQTDIR)/src/3rdparty/zlib
|
||||
DEFINES = UIC @BLX_DEFINES@
|
||||
|
||||
DESTDIR = @PYQT_BINDIR@
|
||||
TARGET = pyuic
|
||||
|
||||
HEADERS = domtool.h \
|
||||
globaldefs.h \
|
||||
uic.h \
|
||||
widgetdatabase.h
|
||||
|
||||
SOURCES = domtool.cpp \
|
||||
uic.cpp \
|
||||
widgetdatabase.cpp
|
@ -1,24 +0,0 @@
|
||||
# This is the build file for pyuic for TQt v2.
|
||||
#
|
||||
# Copyright (c) 2007
|
||||
# Riverbank Computing Limited <info@riverbankcomputing.co.uk>
|
||||
#
|
||||
# This file is part of PyTQt.
|
||||
#
|
||||
# This copy of PyTQt is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation; either version 2, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# PyTQt is supplied 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
|
||||
# PyTQt; see the file LICENSE. If not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
target = pyuic
|
||||
sources = uic.cpp widgetdatabase.cpp domtool.cpp
|
||||
headers = uic.h widgetdatabase.h domtool.h globaldefs.h
|
@ -1,133 +0,0 @@
|
||||
/**********************************************************************
|
||||
** Copyright (C) 2000 Troll Tech AS. All rights reserved.
|
||||
** Copyright (C) 2000, 2001 Phil Thompson <phil@river-bank.demon.co.uk>
|
||||
**
|
||||
** This file is part of TQt GUI Designer.
|
||||
**
|
||||
** This file may be distributed under the terms of the GNU General
|
||||
** Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file COPYING included in the
|
||||
** packaging of this file. If you did not get the file, send email
|
||||
** to info@trolltech.com
|
||||
**
|
||||
** The file is provided AS IS with NO WARRANTY OF ANY KIND,
|
||||
** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
|
||||
** A PARTICULAR PURPOSE.
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef UIC_H
|
||||
#define UIC_H
|
||||
|
||||
#include <tqnamespace.h>
|
||||
#include <tqdom.h>
|
||||
#include <tqstring.h>
|
||||
#include <tqstringlist.h>
|
||||
#include <tqmap.h>
|
||||
#include <tqtextstream.h>
|
||||
#include <tqcolor.h>
|
||||
|
||||
|
||||
#define PYTQT_VERSION "3.18.1"
|
||||
|
||||
|
||||
class Uic : public TQt
|
||||
{
|
||||
public:
|
||||
Uic( TQTextStream& out, TQDomDocument doc, const TQString &trm );
|
||||
|
||||
void createFormImpl( const TQDomElement &e );
|
||||
|
||||
TQString createObjectImpl( const TQDomElement &e, const TQString& parentClass, const TQString& parent, const TQString& layout = TQString::null );
|
||||
TQString createLayoutImpl( const TQDomElement &e, const TQString& parentClass, const TQString& parent, const TQString& layout = TQString::null );
|
||||
TQString createObjectInstance( const TQString& objClass, const TQString& parent, const TQString& objName );
|
||||
TQString createSpacerImpl( const TQDomElement &e, const TQString& parentClass, const TQString& parent, const TQString& layout = TQString::null );
|
||||
void createExclusiveProperty( const TQDomElement & e, const TQString& exclusiveProp );
|
||||
TQString createListBoxItemImpl( const TQDomElement &e, const TQString &parent );
|
||||
TQString createIconViewItemImpl( const TQDomElement &e, const TQString &parent );
|
||||
TQString createListViewColumnImpl( const TQDomElement &e, const TQString &parent );
|
||||
TQString createListViewItemImpl( const TQDomElement &e, const TQString &parent,
|
||||
const TQString &parentItem );
|
||||
void createColorGroupImpl( const TQString& cg, const TQDomElement& e );
|
||||
TQColorGroup loadColorGroup( const TQDomElement &e );
|
||||
|
||||
TQString getClassName( const TQDomElement& e );
|
||||
TQString getObjectName( const TQDomElement& e );
|
||||
TQString getLayoutName( const TQDomElement& e );
|
||||
|
||||
TQString setObjectProperty( const TQString& objClass, const TQString& obj, const TQString &prop, const TQDomElement &e, bool stdset );
|
||||
|
||||
TQString registerObject( const TQString& name );
|
||||
TQString registeredName( const TQString& name );
|
||||
bool isObjectRegistered( const TQString& name );
|
||||
TQStringList unique( const TQStringList& );
|
||||
|
||||
private:
|
||||
void pushIndent()
|
||||
{
|
||||
++nrindents;
|
||||
setIndent();
|
||||
}
|
||||
|
||||
void popIndent()
|
||||
{
|
||||
--nrindents;
|
||||
setIndent();
|
||||
}
|
||||
|
||||
void setIndent()
|
||||
{
|
||||
indent = "";
|
||||
|
||||
for (int i = 0; i < nrindents; ++i)
|
||||
indent += newindent;
|
||||
}
|
||||
|
||||
void initIndent()
|
||||
{
|
||||
newindent = " ";
|
||||
indent = "";
|
||||
nrindents = 0;
|
||||
}
|
||||
|
||||
TQString indent, newindent;
|
||||
int nrindents;
|
||||
|
||||
TQTextStream& out;
|
||||
TQStringList objectNames;
|
||||
TQMap<TQString,TQString> objectMapper;
|
||||
TQStringList tags;
|
||||
TQStringList layouts;
|
||||
TQString formName;
|
||||
TQString lastItem;
|
||||
TQString trmacro;
|
||||
|
||||
struct Buddy
|
||||
{
|
||||
Buddy( const TQString& k, const TQString& b )
|
||||
: key( k ), buddy( b ) {}
|
||||
Buddy(){}; // for valuelist
|
||||
TQString key;
|
||||
TQString buddy;
|
||||
bool operator==( const Buddy& other ) const
|
||||
{ return (key == other.key); }
|
||||
};
|
||||
struct CustomInclude
|
||||
{
|
||||
TQString header;
|
||||
TQString location;
|
||||
};
|
||||
TQValueList<Buddy> buddies;
|
||||
|
||||
TQStringList layoutObjects;
|
||||
bool isLayout( const TQString& name ) const;
|
||||
|
||||
uint item_used : 1;
|
||||
uint cg_used : 1;
|
||||
uint pal_used : 1;
|
||||
|
||||
TQString pixmapLoaderFunction;
|
||||
TQString nameOfClass;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,640 +0,0 @@
|
||||
/**********************************************************************
|
||||
** Copyright (C) 2000 Trolltech AS. All rights reserved.
|
||||
**
|
||||
** This file is part of TQt Designer.
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
||||
**
|
||||
** Contact info@trolltech.com if any conditions of this licensing are
|
||||
** not clear to you.
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#include <tqvariant.h> // HP-UX compiler needs this here
|
||||
|
||||
#include "widgetdatabase.h"
|
||||
|
||||
#if defined(DESIGNER)
|
||||
#include "../designer/formwindow.h"
|
||||
#include "../designer/pixmapchooser.h"
|
||||
#endif
|
||||
|
||||
//#include "../integration/tdevelop/tdewidgets.h"
|
||||
|
||||
#include <globaldefs.h>
|
||||
#include <tqstrlist.h>
|
||||
#include <tqdict.h>
|
||||
#include <tqfile.h>
|
||||
#include <tqtextstream.h>
|
||||
|
||||
#include <tqmodules.h>
|
||||
|
||||
const int dbsize = 300;
|
||||
const int dbcustom = 200;
|
||||
const int dbdictsize = 211;
|
||||
static WidgetDatabaseRecord* db[ dbsize ];
|
||||
static TQDict<int> *className2Id = 0;
|
||||
static int dbcount = 0;
|
||||
static int dbcustomcount = 200;
|
||||
static TQStrList *wGroups;
|
||||
static TQStrList *invisibleGroups;
|
||||
static bool whatsThisLoaded = FALSE;
|
||||
|
||||
|
||||
WidgetDatabaseRecord::WidgetDatabaseRecord()
|
||||
{
|
||||
isContainer = FALSE;
|
||||
icon = 0;
|
||||
nameCounter = 0;
|
||||
}
|
||||
|
||||
WidgetDatabaseRecord::~WidgetDatabaseRecord()
|
||||
{
|
||||
delete icon;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\class WidgetDatabase widgetdatabase.h
|
||||
\brief The WidgetDatabase class holds information about widgets
|
||||
|
||||
The WidgetDatabase holds information about widgets like toolTip(),
|
||||
iconSet(), ... It works Id-based, so all access functions take the
|
||||
widget id as parameter. To get the id for a widget (classname), use
|
||||
idFromClassName().
|
||||
|
||||
All access functions are static. Having multiple widgetdatabases in
|
||||
one application doesn't make sense anyway and so you don't need more
|
||||
than an instance of the widgetdatabase.
|
||||
|
||||
For creating widgets, layouts, etc. see WidgetFactory.
|
||||
*/
|
||||
|
||||
/*!
|
||||
Creatse widget database. Does nothing
|
||||
*/
|
||||
|
||||
WidgetDatabase::WidgetDatabase()
|
||||
{
|
||||
}
|
||||
|
||||
/*! Sets up the widget database. If the static widgetdatabase already
|
||||
exists, the functions returns immediately.
|
||||
*/
|
||||
|
||||
void WidgetDatabase::setupDataBase()
|
||||
{
|
||||
if ( dbcount )
|
||||
return;
|
||||
|
||||
wGroups = new TQStrList;
|
||||
invisibleGroups = new TQStrList;
|
||||
invisibleGroups->append( "Forms" );
|
||||
invisibleGroups->append( "Temp" );
|
||||
className2Id = new TQDict<int>( dbdictsize );
|
||||
className2Id->setAutoDelete( TRUE );
|
||||
|
||||
WidgetDatabaseRecord *r = 0;
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "pushbutton.xpm";
|
||||
r->name = "TQPushButton";
|
||||
r->group = widgetGroup( "Buttons" );
|
||||
r->toolTip = "Push Button";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "toolbutton.xpm";
|
||||
r->name = "TQToolButton";
|
||||
r->group = widgetGroup( "Buttons" );
|
||||
r->toolTip = "Tool Button";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "radiobutton.xpm";
|
||||
r->name = "TQRadioButton";
|
||||
r->group = widgetGroup( "Buttons" );
|
||||
r->toolTip = "Radio Button";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "checkbox.xpm";
|
||||
r->name = "TQCheckBox";
|
||||
r->group = widgetGroup( "Buttons" );
|
||||
r->toolTip = "Check Box";
|
||||
|
||||
|
||||
|
||||
|
||||
append( r );
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "groupbox.xpm";
|
||||
r->name = "TQGroupBox";
|
||||
r->group = widgetGroup( "Containers" );
|
||||
r->toolTip = "Group Box";
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "buttongroup.xpm";
|
||||
r->name = "TQButtonGroup";
|
||||
r->group = widgetGroup( "Containers" );
|
||||
r->toolTip = "Button Group";
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "frame.xpm";
|
||||
r->name = "TQFrame";
|
||||
r->group = widgetGroup( "Containers" );
|
||||
r->toolTip = "Frame";
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "tabwidget.xpm";
|
||||
r->name = "TQTabWidget";
|
||||
r->group = widgetGroup( "Containers" );
|
||||
r->toolTip = "Tabwidget";
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "listbox.xpm";
|
||||
r->name = "TQListBox";
|
||||
r->group = widgetGroup( "Views" );
|
||||
r->toolTip = "List Box";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "listview.xpm";
|
||||
r->name = "TQListView";
|
||||
r->group = widgetGroup( "Views" );
|
||||
r->toolTip = "List View";
|
||||
|
||||
append( r );
|
||||
|
||||
#if defined(TQT_MODULE_ICONVIEW) || defined(UIC)
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "iconview.xpm";
|
||||
r->name = "TQIconView";
|
||||
r->group = widgetGroup( "Views" );
|
||||
r->toolTip = "Icon View";
|
||||
|
||||
append( r );
|
||||
#endif
|
||||
|
||||
#if defined(TQT_MODULE_TABLE)
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "table.xpm";
|
||||
r->name = "TQTable";
|
||||
r->group = widgetGroup( "Views" );
|
||||
r->toolTip = "Table";
|
||||
|
||||
append( r );
|
||||
#endif
|
||||
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "lineedit.xpm";
|
||||
r->name = "TQLineEdit";
|
||||
r->group = widgetGroup( "Input" );
|
||||
r->toolTip = "Line Edit";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "spinbox.xpm";
|
||||
r->name = "TQSpinBox";
|
||||
r->group = widgetGroup( "Input" );
|
||||
r->toolTip = "Spin Box";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "multilineedit.xpm";
|
||||
r->name = "TQMultiLineEdit";
|
||||
r->group = widgetGroup( "Input" );
|
||||
r->toolTip = "Multi Line Edit";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "combobox.xpm";
|
||||
r->name = "TQComboBox";
|
||||
r->group = widgetGroup( "Input" );
|
||||
r->toolTip = "Combo Box";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "slider.xpm";
|
||||
r->name = "TQSlider";
|
||||
r->group = widgetGroup( "Input" );
|
||||
r->toolTip = "Slider";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "dial.xpm";
|
||||
r->name = "TQDial";
|
||||
r->group = widgetGroup( "Input" );
|
||||
r->toolTip = "Dial";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "label.xpm";
|
||||
r->name = "TQLabel";
|
||||
r->group = widgetGroup( "Temp" );
|
||||
r->toolTip = "Label";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "label.xpm";
|
||||
r->name = "TextLabel";
|
||||
r->group = widgetGroup( "Display" );
|
||||
r->toolTip = "Text Label";
|
||||
r->whatsThis = "The Text Label provides a widget to display static text.";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "pixlabel.xpm";
|
||||
r->name = "PixmapLabel";
|
||||
r->group = widgetGroup( "Display" );
|
||||
r->toolTip = "Pixmap Label";
|
||||
r->whatsThis = "The Pixmap Label provides a widget to display pixmaps.";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "lcdnumber.xpm";
|
||||
r->name = "TQLCDNumber";
|
||||
r->group = widgetGroup( "Display" );
|
||||
r->toolTip = "LCD Number";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "line.xpm";
|
||||
r->name = "Line";
|
||||
r->group = widgetGroup( "Display" );
|
||||
r->toolTip = "Line";
|
||||
r->includeFile = "qframe.h";
|
||||
r->whatsThis = "The Line widget provides horizontal and vertical lines.";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "progress.xpm";
|
||||
r->name = "TQProgressBar";
|
||||
r->group = widgetGroup( "Display" );
|
||||
r->toolTip = "Progress Bar";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "textview.xpm";
|
||||
r->name = "TQTextView";
|
||||
r->group = widgetGroup( "Display" );
|
||||
r->toolTip = "Text View";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "textbrowser.xpm";
|
||||
r->name = "TQTextBrowser";
|
||||
r->group = widgetGroup( "Display" );
|
||||
r->toolTip = "Text Browser";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "spacer.xpm";
|
||||
r->name = "Spacer";
|
||||
r->group = widgetGroup( "Temp" );
|
||||
r->toolTip = "Spacer";
|
||||
r->whatsThis = "The Spacer provides horizontal and vertical spacing to be able to manipulate the bahviour of layouts.";
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->name = "TQWidget";
|
||||
r->isContainer = FALSE;
|
||||
r->group = widgetGroup( "Forms" );
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->name = "TQDialog";
|
||||
r->group = widgetGroup( "Forms" );
|
||||
r->isContainer = FALSE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->name = "TQWizard";
|
||||
r->group = widgetGroup( "Forms" );
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->name = "TQDesignerWizard";
|
||||
r->group = widgetGroup( "Forms" );
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->name = "TQLayoutWidget";
|
||||
r->group = widgetGroup( "Temp" );
|
||||
r->includeFile = "";
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "tabwidget.xpm";
|
||||
r->name = "TQDesignerTabWidget";
|
||||
r->group = widgetGroup( "Temp" );
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "tabwidget.xpm";
|
||||
r->name = "TQDesignerWidget";
|
||||
r->group = widgetGroup( "Temp" );
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
r = new WidgetDatabaseRecord;
|
||||
r->iconSet = "tabwidget.xpm";
|
||||
r->name = "TQDesignerDialog";
|
||||
r->group = widgetGroup( "Temp" );
|
||||
r->isContainer = TRUE;
|
||||
|
||||
append( r );
|
||||
|
||||
// tqt_init_kde_widget_database();
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the number of elements in the widget database.
|
||||
*/
|
||||
|
||||
int WidgetDatabase::count()
|
||||
{
|
||||
setupDataBase();
|
||||
return dbcount;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the id at which the ids of custom widgets start.
|
||||
*/
|
||||
|
||||
int WidgetDatabase::startCustom()
|
||||
{
|
||||
setupDataBase();
|
||||
return dbcustom;
|
||||
}
|
||||
|
||||
/*! Returns the iconset which represents the class registered as \a
|
||||
id.
|
||||
*/
|
||||
|
||||
TQIconSet WidgetDatabase::iconSet( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return TQIconSet();
|
||||
#if defined(DESIGNER)
|
||||
if ( !r->icon )
|
||||
r->icon = new TQIconSet( PixmapChooser::loadPixmap( r->iconSet, PixmapChooser::Small ),
|
||||
PixmapChooser::loadPixmap( r->iconSet, PixmapChooser::Large ) );
|
||||
return *r->icon;
|
||||
#endif
|
||||
|
||||
return TQIconSet();
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the classname of the widget which is registered as \a id.
|
||||
*/
|
||||
|
||||
TQString WidgetDatabase::className( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return TQString::null;
|
||||
return r->name;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the group to which the widget registered as \a id belongs.
|
||||
*/
|
||||
|
||||
TQString WidgetDatabase::group( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return TQString::null;
|
||||
return r->group;
|
||||
}
|
||||
|
||||
/*! Returns the tooltip text of the widget which is registered as \a
|
||||
id.
|
||||
*/
|
||||
|
||||
TQString WidgetDatabase::toolTip( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return TQString::null;
|
||||
return r->toolTip;
|
||||
}
|
||||
|
||||
/*! Returns the what's this? test of the widget which is registered
|
||||
as \a id.
|
||||
*/
|
||||
|
||||
TQString WidgetDatabase::whatsThis( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return TQString::null;
|
||||
return r->whatsThis;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the include file if the widget which is registered as \a id.
|
||||
*/
|
||||
|
||||
TQString WidgetDatabase::includeFile( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return TQString::null;
|
||||
if ( r->includeFile.isNull() )
|
||||
return r->name.lower() + ".h";
|
||||
return r->includeFile;
|
||||
}
|
||||
|
||||
/*! Returns wheather the widget registered as \a id is a container
|
||||
(can have children) or not.
|
||||
*/
|
||||
|
||||
bool WidgetDatabase::isContainer( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return FALSE;
|
||||
return r->isContainer;
|
||||
}
|
||||
|
||||
TQString WidgetDatabase::createWidgetName( int id )
|
||||
{
|
||||
setupDataBase();
|
||||
TQString n = className( id );
|
||||
if ( n == "TQLayoutWidget" )
|
||||
n = "Layout";
|
||||
if ( n[ 0 ] == 'Q' )
|
||||
n = n.mid( 1 );
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( !r )
|
||||
return n;
|
||||
n += TQString::number( ++r->nameCounter );
|
||||
return n;
|
||||
}
|
||||
|
||||
/*! Returns the id for \a name or -1 if \a name is unknown.
|
||||
*/
|
||||
int WidgetDatabase::idFromClassName( const TQString &name )
|
||||
{
|
||||
setupDataBase();
|
||||
if ( name.isEmpty() )
|
||||
return 0;
|
||||
int *i = className2Id->find( name );
|
||||
if ( i )
|
||||
return *i;
|
||||
if ( name == "FormWindow" )
|
||||
return idFromClassName( "TQLayoutWidget" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
WidgetDatabaseRecord *WidgetDatabase::at( int index )
|
||||
{
|
||||
if ( index < 0 )
|
||||
return 0;
|
||||
if ( index >= dbcustom && index < dbcustomcount )
|
||||
return db[ index ];
|
||||
if ( index < dbcount )
|
||||
return db[ index ];
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WidgetDatabase::insert( int index, WidgetDatabaseRecord *r )
|
||||
{
|
||||
if ( index < 0 || index >= dbsize )
|
||||
return;
|
||||
db[ index ] = r;
|
||||
className2Id->insert( r->name, new int( index ) );
|
||||
if ( index < dbcustom )
|
||||
dbcount = TQMAX( dbcount, index );
|
||||
}
|
||||
|
||||
void WidgetDatabase::append( WidgetDatabaseRecord *r )
|
||||
{
|
||||
insert( dbcount++, r );
|
||||
}
|
||||
|
||||
TQString WidgetDatabase::widgetGroup( const TQString &g )
|
||||
{
|
||||
if ( wGroups->find( g ) == -1 )
|
||||
wGroups->append( g );
|
||||
return g;
|
||||
}
|
||||
|
||||
TQString WidgetDatabase::widgetGroup( int i )
|
||||
{
|
||||
setupDataBase();
|
||||
if ( i >= 0 && i < (int)wGroups->count() )
|
||||
return wGroups->at( i );
|
||||
return TQString::null;
|
||||
}
|
||||
|
||||
int WidgetDatabase::numWidgetGroups()
|
||||
{
|
||||
setupDataBase();
|
||||
return wGroups->count();
|
||||
}
|
||||
|
||||
bool WidgetDatabase::isGroupVisible( const TQString &g )
|
||||
{
|
||||
setupDataBase();
|
||||
return invisibleGroups->find( g ) == -1;
|
||||
}
|
||||
|
||||
int WidgetDatabase::addCustomWidget( WidgetDatabaseRecord *r )
|
||||
{
|
||||
insert( dbcustomcount++, r );
|
||||
return dbcustomcount - 1;
|
||||
}
|
||||
|
||||
bool WidgetDatabase::isCustomWidget( int id )
|
||||
{
|
||||
if ( id >= dbcustom && id < dbcustomcount )
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool WidgetDatabase::isWhatsThisLoaded()
|
||||
{
|
||||
return whatsThisLoaded;
|
||||
}
|
||||
|
||||
void WidgetDatabase::loadWhatsThis( const TQString &docPath )
|
||||
{
|
||||
TQString whatsthisFile = docPath + "/whatsthis";
|
||||
TQFile f( whatsthisFile );
|
||||
if ( !f.open( IO_ReadOnly ) )
|
||||
return;
|
||||
TQTextStream ts( &f );
|
||||
while ( !ts.atEnd() ) {
|
||||
TQString s = ts.readLine();
|
||||
TQStringList l = TQStringList::split( " | ", s );
|
||||
int id = idFromClassName( l[ 1 ] );
|
||||
WidgetDatabaseRecord *r = at( id );
|
||||
if ( r )
|
||||
r->whatsThis = l[ 0 ];
|
||||
}
|
||||
whatsThisLoaded = TRUE;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/**********************************************************************
|
||||
** Copyright (C) 2000 Trolltech AS. All rights reserved.
|
||||
**
|
||||
** This file is part of TQt Designer.
|
||||
**
|
||||
** This file may be distributed and/or modified under the terms of the
|
||||
** GNU General Public License version 2 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.GPL included in the
|
||||
** packaging of this file.
|
||||
**
|
||||
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
**
|
||||
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
||||
**
|
||||
** Contact info@trolltech.com if any conditions of this licensing are
|
||||
** not clear to you.
|
||||
**
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef WIDGETDATABASE_H
|
||||
#define WIDGETDATABASE_H
|
||||
|
||||
#include <tqiconset.h>
|
||||
#include <tqstring.h>
|
||||
#include <tqstringlist.h>
|
||||
|
||||
struct WidgetDatabaseRecord
|
||||
{
|
||||
WidgetDatabaseRecord();
|
||||
~WidgetDatabaseRecord();
|
||||
TQString iconSet, name, group, toolTip, whatsThis, includeFile;
|
||||
uint isContainer : 1;
|
||||
TQIconSet *icon;
|
||||
int nameCounter;
|
||||
};
|
||||
|
||||
class WidgetDatabase : public TQt
|
||||
{
|
||||
public:
|
||||
WidgetDatabase();
|
||||
static void setupDataBase();
|
||||
|
||||
static int count();
|
||||
static int startCustom();
|
||||
|
||||
static TQIconSet iconSet( int id );
|
||||
static TQString className( int id );
|
||||
static TQString group( int id );
|
||||
static TQString toolTip( int id );
|
||||
static TQString whatsThis( int id );
|
||||
static TQString includeFile( int id );
|
||||
static bool isContainer( int id );
|
||||
|
||||
static int idFromClassName( const TQString &name );
|
||||
static TQString createWidgetName( int id );
|
||||
|
||||
static WidgetDatabaseRecord *at( int index );
|
||||
static void insert( int index, WidgetDatabaseRecord *r );
|
||||
static void append( WidgetDatabaseRecord *r );
|
||||
|
||||
static TQString widgetGroup( const TQString &g );
|
||||
static TQString widgetGroup( int i );
|
||||
static int numWidgetGroups();
|
||||
static bool isGroupVisible( const TQString &g );
|
||||
|
||||
static int addCustomWidget( WidgetDatabaseRecord *r );
|
||||
static bool isCustomWidget( int id );
|
||||
|
||||
static bool isWhatsThisLoaded();
|
||||
static void loadWhatsThis( const TQString &docPath );
|
||||
|
||||
};
|
||||
|
||||
#endif
|