diff options
author | Timothy Pearson <[email protected]> | 2011-11-29 00:31:00 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-29 00:31:00 -0600 |
commit | b388516ca2691303a076a0764fd40bf7116fe43d (patch) | |
tree | 6f1615d1f12b325f4d1cd9c25d1519303794001a /examples3 | |
download | pytqt-b388516ca2691303a076a0764fd40bf7116fe43d.tar.gz pytqt-b388516ca2691303a076a0764fd40bf7116fe43d.zip |
Initial import of python-qt3
Diffstat (limited to 'examples3')
111 files changed, 14004 insertions, 0 deletions
diff --git a/examples3/README b/examples3/README new file mode 100644 index 0000000..4a8f9eb --- /dev/null +++ b/examples3/README @@ -0,0 +1,12 @@ +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 Qt v3.x. + +A much better source of information about using PyQt is Boudewijn Rempt's +book at http://stage.linuxports.com/projects/pyqt/. + + +Phil Thompson diff --git a/examples3/SQL/README b/examples3/SQL/README new file mode 100644 index 0000000..9dfc5d4 --- /dev/null +++ b/examples3/SQL/README @@ -0,0 +1,76 @@ +This directory contains some translated sql examples from Qt 3.x. + +runform1.py, form1.ui: + + A simple designer generated QDataTable. Run "pyuic form1.ui -o form1.py". + +runform2.py, form2.ui: + + A simple designer generated QDataBrowser. Run "pyuic form2.ui -o form2.py". + +sqlcustom1.py: + + QSqlForm based form with a simple custom editor forcing all input to + be uppercase + +sqltable4.py: + + Custom QDataTable with reimplemented paintField method, combined with + a QComboBox based custom field editor (StatusPicker), gathering its + items from a different table (status) and a calculated column (monsalary). + Note, that QSqlEditorFactory based field editors are somewhat restricted, + because Qt's Q_PROPERTY feature isn't supported, yet. I've circumvented + this limitation by choosing the status table ids corresponding to the + index in the QComboBox. + +sqlsubclass5.py: + + Similar to the former, and even more deviated from its qt ancestor, + because the sense escaped me. This could be related to the different + database layout needed for MySQL (Trolltech used PostgreSQL sequences, + while we're using the simpler, but less powerful auto_increment here). + If you enter and invalid date (e.g. day: 0) in the Paid column, it is + shown as "not yet", but produces some qt warnings. + +runsqlex.py, sqlex.ui, sqlex.ui.h, connect.ui, connect.ui.h: + + This one is a most advanced example, showing the use of a QSqlCursor + driven by QSqlQuery and iterating through database tables and fields. + Definitely worth a look. + +Unfortunately you will have to make sure that these prerequisites are met +before trying the examples: + + - Install MySQL or PostgreSQL and any development packages + + - Create a database user with sufficient rights + + - Create the testdb database + - For MySQL, run: mysql -u user -p password < testdb_mysql.sql + - For PostgreSQL, run: psql -U user template1 -f testdb_pg.sql + + - Build Qt with the mysql and/or psql modules activated. + +Now you should be ready for the fun part. You can run dbconnect.py from +a command line and try to connect to the database. If all went well, +'ok' should be printed after pressing OK. If you don't want to enter all +your data over and over again, create a file named local_dbpar.py here, +with the following keys (with your own data, of course): + +DB_HOSTNAMES = ["localhost"] +DB_DATABASES = ["testdb"] +DB_USERNAME = "name" +DB_PASSWORD = "pass" + +The dbconnect.py script is generated from dbconnect.ui, which was created +with qt's designer. You can find it also in Boudewijn Rempt's book +"GUI Programming with Python, using the Qt Toolkit". Although you won't find +the SQL widgets discussed there, for the simple reason of the book being +written before they appeared, it is a valuable source for anybody new in +this area. + +Please direct any comments, patches and questions to <[email protected]>. + +Good luck + +Hans-Peter Jansen <[email protected]> diff --git a/examples3/SQL/connect.ui b/examples3/SQL/connect.ui new file mode 100644 index 0000000..cc41920 --- /dev/null +++ b/examples3/SQL/connect.ui @@ -0,0 +1,238 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>ConnectDialog</class> +<widget class="QDialog"> + <property name="name"> + <cstring>ConnectDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>303</width> + <height>251</height> + </rect> + </property> + <property name="caption"> + <string>Connect...</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QGroupBox"> + <property name="name"> + <cstring>GroupBox3</cstring> + </property> + <property name="title"> + <string>Connection settings</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>editDatabase</cstring> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>TextLabel3</cstring> + </property> + <property name="text"> + <string>Database Name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>comboDatabase</cstring> + </property> + </widget> + <widget class="QLineEdit" row="3" column="1"> + <property name="name"> + <cstring>editPassword</cstring> + </property> + <property name="echoMode"> + <enum>Password</enum> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>TextLabel4</cstring> + </property> + <property name="text"> + <string>&Username:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>editUsername</cstring> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>TextLabel4_2</cstring> + </property> + <property name="text"> + <string>&Password:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>editPassword</cstring> + </property> + </widget> + <widget class="QComboBox" row="0" column="1"> + <property name="name"> + <cstring>comboDriver</cstring> + </property> + </widget> + <widget class="QLineEdit" row="2" column="1"> + <property name="name"> + <cstring>editUsername</cstring> + </property> + </widget> + <widget class="QLineEdit" row="4" column="1"> + <property name="name"> + <cstring>editHostname</cstring> + </property> + </widget> + <widget class="QLabel" row="4" column="0"> + <property name="name"> + <cstring>TextLabel5</cstring> + </property> + <property name="text"> + <string>&Hostname:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>editHostname</cstring> + </property> + </widget> + <widget class="QLabel" row="5" column="0"> + <property name="name"> + <cstring>TextLabel5_2</cstring> + </property> + <property name="text"> + <string>P&ort:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>portSpinBox</cstring> + </property> + </widget> + <widget class="QSpinBox" row="5" column="1"> + <property name="name"> + <cstring>portSpinBox</cstring> + </property> + <property name="specialValueText"> + <string>Default</string> + </property> + <property name="maxValue"> + <number>65535</number> + </property> + <property name="minValue"> + <number>-1</number> + </property> + <property name="value"> + <number>-1</number> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>TextLabel2</cstring> + </property> + <property name="text"> + <string>D&river</string> + </property> + <property name="buddy" stdset="0"> + <cstring>comboDriver</cstring> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>Layout25</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButton1</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButton2</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<connections> + <connection> + <sender>PushButton1</sender> + <signal>clicked()</signal> + <receiver>ConnectDialog</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>PushButton2</sender> + <signal>clicked()</signal> + <receiver>ConnectDialog</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>comboDriver</tabstop> + <tabstop>editDatabase</tabstop> + <tabstop>editUsername</tabstop> + <tabstop>editPassword</tabstop> + <tabstop>editHostname</tabstop> + <tabstop>portSpinBox</tabstop> + <tabstop>PushButton1</tabstop> + <tabstop>PushButton2</tabstop> +</tabstops> +<includes> + <include location="local" impldecl="in implementation">connect.ui.h</include> +</includes> +<slots> + <slot>init()</slot> + <slot>destroy()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/examples3/SQL/connect.ui.h b/examples3/SQL/connect.ui.h new file mode 100644 index 0000000..cbeeabd --- /dev/null +++ b/examples3/SQL/connect.ui.h @@ -0,0 +1,21 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename slots use Qt Designer which will +** update this file, preserving your code. Create an init() slot in place of +** a constructor, and a destroy() slot in place of a destructor. +*****************************************************************************/ + + +void ConnectDialog::init() +{ +from qtsql import QSqlDatabase +#qDebug("ConnectDialog init") +self.comboDriver.clear() +self.comboDriver.insertStringList(QSqlDatabase.drivers()) +} + +void ConnectDialog::destroy() +{ + +} diff --git a/examples3/SQL/dbconnect.py b/examples3/SQL/dbconnect.py new file mode 100755 index 0000000..fdae7de --- /dev/null +++ b/examples3/SQL/dbconnect.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +import sys +from qt import * +from qtsql import * + +from frmconnect import frmConnect +from dbpar import * + +TRUE = 1 +FALSE = 0 + +def createConnection(): + driver = DB_DRIVER + # all qt examples use QSqlDatabase::addDatabase, but + # this never returns NULL in my experience + drivers = map(str, QSqlDatabase.drivers()) + if driver in drivers: + dlg = dbConnect(driver) + #TODO: make connection parameters accessible + return dlg.exec_loop() + else: + QMessageBox.warning(None, "Database Error", + "<%s> database driver not found!\n\n" + "Please make sure, that this database adaptor\n" + "is available in your Qt installation.\n" % + (driver), QMessageBox.Abort | QMessageBox.Escape) + return FALSE + +class dbConnect(frmConnect): + def __init__(self, driver, parent = None): + frmConnect.__init__(self, parent) + self.hostnames = DB_HOSTNAMES + self.hostname = DB_HOSTNAMES[0] + self.databases = DB_DATABASES + self.database = DB_DATABASES[0] + self.username = DB_USERNAME + self.password = DB_PASSWORD + self.dbdriver = driver + + self.txtName.setText(self.username) + self.txtPasswd.setText(self.password) + map(self.cmbServer.insertItem, self.hostnames) + map(self.cmbDatabase.insertItem, self.databases) + self.connect(self.buttonHelp, SIGNAL("clicked()"), + self.buttonHelp_clicked) + + def accept(self): + self.hostname = self.cmbServer.currentText() + self.database = self.cmbDatabase.currentText() + self.username = self.txtName.text() + self.password = self.txtPasswd.text() + db = QSqlDatabase.addDatabase(self.dbdriver) + if db: + db.setHostName(self.hostname) + db.setDatabaseName(self.database) + db.setUserName(self.username) + db.setPassword(self.password) + if db.open(): + frmConnect.accept(self) + else: + QMessageBox.warning(self, "Database Error", + "Cannot open %s database on %s!\n\n%s\n%s\n" % + (self.database, self.hostname, + db.lastError().driverText(), + db.lastError().databaseText()), " Ooops ") + + + def buttonHelp_clicked(self): + QMessageBox.information(self, "About Connecting", + "Here you specify userid, password, host and database\n" + "for the PyQt sql examples. If you encounter any problems,\n" + "please read the README file in this folder before posting.\n\n" + "Thanks,\nHans-Peter Jansen <[email protected]>\n") + + +if __name__ == "__main__": + app = QApplication(sys.argv) + if createConnection(): + print "ok" + else: + print "cancel" diff --git a/examples3/SQL/dbpar.py b/examples3/SQL/dbpar.py new file mode 100644 index 0000000..90e9270 --- /dev/null +++ b/examples3/SQL/dbpar.py @@ -0,0 +1,22 @@ +# sql examples default database parameter + +# you can create a local_dbpar.py module with definitons +# of your own parameters to overrule these defaults + +#DB_DRIVER = "QPSQL7" +DB_DRIVER = "QMYSQL3" +# list of servers +DB_HOSTNAMES = ["localhost"] +# list of databases +DB_DATABASES = ["testdb"] +# database user id +DB_USERNAME = "" +# database password +DB_PASSWORD = "" + +# remove this in your local_dbpar.py +try: + from local_dbpar import * +except: + pass + diff --git a/examples3/SQL/form1.ui b/examples3/SQL/form1.ui new file mode 100644 index 0000000..38b3cb2 --- /dev/null +++ b/examples3/SQL/form1.ui @@ -0,0 +1,77 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>Form1</class> +<widget class="QDialog"> + <property name="name"> + <cstring>Form1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>370</height> + </rect> + </property> + <property name="caption"> + <string>Form1</string> + </property> + <widget class="QDataTable"> + <column> + <property name="text"> + <string>Forename</string> + </property> + <property name="field"> + <string>forename</string> + </property> + </column> + <column> + <property name="text"> + <string>Surname</string> + </property> + <property name="field"> + <string>surname</string> + </property> + </column> + <column> + <property name="text"> + <string>Salary</string> + </property> + <property name="field"> + <string>salary</string> + </property> + </column> + <column> + <property name="text"> + <string>Statusid</string> + </property> + <property name="field"> + <string>statusid</string> + </property> + </column> + <property name="name"> + <cstring>DataTable2</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>370</height> + </rect> + </property> + <property name="sorting"> + <bool>true</bool> + </property> + <property name="confirmDelete"> + <bool>true</bool> + </property> + <property name="database" stdset="0"> + <stringlist> + <string>(default)</string> + <string>staff</string> + </stringlist> + </property> + </widget> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/examples3/SQL/form2.ui b/examples3/SQL/form2.ui new file mode 100644 index 0000000..ffe2beb --- /dev/null +++ b/examples3/SQL/form2.ui @@ -0,0 +1,327 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>Form2</class> +<widget class="QDialog"> + <property name="name"> + <cstring>Form2</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>367</width> + <height>152</height> + </rect> + </property> + <property name="caption"> + <string>Form2</string> + </property> + <widget class="QDataBrowser"> + <property name="name"> + <cstring>DataBrowser1</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>366</width> + <height>150</height> + </rect> + </property> + <property name="sort"> + <stringlist> + <string>surname ASC</string> + <string>forename ASC</string> + </stringlist> + </property> + <property name="database" stdset="0"> + <stringlist> + <string>(default)</string> + <string>staff</string> + </stringlist> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>Layout2</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>labelSurname</cstring> + </property> + <property name="text"> + <string>Surname</string> + </property> + </widget> + <widget class="QSpinBox" row="1" column="3"> + <property name="name"> + <cstring>QSpinBoxStatusid</cstring> + </property> + <property name="maxValue"> + <number>2147483647</number> + </property> + <property name="database" stdset="0"> + <stringlist> + <string>(default)</string> + <string>staff</string> + <string>statusid</string> + </stringlist> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>QLineEditSurname</cstring> + </property> + <property name="database" stdset="0"> + <stringlist> + <string>(default)</string> + <string>staff</string> + <string>surname</string> + </stringlist> + </property> + </widget> + <widget class="QLabel" row="1" column="2"> + <property name="name"> + <cstring>labelStatusid</cstring> + </property> + <property name="text"> + <string>Statusid</string> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>labelForename</cstring> + </property> + <property name="text"> + <string>Forename</string> + </property> + </widget> + <widget class="QLineEdit" row="0" column="3"> + <property name="name"> + <cstring>QLineEditSalary</cstring> + </property> + <property name="alignment"> + <set>AlignRight</set> + </property> + <property name="database" stdset="0"> + <stringlist> + <string>(default)</string> + <string>staff</string> + <string>salary</string> + </stringlist> + </property> + </widget> + <widget class="QLabel" row="0" column="2"> + <property name="name"> + <cstring>labelSalary</cstring> + </property> + <property name="text"> + <string>Salary</string> + </property> + </widget> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>QLineEditForename</cstring> + </property> + <property name="database" stdset="0"> + <stringlist> + <string>(default)</string> + <string>staff</string> + <string>forename</string> + </stringlist> + </property> + </widget> + </grid> + </widget> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>Layout3</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButtonFirst</cstring> + </property> + <property name="text"> + <string>|< &First</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButtonPrev</cstring> + </property> + <property name="text"> + <string><< &Prev</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButtonNext</cstring> + </property> + <property name="text"> + <string>&Next >></string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButtonLast</cstring> + </property> + <property name="text"> + <string>&Last >|</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QLayoutWidget" row="2" column="0"> + <property name="name"> + <cstring>Layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButtonInsert</cstring> + </property> + <property name="text"> + <string>&Insert</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButtonUpdate</cstring> + </property> + <property name="text"> + <string>&Update</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>PushButtonDelete</cstring> + </property> + <property name="text"> + <string>&Delete</string> + </property> + </widget> + </hbox> + </widget> + </grid> + </widget> +</widget> +<connections> + <connection> + <sender>PushButtonFirst</sender> + <signal>clicked()</signal> + <receiver>DataBrowser1</receiver> + <slot>first()</slot> + </connection> + <connection> + <sender>DataBrowser1</sender> + <signal>firstRecordAvailable( bool )</signal> + <receiver>PushButtonFirst</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>PushButtonPrev</sender> + <signal>clicked()</signal> + <receiver>DataBrowser1</receiver> + <slot>prev()</slot> + </connection> + <connection> + <sender>DataBrowser1</sender> + <signal>prevRecordAvailable( bool )</signal> + <receiver>PushButtonPrev</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>PushButtonNext</sender> + <signal>clicked()</signal> + <receiver>DataBrowser1</receiver> + <slot>next()</slot> + </connection> + <connection> + <sender>DataBrowser1</sender> + <signal>nextRecordAvailable( bool )</signal> + <receiver>PushButtonNext</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>PushButtonLast</sender> + <signal>clicked()</signal> + <receiver>DataBrowser1</receiver> + <slot>last()</slot> + </connection> + <connection> + <sender>DataBrowser1</sender> + <signal>lastRecordAvailable( bool )</signal> + <receiver>PushButtonLast</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>PushButtonInsert</sender> + <signal>clicked()</signal> + <receiver>DataBrowser1</receiver> + <slot>insert()</slot> + </connection> + <connection> + <sender>PushButtonUpdate</sender> + <signal>clicked()</signal> + <receiver>DataBrowser1</receiver> + <slot>update()</slot> + </connection> + <connection> + <sender>PushButtonDelete</sender> + <signal>clicked()</signal> + <receiver>DataBrowser1</receiver> + <slot>del()</slot> + </connection> +</connections> +<tabstops> + <tabstop>QLineEditForename</tabstop> + <tabstop>QLineEditSurname</tabstop> + <tabstop>QLineEditSalary</tabstop> + <tabstop>QSpinBoxStatusid</tabstop> + <tabstop>PushButtonFirst</tabstop> + <tabstop>PushButtonPrev</tabstop> + <tabstop>PushButtonNext</tabstop> + <tabstop>PushButtonLast</tabstop> + <tabstop>PushButtonInsert</tabstop> + <tabstop>PushButtonUpdate</tabstop> + <tabstop>PushButtonDelete</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/examples3/SQL/frmconnect.py b/examples3/SQL/frmconnect.py new file mode 100644 index 0000000..23cd067 --- /dev/null +++ b/examples3/SQL/frmconnect.py @@ -0,0 +1,120 @@ +# Form implementation generated from reading ui file 'frmconnect.ui' +# +# Created: Sam Jul 6 12:47:10 2002 +# by: The PyQt User Interface Compiler (pyuic) +# +# WARNING! All changes made in this file will be lost! + + +from qt import * + + +class frmConnect(QDialog): + def __init__(self,parent = None,name = None,modal = 0,fl = 0): + QDialog.__init__(self,parent,name,modal,fl) + + if name == None: + self.setName("frmConnect") + + self.resize(415,154) + self.setCaption(self.trUtf8("Connecting")) + self.setSizeGripEnabled(1) + + frmConnectLayout = QGridLayout(self,1,1,11,6,"frmConnectLayout") + + Layout7 = QVBoxLayout(None,0,6,"Layout7") + + self.buttonOK = QPushButton(self,"buttonOK") + self.buttonOK.setText(self.trUtf8("&OK")) + self.buttonOK.setAutoDefault(1) + self.buttonOK.setDefault(1) + QToolTip.add(self.buttonOK,self.trUtf8("Connect to Database")) + Layout7.addWidget(self.buttonOK) + + self.buttonCancel = QPushButton(self,"buttonCancel") + self.buttonCancel.setText(self.trUtf8("&Cancel")) + QToolTip.add(self.buttonCancel,self.trUtf8("Cancel Connecting")) + Layout7.addWidget(self.buttonCancel) + + self.buttonHelp = QPushButton(self,"buttonHelp") + self.buttonHelp.setText(self.trUtf8("&Help")) + QToolTip.add(self.buttonHelp,self.trUtf8("About Connecting")) + Layout7.addWidget(self.buttonHelp) + spacer = QSpacerItem(0,0,QSizePolicy.Minimum,QSizePolicy.Expanding) + Layout7.addItem(spacer) + + frmConnectLayout.addLayout(Layout7,0,1) + + self.grpConnection = QGroupBox(self,"grpConnection") + self.grpConnection.setTitle(self.trUtf8("")) + self.grpConnection.setColumnLayout(0,Qt.Vertical) + self.grpConnection.layout().setSpacing(6) + self.grpConnection.layout().setMargin(11) + grpConnectionLayout = QGridLayout(self.grpConnection.layout()) + grpConnectionLayout.setAlignment(Qt.AlignTop) + + self.txtName = QLineEdit(self.grpConnection,"txtName") + self.txtName.setMaxLength(16) + QToolTip.add(self.txtName,self.trUtf8("Database User ID")) + + grpConnectionLayout.addWidget(self.txtName,0,1) + + self.lblDatabase = QLabel(self.grpConnection,"lblDatabase") + self.lblDatabase.setText(self.trUtf8("&Database")) + + grpConnectionLayout.addWidget(self.lblDatabase,3,0) + + self.lblServer = QLabel(self.grpConnection,"lblServer") + self.lblServer.setText(self.trUtf8("&Server")) + + grpConnectionLayout.addWidget(self.lblServer,2,0) + + self.lblName = QLabel(self.grpConnection,"lblName") + self.lblName.setText(self.trUtf8("&Name")) + + grpConnectionLayout.addWidget(self.lblName,0,0) + + self.cmbDatabase = QComboBox(0,self.grpConnection,"cmbDatabase") + self.cmbDatabase.setEditable(1) + self.cmbDatabase.setAutoCompletion(1) + self.cmbDatabase.setDuplicatesEnabled(0) + QToolTip.add(self.cmbDatabase,self.trUtf8("Database Name")) + + grpConnectionLayout.addWidget(self.cmbDatabase,3,1) + + self.txtPasswd = QLineEdit(self.grpConnection,"txtPasswd") + self.txtPasswd.setMaxLength(16) + self.txtPasswd.setEchoMode(QLineEdit.Password) + QToolTip.add(self.txtPasswd,self.trUtf8("Database User Password")) + + grpConnectionLayout.addWidget(self.txtPasswd,1,1) + + self.lblPasswd = QLabel(self.grpConnection,"lblPasswd") + self.lblPasswd.setText(self.trUtf8("&Password")) + + grpConnectionLayout.addWidget(self.lblPasswd,1,0) + + self.cmbServer = QComboBox(0,self.grpConnection,"cmbServer") + self.cmbServer.setEditable(1) + self.cmbServer.setAutoCompletion(1) + self.cmbServer.setDuplicatesEnabled(0) + QToolTip.add(self.cmbServer,self.trUtf8("Database Server Address")) + + grpConnectionLayout.addWidget(self.cmbServer,2,1) + + frmConnectLayout.addWidget(self.grpConnection,0,0) + + self.connect(self.buttonOK,SIGNAL("clicked()"),self,SLOT("accept()")) + self.connect(self.buttonCancel,SIGNAL("clicked()"),self,SLOT("reject()")) + + self.setTabOrder(self.txtName,self.txtPasswd) + self.setTabOrder(self.txtPasswd,self.cmbServer) + self.setTabOrder(self.cmbServer,self.cmbDatabase) + self.setTabOrder(self.cmbDatabase,self.buttonOK) + self.setTabOrder(self.buttonOK,self.buttonCancel) + self.setTabOrder(self.buttonCancel,self.buttonHelp) + + self.lblDatabase.setBuddy(self.cmbDatabase) + self.lblServer.setBuddy(self.cmbServer) + self.lblName.setBuddy(self.txtName) + self.lblPasswd.setBuddy(self.txtPasswd) diff --git a/examples3/SQL/frmconnect.ui b/examples3/SQL/frmconnect.ui new file mode 100644 index 0000000..a6fc15c --- /dev/null +++ b/examples3/SQL/frmconnect.ui @@ -0,0 +1,245 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>frmConnect</class> +<widget class="QDialog"> + <property name="name"> + <cstring>frmConnect</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>415</width> + <height>154</height> + </rect> + </property> + <property name="caption"> + <string>Connecting</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="0" column="1"> + <property name="name"> + <cstring>Layout7</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonOK</cstring> + </property> + <property name="text"> + <string>&OK</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Connect to Database</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonCancel</cstring> + </property> + <property name="text"> + <string>&Cancel</string> + </property> + <property name="toolTip" stdset="0"> + <string>Cancel Connecting</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>buttonHelp</cstring> + </property> + <property name="text"> + <string>&Help</string> + </property> + <property name="toolTip" stdset="0"> + <string>About Connecting</string> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + </spacer> + </vbox> + </widget> + <widget class="QGroupBox" row="0" column="0"> + <property name="name"> + <cstring>grpConnection</cstring> + </property> + <property name="title"> + <string></string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLineEdit" row="0" column="1"> + <property name="name"> + <cstring>txtName</cstring> + </property> + <property name="maxLength"> + <number>16</number> + </property> + <property name="toolTip" stdset="0"> + <string>Database User ID</string> + </property> + </widget> + <widget class="QLabel" row="3" column="0"> + <property name="name"> + <cstring>lblDatabase</cstring> + </property> + <property name="text"> + <string>&Database</string> + </property> + <property name="buddy" stdset="0"> + <cstring>cmbDatabase</cstring> + </property> + </widget> + <widget class="QLabel" row="2" column="0"> + <property name="name"> + <cstring>lblServer</cstring> + </property> + <property name="text"> + <string>&Server</string> + </property> + <property name="buddy" stdset="0"> + <cstring>cmbServer</cstring> + </property> + </widget> + <widget class="QLabel" row="0" column="0"> + <property name="name"> + <cstring>lblName</cstring> + </property> + <property name="text"> + <string>&Name</string> + </property> + <property name="buddy" stdset="0"> + <cstring>txtName</cstring> + </property> + </widget> + <widget class="QComboBox" row="3" column="1"> + <property name="name"> + <cstring>cmbDatabase</cstring> + </property> + <property name="editable"> + <bool>true</bool> + </property> + <property name="autoCompletion"> + <bool>true</bool> + </property> + <property name="duplicatesEnabled"> + <bool>false</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Database Name</string> + </property> + </widget> + <widget class="QLineEdit" row="1" column="1"> + <property name="name"> + <cstring>txtPasswd</cstring> + </property> + <property name="maxLength"> + <number>16</number> + </property> + <property name="echoMode"> + <enum>Password</enum> + </property> + <property name="toolTip" stdset="0"> + <string>Database User Password</string> + </property> + </widget> + <widget class="QLabel" row="1" column="0"> + <property name="name"> + <cstring>lblPasswd</cstring> + </property> + <property name="text"> + <string>&Password</string> + </property> + <property name="buddy" stdset="0"> + <cstring>txtPasswd</cstring> + </property> + </widget> + <widget class="QComboBox" row="2" column="1"> + <property name="name"> + <cstring>cmbServer</cstring> + </property> + <property name="editable"> + <bool>true</bool> + </property> + <property name="autoCompletion"> + <bool>true</bool> + </property> + <property name="duplicatesEnabled"> + <bool>false</bool> + </property> + <property name="toolTip" stdset="0"> + <string>Database Server Address</string> + </property> + </widget> + </grid> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>buttonOK</sender> + <signal>clicked()</signal> + <receiver>frmConnect</receiver> + <slot>accept()</slot> + </connection> + <connection> + <sender>buttonCancel</sender> + <signal>clicked()</signal> + <receiver>frmConnect</receiver> + <slot>reject()</slot> + </connection> +</connections> +<tabstops> + <tabstop>txtName</tabstop> + <tabstop>txtPasswd</tabstop> + <tabstop>cmbServer</tabstop> + <tabstop>cmbDatabase</tabstop> + <tabstop>buttonOK</tabstop> + <tabstop>buttonCancel</tabstop> + <tabstop>buttonHelp</tabstop> +</tabstops> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/examples3/SQL/runform1.py b/examples3/SQL/runform1.py new file mode 100755 index 0000000..d5760ce --- /dev/null +++ b/examples3/SQL/runform1.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import sys +from qt import * + +from form1 import Form1 +from dbconnect import createConnection + +class mainWindow(Form1): + def __init__(self,parent = None,name = None,fl = 0): + Form1.__init__(self,parent,name,fl) + +if __name__ == "__main__": + a = QApplication(sys.argv) + if createConnection(): + QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()")) + w = mainWindow() + a.setMainWidget(w) + w.show() + a.exec_loop() + diff --git a/examples3/SQL/runform2.py b/examples3/SQL/runform2.py new file mode 100755 index 0000000..ba0ca4a --- /dev/null +++ b/examples3/SQL/runform2.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import sys +from qt import * + +from form2 import Form2 +from dbconnect import createConnection + +class mainWindow(Form2): + def __init__(self,parent = None,name = None,fl = 0): + Form2.__init__(self,parent,name,fl) + +if __name__ == "__main__": + a = QApplication(sys.argv) + if createConnection(): + QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()")) + w = mainWindow() + a.setMainWidget(w) + w.show() + a.exec_loop() + diff --git a/examples3/SQL/runsqlex.py b/examples3/SQL/runsqlex.py new file mode 100755 index 0000000..7f2afa7 --- /dev/null +++ b/examples3/SQL/runsqlex.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python + +import sys +from qt import * +from qtsql import * + +from sqlex import SqlEx +from connect import ConnectDialog + +from dbpar import * + +TRUE = 1 +FALSE = 0 + +def showError(err, parent): + errStr = QString("The database reported an error:\n\n") + if not err.databaseText().isEmpty(): + errStr.append(err.databaseText()) + errStr.append("\n") + if not err.driverText().isEmpty(): + errStr.append(err.driverText()) + errStr.append("\n") + QMessageBox.warning(parent, "Error", errStr) + +class CustomSqlCursor(QSqlCursor): + def __init__(self, query = None, autopopulate = TRUE, db = None): + QSqlCursor.__init__(self, None, autopopulate, db) + self.execQuery(query) + if self.isSelect() and autopopulate: + fields = self.driver().recordInfo(self) + for f in fields: + self.append(f) + self.setMode(QSqlCursor.ReadOnly) + + def select(self, filter, sort = QSqlIndex()): + return self.execQuery(self.lastQuery()) + + def primaryIndex(self, prime = TRUE): + return QSqlIndex() + + def insert(self, invalidate = TRUE): + return FALSE + + def update(self, invalidate = TRUE): + return FALSE + + def delRecords(self, invalidate = TRUE): + return FALSE + + def setName(self, name, autopopulate = TRUE): + return + + +class MainWindow(SqlEx): + def __init__(self,parent = None,name = None,fl = 0): + SqlEx.__init__(self,parent,name,fl) + self.conDiag = ConnectDialog(self, "Connection Dialog", TRUE) + self.firstconn = TRUE + + def dbConnect(self): + if self.firstconn: + self.firstconn = FALSE + self.conDiag.editUsername.setText(DB_USERNAME) + self.conDiag.editPassword.setText(DB_PASSWORD) + self.conDiag.editHostname.setText(DB_HOSTNAMES[0]) + self.conDiag.editDatabase.setText(DB_DATABASES[0]) + for i in range(self.conDiag.comboDriver.count()): + if str(self.conDiag.comboDriver.text(i)) == DB_DRIVER: + self.conDiag.comboDriver.setCurrentItem(i) + break + if self.conDiag.exec_loop() != QDialog.Accepted: + return + if self.dt.sqlCursor(): + self.dt.setSqlCursor() + + # close old connection (if any) + if QSqlDatabase.contains("SqlEx"): + oldDb = QSqlDatabase.database("SqlEx") + oldDb.close() + QSqlDatabase.removeDatabase("SqlEx") + + # open the new connection + db = QSqlDatabase.addDatabase(self.conDiag.comboDriver.currentText(), "SqlEx") + if not db: + QMessageBox.warning(self, "Error", "Could not open database") + return + + db.setHostName(self.conDiag.editHostname.text()) + db.setDatabaseName(self.conDiag.editDatabase.text()) + db.setPort(self.conDiag.portSpinBox.value()) + if not db.open(self.conDiag.editUsername.text(), + self.conDiag.editPassword.text()): + showError(db.lastError(), self) + return + + self.lbl.setText("Double-Click on a table-name to view the contents") + self.lv.clear() + + tables = db.tables() + for t in tables: + lvi = QListViewItem(self.lv, t) + fields = db.recordInfo(t) + for f in fields: + req = "?" + if f.isRequired() > 0: + req = "Yes" + elif f.isRequired() == 0: + req = "No" + fi = QListViewItem(lvi, f.name(), QVariant.typeToName(f.type()), req) + lvi.insertItem(fi) + self.lv.insertItem(lvi) + + self.submitBtn.setEnabled(TRUE) + + def execQuery(self): + cursor = CustomSqlCursor(self.te.text(), TRUE, + QSqlDatabase.database("SqlEx", TRUE)) + if cursor.isSelect(): + self.dt.setSqlCursor(cursor, TRUE, TRUE) + self.dt.refresh() + txt = QString("Query OK") + if cursor.size() >= 0: + txt.append(", returned rows: %s" % cursor.size()) + self.lbl.setText(txt) + else: + if not cursor.isActive(): + # an error occured + showError(cursor.lastError(), self) + else: + self.lbl.setText("Query OK, affected rows: %s" % + cursor.numRowsAffected()) + + def showTable(self, item): + i = item.parent() + if not i: + i = item + cursor = QSqlCursor(i.text(0), TRUE, QSqlDatabase.database("SqlEx", TRUE)) + self.dt.setSqlCursor(cursor, TRUE, TRUE) + self.dt.setSort(cursor.primaryIndex()) + self.dt.refresh(QDataTable.RefreshAll) + self.lbl.setText("Displaying table %s" % i.text(0)) + + +if __name__ == "__main__": + a = QApplication(sys.argv) + QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()")) + w = MainWindow() + a.setMainWidget(w) + w.show() + a.exec_loop() + diff --git a/examples3/SQL/sqlcustom1.py b/examples3/SQL/sqlcustom1.py new file mode 100755 index 0000000..cacb010 --- /dev/null +++ b/examples3/SQL/sqlcustom1.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: sqlcustom1.py,v 1.3 2002/07/06 13:35:41 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +from qt import * +from qtsql import * + +from dbconnect import createConnection + +TRUE = 1 +FALSE = 0 + +class CustomEdit(QLineEdit): + def __init__(self, parent = None, name = None): + QLineEdit.__init__(self, parent, name) + QObject.connect(self, SIGNAL("textChanged(const QString &)"), + self.changed) + + def changed(self, line): + self.setUpperLine(line) + + def setUpperLine(self, line): + self.upperLineText = line.upper() + self.setText(self.upperLineText) + + +class FormDialog(QDialog): + def __init__(self): + QDialog.__init__(self) + forenameLabel = QLabel("Forename:", self) + forenameEdit = CustomEdit(self) + surnameLabel = QLabel("Surname:", self) + surnameEdit = CustomEdit(self) + salaryLabel = QLabel("Salary:", self) + salaryEdit = QLineEdit(self) + salaryEdit.setAlignment(Qt.AlignRight) + saveButton = QPushButton("&Save", self) + self.connect(saveButton, SIGNAL("clicked()"), self.save) + + grid = QGridLayout(self) + grid.addWidget(forenameLabel, 0, 0) + grid.addWidget(forenameEdit, 0, 1) + grid.addWidget(surnameLabel, 1, 0) + grid.addWidget(surnameEdit, 1, 1) + grid.addWidget(salaryLabel, 2, 0) + grid.addWidget(salaryEdit, 2, 1) + grid.addWidget(saveButton, 3, 0) + grid.activate() + + self.staffCursor = QSqlCursor("staff") + self.staffCursor.setTrimmed("forename", TRUE) + self.staffCursor.setTrimmed("surname", TRUE) + self.idIndex = self.staffCursor.index("id") + self.staffCursor.select(self.idIndex) + self.staffCursor.first() + + self.propMap = QSqlPropertyMap() + self.propMap.insert(forenameEdit.className(), "upperLine") + + self.sqlForm = QSqlForm() + self.sqlForm.setRecord(self.staffCursor.primeUpdate()) + self.sqlForm.installPropertyMap(self.propMap) + self.sqlForm.insert(forenameEdit, "forename") + self.sqlForm.insert(surnameEdit, "surname") + self.sqlForm.insert(salaryEdit, "salary") + self.sqlForm.readFields() + + def save(self): + self.sqlForm.writeFields() + self.staffCursor.update() + self.staffCursor.select(self.idIndex) + self.staffCursor.first() + + +if __name__=='__main__': + app = QApplication( sys.argv ) + + if createConnection(): + formDialog = FormDialog() + formDialog.show() + + app.setMainWidget(formDialog) + app.exec_loop() + + diff --git a/examples3/SQL/sqlex.ui b/examples3/SQL/sqlex.ui new file mode 100644 index 0000000..022fed9 --- /dev/null +++ b/examples3/SQL/sqlex.ui @@ -0,0 +1,303 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> +<class>SqlEx</class> +<widget class="QWidget"> + <property name="name"> + <cstring>SqlEx</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>669</width> + <height>438</height> + </rect> + </property> + <property name="caption"> + <string>SQL Browser</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>Layout23</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>lbl</cstring> + </property> + <property name="text"> + <string>Press "Connect" to open a database</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>conBtn</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>80</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>&Connect...</string> + </property> + </widget> + </hbox> + </widget> + <widget class="QSplitter" row="0" column="0"> + <property name="name"> + <cstring>vsplit</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <widget class="QSplitter"> + <property name="name"> + <cstring>hsplit</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <widget class="QListView"> + <column> + <property name="text"> + <string>Tables</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizeable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Type</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizeable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Required</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizeable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>lv</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="allColumnsShowFocus"> + <bool>true</bool> + </property> + <property name="rootIsDecorated"> + <bool>true</bool> + </property> + <property name="resizeMode"> + <enum>LastColumn</enum> + </property> + </widget> + <widget class="QDataTable"> + <property name="name"> + <cstring>dt</cstring> + </property> + <property name="frameworkCode" stdset="0"> + <bool>false</bool> + </property> + </widget> + </widget> + <widget class="QGroupBox"> + <property name="name"> + <cstring>gb</cstring> + </property> + <property name="title"> + <string>SQL Query</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>11</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>Layout22</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <widget class="QTextEdit"> + <property name="name"> + <cstring>te</cstring> + </property> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>Layout21</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>6</number> + </property> + <spacer> + <property name="name"> + <cstring>Spacer3</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + </spacer> + <widget class="QPushButton"> + <property name="name"> + <cstring>submitBtn</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>80</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>&Submit</string> + </property> + </widget> + <widget class="QPushButton"> + <property name="name"> + <cstring>clearBtn</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>80</width> + <height>0</height> + </size> + </property> + <property name="text"> + <string>C&lear</string> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + </grid> + </widget> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>clearBtn</sender> + <signal>clicked()</signal> + <receiver>te</receiver> + <slot>clear()</slot> + </connection> + <connection> + <sender>conBtn</sender> + <signal>clicked()</signal> + <receiver>SqlEx</receiver> + <slot>dbConnect()</slot> + </connection> + <connection> + <sender>lv</sender> + <signal>returnPressed(QListViewItem*)</signal> + <receiver>SqlEx</receiver> + <slot>showTable(QListViewItem*)</slot> + </connection> + <connection> + <sender>lv</sender> + <signal>doubleClicked(QListViewItem*)</signal> + <receiver>SqlEx</receiver> + <slot>showTable(QListViewItem*)</slot> + </connection> + <connection> + <sender>submitBtn</sender> + <signal>clicked()</signal> + <receiver>SqlEx</receiver> + <slot>execQuery()</slot> + </connection> +</connections> +<includes> + <include location="local" impldecl="in implementation">sqlex.ui.h</include> +</includes> +<slots> + <slot>init()</slot> + <slot>dbConnect()</slot> + <slot>showTable( QListViewItem * )</slot> + <slot>execQuery()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/examples3/SQL/sqlex.ui.h b/examples3/SQL/sqlex.ui.h new file mode 100644 index 0000000..1acdc5d --- /dev/null +++ b/examples3/SQL/sqlex.ui.h @@ -0,0 +1,35 @@ +/**************************************************************************** +** ui.h extension file, included from the uic-generated form implementation. +** +** If you wish to add, delete or rename slots use Qt Designer which will +** update this file, preserving your code. Create an init() slot in place of +** a constructor, and a destroy() slot in place of a destructor. +*****************************************************************************/ + + +void SqlEx::init() +{ +self.hsplit.setSizes([250]) +self.hsplit.setResizeMode(self.lv, QSplitter.KeepSize) +self.vsplit.setResizeMode(self.gb, QSplitter.KeepSize) +self.submitBtn.setEnabled(0) +} + + +void SqlEx::dbConnect() +{ + +} + + +void SqlEx::showTable( QListViewItem * ) +{ + +} + + + +void SqlEx::execQuery() +{ + +} diff --git a/examples3/SQL/sqlsubclass5.py b/examples3/SQL/sqlsubclass5.py new file mode 100755 index 0000000..137ff93 --- /dev/null +++ b/examples3/SQL/sqlsubclass5.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: sqlsubclass5.py,v 1.3 2002/07/06 13:35:41 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +from qt import * +from qtsql import * + +from dbconnect import createConnection + +TRUE = 1 +FALSE = 0 + +class CustomTable(QDataTable): + def __init__(self, cursor, autoPopulate = FALSE, parent = None, name = None): + QDataTable.__init__(self, cursor, autoPopulate, parent, name) + + def paintField(self, p, field, cr, b): + if not field: + return + fn = str(field.name()) + if fn == "pricesid": + query = QSqlQuery("SELECT name FROM prices WHERE id=%s" % + field.value().toString()) + value = "" + if query.next(): + value = query.value(0).toString() + p.drawText(2, 2, cr.width()-4, cr.height()-4, + self.fieldAlignment(field), value) + elif fn == "quantity": + p.drawText(2, 2, cr.width()-6, cr.height()-4, + Qt.AlignRight|Qt.AlignVCenter, field.value().toString()) + elif fn in ("price", "cost"): + v = field.value().toDouble() + if v < 0: + p.setPen(QColor("red")) + value = QString(u"%.2f \u20ac" % v) + p.drawText(2, 2, cr.width()-6, cr.height()-4, + Qt.AlignRight|Qt.AlignVCenter, value) + elif fn == "paiddate": + if field.value().toDate().isNull(): + v = QString("not yet") + p.setPen(QColor("red")) + else: + v = field.value().toDate().toString(Qt.LocalDate) + p.drawText(2, 2, cr.width()-4, cr.height()-4, + Qt.AlignHCenter|Qt.AlignVCenter, v) + else: + QDataTable.paintField(self, p, field, cr, b) + + +class InvoiceItemCursor(QSqlCursor): + def __init__(self): + QSqlCursor.__init__(self, "invoiceitem") + + productPrice = QSqlFieldInfo("price", QVariant.Double) + self.append(productPrice) + self.setCalculated(productPrice.name(), TRUE) + + productCost = QSqlFieldInfo("cost", QVariant.Double) + self.append(productCost) + self.setCalculated(productCost.name(), TRUE) + + def calculateField(self, name): + fn = str(name) + if fn == "productname": + query = QSqlQuery("SELECT name FROM prices WHERE id=%d;" % + (self.field("pricesid").value().toInt())) + if query.next(): + return query.value(0) + elif fn == "price": + query = QSqlQuery("SELECT price FROM prices WHERE id=%d;" % + (self.field("pricesid").value().toInt())) + if query.next(): + return query.value(0) + elif fn == "cost": + query = QSqlQuery("SELECT price FROM prices WHERE id=%d;" % + (self.field("pricesid").value().toInt())) + if query.next(): + return QVariant(query.value(0).toDouble() * + self.value("quantity").toDouble()) + return QVariant(QString.null) + + def primeInsert(self): + buffer = self.editBuffer() + buffer.setValue("id", QVariant(0)) + buffer.setValue("paiddate", QVariant(QDate.currentDate())) + buffer.setValue("quantity", QVariant(1)) + return buffer + + +class ProductPicker(QComboBox): + def __init__(self, parent = None, name = None): + QComboBox.__init__(self, parent, name) + cur = QSqlCursor("prices") + cur.select(cur.index("id")) + while cur.next(): + self.insertItem(cur.value("name").toString(), cur.value("id").toInt()) + + +class CustomSqlEditorFactory(QSqlEditorFactory): + def __init__(self): + QSqlEditorFactory.__init__(self) + + def createEditor(self, parent, field): + try: + if str(field.name()) == "pricesid": + return ProductPicker(parent) + except AttributeError: + pass + return QSqlEditorFactory.createEditor(self, parent, field) + +class Table(CustomTable): + def __init__(self): + self.invoiceItemCursor = InvoiceItemCursor() + QDataTable.__init__(self, self.invoiceItemCursor) + self.propMap = QSqlPropertyMap() + self.editorFactory = CustomSqlEditorFactory() + self.propMap.insert("ProductPicker", "pricesid") + self.installPropertyMap(self.propMap) + self.installEditorFactory(self.editorFactory) + + for cn, ch in (("pricesid", "Product"), + ("quantity", "Quantity"), + ("price", "Price" ), + ("cost", "Cost"), + ("paiddate", "Paid")): + self.addColumn(cn, ch) + self.setColumnWidth(0 , 150) + self.setColumnWidth(1, 70) + self.resize(600, 250) + self.refresh() + + +if __name__=='__main__': + app = QApplication(sys.argv) + if createConnection(): + t = Table() + app.setMainWidget(t) + t.show() + app.exec_loop() + + diff --git a/examples3/SQL/sqltable4.py b/examples3/SQL/sqltable4.py new file mode 100755 index 0000000..8f488d3 --- /dev/null +++ b/examples3/SQL/sqltable4.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: sqltable4.py,v 1.3 2002/07/06 13:35:41 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +from qt import * +from qtsql import * + +from dbconnect import createConnection + +TRUE = 1 +FALSE = 0 + +class CustomTable(QDataTable): + def __init__(self, cursor, autoPopulate = FALSE, parent = None, name = None): + QDataTable.__init__(self, cursor, autoPopulate, parent, name) + + def paintField(self, p, field, cr, b): + if not field: + return + fn = str(field.name()) + if fn in ("salary", "monsalary"): + v = field.value().toDouble() + if v < 0: + p.setPen(QColor("red")) + value = QString(u"%.2f \u20ac" % v) + #print unicode(value).encode("iso-8859-15") + p.drawText(2, 2, cr.width()-6, cr.height()-4, + Qt.AlignRight|Qt.AlignVCenter, value) + elif fn == "statusid": + query = QSqlQuery("SELECT name FROM status WHERE id=%s" % + field.value().toString()) + value = "" + if query.next(): + value = query.value(0).toString() + p.drawText(2, 2, cr.width()-4, cr.height()-4, + self.fieldAlignment(field), value) + else: + QDataTable.paintField(self, p, field, cr, b) + + +class StatusPicker(QComboBox): + def __init__(self, parent = None, name = None): + QComboBox.__init__(self, parent, name) + cur = QSqlCursor("status") + cur.select(cur.index("id")) + while cur.next(): + self.insertItem(cur.value("name").toString(), cur.value("id").toInt()) + + +class CustomSqlEditorFactory(QSqlEditorFactory): + def __init__(self): + QSqlEditorFactory.__init__(self) + + def createEditor(self, parent, field): + try: + if str(field.name()) == "statusid": + return StatusPicker(parent) + except AttributeError: + pass + return QSqlEditorFactory.createEditor(self, parent, field) + + +class StaffCursor(QSqlCursor): + def __init__(self): + QSqlCursor.__init__(self, "staff") + monSalary = QSqlFieldInfo("monsalary", QVariant.Double) + self.append(monSalary) + self.setCalculated(monSalary.name(), TRUE) + + def calculateField(self, name): + if str(name) == "monsalary": + return QVariant(self.value("salary").toDouble() / 12) + return QVariant(QString.null) + + +class Table(CustomTable): + def __init__(self): + #self.staffCursor = QSqlCursor("staff") + self.staffCursor = StaffCursor() + QDataTable.__init__(self, self.staffCursor) + self.propMap = QSqlPropertyMap() + self.editorFactory = CustomSqlEditorFactory() + self.propMap.insert("StatusPicker", "statusid") + self.installPropertyMap(self.propMap) + self.installEditorFactory(self.editorFactory) + for cn, ch in (("forename", "Forename"), + ("surname", "Surname" ), + ("salary", "Annual Salary"), + ("monsalary","Monthly Salary"), + ("statusid", "Status")): + self.addColumn(cn, ch) + self.order = QStringList("surname") + self.order.append("forename") + self.setSort(self.order) + self.refresh() + + +if __name__=='__main__': + app = QApplication(sys.argv) + #app.setFont(QFont("Verdana", 11)) + + if createConnection(): + t = Table() + app.setMainWidget(t) + t.resize(600, 250) + t.show() + app.exec_loop() + + diff --git a/examples3/SQL/testdb_mysql.sql b/examples3/SQL/testdb_mysql.sql new file mode 100644 index 0000000..144d4c9 --- /dev/null +++ b/examples3/SQL/testdb_mysql.sql @@ -0,0 +1,57 @@ +drop database testdb; +create database testdb; +use testdb; + +create table people (id integer primary key auto_increment, + name char(40)); + +create table staff (id integer primary key auto_increment, + forename char(40), + surname char(40), + salary float(10,2), + statusid integer); + +create table status (id integer primary key, + name char(30)); + +create table creditors (id integer primary key auto_increment, + forename char(40), + surname char(40), + city char(30)); + +create table prices (id integer primary key, + name char(40), + price float); + +create table invoiceitem (id integer primary key auto_increment, + pricesid integer, + quantity integer, + paiddate date); + +insert into staff (forename, surname, salary, statusid) values + ("Hugo", "Hurtig", 123450.50, 0), + ("Alfred E.", "Neumann", 56780.90, 1), + ("Agate", "Schnell-Fertig", 12340.56, 2), + ("Emil", "Dotterschreck", -5670.23, 3), + ("Eugen", "Nutzlos", -7833.56, 3), + ("Harald", "Schmidt", -150000.0, 3), + ("Urmel", "auf dem Eis", 7778.0, 2); + +insert into status (id, name) values + (0, 'Chief'), + (1, 'Programmer'), + (2, 'Secretary'), + (3, 'Driver'); + +insert into prices (id, name, price) values + (0, "Waschbecken", 150.25), + (1, "Wellensittich", 27.95), + (2, "Roter Papagei", 850.0), + (3, "Spam & Eggs", -7.50), + (4, "Renault Espace", 9000.0), + (5, "Tux, der Pinguin", 65.35), + (6, "Makroskop", 985000.0), + (7, "Regenbaum", 1235.65), + (8, "Blutergu�", 23.95), + (9, "Weltmeisterschaft", 2.95), + (10, "Premiere Dekoder", -185.75); diff --git a/examples3/SQL/testdb_pg.sql b/examples3/SQL/testdb_pg.sql new file mode 100644 index 0000000..73a4270 --- /dev/null +++ b/examples3/SQL/testdb_pg.sql @@ -0,0 +1,232 @@ +-- +-- Selected TOC Entries: +-- +-- +-- TOC Entry ID 1 (OID 0) +-- +-- Name: testdb Type: DATABASE Owner: postgres +-- + +CREATE DATABASE "testdb"; + +\connect testdb postgres +-- +-- TOC Entry ID 16 (OID 17332) +-- +-- Name: people Type: TABLE Owner: postgres +-- + +CREATE TABLE "people" ( + "id" integer DEFAULT nextval('people_id_seq'::text) NOT NULL, + "name" character(40), + Constraint "people_pkey" Primary Key ("id") +); + +-- +-- TOC Entry ID 17 (OID 17335) +-- +-- Name: staff Type: TABLE Owner: postgres +-- + +CREATE TABLE "staff" ( + "id" integer DEFAULT nextval('staff_id_seq'::text) NOT NULL, + "forename" character(40), + "surname" character(40), + "salary" money, + "statusid" integer, + Constraint "staff_pkey" Primary Key ("id") +); + +-- +-- TOC Entry ID 18 (OID 17338) +-- +-- Name: status Type: TABLE Owner: postgres +-- + +CREATE TABLE "status" ( + "id" integer NOT NULL, + "name" character(30), + Constraint "status_pkey" Primary Key ("id") +); + +-- +-- TOC Entry ID 19 (OID 17341) +-- +-- Name: creditors Type: TABLE Owner: postgres +-- + +CREATE TABLE "creditors" ( + "id" integer DEFAULT nextval('creditors_id_seq'::text) NOT NULL, + "forename" character(40), + "surname" character(40), + "city" character(30), + Constraint "creditors_pkey" Primary Key ("id") +); + +-- +-- TOC Entry ID 20 (OID 17344) +-- +-- Name: prices Type: TABLE Owner: postgres +-- + +CREATE TABLE "prices" ( + "id" integer NOT NULL, + "name" character(40), + "price" real, + Constraint "prices_pkey" Primary Key ("id") +); + +-- +-- TOC Entry ID 21 (OID 17347) +-- +-- Name: invoiceitem Type: TABLE Owner: postgres +-- + +CREATE TABLE "invoiceitem" ( + "id" integer DEFAULT nextval('invoice_id_seq'::text) NOT NULL, + "pricesid" integer, + "quantity" integer, + "paiddate" date, + Constraint "invoiceitem_pkey" Primary Key ("id") +); + +-- +-- TOC Entry ID 2 (OID 17351) +-- +-- Name: people_id_seq Type: SEQUENCE Owner: postgres +-- + +CREATE SEQUENCE "people_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1; + +-- +-- TOC Entry ID 4 (OID 17353) +-- +-- Name: staff_id_seq Type: SEQUENCE Owner: postgres +-- + +CREATE SEQUENCE "staff_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1; + +-- +-- TOC Entry ID 6 (OID 17355) +-- +-- Name: creditors_id_seq Type: SEQUENCE Owner: postgres +-- + +CREATE SEQUENCE "creditors_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1; + +-- +-- TOC Entry ID 8 (OID 17357) +-- +-- Name: invoice_id_seq Type: SEQUENCE Owner: postgres +-- + +CREATE SEQUENCE "invoice_id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1; + +-- +-- Data for TOC Entry ID 28 (OID 17332) +-- +-- Name: people Type: TABLE DATA Owner: postgres +-- + + +COPY "people" FROM stdin; +\. +-- +-- Data for TOC Entry ID 29 (OID 17335) +-- +-- Name: staff Type: TABLE DATA Owner: postgres +-- + + +COPY "staff" FROM stdin; +1 Hugo Hurtig $123,450.50 0 +2 Alfred E. Neumann $56,780.90 1 +3 Agate Schnell-Fertig $12,340.56 2 +6 Eugen Nutzlos -$7,833.56 3 +7 Harald Schmidt -$150,000.00 3 +4 Urmel auf dem Eis $7,778.00 2 +5 Emil Dotterschreck -$5,670.23 3 +\. +-- +-- Data for TOC Entry ID 30 (OID 17338) +-- +-- Name: status Type: TABLE DATA Owner: postgres +-- + + +COPY "status" FROM stdin; +0 Chief +1 Programmer +2 Secretary +3 Driver +\. +-- +-- Data for TOC Entry ID 31 (OID 17341) +-- +-- Name: creditors Type: TABLE DATA Owner: postgres +-- + + +COPY "creditors" FROM stdin; +\. +-- +-- Data for TOC Entry ID 32 (OID 17344) +-- +-- Name: prices Type: TABLE DATA Owner: postgres +-- + + +COPY "prices" FROM stdin; +0 Waschbecken 150.25 +1 Wellensittich 27.95 +2 Roter Papagei 850 +3 Spam & Eggs -7.5 +4 Renault Espace 9000 +5 Tux, der Pinguin 65.35 +6 Makroskop 985000 +7 Regenbaum 1235.65 +8 Blutergu� 23.95 +9 Weltmeisterschaft 2.95 +10 Premiere Dekoder -185.75 +\. +-- +-- Data for TOC Entry ID 33 (OID 17347) +-- +-- Name: invoiceitem Type: TABLE DATA Owner: postgres +-- + + +COPY "invoiceitem" FROM stdin; +\. +-- +-- TOC Entry ID 3 (OID 17351) +-- +-- Name: people_id_seq Type: SEQUENCE SET Owner: postgres +-- + +SELECT setval ('"people_id_seq"', 1, false); + +-- +-- TOC Entry ID 5 (OID 17353) +-- +-- Name: staff_id_seq Type: SEQUENCE SET Owner: postgres +-- + +SELECT setval ('"staff_id_seq"', 8, true); + +-- +-- TOC Entry ID 7 (OID 17355) +-- +-- Name: creditors_id_seq Type: SEQUENCE SET Owner: postgres +-- + +SELECT setval ('"creditors_id_seq"', 1, false); + +-- +-- TOC Entry ID 9 (OID 17357) +-- +-- Name: invoice_id_seq Type: SEQUENCE SET Owner: postgres +-- + +SELECT setval ('"invoice_id_seq"', 1, false); + diff --git a/examples3/aclock.py b/examples3/aclock.py new file mode 100755 index 0000000..38ed36c --- /dev/null +++ b/examples3/aclock.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +import sys +from qt import * + +def QMIN(x, y): + if y > x: return y + return x +class AnalogClock(QWidget): + def __init__(self, *args): + apply(QWidget.__init__,(self,) + args) + self.time = QTime.currentTime() + internalTimer = QTimer(self) + self.connect(internalTimer, SIGNAL("timeout()"), self.timeout) + internalTimer.start(5000) + + def timeout(self): + new_time = QTime.currentTime() + if new_time.minute() != self.time.minute(): + self.update() + + def paintEvent(self, qe): + if not self.isVisible(): + return + self.time = QTime.currentTime() + + pts = QPointArray() + paint = QPainter(self) + paint.setBrush(self.foregroundColor()) + + cp = QPoint(self.rect().center()) + d = QMIN(self.width(), self.height()) + matrix = QWMatrix() + 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 = QApplication(sys.argv) +clock = AnalogClock() +clock.resize(100,100) +a.setMainWidget(clock) +clock.show() +a.exec_loop() diff --git a/examples3/addressbook.py b/examples3/addressbook.py new file mode 100755 index 0000000..d7316e3 --- /dev/null +++ b/examples3/addressbook.py @@ -0,0 +1,457 @@ +#!/usr/bin/env python + +# A port to PyQt of the application example from Qt v2.x. + + +import sys, string +from 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( QWidget ): + def __init__( self, *args ): + apply( QWidget.__init__, (self, ) + args ) + self.mainGrid = QGridLayout( 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 = QFile( filename ) + if not f.open( IO_WriteOnly ): + return + + t = QTextStream( f ) + + #it = QListViewItemIterator( self.listView ) + + while not t.eof(): + item = QListViewItem( 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 = QFile( filename ) + if not f.open( IO_ReadOnly ): + return + + t = QTextStream( f ) + + while not t.eof(): + item = QListViewItem( self.listView ) + for i in range (0, 4): + item.setText( i, t.readLine() ) + + f.close(); + + + def setupTabWidget( self ): + self.tabWidget = QTabWidget( self ) + + self.input = QWidget( self.tabWidget ) + self.grid1 = QGridLayout( self.input, 2, 5, 5, 5 ) + + self.liFirstName = QLabel( 'First &Name', self.input ) + self.liFirstName.resize( self.liFirstName.sizeHint() ) + self.grid1.addWidget( self.liFirstName, 0, 0 ) + + self.liLastName = QLabel( '&Last Name', self.input ) + self.liLastName.resize( self.liLastName.sizeHint() ) + self.grid1.addWidget( self.liLastName, 0, 1 ) + + self.liAddress = QLabel( '&Address', self.input ) + self.liAddress.resize( self.liAddress.sizeHint() ) + self.grid1.addWidget( self.liAddress, 0, 2 ) + + self.liEMail = QLabel( '&E-Mail', self.input ) + self.liEMail.resize( self.liEMail.sizeHint() ) + self.grid1.addWidget( self.liEMail, 0, 3 ) + + self.add = QPushButton( '&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 = QLineEdit( self.input ) + self.iFirstName.resize( self.iFirstName.sizeHint() ) + self.grid1.addWidget( self.iFirstName, 1, 0 ) + self.liFirstName.setBuddy( self.iFirstName ) + + self.iLastName = QLineEdit( self.input ) + self.iLastName.resize( self.iLastName.sizeHint() ) + self.grid1.addWidget( self.iLastName, 1, 1 ) + self.liLastName.setBuddy( self.iLastName ) + + self.iAddress = QLineEdit( self.input ) + self.iAddress.resize( self.iAddress.sizeHint() ) + self.grid1.addWidget( self.iAddress, 1, 2 ) + self.liAddress.setBuddy( self.iAddress ) + + self.iEMail = QLineEdit( self.input ) + self.iEMail.resize( self.iEMail.sizeHint() ) + self.grid1.addWidget( self.iEMail, 1, 3 ) + self.liEMail.setBuddy( self.iEMail ) + + self.change = QPushButton( '&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 = QWidget( self ) + self.grid2 = QGridLayout( self.search, 2, 5, 5, 5 ) + + self.cFirstName = QCheckBox( '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 = QCheckBox( '&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 = QCheckBox( '&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 = QCheckBox( '&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 = QLineEdit( self.search ) + self.sFirstName.resize( self.sFirstName.sizeHint() ) + self.grid2.addWidget( self.sFirstName, 1, 0 ) + + self.sLastName = QLineEdit( self.search ) + self.sLastName.resize( self.sLastName.sizeHint() ) + self.grid2.addWidget( self.sLastName, 1, 1 ) + + self.sAddress = QLineEdit( self.search ) + self.sAddress.resize( self.sAddress.sizeHint() ) + self.grid2.addWidget( self.sAddress, 1, 2 ) + + self.sEMail = QLineEdit( self.search ) + self.sEMail.resize( self.sEMail.sizeHint() ) + self.grid2.addWidget( self.sEMail, 1, 3 ) + + self.find = QPushButton( '&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 = QListView( self ) + self.listView.addColumn( 'First Name' ) + self.listView.addColumn( 'Last Name' ) + self.listView.addColumn( 'Address' ) + self.listView.addColumn( 'E-Mail' ) + + self.listView.setSelectionMode( QListView.Extended ) + + self.connect( self.listView, SIGNAL( 'clicked( QListViewItem* )' ), 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 = QListViewItem( 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 = QListViewItemIterator( 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(QMainWindow): + def __init__( self ): + QMainWindow.__init__( self, None, 'example addressbook application' ) + + self.filename = QString.null + self.setupMenuBar() + self.setupFileTools() + self.setupStatusBar() + self.setupCentralWidget() + + def setupMenuBar( self ): + self.file = QPopupMenu( self ) + self.menuBar().insertItem( '&File', self.file ) + + openIcon = QIconSet( QPixmap( fileopen ) ) + self.file.insertItem( 'New', self.fileNew, Qt.CTRL + Qt.Key_N ) + self.file.insertItem( openIcon, 'Open', self.fileOpen, Qt.CTRL + Qt.Key_O ) + self.file.insertSeparator() + saveIcon = QIconSet( QPixmap( filesave ) ) + self.file.insertItem( saveIcon, 'Save', self.fileSave, Qt.CTRL + Qt.Key_S ) + self.file.insertItem( 'Save As...', self.fileSaveAs ) + self.file.insertSeparator() + printIcon = QIconSet( QPixmap( fileprint ) ) + self.file.insertItem( printIcon, 'Print...', self.filePrint, Qt.CTRL + Qt.Key_P ) + self.file.insertSeparator() + #self.file.insertItem( 'Close', self.closeWindow, Qt.CTRL + Qt.Key_W ) + self.file.insertItem('Close', self, SLOT('close()'), Qt.CTRL+Qt.Key_W) + self.file.insertItem( 'Quit', qApp, SLOT( 'quit()' ), Qt.CTRL + Qt.Key_Q ) + + def setupFileTools( self ): + pass + #self.fileTools = QToolBar( 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 = QFileDialog.getOpenFileName( QString.null, QString.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 = QFileDialog.getSaveFileName( QString.null, QString.null, self ) + if not fn.isEmpty(): + self.filename = fn + self.fileSave + + def filePrint( self ): + pass + + +a = QApplication( 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() diff --git a/examples3/application.py b/examples3/application.py new file mode 100755 index 0000000..f5c027d --- /dev/null +++ b/examples3/application.py @@ -0,0 +1,277 @@ +#!/usr/bin/env python + +# A simple application. + + +import sys, string +from 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(QMainWindow): + def __init__(self): + QMainWindow.__init__(self,None,'example application main window',Qt.WDestructiveClose) + + self.filename = QString.null + self.printer = QPrinter() + + self.fileTools = QToolBar(self,'file operations') + + openIcon = QPixmap(fileopen) + self.fileOpen = QToolButton(QIconSet(openIcon),'Open File',QString.null,self.load,self.fileTools,'open file') + + saveIcon = QPixmap(filesave) + self.fileSave = QToolButton(QIconSet(saveIcon),'Save File',QString.null,self.save,self.fileTools,'save file') + + printIcon = QPixmap(fileprint) + self.filePrint = QToolButton(QIconSet(printIcon),'Print File',QString.null,self.printDoc,self.fileTools,'print file') + + QWhatsThis.whatsThisButton(self.fileTools) + + QWhatsThis.add(self.fileOpen,fileOpenText) + QMimeSourceFactory.defaultFactory().setPixmap('fileopen',openIcon) + QWhatsThis.add(self.fileSave,fileSaveText) + QWhatsThis.add(self.filePrint,filePrintText) + + self.file = QPopupMenu(self) + self.menuBar().insertItem('&File',self.file) + + self.file.insertItem('&New',self.newDoc,Qt.CTRL + Qt.Key_N) + + id = self.file.insertItem(QIconSet(openIcon),'&Open',self.load,Qt.CTRL + Qt.Key_O) + self.file.setWhatsThis(id,fileOpenText) + + id = self.file.insertItem(QIconSet(saveIcon),'&Save',self.save,Qt.CTRL + Qt.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(QIconSet(printIcon),'&Print',self.printDoc,Qt.CTRL + Qt.Key_P) + self.file.setWhatsThis(id,filePrintText) + + self.file.insertSeparator() + + self.file.insertItem('&Close',self,SLOT('close()'),Qt.CTRL + Qt.Key_W) + self.file.insertItem('&Quit',qApp,SLOT('closeAllWindows()'),Qt.CTRL + Qt.Key_Q) + + self.help = QPopupMenu(self) + self.menuBar().insertSeparator() + self.menuBar().insertItem('&Help',self.help) + + self.help.insertItem('&About',self.about,Qt.Key_F1) + self.help.insertItem('About &Qt',self.aboutQt) + + self.e = QMultiLineEdit(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 = QFileDialog.getOpenFileName(QString.null,QString.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(string.rstrip(l)) + + 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 = QFileDialog.getSaveFileName(QString.null,QString.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 = QPainter() + p.begin(self.printer) + p.setFont(self.e.font()) + yPos = 0 + fm = p.fontMetrics() + metrics = QPaintDeviceMetrics(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(),Qt.ExpandTabs | Qt.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 = QMessageBox.information(self,'Qt 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): + QMessageBox.about(self,'Qt Application Example', + 'This example demonstrates simple use of QMainWindow,\nQMenuBar and QToolBar.') + + def aboutQt(self): + QMessageBox.aboutQt(self,'Qt Application Example') + + +a = QApplication(sys.argv) +mw = ApplicationWindow() +mw.setCaption('Document 1') +mw.show() +a.connect(a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()')) +a.exec_loop() diff --git a/examples3/biff.py b/examples3/biff.py new file mode 100755 index 0000000..ee5bfe3 --- /dev/null +++ b/examples3/biff.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python + +import os, sys, string +from qt import * + + +if QT_VERSION < 0x030100: + print "This example requires Qt v3.1.0 or later." + sys.exit(1) + + +FALSE = 0 +TRUE = 1 + +hasmail_bmp_data = [ +"48 48 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +"................................................", +".............................++++++++++.........", +".............................++++++++++.........", +"........................++++.+++.+.+.++.........", +"......................++++.++++.+.+.+++.........", +".....................+++.....+++.+.+.++.........", +"....................++.......++.+.+.+++.........", +"...................++........++++++++++.........", +"..................++.........++++++++++.........", +".................++..........+++..+.............", +"................++...........+++..+.............", +"...............++............+++.++.............", +"..............+++++++........++++++.............", +".............++++++++++......++++++.............", +"............+++......+++.....++++.+.............", +"...........+++.........++....+++..+.............", +"...........++..........++...++++..+.............", +"..........++............++.+++++..+.............", +"..........++............++++++++..+.............", +".........++....++++++....+++.+++..+.............", +".........++......++......++..+++..+.............", +".........++..............++..+++..+.............", +".........++..............++..+++..+.............", +".........++..............++..++...+.............", +"+++++++..++.+.+..+..+.+..++.......+..+++++++++++", +".........++.+++.+.+.+.+..++.......+.............", +".........++.+.+.+++.+.+..++.......+.............", +".........++.+.+.+.+.+.+..++......++.............", +".........++.+.+.+.+.+.++.++.....++..............", +".........++..............++....++...............", +"..+.+.+..++..............++...++..+.+.+.+.+.+.+.", +".+.+.+.+.++..............++..++..+.+.+.+.+.+.+..", +"..+.+.+..++..............++.++..+.+.+.+.+.+.+.+.", +".+.+.+.+.++..............+++++.+.+.+.+.+.+.+.+..", +"..+.+.+..+++++++++++++++++++.++.+.+.+.+.+.+.+.+.", +".+.+.+.+..+++++++++++++++++..+.+.+.+.+.+.+.+.+..", +"..+.+.+.+..........+...+.....++.+.+.+.+.+.+.+.+.", +".+.+.+.+.+.+.+.+.+.+...+.....+.+.+.+.+.+.+.+.+..", +"..+.+.+.+.+.+.+.+.++...+.....++.+.+.+.+.+.+.+.+.", +".+.+.+.+.+.+.+.+.+.+...+.....+.+.+.+.+.+.+.+.+..", +"..+.+.+.+.+.+.+.+.++...+.....++.+.+.+.+.+.+.+.+.", +".+.+.+.+.+.+.+.+.+.+...+.....+.+.+.+.+.+.+.+.+..", +"..+.+.+.+.+.+.+.+.++...+....+.+.+.+.+.+.+.+.+.+.", +".+.+.+.+.+.+.+.+.+.+...+...+.+.+.+.+.+.+.+.+.+..", +"..+.+.+.+.+.+.+.+.+.+..+..+.+.+.+.+.+.+.+.+.+.+.", +".+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+..", +"..+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+...", +"................................................" +] + +nomail_bmp_data = [ +"48 48 3 1", +" c None", +". c #FFFFFF", +"+ c #000000", +"................................................", +"................................................", +"................................................", +".........................++++...................", +".......................++++++++.................", +".....................++++....+++................", +"....................+++........++...............", +"...................++...........++..............", +"..................++............++..............", +".................++..............++.......+.....", +"................++...............++......++.....", +"...............++................++.....+++.....", +"..............+++++++...........+++....++++.....", +".............++++++++++........++++...+++++.....", +"............+++......+++......+++.+..++++++.....", +"...........+++.........++....+++..+.+++.+++.....", +"...........++..........++...+++...++++..+++.....", +"..........++............++.+++...++++...++......", +"..........++............+++++...++++............", +".........++....++++++....+++...++++.............", +".........++......++......++...+++.+.............", +".........++..............++...+++.+.............", +".........++..............++...++..+.............", +".........++..............++.......+.............", +"+++++++..++..............++.......+..+++++++++++", +".........++..............++.......+.............", +".........++..............++.......+.............", +".........++..............++......++.............", +".........++..............++.....++..............", +".........++..............++....++...............", +".........++..............++...++................", +".........++..............++..++.................", +".........++..............++.++..................", +".........++..............+++++..................", +".........+++++++++++++++++++.+..................", +"..........+++++++++++++++++..+..................", +"...................+...+.....+..................", +"...................+...+.....+..................", +"...................+...+.....+..................", +"...................+...+.....+..................", +"...................+...+.....+..................", +"...................+...+.....+..................", +"...................+...+.....+..................", +"...................+...+.....+..................", +"+++.++++++++++.+.+++...+..+++++++++++.++...+++++", +"+.+++..+++.+.+++++.++..+.++.+++..+..+.++.+.++++.", +".++...+.....++...+...+++++++....+....++++++...+.", +"++++++++++++++++++++++++++++++++++++++++++++++++" +] + +class Biff(QWidget): + def __init__(self): + QWidget.__init__(self, None, "Biff - example application") + + mail = os.getenv("MAIL") + fi = QFileInfo(mail); + if not fi.exists(): + s = "/var/spool/mail/"+os.getenv("USER") + fi.setFile(s) + + if fi.exists(): + self.mailbox = fi.absFilePath() + self.startTimer(1000) + + self.setMinimumSize(48, 48) + self.setMaximumSize(48, 48) + self.resize(48, 48) + + self.hasNewMail = QPixmap(hasmail_bmp_data) + self.noNewMail = QPixmap(nomail_bmp_data) + + self.gotMail = FALSE + self.lastModified = fi.lastModified() + + def timerEvent(self, te): + fi = QFileInfo(self.mailbox) + newState = ( fi.lastModified().toTime_t() != self.lastModified.toTime_t() and fi.lastModified().toTime_t() > fi.lastRead().toTime_t()) + if newState != self.gotMail: + if self.gotMail == TRUE: + self.lastModified = fi.lastModified() + self.gotMail = newState + self.repaint(FALSE) + + def paintEvent(self, pe): + if self.gotMail: + bitBlt(self, 0, 0, self.hasNewMail) + else: + bitBlt(self, 0, 0, self.noNewMail) + + def mousePressEvent(self, me): + fi = QFileInfo(self.mailbox) + lastModified = fi.lastModified() + + +a = QApplication(sys.argv) +b = Biff() +a.setMainWidget(b) +b.show() +a.exec_loop() diff --git a/examples3/bigtable.py b/examples3/bigtable.py new file mode 100755 index 0000000..da17619 --- /dev/null +++ b/examples3/bigtable.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: bigtable.py,v 1.1 2002/06/19 07:56:07 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +import os +from qt import * +from qttable import * + +TRUE = 1 +FALSE = 0 + +numRows = 1000000 +numCols = 1000000 + +class MyTable(QTable): + def __init__(self, r, c): + QTable.__init__(self, r, c) + self.items = {} + self.widgets = {} + self.setCaption("This is a big table with 1.000.000x1.000.000 cells...") + self.setLeftMargin(self.fontMetrics().width("W999999W")) + + def resizeData(self, v): + return + + def item(self, r, c): + try: + return self.items[self.indexOf(r, c)] + except KeyError: + return None + + def setItem(self, r, c, i): + self.items[self.indexOf(r, c)] = i + + def clearCell(self, r, c): + try: + del self.items[self.indexOf(r, c)] + except KeyError: + pass + + def insertWidget(self, r, c, w): + self.widgets[self.indexOf(r, c)] = w + + def cellWidget(self, r, c): + try: + return self.widgets[self.indexOf(r, c)] + except KeyError: + return None + + def clearCellWidget(self, r, c): + try: + del self.widgets[self.indexOf(r, c)] + except KeyError: + pass + + +if __name__ == '__main__': + app = QApplication(sys.argv) + + table = MyTable(numRows, numCols) + app.setMainWidget(table) + table.show() + app.exec_loop() diff --git a/examples3/buttongroups.py b/examples3/buttongroups.py new file mode 100755 index 0000000..c998a88 --- /dev/null +++ b/examples3/buttongroups.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +#/**************************************************************************** +#** $Id: buttongroups.py,v 1.2 2002/12/20 18:46:10 phil Exp $ +#** +#** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +#** +#** This file is part of an example program for Qt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +from qt import * + +TRUE = 1 +FALSE = 0 + +## +# Creates all child widgets of the ButtonGroups window +## + +class ButtonsGroups( QWidget ): + def __init__( self, *args ): + apply( QWidget.__init__, (self,) + args ) + + # Create Widgets which allow easy layouting + self.vbox = QVBoxLayout( self, 11, 6 ) + self.box1 = QHBoxLayout( self.vbox ) + self.box2 = QHBoxLayout( self.vbox ) + + # ------- first group + + # Create an exclusive button group + self.grp1 = QButtonGroup( 1, QGroupBox.Horizontal, "Button Group 1 (exclusive)", self ) + self.box1.addWidget( self.grp1 ) + self.grp1.setExclusive( TRUE ) + + # insert 3 radiobuttons + self.rb11 = QRadioButton( "&Radiobutton 1", self.grp1 ) + self.rb11.setChecked( TRUE ) + QRadioButton( "R&adiobutton 2", self.grp1 ) + QRadioButton( "Ra&diobutton 3", self.grp1 ) + + # ------- second group + + # Create a non-exclusive buttongroup + self.grp2 = QButtonGroup( 1, QGroupBox.Horizontal, "Button Group 2 (non-exclusive)", self ) + self.box1.addWidget( self.grp2 ) + self.grp2.setExclusive( FALSE ) + + # insert 3 checkboxes + QCheckBox( "&Checkbox 1", self.grp2 ) + self.cb12 = QCheckBox( "C&heckbox 2", self.grp2 ) + self.cb12.setChecked( TRUE ) + self.cb13 = QCheckBox( "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 = QButtonGroup( 1, QGroupBox.Horizontal, "Button Group 3 (Radiobutton-exclusive)", self ) + self.box2.addWidget( self.grp3 ) + self.grp3.setRadioButtonExclusive( TRUE ) + + # insert three radiobuttons + self.rb21 = QRadioButton( "Rad&iobutton 1", self.grp3 ) + self.rb22 = QRadioButton( "Radi&obutton 2", self.grp3 ) + self.rb23 = QRadioButton( "Radio&button 3", self.grp3 ) + self.rb23.setChecked( TRUE ) + + # insert a checkbox... + self.state = QCheckBox( "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 = QButtonGroup( 1, QGroupBox.Horizontal, "Groupbox with normal buttons", self ) + self.box2.addWidget( self.grp4 ) + + # insert two pushbuttons... + QPushButton( "&Push Button", self.grp4 ) + self.tb2 = QPushButton( "&Toggle Button", self.grp4 ) + + # ... and make the second one a toggle button + self.tb2.setToggleButton( TRUE ) + self.tb2.setOn( TRUE ) + + # ... and make the third one a flat button + self.tb3 = QPushButton( "&Flat Button", self.grp4 ) + self.tb3.setFlat( TRUE ) + + # .. and the fourth a button with a menu + self.tb4 = QPushButton( "Popup Button", self.grp4 ) + menu = QPopupMenu(self.tb4) + menu.insertItem("Item1", 0) + menu.insertItem("Item2", 0) + menu.insertItem("Item3", 0) + menu.insertItem("Item4", 0) + self.tb4.setPopup(menu) + + # + # 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 = QApplication( sys.argv ) + +buttonsgroups = ButtonsGroups() +buttonsgroups.resize( 500, 250 ) +buttonsgroups.setCaption( "PyQT Example - Buttons and Groups" ) +a.setMainWidget( buttonsgroups ) +buttonsgroups.show() + +a.exec_loop() diff --git a/examples3/canvas/butterfly.png b/examples3/canvas/butterfly.png Binary files differnew file mode 100644 index 0000000..d8912d2 --- /dev/null +++ b/examples3/canvas/butterfly.png diff --git a/examples3/canvas/canvas.py b/examples3/canvas/canvas.py new file mode 100755 index 0000000..178a6e6 --- /dev/null +++ b/examples3/canvas/canvas.py @@ -0,0 +1,619 @@ +#!/usr/bin/env python + +import sys +from qt import * +from qtcanvas import * +import random + + +True = 1 +False = 0 +butterfly_fn = QString.null +butterflyimg = [] +logo_fn = QString.null +logoimg = [] +bouncy_logo = None +views = [] + + +class ImageItem(QCanvasRectangle): + def __init__(self,img,canvas): + QCanvasRectangle.__init__(self,canvas) + self.imageRTTI=984376 + self.image=img + self.pixmap=QPixmap() + self.setSize(self.image.width(), self.image.height()) + self.pixmap.convertFromImage(self.image, Qt.OrderedAlphaDither); + + def rtti(self): + return self.imageRTTI + + def hit(self,p): + ix = p.x()-self.x() + iy = p.y()-self.y() + if not self.image.valid( ix , iy ): + return False + self.pixel = self.image.pixel( ix, iy ) + return (qAlpha( self.pixel ) != 0) + + def drawShape(self,p): + p.drawPixmap( self.x(), self.y(), self.pixmap ) + + +class NodeItem(QCanvasEllipse): + def __init__(self,canvas): + QCanvasEllipse.__init__(self,6,6,canvas) + self.__inList=[] + self.__outList=[] + self.setPen(QPen(Qt.black)) + self.setBrush(QBrush(Qt.red)) + self.setZ(128) + + def addInEdge(self,edge): + self.__inList.append(edge) + + def addOutEdge(self,edge): + self.__outList.append(edge) + + def moveBy(self,dx,dy): + QCanvasEllipse.moveBy(self,dx,dy) + for each_edge in self.__inList: + each_edge.setToPoint( int(self.x()), int(self.y()) ) + for each_edge in self.__outList: + each_edge.setFromPoint( int(self.x()), int(self.y()) ) + +class EdgeItem(QCanvasLine): + __c=0 + def __init__(self,fromNode, toNode,canvas): + QCanvasLine.__init__(self,canvas) + self.__c=self.__c+1 + self.setPen(QPen(Qt.black)) + self.setBrush(QBrush(Qt.red)) + fromNode.addOutEdge(self) + toNode.addInEdge(self) + self.setPoints(int(fromNode.x()),int(fromNode.y()), int(toNode.x()), int(toNode.y())) + self.setZ(127) + + def setFromPoint(self,x,y): + self.setPoints(x,y,self.endPoint().x(),self.endPoint().y()) + + def setToPoint(self,x,y): + self.setPoints(self.startPoint().x(), self.startPoint().y(),x,y) + + def count(self): + return self.__c + + def moveBy(self,dx,dy): + pass + + +class FigureEditor(QCanvasView): + def __init__(self,c,parent,name,f): + QCanvasView.__init__(self,c,parent,name,f) + self.__moving=0 + self.__moving_start= 0 + + def contentsMousePressEvent(self,e): # QMouseEvent e + point = self.inverseWorldMatrix().map(e.pos()) + ilist = self.canvas().collisions(point) #QCanvasItemList ilist + for each_item in ilist: + if each_item.rtti()==984376: + if not each_item.hit(point): + continue + self.__moving=each_item + self.__moving_start=point + return + self.__moving=0 + + def clear(self): + ilist = self.canvas().allItems() + for each_item in ilist: + if each_item: + each_item.setCanvas(None) + del each_item + self.canvas().update() + + def contentsMouseMoveEvent(self,e): + if self.__moving : + point = self.inverseWorldMatrix().map(e.pos()); + self.__moving.moveBy(point.x() - self.__moving_start.x(),point.y() - self.__moving_start.y()) + self.__moving_start = point + self.canvas().update() + + +class BouncyLogo(QCanvasSprite): + def __init__(self,canvas): + # Make sure the logo exists. + global bouncy_logo + if bouncy_logo is None: + bouncy_logo=QCanvasPixmapArray("qt-trans.xpm") + + QCanvasSprite.__init__(self,None,canvas) + self.setSequence(bouncy_logo) + self.setAnimated(True) + self.initPos() + self.logo_rtti=1234 + + def rtti(self): + return self.logo_rtti + + def initPos(self): + self.initSpeed() + trial=1000 + self.move(random.random()%self.canvas().width(), random.random()%self.canvas().height()) + self.advance(0) + trial=trial-1 + while (trial & (self.xVelocity()==0 )& (self.yVelocity()==0)): + elf.move(random.random()%self.canvas().width(), random.random()%self.canvas().height()) + self.advance(0) + trial=trial-1 + + def initSpeed(self): + speed=4.0 + d=random.random()%1024/1024.0 + self.setVelocity(d*speed*2-speed, (1-d)*speed*2-speed) + + def advance(self,stage): + if stage==0: + vx=self.xVelocity() + vy=self.yVelocity() + if (vx==0.0) & (vy==0.0): + self.initSpeed() + vx=self.xVelocity() + vy=self.yVelocity() + + nx=self.x()+vx + ny=self.y()+vy + + if (nx<0) | (nx >= self.canvas().width()): + vx=-vx + if (ny<0) | (ny >= self.canvas().height()): + vy=-vy + + for bounce in [0,1,2,3]: + l=self.collisions(False) + for hit in l: + if (hit.rtti()==1234) & (hit.collidesWith(self)): + if bounce==0: + vx=-vx + elif bounce==1: + vy=-vy + vx=-vx + elif bounce==2: + vx=-vx + elif bounce==3: + vx=0 + vy=0 + self.setVelocity(vx,vy) + break + + if (self.x()+vx < 0) | (self.x()+vx >= self.canvas().width()): + vx=0 + if (self.y()+vy < 0) | (self.y()+vy >= self.canvas().height()): + vy=0 + + self.setVelocity(vx,vy) + elif stage==1: + QCanvasItem.advance(self,stage) + + +class Main (QMainWindow): + def __init__(self,c,parent,name,f=0): + QMainWindow.__init__(self,parent,name,f) + self.editor=FigureEditor(c,self,name,f) + self.printer=QPrinter() + self.dbf_id=0 + self.canvas=c + self.mainCount=0 + file=QPopupMenu(self.menuBar()) + file.insertItem("&Fill canvas", self.init, Qt.CTRL+Qt.Key_F) + file.insertItem("&Erase canvas", self.clear, Qt.CTRL+Qt.Key_E) + file.insertItem("&New view", self.newView, Qt.CTRL+Qt.Key_N) + file.insertSeparator(); + file.insertItem("&Print", self._print, Qt.CTRL+Qt.Key_P) + file.insertSeparator() + file.insertItem("E&xit", qApp, SLOT("quit()"), Qt.CTRL+Qt.Key_Q) + self.menuBar().insertItem("&File", file) + + edit = QPopupMenu(self.menuBar() ) + edit.insertItem("Add &Circle", self.addCircle, Qt.ALT+Qt.Key_C) + edit.insertItem("Add &Hexagon", self.addHexagon, Qt.ALT+Qt.Key_H) + edit.insertItem("Add &Polygon", self.addPolygon, Qt.ALT+Qt.Key_P) + edit.insertItem("Add Spl&ine", self.addSpline, Qt.ALT+Qt.Key_I) + edit.insertItem("Add &Text", self.addText, Qt.ALT+Qt.Key_T) + edit.insertItem("Add &Line", self.addLine, Qt.ALT+Qt.Key_L) + edit.insertItem("Add &Rectangle", self.addRectangle, Qt.ALT+Qt.Key_R) + edit.insertItem("Add &Sprite", self.addSprite, Qt.ALT+Qt.Key_S) + edit.insertItem("Create &Mesh", self.addMesh, Qt.ALT+Qt.Key_M ) + edit.insertItem("Add &Alpha-blended image", self.addButterfly, Qt.ALT+Qt.Key_A) + self.menuBar().insertItem("&Edit", edit) + + view = QPopupMenu(self.menuBar() ); + view.insertItem("&Enlarge", self.enlarge, Qt.SHIFT+Qt.CTRL+Qt.Key_Plus); + view.insertItem("Shr&ink", self.shrink, Qt.SHIFT+Qt.CTRL+Qt.Key_Minus); + view.insertSeparator(); + view.insertItem("&Rotate clockwise", self.rotateClockwise, Qt.CTRL+Qt.Key_PageDown); + view.insertItem("Rotate &counterclockwise", self.rotateCounterClockwise, Qt.CTRL+Qt.Key_PageUp); + view.insertItem("&Zoom in", self.zoomIn, Qt.CTRL+Qt.Key_Plus); + view.insertItem("Zoom &out", self.zoomOut, Qt.CTRL+Qt.Key_Minus); + view.insertItem("Translate left", self.moveL, Qt.CTRL+Qt.Key_Left); + view.insertItem("Translate right", self.moveR, Qt.CTRL+Qt.Key_Right); + view.insertItem("Translate up", self.moveU, Qt.CTRL+Qt.Key_Up); + view.insertItem("Translate down", self.moveD, Qt.CTRL+Qt.Key_Down); + view.insertItem("&Mirror", self.mirror, Qt.CTRL+Qt.Key_Home); + self.menuBar().insertItem("&View", view) + + self.options = QPopupMenu( self.menuBar() ); + self.dbf_id = self.options.insertItem("Double buffer", self.toggleDoubleBuffer) + self.options.setItemChecked(self.dbf_id, True) + self.menuBar().insertItem("&Options",self.options) + + self.menuBar().insertSeparator(); + + help = QPopupMenu( self.menuBar() ) + help.insertItem("&About", self.help, Qt.Key_F1) + help.insertItem("&About Qt", self.aboutQt, Qt.Key_F2) + help.setItemChecked(self.dbf_id, True) + self.menuBar().insertItem("&Help",help) + + self.statusBar() + + self.setCentralWidget(self.editor) + + self.printer = 0 + self.tb=0 + self.tp=0 + + self.init() + + def init(self): + self.clear() + r=24 + r=r+1 + random.seed(r) + for i in range(self.canvas.width()/56): + self.addButterfly() + for j in range(self.canvas.width()/85): + self.addHexagon() + for k in range(self.canvas.width()/128): + self.addLogo() + + def newView(self): + m=Main(self.canvas,None,"new windiw",Qt.WDestructiveClose) + qApp.setMainWidget(m) + m.show() + qApp.setMainWidget(None) + views.append(m) + + def clear(self): + self.editor.clear() + + def help(self): + QMessageBox.information(None, "PyQt Canvas Example", + "<h3>The PyQt QCanvas classes example</h3><hr>" + "<p>This is the PyQt implementation of " + "Qt canvas example.</p> by Sadi Kose " + "<i>([email protected])</i><hr>" + "<ul>" + "<li> Press ALT-S for some sprites." + "<li> Press ALT-C for some circles." + "<li> Press ALT-L for some lines." + "<li> Drag the objects around." + "<li> Read the code!" + "</ul>","Dismiss") + + def aboutQt(self): + QMessageBox.aboutQt(self,"PyQt Canvas Example") + + def toggleDoubleBuffer(self): + s = not self.options.isItemChecked(self.dbf_id) + self.options.setItemChecked(self.dbf_id,s) + self.canvas.setDoubleBuffering(s) + + def enlarge(self): + self.canvas.resize(self.canvas.width()*4/3, self.canvas.height()*4/3) + + def shrink(self): + self.canvas.resize(self.canvas.width()*3/4, self.canvas.height()*3/4) + + def rotateClockwise(self): + m = self.editor.worldMatrix() + m.rotate( 22.5 ) + self.editor.setWorldMatrix( m ) + + def rotateCounterClockwise(self): + m = self.editor.worldMatrix() + m.rotate( -22.5 ) + self.editor.setWorldMatrix( m ) + + def zoomIn(self): + m = self.editor.worldMatrix() + m.scale( 2.0, 2.0 ) + self.editor.setWorldMatrix( m ) + + def zoomOut(self): + m = self.editor.worldMatrix() + m.scale( 0.5, 0.5 ) + self.editor.setWorldMatrix( m ) + + def mirror(self): + m = self.editor.worldMatrix() + m.scale( -1, 1 ) + self.editor.setWorldMatrix( m ) + + def moveL(self): + m = self.editor.worldMatrix() + m.translate( -16, 0 ) + self.editor.setWorldMatrix( m ) + + def moveR(self): + m = self.editor.worldMatrix() + m.translate( +16, 0 ) + self.editor.setWorldMatrix( m ) + + def moveU(self): + m = self.editor.worldMatrix() + m.translate( 0, -16 ) + self.editor.setWorldMatrix( m ) + + def moveD(self): + m = self.editor.worldMatrix(); + m.translate( 0, +16 ); + self.editor.setWorldMatrix( m ) + + def _print(self): + if not self.printer: + self.printer = QPrinter() + if self.printer.setup(self) : + pp=QPainter(self.printer) + self.canvas.drawArea(QRect(0,0,self.canvas.width(),self.canvas.height()),pp,False) + + def addSprite(self): + i = BouncyLogo(self.canvas) + i.setZ(256*random.random()%256); + i.show(); + + def addButterfly(self): + if butterfly_fn.isEmpty(): + return + if not butterflyimg: + butterflyimg.append(QImage()) + butterflyimg[0].load(butterfly_fn) + butterflyimg.append(QImage()) + butterflyimg[1] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.75), + int(butterflyimg[0].height()*0.75) ) + butterflyimg.append(QImage()) + butterflyimg[2] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.5), + int(butterflyimg[0].height()*0.5) ) + butterflyimg.append(QImage()) + butterflyimg[3] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.25), + int(butterflyimg[0].height()*0.25) ) + + i = ImageItem(butterflyimg[int(4*random.random()%4)],self.canvas) + i.move((self.canvas.width()-butterflyimg[0].width())*random.random()%(self.canvas.width()-butterflyimg[0].width()), + (self.canvas.height()-butterflyimg[0].height())*random.random()%(self.canvas.height()-butterflyimg[0].height())) + i.setZ(256*random.random()%256+250); + i.show() + + def addLogo(self): + if logo_fn.isEmpty(): + return; + if not logoimg: + logoimg.append(QImage()) + logoimg[0].load( logo_fn ) + logoimg.append(QImage()) + logoimg[1] = logoimg[0].smoothScale( int(logoimg[0].width()*0.75), + int(logoimg[0].height()*0.75) ) + logoimg.append(QImage()) + logoimg[2] = logoimg[0].smoothScale( int(logoimg[0].width()*0.5), + int(logoimg[0].height()*0.5) ) + logoimg.append(QImage()) + logoimg[3] = logoimg[0].smoothScale( int(logoimg[0].width()*0.25), + int(logoimg[0].height()*0.25) ); + + i = ImageItem(logoimg[int(4*random.random()%4)],self.canvas) + i.move((self.canvas.width()-logoimg[0].width())*random.random()%(self.canvas.width()-logoimg[0].width()), + (self.canvas.height()-logoimg[0].width())*random.random()%(self.canvas.height()-logoimg[0].width())) + i.setZ(256*random.random()%256+256) + i.show() + + def addCircle(self): + i = QCanvasEllipse(50,50,self.canvas) + i.setBrush( QBrush(QColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8) )) + i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height()) + i.setZ(256*random.random()%256) + i.show() + + def addHexagon(self): + i = QCanvasPolygon(self.canvas) + size = canvas.width() / 25 + pa=QPointArray(6) + pa.setPoint(0,QPoint(2*size,0)) + pa.setPoint(1,QPoint(size,-size*173/100)) + pa.setPoint(2,QPoint(-size,-size*173/100)) + pa.setPoint(3,QPoint(-2*size,0)) + pa.setPoint(4,QPoint(-size,size*173/100)) + pa.setPoint(5,QPoint(size,size*173/100)) + i.setPoints(pa) + i.setBrush( QBrush(QColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8) )) + i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height()) + i.setZ(256*random.random()%256) + i.show() + + def addPolygon(self): + i = QCanvasPolygon(self.canvas) + size = self.canvas.width()/2 + pa=QPointArray(6) + pa.setPoint(0, QPoint(0,0)) + pa.setPoint(1, QPoint(size,size/5)) + pa.setPoint(2, QPoint(size*4/5,size)) + pa.setPoint(3, QPoint(size/6,size*5/4)) + pa.setPoint(4, QPoint(size*3/4,size*3/4)) + pa.setPoint(5, QPoint(size*3/4,size/4)) + + i.setPoints(pa) + i.setBrush(QBrush( QColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8)) ) + i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height()) + i.setZ(256*random.random()%256) + i.show() + + def addSpline(self): + i = QCanvasSpline(self.canvas) + size = canvas.width()/6 + pa=QPointArray(12) + pa.setPoint(0,QPoint(0,0)) + pa.setPoint(1,QPoint(size/2,0)) + pa.setPoint(2,QPoint(size,size/2)) + pa.setPoint(3,QPoint(size,size)) + pa.setPoint(4,QPoint(size,size*3/2)) + pa.setPoint(5,QPoint(size/2,size*2)) + pa.setPoint(6,QPoint(0,size*2)) + pa.setPoint(7,QPoint(-size/2,size*2)) + pa.setPoint(8,QPoint(size/4,size*3/2)) + pa.setPoint(9,QPoint(0,size)) + pa.setPoint(10,QPoint(-size/4,size/2)) + pa.setPoint(11,QPoint(-size/2,0)) + i.setControlPoints(pa) + i.setBrush( QBrush(QColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8) )) + i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height()) + i.setZ(256*random.random()%256) + i.show() + + def addText(self): + i = QCanvasText(self.canvas) + i.setText("QCanvasText") + i.move(self.canvas.width()*random.random()%self.canvas.width(),self.canvas.width()*random.random()%self.canvas.height()) + i.setZ(256*random.random()%256) + i.show() + + def addLine(self): + i = QCanvasLine(self.canvas); + i.setPoints( self.canvas.width()*random.random()%self.canvas.width(), self.canvas.width()*random.random()%self.canvas.height(), + self.canvas.width()*random.random()%self.canvas.width(), self.canvas.width()*random.random()%self.canvas.height() ) + i.setPen( QPen(QColor(256*random.random()%32*8,256*random.random()%32*8,256*random.random()%32*8), 6) ) + i.setZ(256*random.random()%256) + i.show() + + def ternary(self,exp,x,y): + if exp: + return x + else: + return y + + def addMesh(self): + x0 = 0; + y0 = 0; + + if not self.tb: + self.tb = QBrush( Qt.red ) + if not self.tp: + self.tp = QPen( Qt.black ) + + nodecount = 0; + + w = self.canvas.width() + h = self.canvas.height() + + dist = 30 + rows = h / dist + cols = w / dist + + #ifndef QT_NO_PROGRESSDIALOG + #progress=QProgressDialog( "Creating mesh...", "Abort", rows, + # self, "progress", True ); + #endif + + lastRow=[] + for c in range(cols): + lastRow.append(NodeItem(self.canvas)) + for j in range(rows): + n = self.ternary(j%2 , cols-1 , cols) + prev = 0; + for i in range(n): + el = NodeItem( self.canvas ) + nodecount=nodecount+1 + r = 20*20*random.random() + xrand = r %20 + yrand = (r/20) %20 + el.move( xrand + x0 + i*dist + self.ternary(j%2 , dist/2 , 0 ), + yrand + y0 + j*dist ); + + if j > 0 : + if i < cols-1 : + EdgeItem( lastRow[i], el, self.canvas ).show() + if j%2 : + EdgeItem( lastRow[i+1], el, self.canvas ).show() + elif i > 0 : + EdgeItem( lastRow[i-1], el, self.canvas ).show() + if prev: + EdgeItem( prev, el, self.canvas ).show() + + if i > 0 : + lastRow[i-1] = prev + prev = el + el.show() + + lastRow[n-1]=prev + #ifndef QT_NO_PROGRESSDIALOG + #progress.setProgress( j ) + #if progress.wasCancelled() : + # break + #endif + + #ifndef QT_NO_PROGRESSDIALOG + #progress.setProgress( rows ) + #endif + #// qDebug( "%d nodes, %d edges", nodecount, EdgeItem::count() ); + + def addRectangle(self): + i = QCanvasRectangle( self.canvas.width()*random.random()%self.canvas.width(), + self.canvas.width()*random.random()%self.canvas.height(), + self.canvas.width()/5,self.canvas.width()/5,self.canvas) + z = 256*random.random()%256 + i.setBrush( QBrush(QColor(z,z,z) )) + i.setPen( QPen(QColor(self.canvas.width()*random.random()%32*8, + self.canvas.width()*random.random()%32*8, + self.canvas.width()*random.random()%32*8), 6) ) + i.setZ(z) + i.show() + + +if __name__=='__main__': + app=QApplication(sys.argv) + + if len(sys.argv) > 1: + butterfly_fn=QString(sys.argv[1]) + else: + butterfly_fn=QString("butterfly.png") + + if len(sys.argv) > 2: + logo_fn = QString(sys.argv[2]) + else: + logo_fn=QString("qtlogo.png") + + canvas=QCanvas(800,600) + canvas.setAdvancePeriod(30) + m=Main(canvas,None,"pyqt canvas example") + m.resize(m.sizeHint()) + + qApp.setMainWidget(m) + m.setCaption("Qt Canvas Example ported to PyQt") + if QApplication.desktop().width() > m.width() + 10 and QApplication.desktop().height() > m.height() + 30: + m.show() + else: + m.showMaximized() + + m.show(); + #// m.help(); + qApp.setMainWidget(None); + + QObject.connect( qApp, SIGNAL("lastWindowClosed()"), qApp, SLOT("quit()") ) + + app.exec_loop() + + # We need to explicitly delete the canvas now (and, therefore, the main + # window beforehand) to make sure that the sprite logo doesn't get garbage + # collected first. + views = [] + del m + del canvas diff --git a/examples3/canvas/qt-trans.xpm b/examples3/canvas/qt-trans.xpm new file mode 100644 index 0000000..225f684 --- /dev/null +++ b/examples3/canvas/qt-trans.xpm @@ -0,0 +1,54 @@ +/* XPM */ +static char *qtlogo_xpm[] = { +/* width height ncolors chars_per_pixel */ +"54 34 13 1", +/* colors */ +" c #000000", +". c #999999", +"X c #333366", +"o c #6666CC", +"O c #333333", +"@ c #666699", +"# c #000066", +"$ c #666666", +"% c #3333CC", +"& c #000033", +"* c #9999CC", +"= c #333399", +"+ c None", +/* pixels */ +"+++++++++++++++++++.$OOO$.++++++++++++++++++++++++++++", +"+++++++++++++++++$ O.+++++++++++++++++++++++++", +"+++++++++++++++.O $++++++++++++++++++++++++", +"++++++++++++++. $.++.$ O+++++++++++++++++++++++", +"+++++++++++++. O.+++++++$ O++++++++++++++++++++++", +"+++++++++++++O ++++++++++$ $+++++++++++++++++++++", +"++++++++++++$ .+++++++++++O .++++++++++++++++++++", +"+++++++++++. O+++++++++++++ O++++++.+++++++++++++", +"+++++++++++$ .+++++++++++++$ .+++.O +++++++++++++", +"+++++++++++ +++++++++++++++ O+++. +++++++++++++", +"++++++++++. &Xoooo*++++++++++$ +++. +++++++++++++", +"++++++++++@=%%%%%%%%%%*+++++++. .++. +++++++++++++", +"+++++++**oooooo**++*o%%%%o+++++ $++O +++++++++++++", +"+++++*****$OOX@oooo*++*%%%%%*++O $+. OOO$++++++++*", +"++..+.++....$O$+*ooooo*+*o%%%%%O O+$ $$O.++++++**+", +"***+*+++++$$....+++*oooo**+*o%%# O++O ++++++***o*++", +"*+++++++++O $.....++**oooo**+*X &o*O ++++*ooo*++++", +"++++++++++$ O++.....++**oooo*X &%%& ..*o%%*++++++", +"++++++++++$ ++++.....+++**ooO $*o& @oo*+++++++++", +"++++++++++. .++++++.....+++*O Xo*O .++++++++++++", +"+++++++++++ O+++++++++...... .++O +++++++++++++", +"+++++++++++O +++.$$$.++++++. O+++O +++++++++++++", +"+++++++++++. $$OO O.++++O .+++O +++++++++++++", +"++++++++++++O .+++.O $++. O++++O +++++++++++++", +"++++++++++++. O+++++O $+O +++++O +++++++++++++", +"+++++++++++++. O+++++O O .+++++O .++++++++++++", +"++++++++++++++$ .++++O .++++.+$ O+.$.++++++++", +"+++++++++++++++. O$$O .+++++... +++++++++", +"+++++++++++++++++$ O+++++$$+.O O$.+++++++++", +"+++++++++++++++++++$OO O$.O O.++. .++++++++++++++++", +"+++++++++++++++++++++++++++. OO .++++++++++++++++", +"++++++++++++++++++++++++++++. O+++++++++++++++++", +"+++++++++++++++++++++++++++++. .+++++++++++++++++", +"++++++++++++++++++++++++++++++.O O.++++++++++++++++++" +}; diff --git a/examples3/canvas/qtlogo.png b/examples3/canvas/qtlogo.png Binary files differnew file mode 100644 index 0000000..a48b1a1 --- /dev/null +++ b/examples3/canvas/qtlogo.png diff --git a/examples3/checklists.py b/examples3/checklists.py new file mode 100755 index 0000000..12a3cdb --- /dev/null +++ b/examples3/checklists.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python + +# vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1 +# Copyright (C) 2002 Oleksandr Yakovlyev (yshurik) <[email protected]> + +import sys +from qt import * + +TRUE = 1 +FALSE = 0 + +class CheckLists(QWidget): + def __init__(self, *args): + apply( QWidget.__init__, (self, ) + args ) + + lay = QHBoxLayout(self) + lay.setMargin(5) + + vbox1 = QVBoxLayout(lay) + vbox1.setMargin(5) + + # First child: a Label + vbox1.addWidget(QLabel("Check some items!", self)) + + # Second child: the ListView + self.lv1 = QListView(self) + vbox1.addWidget(self.lv1) + self.lv1.addColumn("Items") + self.lv1.setRootIsDecorated(TRUE) + + # create a list with 4 ListViewItems which will be parent items of other ListViewItems + + parentList = [] + + parentList.append( QListViewItem( self.lv1, "Parent Item 1" ) ) + parentList.append( QListViewItem( self.lv1, "Parent Item 2" ) ) + parentList.append( QListViewItem( self.lv1, "Parent Item 3" ) ) + parentList.append( QListViewItem( self.lv1, "Parent Item 4" ) ) + + num = 0 + + self.childList1 = [] + # go through the list of parent items... + for i in range(4): + it = parentList[i] + it.setOpen( TRUE ) + + # ...and create 5 checkable child ListViewItems for each parent item + for j in range(5): + ci = QCheckListItem( it, QString("%1. Child of Parent %2").arg( j ).arg( i ), QCheckListItem.CheckBox ) + self.childList1.append(ci) + + # Create another widget for layouting + tmp1 = QVBoxLayout( lay ) + tmp1.setMargin( 5 ) + + # create a pushbutton + copy1 = QPushButton( " -> ", self ) + tmp1.addWidget( copy1 ) + copy1.setMaximumWidth( copy1.sizeHint().width() ); + # connect the SIGNAL clicked() of the pushbutton with the SLOT copy1to2() + self.connect( copy1, SIGNAL('clicked()'), self.copy1to2 ) + + # another widget for layouting + vbox2 = QVBoxLayout( lay ) + vbox2.setMargin( 5 ) + + # and another label + vbox2.addWidget( QLabel( "Check one item!", self ) ) + + # create the second listview + self.lv2 = QListView( self ) + vbox2.addWidget( self.lv2 ) + self.lv2.addColumn( "Items" ) + self.lv2.setRootIsDecorated( TRUE ) + + # another widget needed for layouting only + tmp2 = QVBoxLayout( lay ) + tmp2.setMargin( 5 ) + + # create another pushbutton... + copy2 = QPushButton( " -> ", self ) + lay.addWidget( copy2 ) + copy2.setMaximumWidth( copy2.sizeHint().width() ) + # ...and connect its clicked() SIGNAL to the copy2to3() SLOT + self.connect( copy2, SIGNAL('clicked()'), self.copy2to3 ) + + tmp3 = QVBoxLayout( lay ) + tmp3.setMargin( 5 ) + + # and create a label which will be at the right of the window + self.label = QLabel( "No Item yet...", self ) + tmp3.addWidget( self.label ) + + def copy1to2(self): + self.lv2.clear() + + # Insert first a controller Item into the second ListView. Always if Radio-ListViewItems + # are inserted into a Listview, the parent item of these MUST be a controller Item! + item = QCheckListItem( self.lv2, "Controller", QCheckListItem.Controller ) + item.setOpen( TRUE ) + + self.listChild2 = [] + for it in self.childList1: + # ...check state of childs, and... + if it.parent() != None: + # ...if the item is checked... + if it.isOn(): + # ...insert a Radio-ListViewItem with the same text into the second ListView + ri = QCheckListItem(item , it.text(0), QCheckListItem.RadioButton) + self.listChild2.append(ri) + + if item.firstChild() != None: + item.firstChild().setOn(TRUE) + + def copy2to3(self): + self.label.setText( "No Item checked" ) + + # iterate through the second ListView... + for it in self.listChild2: + # ...check state of childs, and... + if it.parent() != None: + # ...if the item is checked... + if it.isOn(): + # ...set the text of the item to the label + self.label.setText( it.text( 0 ) ) + +a = QApplication(sys.argv) + +checkLists = CheckLists() +checkLists.resize(700, 400) +checkLists.setCaption("PyQt example - CheckLists") + +a.setMainWidget(checkLists) +checkLists.show() +a.exec_loop() diff --git a/examples3/cursor.py b/examples3/cursor.py new file mode 100755 index 0000000..d5bbbe1 --- /dev/null +++ b/examples3/cursor.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python + +"""$Id: cursor.py,v 1.1 2003/07/01 14:18:37 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +# cb_bits and cm_bits were generated by X bitmap program. + +cb_width = 32 +cb_height = 32 + +# cursor bitmap +cb_bits = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x0f\x00" \ + "\x00\x06\x30\x00\x80\x01\xc0\x00\x40\x00\x00\x01" \ + "\x20\x00\x00\x02\x10\x00\x00\x04\x08\x3e\x3e\x08" \ + "\x08\x03\xe0\x08\xc4\x00\x00\x11\x04\x1e\x78\x10" \ + "\x02\x0c\x30\x20\x02\x40\x00\x20\x02\x40\x00\x20" \ + "\x02\x40\x00\x20\x02\x20\x04\x20\x02\x20\x04\x20" \ + "\x02\x10\x08\x20\x02\x08\x08\x20\x02\xf0\x07\x20" \ + "\x04\x00\x00\x10\x04\x00\x00\x10\x08\x00\xc0\x08" \ + "\x08\x3c\x30\x08\x10\xe6\x19\x04\x20\x00\x0f\x02" \ + "\x40\x00\x00\x01\x80\x01\xc0\x00\x00\x06\x30\x00" \ + "\x00\xf8\x0f\x00\x00\x00\x00\x00" + +cm_width = 32 +cm_height = 32 + +# cursor bitmap mask +cm_bits = "\x00\x00\x00\x00\x00\xf8\x1f\x00\x00\xfe\x3f\x00" \ + "\x80\x07\xf0\x00\xc0\x01\xc0\x01\x60\x00\x00\x03" \ + "\x30\x00\x00\x06\x18\x00\x00\x0c\x0c\x3e\x3e\x18" \ + "\x0e\x03\xe0\x18\xc6\x00\x00\x31\x07\x1e\x78\x30" \ + "\x03\x0c\x30\x60\x03\x40\x00\x60\x03\x40\x00\x60" \ + "\x03\x40\x00\x60\x03\x20\x04\x60\x03\x20\x04\x60" \ + "\x03\x10\x08\x60\x03\x08\x08\x60\x03\xf0\x07\x60" \ + "\x06\x00\x00\x30\x06\x00\x00\x30\x0c\x00\xc0\x18" \ + "\x0c\x3c\x30\x18\x18\xe6\x19\x0c\x30\x00\x0f\x06" \ + "\x60\x00\x00\x03\xc0\x01\xc0\x01\x80\x07\xf0\x00" \ + "\x00\xfe\x3f\x00\x00\xf8\x0f\x00" + +# The CursorView contains many labels with different cursors. +class CursorView( QWidget ): # cursor view + def __init__( self ): + QWidget.__init__( self ) + # Constructs a cursor view. +#enum CursorShape { ArrowCursor, UpArrowCursor, CrossCursor, WaitCursor, IbeamCursor, SizeVerCursor, SizeHorCursor, SizeBDiagCursor, SizeFDiagCursor, SizeAllCursor, BlankCursor, SplitVCursor, SplitHCursor, PointingHandCursor, ForbiddenCursor, WhatsThisCursor, LastCursor = WhatsThisCursor, BitmapCursor = 24 } + + shape = [ + "ArrowCursor", "UpArrowCursor", "CrossCursor", + "WaitCursor", "IbeamCursor", "SizeVerCursor", + "SizeHorCursor", "SizeBDiagCursor", "SizeFDiagCursor", + "SizeAllCursor", "BlankCursor", "SplitVCursor", + "SplitHCursor", "PointingHandCursor", "ForbiddenCursor", + "WhatsThisCursor" + ] + name = [ + "standard arrow cursor", "upwards arrow", + "crosshair", "hourglass/watch", + "ibeam/text entry", "vertical resize", + "horizontal resize", "diagonal resize (/)", + "diagonal resize (\)", "all directions resize", + "blank/invisible cursor", "vertical splitting", + "horziontal splitting", "a pointing hand", + "a slashed circle", "an arrow with a question mark" + ] + + self.setCaption( "CursorView" ) # set window caption + + grid = QGridLayout( self, 5, 4, 20 ) + + i=0 + for y in range( 0, 4, 1 ) : # create the small labels + for x in range( 0, 4, 1 ) : + label = QLabel( self ) + label.setCursor( QCursor(i) ) + label.setText( shape[i] ); + label.setAlignment( self.AlignCenter ) + label.setFrameStyle( QFrame.Box | QFrame.Raised ) + grid.addWidget( label, x, y ) + QToolTip.add( label, name[i] ) + i += 1 + + cb = QBitmap( cb_width, cb_height, cb_bits, True ) + cm = QBitmap( cm_width, cm_height, cm_bits, True ) + custom = QCursor( cb, cm ) # create bitmap cursor + + label = QLabel( self ) # create the big label + label.setCursor( custom ) + label.setText( "Custom bitmap cursor" ) + QToolTip.add( label, "custom bitmap cursor" ) + label.setAlignment( self.AlignCenter ) + label.setFrameStyle( QFrame.Box | QFrame.Sunken ) + grid.addMultiCellWidget( label, 4, 4, 0, 3 ) + +# Create and display a CursorView. +def main( args ): + a = QApplication(sys.argv) # application object + v = CursorView() # cursor view + v.setCaption( "Qt Example - Cursors" ) + a.setMainWidget( v ) + v.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/dclock.py b/examples3/dclock.py new file mode 100755 index 0000000..5382d4f --- /dev/null +++ b/examples3/dclock.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +# A port to PyQt of the dclock example from Qt v2.x. + + +import sys, string +from qt import * + + +class DigitalClock(QLCDNumber): + def __init__(self, parent=None, name=None): + QLCDNumber.__init__(self, parent, name) + self.showingColon = 0 + self.setFrameStyle(QFrame.Panel | QFrame.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() == Qt.LeftButton: + self.showDate() + + def showDate(self): + if self.showDateTimer != -1: + return + d = QDate.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(QTime.currentTime().toString())[:5]) #.left(5) + if not self.showingColon: + s[2] = ' ' + if s[0] == '0': + s[0] = ' ' + s = string.join(s,'') + self.display(s) + +a = QApplication(sys.argv) +clock = DigitalClock() +clock.resize(170,80) +a.setMainWidget(clock) +clock.show() +a.exec_loop() diff --git a/examples3/desktop.py b/examples3/desktop.py new file mode 100755 index 0000000..7036248 --- /dev/null +++ b/examples3/desktop.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python + +import sys +from 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 + return i + +maxpoints = 5 +maxcurves = 8 + +def poly(): + d = QApplication.desktop() + d.setEraseColor(Qt.white) + xvel = [ 0 ] * maxpoints + yvel = [ 0 ] * maxpoints + head = 0 + tail = -maxcurves + 2 + a = [ QPointArray() ] * 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 = QPainter() + paint.begin(d) + + for ntimes in range(2000): + paint.setBrush(QColor(kindaRand()%360,180,255, QColor.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 = QImage(w, h, 8, 128) + for i in range(128): + image.setColor(i, qRgb(i,0,0)) + for y in range(h): + for x in range(w): + image.setPixel(x,y,(x+y)%128) + + pm = QPixmap() + pm.convertFromImage(image) + pm.setOptimization(QPixmap.BestOptim) + + d = QApplication.desktop() + + for i in range(0,361,2): + m = QWMatrix() + m.rotate(i) + rpm = pm.xForm(m) + d.setErasePixmap(rpm) + d.update() + +def generateStone(pm, c1, c2, c3): + p = QPainter() + p1 = QPen(c1, 0) + p2 = QPen(c2, 0) + p3 = QPen(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(QWidget): + def __init__(self, s, parent=None, name=''): + QWidget.__init__(self, parent, name, Qt.WType_Desktop | Qt.WPaintDesktop) + self.text = s + self.pm = None + + def paintEvent(self, pe): + c1 = self.eraseColor() + c2 = c1.light(104) + c3 = c1.dark(106) + if not self.pm: + self.pm = QPixmap(64, 64) + generateStone(self.pm, c1, c2, c3) + self.setErasePixmap(self.pm) + self.update() + br = self.fontMetrics().boundingRect(self.text) + offscreen = QPixmap(br.width(), br.height()) + x = self.width()/2 - br.width()/2 + y = self.height()/2 - br.height()/2 + offscreen.fill(self, x, y) + p = QPainter() + p.begin(offscreen) + drawShadeText(p, -br.x(), -br.y(), self.text, c2, c3, 3) + p.end() + bitBlt(self, x, y, offscreen) + +def desktopWidget(s='Trolltech'): + t = DesktopWidget(s) + t.update() + qApp.exec_loop() + +def desktopText(s='Trolltech'): + border = 20 + + c1 = qApp.palette().normal().background() + c2 = c1.light(104) + c3 = c1.dark(106) + + pm = QPixmap(10, 10) + p = QPainter() + p.begin(pm) + r = p.fontMetrics().boundingRect(s) + p.end() + + appWidth = qApp.desktop().width() + appHeight = qApp.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() + + qApp.desktop().setErasePixmap(pm) + +a = QApplication(sys.argv) +if len(sys.argv) > 1: + f = QFont('charter', 96, QFont.Black) + f.setStyleHint(QFont.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: + print """Usage: +\tdesktop -poly +\tdesktop -rotate +\tdesktop -troll +\tdesktop -trollwidget +\tdesktop -shadetext <text> +\tdesktop -shadewidget <text>""" + rotate() diff --git a/examples3/dirview.py b/examples3/dirview.py new file mode 100755 index 0000000..eb5393e --- /dev/null +++ b/examples3/dirview.py @@ -0,0 +1,452 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: dirview.py,v 1.7 2005/11/14 17:21:26 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** Some corrections by M. Biermaier (http://www.office-m.at) +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +folder_closed_xpm = [ + "16 16 9 1", + "g c #808080", + "b c #c0c000", + "e c #c0c0c0", + "# c #000000", + "c c #ffff00", + ". c None", + "a c #585858", + "f c #a0a0a4", + "d c #ffffff", + "..###...........", + ".#abc##.........", + ".#daabc#####....", + ".#ddeaabbccc#...", + ".#dedeeabbbba...", + ".#edeeeeaaaab#..", + ".#deeeeeeefe#ba.", + ".#eeeeeeefef#ba.", + ".#eeeeeefeff#ba.", + ".#eeeeefefff#ba.", + ".##geefeffff#ba.", + "...##gefffff#ba.", + ".....##fffff#ba.", + ".......##fff#b##", + ".........##f#b##", + "...........####." +] + +folder_open_xpm = [ + "16 16 11 1", + "# c #000000", + "g c #c0c0c0", + "e c #303030", + "a c #ffa858", + "b c #808080", + "d c #a0a0a4", + "f c #585858", + "c c #ffdca8", + "h c #dcdcdc", + "i c #ffffff", + ". c None", + "....###.........", + "....#ab##.......", + "....#acab####...", + "###.#acccccca#..", + "#ddefaaaccccca#.", + "#bdddbaaaacccab#", + ".eddddbbaaaacab#", + ".#bddggdbbaaaab#", + "..edgdggggbbaab#", + "..#bgggghghdaab#", + "...ebhggghicfab#", + "....#edhhiiidab#", + "......#egiiicfb#", + "........#egiibb#", + "..........#egib#", + "............#ee#" +] + +folder_locked = [ + "16 16 10 1", + "h c #808080", + "b c #ffa858", + "f c #c0c0c0", + "e c #c05800", + "# c #000000", + "c c #ffdca8", + ". c None", + "a c #585858", + "g c #a0a0a4", + "d c #ffffff", + "..#a#...........", + ".#abc####.......", + ".#daa#eee#......", + ".#ddf#e##b#.....", + ".#dfd#e#bcb##...", + ".#fdccc#daaab#..", + ".#dfbbbccgfg#ba.", + ".#ffb#ebbfgg#ba.", + ".#ffbbe#bggg#ba.", + ".#fffbbebggg#ba.", + ".##hf#ebbggg#ba.", + "...###e#gggg#ba.", + ".....#e#gggg#ba.", + "......###ggg#b##", + ".........##g#b##", + "...........####." +] + +pix_file = [ + "16 16 7 1", + "# c #000000", + "b c #ffffff", + "e c #000000", + "d c #404000", + "c c #c0c000", + "a c #ffffc0", + ". c None", + "................", + ".........#......", + "......#.#a##....", + ".....#b#bbba##..", + "....#b#bbbabbb#.", + "...#b#bba##bb#..", + "..#b#abb#bb##...", + ".#a#aab#bbbab##.", + "#a#aaa#bcbbbbbb#", + "#ccdc#bcbbcbbb#.", + ".##c#bcbbcabb#..", + "...#acbacbbbe...", + "..#aaaacaba#....", + "...##aaaaa#.....", + ".....##aa#......", + ".......##......." +] + +folderLocked = None +folderClosed = None +folderOpened = None +fileNormal = None + +class FileItem( QListViewItem ) : + def __init__( self, parent=None, s1=QString.null, s2=QString.null ): + QListViewItem.__init__( self, parent, s1, s2 ) + self.pix = None + + def setPixmap( self, p ) : + self.pix = p + self.setup() + self.widthChanged( 0 ) + self.invalidateHeight() + self.repaint() + + def pixmap( self, i ) : + if i : return None + else : return self.pix; + +# Class Directory +class Directory( QListViewItem ) : + def __init__( self, parent=None, filename=QString.null, col2=QString.null ): + QListViewItem.__init__( self, parent, filename, col2 ) + self.pix = None + global folderLocked, folderClosed, folderOpened, fileNormal + self.showDirsOnly = False + if isinstance(parent, QListView): + self.p = None + self.showDirsOnly = parent.showDirsOnly() + self.f = QFile( QString('/') ) + else: + self.p = parent + self.showDirsOnly = parent.showDirsOnly + self.f = QFile( QString(filename) ) + + self.readable = QDir( self.fullName() ).isReadable() + if not self.readable : self.setPixmap( folderLocked ) + else : self.setPixmap( folderClosed ) + + def setPixmap( self, px ) : + self.pix = px + self.setup() + self.widthChanged( 0 ) + self.invalidateHeight() + self.repaint() + + def pixmap( self, i ) : + if i : return None + else : return self.pix + + def setOpen( self, o ) : + if o : self.setPixmap( folderOpened ) + else : self.setPixmap( folderClosed ) + + if o and not self.childCount() : + s = QString( self.fullName() ) + thisDir = QDir( s ) + if not thisDir.isReadable() : + self.readable = False + self.setExpandable( False ) + return + + self.listView().setUpdatesEnabled( False ) + files = thisDir.entryInfoList() + if files : + fi = QFileInfo() + for it in files: + fi = it + if str(fi.fileName()) == "." or str(fi.fileName()) == ".." : + continue # nothing + elif fi.isSymLink() and not self.showDirsOnly : + item = FileItem( self, fi.fileName(), "Symbolic Link" ) + item.setPixmap( fileNormal ) + elif fi.isDir() : + Directory( self, fi.fileName() ) + elif not self.showDirsOnly : + if fi.isFile() : item = FileItem( self, fi.fileName(), "File" ) + else : item = FileItem( self, fi.fileName(), "Special" ) + item.setPixmap( fileNormal ) + + self.listView().setUpdatesEnabled( True ) + QListViewItem.setOpen( self, o ) + + def setup( self ): + self.setExpandable( True ) + QListViewItem.setup( self ) + + def fullName( self ): + s = QString() + if self.p : + s = self.p.fullName() + s.append( self.f.name() ) + s.append( "/" ) + else : + s = self.f.name() + return s + + def text( self, column ) : + if column == 0 : return self.f.name() + elif self.readable : return "Directory" + else : return "Unreadable Directory" + +# Class DirectoryView + +class DirectoryView( QListView ): + def __init__( self, parent=None, name=None, sdo=False ): + QListView.__init__( self, parent, name ) + self.dirsOnly = sdo + self.oldCurrent = 0 + self.dropItem = 0 + self.presspos = QPoint(0,0) + self.mousePressed = False + global folderLocked, folderClosed, folderOpened, fileNormal #= QPixmap() + self.autoopenTime = 750 + + self.autoopen_timer = QTimer( self ) + if not folderLocked : + folderLocked = QPixmap( folder_locked ) + folderClosed = QPixmap( folder_closed_xpm ) + folderOpened = QPixmap( folder_open_xpm ) + fileNormal = QPixmap( pix_file ) + + self.connect( self, SIGNAL("doubleClicked(QListViewItem *)"), + self.slotFolderSelected ) + self.connect( self, SIGNAL("returnPressed(QListViewItem *)"), + self.slotFolderSelected ) + + self.setAcceptDrops( True ) + self.viewport().setAcceptDrops( True ) + + self.connect( self.autoopen_timer, SIGNAL("timeout()"), self.openFolder ) + + def showDirsOnly( self ): + return self.dirsOnly + + def slotFolderSelected( self, i ): + if not i or not self.showDirsOnly(): + return + dir = i + self.emit( PYSIGNAL("folderSelected(const QString &)"), (dir.fullName(), ) ) + + def openFolder( self ): + self.autoopen_timer.stop() + if self.dropItem and not self.dropItem.isOpen(): + self.dropItem.setOpen( True ) + self.dropItem.repaint() + + def contentsDragEnterEvent( self, e ): + if not QUriDrag.canDecode(e) : + e.ignore() + return + self.oldCurrent = self.currentItem() + i = self.itemAt( self.contentsToViewport(e.pos()) ) + if i : + self.dropItem = i + self.autoopen_timer.start( self.autoopenTime ) + + def contentsDragMoveEvent( self, e ) : + if not QUriDrag.canDecode(e) : + e.ignore() + return + vp = self.contentsToViewport( e.pos() ) + i = self.itemAt( vp ) + if i : + self.setSelected( i, True ) + e.accept() + if i != self.dropItem : + self.autoopen_timer.stop() + self.dropItem = i + self.autoopen_timer.start( self.autoopenTime ) + + if e.action() == QDropEvent.Copy: + pass + elif e.action() == QDropEvent.Move: + e.acceptAction() + elif e.action() == QDropEvent.Link: + e.acceptAction() + else: + pass + else : + e.ignore() + self.autoopen_timer.stop() + self.dropItem = 0 + + def contentsDragLeaveEvent( self, QDragLeaveEvent ) : + self.autoopen_timer.stop() + self.dropItem = 0 + + self.setCurrentItem( self.oldCurrent ) + self.setSelected( self.oldCurrent, True ) + + def contentsDropEvent( self, e ): + self.autoopen_timer.stop() + if not QUriDrag.canDecode(e) : + e.ignore() + return + item = self.itemAt( self.contentsToViewport(e.pos()) ) + if item : + lst = QStringList() + QUriDrag.decodeLocalFiles( e, lst ) + if e.action() == QDropEvent.Copy: + s = QString("Copy") + elif e.action() == QDropEvent.Move: + s = QString("Move") + e.acceptAction() + elif e.action() == QDropEvent.Link: + s = QString("Link") + e.acceptAction() + else: + s = QString("Unknown") + + s += "\n\n" + e.accept() + + for filename in lst: + s += filename + s += "\n" + + s += "\nTo\n\n " + s += self.fullPath(item) + QMessageBox.information( self, "Drop target", s, "Not implemented" ) + else : + e.ignore() + + def fullPath( self, item ): + fullpath = QString( item.text(0) ) + item = item.parent() + while item: + newpath = item.text(0) + + if item.parent(): + newpath += "/" + + newpath += fullpath + fullpath = newpath + item = item.parent() + + return fullpath + + def contentsMousePressEvent( self, e ) : + QListView.contentsMousePressEvent( self, e ) + p = QPoint( self.contentsToViewport( e.pos() ) ) + i = self.itemAt( p ) + if i : + # if the user clicked into the root decoration of the item, don't try to start a drag! + if self.rootIsDecorated(): isdecorated = 1 + else : isdecorated = 0 + if p.x() > self.header().sectionPos( self.header().mapToIndex( 0 )) + self.treeStepSize() * ( i.depth() + isdecorated + self.itemMargin() or + p.x() < self.header().sectionPos( self.header().mapToIndex( 0 ) ) ) : + self.presspos.setX(e.pos().x()) + self.presspos.setY(e.pos().y()) + self.mousePressed = True + + def contentsMouseMoveEvent( self, e ): + offset = QPoint( self.presspos.x() - e.pos().x(), + self.presspos.y() - e.pos().y() ) + if self.mousePressed and (offset).manhattanLength() > QApplication.startDragDistance() : + self.mousePressed = False + item = self.itemAt( self.contentsToViewport(self.presspos) ) + if item : + source = self.fullPath(item) + if QFile.exists(source) : + ud = QUriDrag(self.viewport()) + ud.setFileNames( QStringList (source) ) + if ud.drag() : + QMessageBox.information( self, "Drag source", + QString("Delete ")+source, "Not implemented" ) + + def contentsMouseReleaseEvent( self, QMouseEvent ): + self.mousePressed = False + + def setDir( self, s ): + it = QListViewItem( self ) + it.setOpen(False) + thisDir = QDir( s ) + it = QListViewItem( self ) + it.setOpen(False) + lst = QStringList( QStringList.split( "/", s ) ) + listview2 = [] + listview2.extend( lst ) + + item = self.firstChild() + for it2 in listview2 : + while item : + if item.text( 0 ) == it2 : + item.setOpen( True ) + break + item = item.itemBelow() + if item: + self.setCurrentItem( item ) + +def main( args ): + a = QApplication( args ) + + mw = DirectoryView() + mw.addColumn( "Name" ) + mw.addColumn( "Type" ) + mw.setTreeStepSize( 20 ) + + roots = QDir.drives() + if roots : + for it in roots: + fi = it + root = Directory( mw, fi.filePath() ) + if roots.count(it) <= 1 : + root.setOpen( True ) # be interesting + + mw.resize( 400, 400 ) + mw.setCaption( "Qt Example - Directory Browser" ) + mw.setAllColumnsShowFocus( True ) + a.setMainWidget( mw ) + mw.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/dragdrop.py b/examples3/dragdrop.py new file mode 100755 index 0000000..4cc8c73 --- /dev/null +++ b/examples3/dragdrop.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# Ported to PyQt by Issac Trotts on Jan 1, 2002 + +import sys +from qt import * + +import dropsite, secret + + +def addStuff( parent, yn_image, yn_secret = 0 ): + tll = QVBoxLayout( parent, 10 ) + d = dropsite.DropSite( parent, 'dropsite' ) + d.setFrameStyle( QFrame.Sunken + QFrame.WinPanel ) + tll.addWidget( d ) + if yn_image: + stuff = QPixmap() + if not stuff.load( "trolltech.bmp" ): + stuff = QPixmap(20,20) + stuff.fill(Qt.green) + d.setPixmap( stuff ) + else: + d.setText("Drag and Drop") + d.setFont(QFont("Helvetica",18)) + if secret: + s = secret.SecretSource( 42, parent ) + tll.addWidget( s ) + + format = QLabel( "\n\n\n\nNone\n\n\n\n", parent ) + tll.addWidget( format ) + tll.activate() + parent.resize( parent.sizeHint() ) + + QObject.connect( d, PYSIGNAL('message(QString &)'), + format, SLOT('setText(QString &)') ) + + +app = QApplication( sys.argv ) + +mw = QWidget() +addStuff( mw, 1 ) +mw.setCaption( "Qt Example - Drag and Drop" ) +mw.show() + +mw2 = QWidget() +addStuff( mw2, 0 ) +mw2.setCaption( "Qt Example - Drag and Drop" ) +mw2.show() + +mw3 = QWidget() +addStuff( mw3, 1, 1 ) +mw3.setCaption( "Qt Example - Drag and Drop" ) +mw3.show() + +QObject.connect(qApp,SIGNAL('lastWindowClosed()'),qApp,SLOT('quit()')) + +app.exec_loop() diff --git a/examples3/drawlines.py b/examples3/drawlines.py new file mode 100755 index 0000000..3e21db7 --- /dev/null +++ b/examples3/drawlines.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +import sys, random +from qt import * + +TRUE = 1 +FALSE = 0 + +MAXPOINTS = 2000; # maximum number of points +MAXCOLORS = 40; + +# +# ConnectWidget - draws connected lines +# + +class ConnectWidget(QWidget): + def __init__(self): + QWidget.__init__(self) + self.setEraseColor( Qt.white ) # white background + self.count = 0; + self.down = FALSE + + self.points = [] + self.colors = [] + + for i in range(MAXPOINTS): # init arrays + self.points.append(QPoint()) + for i in range(MAXCOLORS): + self.colors.append(QColor( random.randint(0,255), random.randint(0,255), random.randint(0,255) )) + +# +# Handles paint events for the connect widget. +# + def paintEvent(self, pe): + paint = QPainter( self ) + for i in range(self.count-1): # connect all points + for j in range(i+1, self.count): + paint.setPen( self.colors[random.randint(0,MAXCOLORS-1)] ) # set random pen color + paint.drawLine( self.points[i], self.points[j] ) # draw line + +# +# Handles mouse press events for the connect widget. +# + def mousePressEvent(self, me): + self.down = TRUE + self.count = 0 # start recording points + self.erase() # erase widget contents + +# +# Handles mouse release events for the connect widget. +# + def mouseReleaseEvent(self, me ): + self.down = FALSE # done recording points + self.update() # draw the lines + +# +# Handles mouse move events for the connect widget. +# + def mouseMoveEvent(self, me): + if self.down and self.count < MAXPOINTS: + paint = QPainter( self ) + self.points[self.count] = QPoint(me.pos()) # add point + paint.drawPoint( me.pos() ) # plot point + self.count = self.count+1 + +# +# Create and display a ConnectWidget. +# +a = QApplication( sys.argv ) +connect = ConnectWidget() +connect.setCaption( "PyQt Example - Draw lines") +a.setMainWidget( connect ) +connect.show() +a.exec_loop() diff --git a/examples3/dropsite.py b/examples3/dropsite.py new file mode 100644 index 0000000..11d9707 --- /dev/null +++ b/examples3/dropsite.py @@ -0,0 +1,96 @@ +# This is part of the dragdrop example. + + +from qt import * + +import secret + + +class DropSite(QLabel): + def __init__(self, parent=None, name=None): + QLabel.__init__( self, parent, name ) + self.setAcceptDrops(1) + + # this is a normal event + def mousePressEvent( self, e ): + if ( self.pixmap() ) : + drobj = QImageDrag( self.pixmap().convertToImage(), self ) + pm = QPixmap() + pm.convertFromImage(self.pixmap().convertToImage().smoothScale( + self.pixmap().width()/3,self.pixmap().height()/3)) + drobj.setPixmap(pm,QPoint(-5,-7)) + else : + drobj = QTextDrag( 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 + QTextDrag.canDecode( e ) or + QImageDrag.canDecode( e ) or + QUriDrag.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(QString &)'), (QString(t),)) + self.setEraseColor(Qt.white) + + def dragLeaveEvent( self, QDragLeaveEvent ): + # Give the user some feedback... + self.emit(PYSIGNAL('message(QString &)'), (QString(''),)) + self.setEraseColor(Qt.lightGray) + + def dropEvent( self, e ): + self.setEraseColor(Qt.lightGray) + # Try to decode to the data you understand... + str = QString() + if ( QTextDrag.decode( e, str ) ) : + self.setText( str ) + self.setMinimumSize( self.minimumSize().expandedTo(self.sizeHint()) ) + return + + pm = QPixmap() + if ( QImageDrag.decode( e, pm ) ) : + self.setPixmap( pm ) + self.setMinimumSize(self.minimumSize().expandedTo(self.sizeHint())) + return + + # QStrList strings + #strings = QStrList() + strings = [] + if ( QUriDrag.decode( e, strings ) ) : + m = QString("Full URLs:\n") + for u in strings: + m = m + " " + u + '\n' + # QStringList files + files = [] + if ( QUriDrag.decodeLocalFiles( e, files ) ) : + m += "Files:\n" + # for (QStringList.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 diff --git a/examples3/fileopen.xpm b/examples3/fileopen.xpm new file mode 100644 index 0000000..880417e --- /dev/null +++ b/examples3/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *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" +}; diff --git a/examples3/fontdisplayer.py b/examples3/fontdisplayer.py new file mode 100755 index 0000000..f6015df --- /dev/null +++ b/examples3/fontdisplayer.py @@ -0,0 +1,148 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: fontdisplayer.py,v 1.2 2004/07/19 18:41:53 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +class FontRowTable( QFrame ): + def __init__( self, parent=None, name=None ): + QFrame.__init__( self, parent, name ) + + self.setBackgroundMode(self.PaletteBase) + self.setFrameStyle(self.Panel|self.Sunken) + self.setMargin(8) + self.setRow(0) + self.row = 0 + self.tablefont = QFont( QApplication.font() ) + + def sizeHint( self ) : + width = 16*self.cellSize().width()+QSize(2,2).width()*(self.margin()+self.frameWidth()) + height = 16*self.cellSize().height()+QSize(2,2).height()*(self.margin()+self.frameWidth()) + return QSize(width,height) + + def cellSize( self ) : + fm = self.fontMetrics() + return QSize( fm.maxWidth(), fm.lineSpacing() + 1 ) + + def paintEvent( self, e ): + QFrame.paintEvent(self, e) + p = QPainter(self) + p.setClipRegion(e.region()) + r = QRect(e.rect()) + fm = self.fontMetrics() + ml = self.frameWidth() + self.margin() + 1 + max(0,-fm.minLeftBearing()) + mt = self.frameWidth() + self.margin() + cell = QSize((self.width()-15-ml)/16,(self.height()-15-mt)/16) + + if not cell.width() or not cell.height() : + return + + mini = r.left() / cell.width() + maxi = (r.right()+cell.width()-1) / cell.width() + minj = r.top() / cell.height() + maxj = (r.bottom()+cell.height()-1) / cell.height() + + h = fm.height() + + body = QColor(255,255,192); + negative = QColor(255,192,192); + positive = QColor(192,192,255); + rnegative = QColor(255,128,128); + rpositive = QColor(128,128,255); + + for j in range(minj, maxj+1, 1) : + for i in range(mini, maxi+1, 1) : + if i < 16 and j < 16 : + x = i*cell.width() + y = j*cell.height() + + ch = QChar(j*16+i) #,self.row) # just accept one argument!!! + + if fm.inFont(ch) : + w = fm.width(ch) + l = fm.leftBearing(ch) + r = fm.rightBearing(ch) + + x += ml + y += mt+h + + p.fillRect(x,y,w,-h,QBrush(body)) + + if w : + if l : + if l < 0: sign = negative + else: sign = positive + if l > 0: lsign = 0 + else: lsign = 1 + p.fillRect(x+lsign, y-h/2, abs(l),-h/2, QBrush(sign)) + if r : + if r < 0: sign = rnegative + else: sign = rpositive + if r > 0: rsign = r + else: rsign = 0 + p.fillRect(x+w-rsign,y+2, abs(r),-h/2, QBrush(sign)) + s = QString( ch ) + p.setPen(QPen(Qt.black)) + p.drawText(x,y,s) + + def setRow( self, r ) : + self.row = r + + fm = self.fontMetrics() + str = " minLB=%d minRB=%d maxW=%d" % (fm.minLeftBearing(), fm.minRightBearing(), fm.maxWidth()) + self.emit( PYSIGNAL("fontInformation"), ( QString(str), ) ) + self.update() + + def chooseFont( self ) : + ok = 0 + oldfont = QFont( self.tablefont ) + self.tablefont, ok = QFontDialog.getFont(oldfont, self) + if ok: + self.setFont(self.tablefont) + else: + self.tablefont = oldfont + +class FontDisplayer( QMainWindow ) : + def __init__( self, parent=None, name=None ): + QMainWindow.__init__( self, parent, name ) + table = FontRowTable(self) + controls = QToolBar(self) + + QLabel(self.tr("Row:"), controls) + self.row = QSpinBox(0,255,1,controls) + controls.addSeparator() + fontbutton = QPushButton(self.tr("Font..."), controls) + status = QStatusBar(self) + + self.connect( self.row, SIGNAL("valueChanged(int)"), table.setRow ) + self.connect( fontbutton, SIGNAL("clicked()"), table.chooseFont ) + self.connect( table, PYSIGNAL("fontInformation"), + status, SLOT("message(const QString&)") ) + table.setRow(0) + self.setCentralWidget(table) + +def main( args ): + # Use an interesting font + QApplication.setFont(QFont("unifont",16)) + app = QApplication(sys.argv) + + m = FontDisplayer() + sh = QSize( m.centralWidget().sizeHint() ) + m.resize(sh.width(), sh.height() + 3 * m.statusBar().height()) + app.setMainWidget(m); + m.setCaption("Qt Example - QFD"); + m.show() + + app.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/fonts.py b/examples3/fonts.py new file mode 100755 index 0000000..d3166ce --- /dev/null +++ b/examples3/fonts.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: fonts.py,v 1.1 2003/07/01 14:18:37 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +class Viewer( QWidget ): + def __init__( self ): + QWidget.__init__( self ) + + self.setFontSubstitutions() + + #greeting_heb = QString.fromUtf8( "\327\251\327\234\327\225\327\235" ) + greeting_heb = unicode( '\327\251\327\234\327\225\327\235','utf8' ) + #greeting_ru = QString.fromUtf8( "\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265" ) + greeting_ru = unicode('\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265','utf8' ) + greeting_en = "Hello" + + self.greetings = QTextView( self, "textview" ) + + self.greetings.setText( greeting_en + "\n" + + greeting_ru + "\n" + + greeting_heb ) + + self.fontInfo = QTextView( self, "fontinfo" ) + + self.setDefault() + + self.defaultButton = QPushButton( "Default", self, "pushbutton1" ) + self.defaultButton.setFont( QFont( "times" ) ) + self.connect( self.defaultButton, SIGNAL("clicked()"), self.setDefault ) + + self.sansSerifButton = QPushButton( "Sans Serif", self, "pushbutton2" ) + self.sansSerifButton.setFont( QFont( "Helvetica", 12 ) ) + self.connect( self.sansSerifButton, SIGNAL("clicked()"), self.setSansSerif ) + + self.italicsButton = QPushButton( "Italics", self, "pushbutton3" ) + self.italicsButton.setFont( QFont( "lucida", 12, QFont.Bold, True ) ) + self.connect( self.italicsButton, SIGNAL("clicked()"), self.setItalics ) + + self.layout() + + def setDefault( self ): + font = QFont( "Bavaria" ) + font.setPointSize( 24 ) + font.setWeight( QFont.Bold ) + font.setUnderline( True ) + + self.greetings.setFont( font ) + + self.showFontInfo( font ) + + def setSansSerif( self ): + font = QFont( "Newyork", 18 ) + font.setStyleHint( QFont.SansSerif ) + + self.greetings.setFont( font ) + + self.showFontInfo( font ) + + def setItalics( self ): + font = QFont( "Tokyo" ) + font.setPointSize( 32 ) + font.setWeight( QFont.Bold ) + font.setItalic( True ) + + self.greetings.setFont( font ) + + self.showFontInfo( font ) + + def showFontInfo( self, font ): + info = QFontInfo( font ) + + messageText = "Font requested: \"" + str(font.family()) + "\" " \ + + str(QString.number( font.pointSize() )) + "pt<BR>" \ + + "Font used: \"" + str(info.family()) + "\" " \ + + str(QString.number( info.pointSize() )) + "pt<P>" + + if not self.substitutes.isEmpty() : + messageText += "The following substitutions exist for " + \ + str(font.family()) + ":<UL>" + for i in self.substitutes : + messageText += "<LI>\"" + str(i) + "\"" + messageText += "</UL>"; + else : + messageText += "No substitutions exist for " + \ + str(font.family()) + "." + + self.fontInfo.setText( messageText ) + + def setFontSubstitutions( self ): + self.substitutes = QStringList() + self.substitutes.append( "Times" ) + self.substitutes.append( "Mincho" ) + self.substitutes.append( "Arabic Newspaper" ) + self.substitutes.append( "crox" ) + #QFont.insertSubstitutions( "Bavaria", self.substitutes ) + QFont.insertSubstitution( "Bavaria", "Times" ) + QFont.insertSubstitution( "Tokyo", "Lucida" ) + + # For those who prefer to use Qt Designer for creating GUIs + # the following function might not be of particular interest: + # all it does is creating the widget layout. + def layout( self ): + textViewContainer = QHBoxLayout() + textViewContainer.addWidget( self.greetings ) + textViewContainer.addWidget( self.fontInfo ) + + buttonContainer = QHBoxLayout() + buttonContainer.addWidget( self.defaultButton ) + buttonContainer.addWidget( self.sansSerifButton ) + buttonContainer.addWidget( self.italicsButton ) + + maxButtonHeight = self.defaultButton.height() + + if self.sansSerifButton.height() > maxButtonHeight : + maxButtonHeight = self.sansSerifButton.height() + if self.italicsButton.height() > maxButtonHeight : + maxButtonHeight = self.italicsButton.height() + + self.defaultButton.setFixedHeight( maxButtonHeight ) + self.sansSerifButton.setFixedHeight( maxButtonHeight ) + self.italicsButton.setFixedHeight( maxButtonHeight ) + + container = QVBoxLayout( self ) + container.addLayout( textViewContainer ) + container.addLayout( buttonContainer ) + + self.resize( 700, 250 ) + +def main( args ): + app = QApplication(sys.argv) # application object + + textViewer = Viewer() + textViewer.setCaption( "Qt Example - Simple QFont Demo" ) + app.setMainWidget( textViewer ) + textViewer.show() + + app.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/gears.py b/examples3/gears.py new file mode 100755 index 0000000..c89a7a2 --- /dev/null +++ b/examples3/gears.py @@ -0,0 +1,235 @@ +#!/usr/bin/env python + + +import sys +import math +from qt import * +from 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(QGLWidget): + def __init__(self,parent=None,name=None): + QGLWidget.__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__': + QApplication.setColorSpec(QApplication.CustomColor) + app=QApplication(sys.argv) + + if not QGLFormat.hasOpenGL(): + raise 'No Qt OpenGL support.' + + widget=GearWidget() + app.setMainWidget(widget) + widget.show() + app.exec_loop() diff --git a/examples3/i18n/i18n.pro b/examples3/i18n/i18n.pro new file mode 100644 index 0000000..fc55895 --- /dev/null +++ b/examples3/i18n/i18n.pro @@ -0,0 +1,15 @@ +SOURCES = mywidget.py \ + i18n.py + +TRANSLATIONS = mywidget_cs.ts \ + mywidget_de.ts \ + mywidget_el.ts \ + mywidget_en.ts \ + mywidget_eo.ts \ + mywidget_fr.ts \ + mywidget_it.ts \ + mywidget_jp.ts \ + mywidget_ko.ts \ + mywidget_no.ts \ + mywidget_ru.ts \ + mywidget_zh.ts diff --git a/examples3/i18n/i18n.py b/examples3/i18n/i18n.py new file mode 100755 index 0000000..06cc97f --- /dev/null +++ b/examples3/i18n/i18n.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python + +# Copyright (c) 2002 Detlev Offenbach <[email protected]> + +from whrandom import randint +import sys + +from qt import * + +from mywidget import MyWidget + +class QVDialog(QDialog): + def __init__(self, parent=None, name=None, modal=0, flags=0): + QDialog.__init__(self, parent, name, modal, flags) + + self.vb = QVBoxLayout(self, 8) + self.vb.setAutoAdd(1) + + self.hb = None + self.map = {} + #self.sm = QSignalMapper(self) + self.connect(self, PYSIGNAL('mapped(int)'), self.done) + + def addButtons(self, cancel=None, ok=None, mid1=None, mid2=None, mid3=None): + if ok is None: + self.addButton(self.tr("OK"),1) + else: + self.addButton(ok,1) + + if mid1 is not None: + self.addButton(mid1,2) + + if mid2 is not None: + self.addButton(mid2,3) + + if mid3 is not None: + self.addButton(mid3,4) + + if cancel is None: + self.addButton(self.tr('Cancel'),0) + else: + self.addButton(cancel,0) + + def addButton(self, text, result): + if self.hb is None: + self.hb = QHBox(self) + c = QPushButton(text, self.hb) + self.setMapping(c, result) + self.connect(c, SIGNAL('clicked()'), self.mapit) + + def setMapping(self, c, result): + self.map[c] = result + + def mapit(self): + qo = self.sender() + self.emit(PYSIGNAL('mapped(int)'), (self.map[qo],)) + +translator = None +wlist = [] # keep reference to widgets + +def showLang(lang): + global translator + + qApp.setPalette(QPalette(QColor(220-randint(0,64),220-randint(0,64),220-randint(0,64)))) + + language = "mywidget_"+lang+".qm" + fi = QFileInfo(language) + + if not fi.exists(): + QMessageBox.warning(None, "File error", + "Cannot find translation for language: "+lang+\ + "\n(try eg. 'de' or 'en')") + return None + + if translator is not None: + qApp.removeTranslator(translator) + translator = None + + translator = QTranslator(None) + translator.load(language,".") + qApp.installTranslator(translator) + m = MyWidget() + m.setCaption("PyQt Example - i18n - " + unicode(m.caption())) + wlist.append(m) + return m + +def main(argv): + app = QApplication(argv) + + qm = ["cs", "de", "el", "en", "eo", "fr", "it", "jp", "ko", "no", "ru", "zh"] + + lang = None + if len(argv) == 2: + lang = argv[1] + + if (len(argv) != 2) or (lang == "all"): + dlg = QVDialog(None, None, 1) + qmb = [] + r = 0 + if lang == "all": + r=2 + else: + bg = QButtonGroup(4, Qt.Vertical, "Choose Locales", dlg) + loc = QTextCodec.locale() + for i in range(0,len(qm)): + qmb.append(QCheckBox(qm[i], bg)) + qmb[i].setChecked(str(loc) == qm[i]) + dlg.addButtons("Cancel","OK","All") + r = dlg.exec_loop() + + if r: + tight = qApp.desktop().screen().width < 1024 + x = 5 + y = 25 + for i in range(0,len(qm)): + if (r == 2) or (qmb[i].isChecked()): + w = showLang(qm[i]) + + if w == None: + sys.exit(0) + + app.connect(app, SIGNAL('lastWindowClosed()'), qApp, SLOT('quit()')) + w.setGeometry(x,y,197,356) + w.show() + if tight: + x += 8 + y += 8 + else: + x += 205 + if x > 1000: + x = 5 + y += 384 + + else: + sys.exit(0) + + else: + lang = argv[1] + m = showLang(lang) + app.setMainWidget(m) + m.setCaption("PyQt Example - i18n") + m.show() + + return app.exec_loop() + +if __name__ == "__main__": + main(sys.argv) diff --git a/examples3/i18n/mywidget.py b/examples3/i18n/mywidget.py new file mode 100644 index 0000000..60e267a --- /dev/null +++ b/examples3/i18n/mywidget.py @@ -0,0 +1,47 @@ +# Copyright (c) 2002 Detlev Offenbach <[email protected]> + +from qt import * + +class MyWidget(QMainWindow): + + def __init__(self, parent=None, name=None): + QMainWindow.__init__(self, parent, name) + + self.central = QVBox(self) + self.central.setMargin(5) + self.central.setSpacing(5) + self.setCentralWidget(self.central) + + self.setCaption(self.trUtf8("""Internationalization Example""")) + + self.file = QPopupMenu(self) + self.file.insertItem(self.trUtf8("E&xit"), qApp, SLOT("quit()"), + QKeySequence(self.trUtf8("Ctrl+Q","File|Quit"))) + self.menuBar().insertItem(self.trUtf8("&File"), self.file) + + self.statusBar().message(self.trUtf8('''Language: English''')) + + self.label = QLabel(self.trUtf8("The Main Window"), self.central) + + self.gbox = QButtonGroup(1, QGroupBox.Horizontal, + self.trUtf8("View"), self.central) + rb = QRadioButton(qApp.translate('MyWidget','Perspective'), self.gbox) + rb = QRadioButton(qApp.translate('MyWidget','Isometric'), self.gbox) + rb = QRadioButton(qApp.translate('MyWidget','Oblique'), self.gbox) + + self.initChoices(self.central) + + choices = [ + QT_TRANSLATE_NOOP("MyWidget", "First"), + QT_TRANSLATE_NOOP("MyWidget", "Second"), + QT_TRANSLATE_NOOP("MyWidget", "Third") + ] + + def initChoices(self, parent): + self.lb = QListBox(parent) + for ch in self.choices: + self.lb.insertItem(self.trUtf8(ch)) + + def closeEvent(self, e): + QWidget.closeEvent(self, e) + self.emit(PYSIGNAL('closed'), ()) diff --git a/examples3/i18n/mywidget_cs.qm b/examples3/i18n/mywidget_cs.qm Binary files differnew file mode 100644 index 0000000..f95090d --- /dev/null +++ b/examples3/i18n/mywidget_cs.qm diff --git a/examples3/i18n/mywidget_cs.ts b/examples3/i18n/mywidget_cs.ts new file mode 100644 index 0000000..4cf61f1 --- /dev/null +++ b/examples3/i18n/mywidget_cs.ts @@ -0,0 +1,75 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">Pohled</translation> + </message> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">&Soubor</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">&Konec</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">První</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">Třetí</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">Jayzk: Český</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">Hlavní okno</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+Q</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Nakloněný</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">Druhý</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Isometrický</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Perspektivní</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">Ukázka lokalizace</translation> + </message> +</context> +<context encoding="UTF-8"> + <name>QAccel</name> + <message encoding="UTF-8"> + <source>Ctrl</source> + <translation type="obsolete">Ctrl</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_de.qm b/examples3/i18n/mywidget_de.qm Binary files differnew file mode 100644 index 0000000..6433855 --- /dev/null +++ b/examples3/i18n/mywidget_de.qm diff --git a/examples3/i18n/mywidget_de.ts b/examples3/i18n/mywidget_de.ts new file mode 100644 index 0000000..d114b8b --- /dev/null +++ b/examples3/i18n/mywidget_de.ts @@ -0,0 +1,69 @@ +<!DOCTYPE TS><TS> +<context> + <name>MyWidget</name> + <message> + <source>First</source> + <translation>Erstens</translation> + </message> + <message> + <source>Second</source> + <translation>Zweitens</translation> + </message> + <message> + <source>Third</source> + <translation>Drittens</translation> + </message> + <message> + <source>Internationalization Example</source> + <translation>Internationalisierungsbeispiel</translation> + </message> + <message> + <source>E&xit</source> + <translation>Be&enden</translation> + </message> + <message> + <source>&File</source> + <translation>&Datei</translation> + </message> + <message> + <source>Language: English</source> + <translation>Sprache: Deutsch</translation> + </message> + <message> + <source>The Main Window</source> + <translation>Das Hauptfenster</translation> + </message> + <message> + <source>View</source> + <translation>Ansicht</translation> + </message> + <message> + <source>Perspective</source> + <translation>Perspektivisch</translation> + </message> + <message> + <source>Isometric</source> + <translation>Isometrisch</translation> + </message> + <message> + <source>Oblique</source> + <translation>Schief</translation> + </message> + <message> + <source>Ctrl+Q</source> + <comment>File|Quit</comment> + <translation>Strg+Q</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation>OK</translation> + </message> + <message> + <source>Cancel</source> + <translation>Abbruch</translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_el.qm b/examples3/i18n/mywidget_el.qm Binary files differnew file mode 100644 index 0000000..15d7689 --- /dev/null +++ b/examples3/i18n/mywidget_el.qm diff --git a/examples3/i18n/mywidget_el.ts b/examples3/i18n/mywidget_el.ts new file mode 100644 index 0000000..59fb228 --- /dev/null +++ b/examples3/i18n/mywidget_el.ts @@ -0,0 +1,68 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">&Αρχείο</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+Q</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">Έ&ξοδος</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">Πρώτο</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">Παράδειγμα διεθνοποίησης</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Ισομετρική</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">Γλώσσα: Ελληνικά</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Πλάγια</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Προοπτική</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">Δεύτερο</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">Κύριο παράθυρο</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">Τρίτο</translation> + </message> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">Όψη</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_en.qm b/examples3/i18n/mywidget_en.qm Binary files differnew file mode 100644 index 0000000..6bd22c4 --- /dev/null +++ b/examples3/i18n/mywidget_en.qm diff --git a/examples3/i18n/mywidget_en.ts b/examples3/i18n/mywidget_en.ts new file mode 100644 index 0000000..f231669 --- /dev/null +++ b/examples3/i18n/mywidget_en.ts @@ -0,0 +1,69 @@ +<!DOCTYPE TS><TS> +<context> + <name>MyWidget</name> + <message> + <source>First</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Second</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Third</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Internationalization Example</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>E&xit</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>&File</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Language: English</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>The Main Window</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>View</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Perspective</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Isometric</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Oblique</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Ctrl+Q</source> + <comment>File|Quit</comment> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_eo.qm b/examples3/i18n/mywidget_eo.qm Binary files differnew file mode 100644 index 0000000..372cf79 --- /dev/null +++ b/examples3/i18n/mywidget_eo.qm diff --git a/examples3/i18n/mywidget_eo.ts b/examples3/i18n/mywidget_eo.ts new file mode 100644 index 0000000..381870d --- /dev/null +++ b/examples3/i18n/mywidget_eo.ts @@ -0,0 +1,72 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">&Dosiero</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+F</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit...</source> + <translation type="obsolete">&Fini...</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">Unue</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">Ekzemplo pri internaciigo</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Isometria</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">Lingvo: Esperanto (ĈĜĤĴŜŬĉĝĥĵŝŭ)</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Oblikva</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Perspektiva</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">Due</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">La Ĉeffenestro</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">Trie</translation> + </message> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">Aspekto</translation> + </message> + <message> + <source>E&xit</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_fr.qm b/examples3/i18n/mywidget_fr.qm Binary files differnew file mode 100644 index 0000000..12a8464 --- /dev/null +++ b/examples3/i18n/mywidget_fr.qm diff --git a/examples3/i18n/mywidget_fr.ts b/examples3/i18n/mywidget_fr.ts new file mode 100644 index 0000000..a029084 --- /dev/null +++ b/examples3/i18n/mywidget_fr.ts @@ -0,0 +1,68 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">Vue</translation> + </message> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">&Fichier</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">&Quitter</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">Premier</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">Troisième</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">Langage : Français</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">La fenêtre principale</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+Q</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Oblique</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">Second</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Isométrique</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Perspective</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">Exemple d'internationalisation</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_it.qm b/examples3/i18n/mywidget_it.qm Binary files differnew file mode 100644 index 0000000..075bee2 --- /dev/null +++ b/examples3/i18n/mywidget_it.qm diff --git a/examples3/i18n/mywidget_it.ts b/examples3/i18n/mywidget_it.ts new file mode 100644 index 0000000..a450deb --- /dev/null +++ b/examples3/i18n/mywidget_it.ts @@ -0,0 +1,72 @@ +<!DOCTYPE TS><TS> +<context> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>E&xit...</source> + <translation type="obsolete">&Esci...</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">Primo</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">Esempio di localizzazione</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Isometrica</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">Lingua: Italiano</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Obliqua</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Prospettica</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">Secondo</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">La Finestra Principale</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">Terzo</translation> + </message> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">Vista</translation> + </message> + <message> + <source>E&xit</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Ctrl+Q</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>&File</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_jp.qm b/examples3/i18n/mywidget_jp.qm Binary files differnew file mode 100644 index 0000000..8942dd7 --- /dev/null +++ b/examples3/i18n/mywidget_jp.qm diff --git a/examples3/i18n/mywidget_jp.ts b/examples3/i18n/mywidget_jp.ts new file mode 100644 index 0000000..2a7345f --- /dev/null +++ b/examples3/i18n/mywidget_jp.ts @@ -0,0 +1,68 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">ファイル(&F)</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+Q</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">終了(&X)</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">第一行</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">国際化(i18n)の例</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">等角投影法</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">言語: 日本語</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">斜め投影法</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">遠近法</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">第二行</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">メインウィンドウ</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">第三行</translation> + </message> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">表示方式</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_ko.qm b/examples3/i18n/mywidget_ko.qm Binary files differnew file mode 100644 index 0000000..dccc2ba --- /dev/null +++ b/examples3/i18n/mywidget_ko.qm diff --git a/examples3/i18n/mywidget_ko.ts b/examples3/i18n/mywidget_ko.ts new file mode 100644 index 0000000..acc8f9b --- /dev/null +++ b/examples3/i18n/mywidget_ko.ts @@ -0,0 +1,68 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">파일&F</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+E</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">종료&X</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">첫번째</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">국제화 예제</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Isometric</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">언어 : 한국어</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Oblique</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Perspective</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">두번째</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">메인 윈도우</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">세번째</translation> + </message> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">보기</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_no.qm b/examples3/i18n/mywidget_no.qm Binary files differnew file mode 100644 index 0000000..2adc136 --- /dev/null +++ b/examples3/i18n/mywidget_no.qm diff --git a/examples3/i18n/mywidget_no.ts b/examples3/i18n/mywidget_no.ts new file mode 100644 index 0000000..341c664 --- /dev/null +++ b/examples3/i18n/mywidget_no.ts @@ -0,0 +1,68 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">Visning</translation> + </message> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">&Fil</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">&Slutt</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">Første</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">Tredje</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">Språk: Norsk</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">Hovedvinduet</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+S</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Skjev</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">Andre</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Isometrisk</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Perspektiv</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">Internasjonaliseringseksempel</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_ru.qm b/examples3/i18n/mywidget_ru.qm Binary files differnew file mode 100644 index 0000000..ebc512e --- /dev/null +++ b/examples3/i18n/mywidget_ru.qm diff --git a/examples3/i18n/mywidget_ru.ts b/examples3/i18n/mywidget_ru.ts new file mode 100644 index 0000000..07070b0 --- /dev/null +++ b/examples3/i18n/mywidget_ru.ts @@ -0,0 +1,68 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">Вид</translation> + </message> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">Файл</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">Выход</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">Первый</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">Третий</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">Язык: Русский</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">Главное окно</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">Курсив</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">Второй</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">Изометрический</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">Перспектива</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">Пример интернациноализации</translation> + </message> + <message> + <source>Ctrl+Q</source> + <translation type="unfinished"></translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/i18n/mywidget_zh.qm b/examples3/i18n/mywidget_zh.qm Binary files differnew file mode 100644 index 0000000..a890c09 --- /dev/null +++ b/examples3/i18n/mywidget_zh.qm diff --git a/examples3/i18n/mywidget_zh.ts b/examples3/i18n/mywidget_zh.ts new file mode 100644 index 0000000..8b015d6 --- /dev/null +++ b/examples3/i18n/mywidget_zh.ts @@ -0,0 +1,68 @@ +<!DOCTYPE TS><TS> +<context encoding="UTF-8"> + <name>MyWidget</name> + <message encoding="UTF-8"> + <source>View</source> + <translation type="unfinished">视图</translation> + </message> + <message encoding="UTF-8"> + <source>&File</source> + <translation type="unfinished">文件[&F]</translation> + </message> + <message encoding="UTF-8"> + <source>E&xit</source> + <translation type="unfinished">退出[&x]</translation> + </message> + <message encoding="UTF-8"> + <source>First</source> + <translation type="unfinished">第一个</translation> + </message> + <message encoding="UTF-8"> + <source>Third</source> + <translation type="unfinished">第三个</translation> + </message> + <message encoding="UTF-8"> + <source>Language: English</source> + <translation type="unfinished">语言: 简体中文</translation> + </message> + <message encoding="UTF-8"> + <source>The Main Window</source> + <translation type="unfinished">主窗口</translation> + </message> + <message encoding="UTF-8"> + <source>Ctrl+Q</source> + <translation type="unfinished">Ctrl+Q</translation> + </message> + <message encoding="UTF-8"> + <source>Oblique</source> + <translation type="unfinished">斜投影</translation> + </message> + <message encoding="UTF-8"> + <source>Second</source> + <translation type="unfinished">第二个</translation> + </message> + <message encoding="UTF-8"> + <source>Isometric</source> + <translation type="unfinished">等角投影</translation> + </message> + <message encoding="UTF-8"> + <source>Perspective</source> + <translation type="unfinished">透视投影</translation> + </message> + <message encoding="UTF-8"> + <source>Internationalization Example</source> + <translation type="unfinished">国际化范例</translation> + </message> +</context> +<context> + <name>QVDialog</name> + <message> + <source>OK</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cancel</source> + <translation type="unfinished"></translation> + </message> +</context> +</TS> diff --git a/examples3/lineedits.py b/examples3/lineedits.py new file mode 100755 index 0000000..7d1a37a --- /dev/null +++ b/examples3/lineedits.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: lineedits.py,v 1.1 2002/06/19 07:56:07 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +from qt import * + +TRUE = 1 +FALSE = 0 + +class LineEdits(QGroupBox): + def __init__(self, parent = None, name = None): + QGroupBox.__init__(self, 0, Qt.Horizontal, "Line Edits", parent, name) + + self.setMargin(10) + + box = QVBoxLayout(self.layout()) + + row1 = QHBoxLayout(box) + row1.setMargin(5) + + label = QLabel("Echo Mode: ", self) + row1.addWidget(label) + + combo1 = QComboBox(FALSE, self) + row1.addWidget(combo1) + combo1.insertItem("Normal", -1) + combo1.insertItem("Password", -1) + combo1.insertItem("No Echo", -1) + + self.connect(combo1, SIGNAL("activated(int)"), self.slotEchoChanged) + self.lined1 = QLineEdit(self) + box.addWidget(self.lined1) + + row2 = QHBoxLayout(box) + row2.setMargin(5) + + label = QLabel("Validator: ", self) + row2.addWidget(label) + + combo2 = QComboBox(FALSE, self) + row2.addWidget(combo2) + combo2.insertItem("No Validator", -1) + combo2.insertItem("Integer Validator", -1) + combo2.insertItem("Double Validator", -1) + + self.connect(combo2, SIGNAL("activated(int)"), self.slotValidatorChanged) + + self.lined2 = QLineEdit(self) + box.addWidget(self.lined2) + + row3 = QHBoxLayout(box) + row3.setMargin(5) + + label = QLabel("Alignment: ", self) + row3.addWidget(label) + + combo3 = QComboBox(FALSE, self) + row3.addWidget(combo3) + combo3.insertItem("Left", -1) + combo3.insertItem("Centered", -1) + combo3.insertItem("Right", -1) + + self.connect(combo3, SIGNAL("activated(int)"), self.slotAlignmentChanged) + self.lined3 = QLineEdit(self) + box.addWidget(self.lined3) + + row4 = QHBox(self) + box.addWidget(row4) + row4.setMargin(5) + + QLabel("Read-Only: ", row4) + + combo4 = QComboBox(FALSE, row4) + combo4.insertItem("False", -1) + combo4.insertItem("True", -1) + + self.connect(combo4, SIGNAL("activated(int)"), self.slotReadOnlyChanged) + + self.lined4 = QLineEdit(self) + box.addWidget(self.lined4) + + self.lined1.setFocus() + + def slotEchoChanged(self, i): + if i == 0: + self.lined1.setEchoMode(QLineEdit.Normal) + elif i == 1: + self.lined1.setEchoMode(QLineEdit.Password) + elif i == 2: + self.lined1.setEchoMode(QLineEdit.NoEcho) + + self.lined1.setFocus() + + def slotValidatorChanged(self, i): + if i == 0: + self.lined2.setValidator(None) + elif i == 1: + self.lined2.setValidator(QIntValidator(self.lined2)) + elif i == 2: + self.lined2.setValidator(QDoubleValidator(-999.0, 999.0, 2, self.lined2)) + + self.lined2.setText("") + self.lined2.setFocus() + + def slotAlignmentChanged(self, i): + if i == 0: + self.lined3.setAlignment(QLineEdit.AlignLeft) + elif i == 1: + self.lined3.setAlignment(QLineEdit.AlignCenter) + elif i == 2: + self.lined3.setAlignment(QLineEdit.AlignRight) + + self.lined3.setFocus() + + def slotReadOnlyChanged(self, i): + if i == 0: + self.lined4.setReadOnly(FALSE) + elif i == 1: + self.lined4.setReadOnly(TRUE) + + self.lined4.setFocus() + + +if __name__=='__main__': + app = QApplication( sys.argv ) + + lineedits = LineEdits() + lineedits.setCaption("Lineedits - PyQt Example") + lineedits.show() + app.setMainWidget(lineedits) + app.exec_loop() diff --git a/examples3/listbox.py b/examples3/listbox.py new file mode 100755 index 0000000..624935d --- /dev/null +++ b/examples3/listbox.py @@ -0,0 +1,176 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: listbox.py,v 1.1 2003/05/30 17:47:57 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +FALSE = 0 +TRUE = 1 + +class ListBoxDemo( QWidget ): + def __init__( self, parent=None, name=None ): + QWidget.__init__( self, parent, name ) + b = FALSE + g = QGridLayout( self, 2, 2, 6 ) + + g.addWidget( QLabel( "<b>Configuration:</b>", self ), 0, 0 ) + g.addWidget( QLabel( "<b>Result:</b>", self ), 0, 1 ) + + self.l = QListBox( self ) + g.addWidget( self.l, 1, 1 ) + self.l.setFocusPolicy( QWidget.StrongFocus ) + + v = QVBoxLayout( ) + g.addLayout( v, 1, 0 ) + + bg = QButtonGroup( self, None ) + + b = QRadioButton( "Fixed number of columns,\n" + "as many rows as needed.", + self ) + bg.insert( b ) + v.addWidget( b ) + b.setChecked( TRUE ) + self.connect( b, SIGNAL("clicked()"), self.setNumCols ) + h = QHBoxLayout() + v.addLayout( h ) + h.addSpacing( 30 ) + h.addSpacing( 100 ) + h.addWidget( QLabel( "Columns:", self ) ) + self.columns = QSpinBox( self ) + h.addWidget( self.columns ) + + v.addSpacing( 12 ) + + b = QRadioButton( "As many columns as fit on-screen,\n" + "as many rows as needed.", + self ) + bg.insert( b ) + v.addWidget( b ) + self.connect( b, SIGNAL("clicked()"), self.setColsByWidth ) + + v.addSpacing( 12 ) + + b = QRadioButton( "Fixed number of rows,\n" + "as many columns as needed.", + self ) + bg.insert( b ) + v.addWidget( b ) + self.connect( b, SIGNAL("clicked()"), self.setNumRows ) + h = QHBoxLayout() + v.addLayout( h ) + h.addSpacing( 30 ) + h.addSpacing( 100 ) + h.addWidget( QLabel( "Rows:", self ) ) + self.rows = QSpinBox( self ) + self.rows.setEnabled( FALSE ) + h.addWidget( self.rows ) + + v.addSpacing( 12 ) + + b = QRadioButton( "As many rows as fit on-screen,\n" + "as many columns as needed.", + self ) + bg.insert( b ) + v.addWidget( b ) + self.connect( b, SIGNAL("clicked()"), self.setRowsByHeight ) + + v.addSpacing( 12 ) + + cb = QCheckBox( "Variable-height rows", self ) + cb.setChecked( TRUE ) + self.connect( cb, SIGNAL("toggled(bool)"), self.setVariableHeight ) + v.addWidget( cb ) + v.addSpacing( 6 ) + + cb = QCheckBox( "Variable-width columns", self ) + self.connect( cb, SIGNAL("toggled(bool)"), self.setVariableWidth ) + v.addWidget( cb ) + + cb = QCheckBox( "Extended-Selection", self ) + self.connect( cb, SIGNAL("toggled(bool)"), self.setMultiSelection ) + v.addWidget( cb ) + + pb = QPushButton( "Sort ascending", self ) + self.connect( pb, SIGNAL("clicked()"), self.sortAscending ) + v.addWidget( pb ) + + pb = QPushButton( "Sort descending", self ) + self.connect( pb, SIGNAL("clicked()"), self.sortDescending ) + v.addWidget( pb ) + + v.addStretch( 100 ) + + i = 0 + while i <= 2560: + i+=1 + self.l.insertItem( str(QString.fromLatin1( "Item " )) + str(QString.number( i )), i ) + self.columns.setRange( 1, 256 ) + self.columns.setValue( 1 ) + self.rows.setRange( 1, 256 ) + self.rows.setValue( 256 ) + + self.connect( self.columns, SIGNAL("valueChanged(int)"), self.setNumCols ) + self.connect( self.rows, SIGNAL("valueChanged(int)"), self.setNumRows ) + + # slots + def setNumCols( self ): + self.columns.setEnabled( TRUE ) + self.rows.setEnabled( FALSE ) + self.l.setColumnMode( self.columns.value() ) + + def setNumRows( self ): + self.columns.setEnabled( FALSE ) + self.rows.setEnabled( TRUE ) + self.l.setRowMode( self.rows.value() ) + + def setRowsByHeight( self ): + self.columns.setEnabled( FALSE ) + self.rows.setEnabled( FALSE ) + self.l.setRowMode( QListBox.FitToHeight ) + + def setColsByWidth( self ): + self.columns.setEnabled( FALSE ) + self.rows.setEnabled( FALSE ) + self.l.setColumnMode( QListBox.FitToWidth ) + + def setVariableWidth( self, b ): + self.l.setVariableWidth( b ) + + def setVariableHeight( self, b ): + self.l.setVariableHeight( b ) + + def setMultiSelection( self, b ): + self.l.clearSelection() + if b : + self.l.setSelectionMode( QListBox.Extended ) + else: + self.l.setSelectionMode( QListBox.Single ) + + def sortAscending( self ): + self.l.sort( TRUE ) + + def sortDescending( self ): + self.l.sort( FALSE ) + + +def main( args ): + a = QApplication( args ) + t = ListBoxDemo() + t.setCaption( "Qt Example - Listbox" ) + a.setMainWidget( t ) + t.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/listboxcombo.py b/examples3/listboxcombo.py new file mode 100755 index 0000000..6958089 --- /dev/null +++ b/examples3/listboxcombo.py @@ -0,0 +1,167 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: listboxcombo.py,v 1.1 2003/05/30 17:47:57 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +FALSE = 0 +TRUE = 1 + +class ListBoxCombo( QVBox ): + # Constructor + # Creates child widgets of the ListBoxCombo widget + def __init__( self, parent=None, name=None ): + QVBox.__init__( self, parent, name ) + + self.setMargin( 5 ) + self.setSpacing( 5 ) + + i = 0 + row1 = QHBox( self ) + row1.setSpacing( 5 ) + + # Create a multi-selection ListBox... + self.lb1 = QListBox( row1 ) + self.lb1.setSelectionMode( QListBox.Multi ) + + # ...insert a pixmap item... + xpm = QPixmap( "qtlogo.png" ) + txt = QString() + QListBoxPixmap( self.lb1, xpm, txt ) + + # ...and 100 text items + for i in range(0, 100, 1) : + xpm = QPixmap() + txt = QString( "Listbox Item %1" ).arg( i ) + if not i % 4 : + xpm = QPixmap( "fileopen.xpm" ) + QListBoxPixmap( self.lb1, xpm, txt ) + + # Create a pushbutton... + arrow1 = QPushButton( " -> ", row1 ) + # ...and connect the clicked SIGNAL with the SLOT slotLeft2Right + self.connect( arrow1, SIGNAL("clicked()"), self.slotLeft2Right ) + + # create an empty single-selection ListBox + self.lb2 = QListBox( row1 ) + + row2 = QHBox( self ) + row2.setSpacing( 5 ) + + box1 = QVBox( row2 ) + box1.setSpacing( 5 ) + + # Create a non-editable Combobox and a label below... + cb1 = QComboBox( FALSE, box1 ) + self.label1 = QLabel( "Current Item: Combobox Item 0", box1 ) + self.label1.setMaximumHeight( self.label1.sizeHint().height() * 2 ) + self.label1.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + #...and insert 50 items into the Combobox + for i in range( 0, 50, 1 ) : + txt = str( QString( "Combobox Item %1" ).arg( i ) ) + if i % 9 : + cb1.insertItem( txt ) + else : + cb1.listBox().insertItem( MyListBoxItem() ) + + box2 = QVBox( row2 ) + box2.setSpacing( 5 ) + + # Create an editable Combobox and a label below... + cb2 = QComboBox( TRUE, box2 ) + self.label2 = QLabel( "Current Item: Combobox Item 0", box2 ) + self.label2.setMaximumHeight( self.label2.sizeHint().height() * 2 ) + self.label2.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + # ... and insert 50 items into the Combobox + for i in range(0, 50, 1 ) : + txt = str(QString( "Combobox Item %1" ).arg( i )) + if not i % 4 : + cb2.insertItem( QPixmap( "fileopen.xpm" ), txt ) + else : + cb2.insertItem( txt ) + + # Connect the activated SIGNALs of the Comboboxes with SLOTs + self.connect( cb1, SIGNAL("activated( const QString & )"), self.slotCombo1Activated ) + self.connect( cb2, SIGNAL("activated( const QString & )"), self.slotCombo2Activated ) + + """ SLOT slotLeft2Right + * Copies all selected items of the first ListBox into the second ListBox + """ + def slotLeft2Right( self ): + # Go through all items of the first ListBox + for i in range( 0, self.lb1.count(), 1 ) : + item = self.lb1.item( i ) + # if the item is selected... + if self.lb1.isSelected( i ): #item.isSelected() : + # ...and it is a text item... + if item.pixmap() and not(item.text().isEmpty()): + self.lb2.insertItem( item.pixmap(), item.text() ) + elif not( item.pixmap() ): + self.lb2.insertItem( item.text() ) + elif item.text().isEmpty() : + self.lb2.insertItem( item.pixmap() ) + + """ SLOT slotCombo1Activated( const QString &s ) + * Sets the text of the item which the user just selected in the + * first Combobox (and is now the value of s) to the first Label. + """ + def slotCombo1Activated( self, s ) : + self.label1.setText( str(QString( "Current Item: %1" ).arg( s ) ) ) + + """ SLOT slotCombo2Activated( const QString &s ) + * Sets the text of the item which the user just selected in the + * second Combobox (and is now the value of s) to the second Label. + """ + def slotCombo2Activated( self, s ) : + self.label2.setText( str(QString( "Current Item: %1" ).arg( s ) ) ) + + +class MyListBoxItem( QListBoxItem ): + def __init__( self, parent=None, name=None ): + QListBoxItem.__init__( self, parent, name ) + self.setCustomHighlighting( TRUE ) + + def paint( self, painter ): + # evil trick: find out whether we are painted onto our listbox + in_list_box = 0 + if self.listBox() and self.listBox().viewport() == painter.device(): + in_list_box = 1 + r = QRect( 0, 0, self.width( self.listBox() ), self.height( self.listBox() ) ) + brush = QBrush( Qt.red, Qt.SolidPattern ) + if in_list_box and isSelected(): + painter.eraseRect( r ) + painter.fillRect( 5, 5, self.width( self.listBox() ) - 10, self.height( self.listBox() ) - 10, brush ) + if in_list_box and isCurrent(): + self.listBox().style().drawPrimitive( QStyle.PE_FocusRect, painter, r, self.listBox().colorGroup() ) + + def width( self, QListBox ): + return 100 + + def height( self, QListBox ): + return 16 + + +def main( args ): + a = QApplication( args ) + + listboxcombo = ListBoxCombo() + listboxcombo.resize( 400, 270 ) + listboxcombo.setCaption( "Qt Example - Listboxes and Comboboxes" ) + a.setMainWidget( listboxcombo ) + listboxcombo.show(); + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/marble.png b/examples3/marble.png Binary files differnew file mode 100644 index 0000000..49ea309 --- /dev/null +++ b/examples3/marble.png diff --git a/examples3/mdi.py b/examples3/mdi.py new file mode 100755 index 0000000..2c1d121 --- /dev/null +++ b/examples3/mdi.py @@ -0,0 +1,360 @@ +#!/usr/bin/env python + +# A simple application. + + +import sys, string +from 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' +] + +document = [ +"12 16 6 1", +" c #040404", +". c None", +"X c white", +"o c #808304", +"O c black", +"+ c #f3f7f3", +" .....", +" XXXXX ....", +" XXXXX X ...", +" XXXXX XX ..", +" XooXX O.", +" X+XXX+XXXO.", +" XXXXXXXXXO.", +" XoooXooXXO.", +" XXXXXXXXXO.", +" XXXXXXXXXO.", +" XoXXoooXXO.", +" XXXXXXXXXO.", +"OXXXXXXXXXO.", +"OXXXXXXXXXO.", +"OOOOOOOOOOO.", +"............" +] + +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.''' + +True=1 +False=0 + +class ApplicationWindow(QMainWindow): + def __init__(self): + QMainWindow.__init__(self,None,'example application main window',Qt.WDestructiveClose) + + self.filename = QString.null + self.printer = QPrinter() + + self.fileTools = QToolBar(self,'file operations') + + openIcon = QPixmap(fileopen) + self.fileOpen = QToolButton(QIconSet(openIcon),'Open File',QString.null,self.load,self.fileTools,'open file') + + saveIcon = QPixmap(filesave) + self.fileSave = QToolButton(QIconSet(saveIcon),'Save File',QString.null,self.save,self.fileTools,'save file') + printIcon = QPixmap(fileprint) + self.filePrint = QToolButton(QIconSet(printIcon),'Print File',QString.null,self.printDoc,self.fileTools,'print file') + + QWhatsThis.whatsThisButton(self.fileTools) + + QWhatsThis.add(self.fileOpen,fileOpenText) + QMimeSourceFactory.defaultFactory().setPixmap('fileopen',openIcon) + QWhatsThis.add(self.fileSave,fileSaveText) + QWhatsThis.add(self.filePrint,filePrintText) + + self.file = QPopupMenu(self) + self.menuBar().insertItem('&File',self.file) + + self.file.insertItem('&New',self.newDoc,Qt.CTRL + Qt.Key_N) + + id = self.file.insertItem(QIconSet(openIcon),'&Open',self.load,Qt.CTRL + Qt.Key_O) + self.file.setWhatsThis(id,fileOpenText) + + id = self.file.insertItem(QIconSet(saveIcon),'&Save',self.save,Qt.CTRL + Qt.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(QIconSet(printIcon),'&Print',self.printDoc,Qt.CTRL + Qt.Key_P) + self.file.setWhatsThis(id,filePrintText) + + self.file.insertSeparator() + + self.file.insertItem('&Close',self,SLOT('close()'),Qt.CTRL + Qt.Key_W) + self.file.insertItem('&Quit',qApp,SLOT('closeAllWindows()'),Qt.CTRL + Qt.Key_Q) + + self.menuBar().insertSeparator() + self.windows = QPopupMenu( self ) + self.windows.setCheckable( True ) + self.connect( self.windows, SIGNAL( "aboutToShow()" ), + self.windowsMenuAboutToShow ) + self.menuBar().insertItem( "&Windows", self.windows ) + + self.help = QPopupMenu(self) + self.menuBar().insertSeparator() + self.menuBar().insertItem('&Help',self.help) + + self.help.insertItem('&About',self.about,Qt.Key_F1) + self.help.insertItem('About &Qt',self.aboutQt) + self.help.insertSeparator() + self.help.insertItem( "What's &This", self, SLOT("whatsThis()"), Qt.SHIFT+Qt.Key_F1) + + self.menuBar().insertSeparator() + + self.vb = QVBox( self ) + self.vb.setFrameStyle( QFrame.StyledPanel | QFrame.Sunken ) + self.ws = QWorkspace( self.vb ) + self.ws.setScrollBarsEnabled( True ) + self.setCentralWidget( self.vb ) + + self.statusBar().message('Ready',2000) + #self.resize(450,600) + + def newDoc(self): + w = MDIWindow( self.ws, "", Qt.WDestructiveClose ) + self.connect( w, PYSIGNAL( "message" ), self.statusBar(), SLOT( "message(const QString&, int )") ) + w.setCaption("unnamed document") + w.setIcon( QPixmap(document) ) + # show the very first window in maximized mode + if len(self.ws.windowList())==0: + w.showMaximized() + else: + w.show() + return w + + def load(self): + fn = QFileDialog.getOpenFileName( QString.null, QString.null, self ) + if not fn.isEmpty(): + w = self.newDoc() + w.load( fn ) + else: + self.statusBar().message( "Loading aborted", 2000 ) + + def save(self): + m = self.ws.activeWindow() + if m: + m.save() + + def saveAs(self): + m = self.ws.activeWindow() + if m: + m.saveAs() + + def printDoc(self): + m = self.ws.activeWindow() + if m: + m.printDoc( self.printer ) + + def closeWindow(self): + m = self.ws.activeWindow() + if m: + m.close() + + def about(self): + QMessageBox.about( self, "Qt Application Example", + "This example demonstrates simple use of\n " + "Qt's Multiple Document Interface (MDI).") + + def aboutQt(self): + QMessageBox.aboutQt( self, "Qt Application Example" ) + + def windowsMenuAboutToShow(self): + self.windows.clear() + cascadeId = self.windows.insertItem("&Cascade", self.ws, SLOT("cascade() ") ) + tileId = self.windows.insertItem("&Tile", self.ws, SLOT("tile()" ) ) + if len(self.ws.windowList())==0 : + self.windows.setItemEnabled( cascadeId, False ) + self.windows.setItemEnabled( tileId, False ) + self.windows.insertSeparator() + windows = self.ws.windowList() + cnt=0 + for i in windows: + id =self.windows.insertItem(i.caption(),self.windowsMenuActivated ) + self.windows.setItemParameter( id, cnt ); + self.windows.setItemChecked( id, self.ws.activeWindow() == i ) + cnt=cnt+1 + + def windowsMenuActivated(self,sid ): + w = self.ws.windowList().at( id ) + if w: + w.showNormal() + w.setFocus() + + +class MDIWindow( QMainWindow): + def __init__(self,parent, name, wflags ): + QMainWindow.__init__(self,parent, name, wflags ) + self.mmovie = 0 + self.medit = QMultiLineEdit( self ) + self.setFocusProxy( self.medit ) + self.setCentralWidget( self.medit ); + + + def load(self, fn ): + self.filename = fn + self.f=QFile( self.filename ) + if not self.f.open( IO_ReadOnly ): + return + + if fn.contains(".gif"): + tmp=QWidget(self) + self.setFocusProxy(tmp) + self.setCentralWidget(tmp) + self.medit.hide() + del self.medit + qm=QMovie(fn) + #ifdef Q_WS_QWS // temporary speed-test hack + #qm->setDisplayWidget(tmp); + #endif + tmp.setBackgroundMode(QWidget.NoBackground) + tmp.show() + self.mmovie=qm + else : + self.mmovie = 0 + t=QTextStream(self.f) + s = t.read() + self.medit.setText( s ) + self.f.close() + self.setCaption( self.filename ) + self.emit(PYSIGNAL( "message"),(QString("Loaded document %1").arg(self.filename),2000 )) + + def save(self): + if self.filename.isEmpty(): + self.saveAs() + return + text = self.medit.text() + output=open(str(self.filename),'w') + output.write(str(text)) + #emit message( QString("Could not write to %1").arg(filename), 2000 ); + #return + output.close() + self.setCaption(self.filename) + self.emit(PYSIGNAL( "message"),(QString("File %1 saved").arg(self.filename),2000 )) + + def saveAs(self): + fn = QFileDialog.getSaveFileName( self.filename, QString.null, self ) + if not fn.isEmpty(): + self.filename = fn + self.save() + else : + self.emit(PYSIGNAL( "message"),(QString("Saving aborted"),2000 )) + + def printDoc(self,printer): + Margin = 10 + pageNo = 1 + + if printer.setup(self): + self.emit(PYSIGNAL( "message"),(QString("Printing..."),2000 )) + p = QPainter() + p.begin(printer) + p.setFont(self.medit.font()) + yPos = 0 + fm = p.fontMetrics() + metrics = QPaintDeviceMetrics(printer) + + for i in range(self.medit.numLines()): + if Margin + yPos > metrics.height() - Margin: + pageNo = pageNo + 1 + self.emit(PYSIGNAL( "message"),(QString("Printing (page %1) ...").arg(pageNo),2000 )) + printer.newPage() + yPos = 0 + + p.drawText(Margin,Margin + yPos,metrics.width(),fm.lineSpacing(),Qt.ExpandTabs | Qt.DontClip,self.medit.textLine(i)) + yPos = yPos + fm.lineSpacing() + + p.end() + self.emit(PYSIGNAL( "message"),(QString("Printing completed"),2000 )) + else: + self.emit(PYSIGNAL( "message"),(QString("Printing aborted"),2000 )) + + +if __name__=='__main__': + a = QApplication(sys.argv) + mw = ApplicationWindow() + mw.setCaption("PyQt Example - Multiple Documents Interface (MDI)") + mw.show() + a.connect(a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()')) + a.exec_loop() diff --git a/examples3/menu.py b/examples3/menu.py new file mode 100755 index 0000000..baab2a6 --- /dev/null +++ b/examples3/menu.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: menu.py,v 1.3 2003/06/06 12:59:26 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys, string +from 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... ", +" ......... ", +" ", +" " +] + + +# Auxiliary class to provide fancy menu items with different fonts. +# Used for the "bold" and "underline" menu items in the options menu. + +class MyMenuItem( QCustomMenuItem ): + def __init__( self, s, f ): + QCustomMenuItem.__init__( self ) + self.string = s + self.font = f + + def paint( self, p, cg, act, enabled, x, y, w, h ) : + p.setFont ( self.font ) + p.drawText( x, y, w, h, Qt.AlignLeft | Qt.AlignVCenter | Qt.ShowPrefix | Qt.DontClip, self.string ) + + def sizeHint( self ): + return QFontMetrics( self.font ).size( Qt.AlignLeft | Qt.AlignVCenter | Qt.ShowPrefix | Qt.DontClip, self.string ) + + +# Implementation of MenuExample class + +class MenuExample( QWidget ): + def __init__( self, parent=None, name=None ): + QWidget.__init__( self, parent, name ) + self.p1 = QIconSet( QPixmap ( p1_xpm ) ) + self.p2 = QIconSet( QPixmap ( p2_xpm ) ) + self.p3 = QIconSet( QPixmap ( p3_xpm ) ) + + self.printer = QPopupMenu( self ) + self.printer.insertTearOffHandle() + self.printer.insertItem( "&Print to printer", self.printDoc ) + self.printer.insertItem( "Print to &file", self.printFile ) + self.printer.insertItem( "Print to fa&x", self.fax ) + self.printer.insertSeparator() + self.printer.insertItem( "Printer &Setup", self.printerSetup ) + + self.file = QPopupMenu( self ) + self.file.insertItem( self.p1, "&Open", self.open, Qt.CTRL+Qt.Key_O ) + self.file.insertItem( self.p2, "&New", self.news, Qt.CTRL+Qt.Key_N ) + self.file.insertItem( self.p3, "&Save", self.save, Qt.CTRL+Qt.Key_S ) + self.file.insertItem( "&Close", self.closeDoc, Qt.CTRL+Qt.Key_W ) + self.file.insertSeparator() + self.file.insertItem( "&Print", self.printer, Qt.CTRL+Qt.Key_P ) + self.file.insertSeparator() + self.file.insertItem( "E&xit", qApp, SLOT( "quit()" ), Qt.CTRL+Qt.Key_Q ) + + self.edit = QPopupMenu( self ) + undoID = self.edit.insertItem( "&Undo", self.undo ) + redoID = self.edit.insertItem( "&Redo", self.redo ) + self.edit.setItemEnabled( undoID, FALSE ) + self.edit.setItemEnabled( redoID, FALSE ) + + self.options = QPopupMenu( self ) + self.options.insertTearOffHandle() + self.options.setCaption( "Options" ) + self.options.insertItem( "&Normal Font", self.normal ) + self.options.insertSeparator() + + self.options.polish() # adjust system settings + f = self.options.font() + f.setBold( TRUE ) + self.boldID = self.options.insertItem( MyMenuItem( "Bold", f ) ) + self.options.setAccel( Qt.CTRL+Qt.Key_B, self.boldID ) + self.options.connectItem( self.boldID, self.bold ) + + f = self.options.font() + f.setUnderline( TRUE ) + self.underlineID = self.options.insertItem( MyMenuItem( "Underline", f ) ) + self.options.setAccel( Qt.CTRL+Qt.Key_U, self.underlineID ) + self.options.connectItem( self.underlineID, self.underline ) + + self.isBold = FALSE + self.isUnderline = FALSE + self.options.setCheckable( TRUE ) + + self.help = QPopupMenu( self ) + self.help.insertItem( "&About", self.about, Qt.CTRL+Qt.Key_H ) + self.help.insertItem( "About &Qt", self.aboutQt ) + + self.menu = QMenuBar( self ) + 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( QMenuBar.InWindowsStyle ) + + msg = QLabel( self ) + msg.setText( "A context menu is available.\n" + "Invoke it by right-clicking or by" + " pressing the 'context' button." ) + msg.setGeometry( 0, self.height() - 60, self.width(), 60 ) + msg.setAlignment( Qt.AlignCenter ) + + self.label = QLabel( self ) + self.label.setGeometry( 20, self.rect().center().y()-20, self.width()-40, 40 ) + self.label.setFrameStyle( QFrame.Box | QFrame.Raised ) + self.label.setLineWidth( 1 ) + self.label.setAlignment( Qt.AlignCenter ) + + self.connect( self, PYSIGNAL( "explain" ), self.label, SLOT( "setText(const QString &" ) ) + + self.setMinimumSize( 100, 80 ) + self.setFocusPolicy( QWidget.ClickFocus ) + + def contextMenuEvent(self, cmev): + contextMenu = QPopupMenu( self ) + caption = QLabel( "<font color=darkblue><u><b>Context Menu</b></u></font>", self ) + caption.setAlignment( Qt.AlignCenter ) + contextMenu.insertItem( caption ) + contextMenu.insertItem( "&New", self.news, Qt.CTRL+Qt.Key_N ) + contextMenu.insertItem( "&Open...", self.open, Qt.CTRL+Qt.Key_O ) + contextMenu.insertItem( "&Save", self.save, Qt.CTRL+Qt.Key_S ) + submenu = QPopupMenu( self ) + submenu.insertItem( "&Print to printer", self.printDoc ) + submenu.insertItem( "Print to &file", self.printFile ) + submenu.insertItem( "Print to fa&x", self.fax ) + contextMenu.insertItem( "&Print", submenu ) + contextMenu.exec_loop( QCursor.pos() ) + + 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 + font = QFont() + self.label.setFont( font ) + 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 + font = QFont() + font.setBold( self.isBold ) + font.setUnderline( self.isUnderline ) + self.label.setFont( font ) + self.options.setItemChecked( self.boldID, self.isBold ) + self.emit( PYSIGNAL( "explain" ), ( "Options/Bold selected", ) ) + + def underline( self ): + self.isUnderline = not self.isUnderline + font = QFont() + font.setBold( self.isBold ) + font.setUnderline( self.isUnderline ) + self.label.setFont( font ) + self.options.setItemChecked( self.underlineID, self.isUnderline ) + self.emit( PYSIGNAL("explain"), ( "Options/Underline selected", )) + + def about( self ): + QMessageBox.about( self, "Qt Menu Example", + "This example demonstrates simple use of Qt menus.\n" + "You can cut and paste lines from it to your own\n" + "programs." ) + + def aboutQt( self ): + QMessageBox.aboutQt( self, "Qt Menu Example" ) + + def printDoc( self ): + self.emit( PYSIGNAL( "explain" ), ( "File/Printer/Print selected", ) ) + + def printFile( 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 = QApplication( sys.argv ) +m = MenuExample() + +m.setCaption( "Qt Examples - Menus" ) +a.setMainWidget( m ) +m.show() +a.exec_loop() diff --git a/examples3/progress.py b/examples3/progress.py new file mode 100755 index 0000000..001be45 --- /dev/null +++ b/examples3/progress.py @@ -0,0 +1,281 @@ +#!/usr/bin/env python + +#/**************************************************************************** +#** $Id: progress.py 3.3.7 edited Aug 31 2005 $ +#** +#** Copyright (C) 1992-2005 Trolltech AS. All rights reserved. +#** +#** This file is part of an example program for Qt. This example +#** program may be used, distributed and modified without limitation. +#** +#** Converted to PyQt3 by Hans-Peter Jansen <[email protected]> +#** +#*****************************************************************************/ + +import sys +from qt import * +from random import randint + +class AnimatedThingy(QLabel): + def __init__(self, parent, s): + QLabel.__init__(self, parent) + self.label = QString(s) + self.setEraseColor(Qt.white) + self.label.append("\n... and wasting CPU\nwith this animation!\n") + self.step = 0 + self.nqix = 10 + self.stepoff = 2 + self.stepmax = 7 + self.lwidth = 2 + self.tdelay = 100 + self.ox, self.oy = [], [] + for i in range(self.nqix): + self.ox.append((0, 0)) + self.oy.append((0, 0)) + self.x0, self.y0, self.x1, self.y1 = 0, 0, 0, 0 + self.dx0 = randint(0, self.stepmax) + self.stepoff + self.dy0 = randint(0, self.stepmax) + self.stepoff + self.dx1 = randint(0, self.stepmax) + self.stepoff + self.dy1 = randint(0, self.stepmax) + self.stepoff + + def show(self): + if not self.isVisible(): + self.startTimer(self.tdelay) + QWidget.show(self) + + def hide(self): + QWidget.hide(self) + self.killTimers() + + def sizeHint(self): + return QSize(120, 100) + + def timerEvent(self, e): + p, pn = self._painter() + pn.setColor(self.eraseColor()) + p.setPen(pn) + self.step = step = (self.step + 1) % self.nqix + # erase line + p.drawLine(self.ox[step][0], self.oy[step][0], + self.ox[step][1], self.oy[step][1]) + # calc new line coordinates + ww, wh = self.width(), self.height() + self.x0, self.dx0 = self._inc(self.x0, self.dx0, ww) + self.y0, self.dy0 = self._inc(self.y0, self.dy0, wh) + self.x1, self.dx1 = self._inc(self.x1, self.dx1, ww) + self.y1, self.dy1 = self._inc(self.y1, self.dy1, wh) + self.ox[step] = (self.x0, self.x1) + self.oy[step] = (self.y0, self.y1) + self._drawqix(p, pn, step) + self._drawtxt(p) + + def paintEvent(self, event): + p, pn = self._painter() + p.setClipRect(event.rect()) + for i in range(self.nqix): + self._drawqix(p, pn, i) + self._drawtxt(p) + + def _painter(self): + p = QPainter(self) + # we need to create a new pen from p.pen() with QPen() in order + # to make it fully functional (changes are discarded otherwise) + pn = QPen(p.pen()) + pn.setWidth(self.lwidth) + p.setPen(pn) + return p, pn + + def _drawqix(self, p, pn, step): + # rainbow effect + pn.setColor(QColor((step * 255)/self.nqix, 255, 255, QColor.Hsv)) + p.setPen(pn) + p.drawLine(self.ox[step][0], self.oy[step][0], + self.ox[step][1], self.oy[step][1]) + + def _drawtxt(self, p): + p.setPen(self.colorGroup().text()) + p.drawText(self.rect(), Qt.AlignCenter, self.label) + + def _inc(self, x, dx, b): + x += dx + if x < 0: + x = 0 + dx = randint(0, self.stepmax) + self.stepoff; + elif x >= b: + x = b - 1 + dx = -(randint(0, self.stepmax) + self.stepoff) + return x, dx + + +class CPUWaster(QWidget): + def __init__(self): + QWidget.__init__(self) + self.first_draw_item = 1000 + self.last_draw_item = 1006 + self.rects = 0 + self.timer_driven = 0 + self.default_label = 0 + self.got_stop = False + self.pb = None # non modal progress dialog + self.menubar = menubar = QMenuBar(self, "menu") + self.file_ = file_ = QPopupMenu() + menubar.insertItem("&File", file_) + for i in range(self.first_draw_item, self.last_draw_item + 1): + file_.insertItem(self.drawItemText(i), i) + file_.setAccel(QKeySequence( + "Ctrl+%s" % (i - self.first_draw_item)), i) + self.connect(menubar, SIGNAL("activated(int)"), self.doMenuItem) + file_.insertSeparator() + file_.insertItem("Quit", qApp, SLOT("quit()"), QKeySequence("Ctrl+Q")) + self.options = options = QPopupMenu() + menubar.insertItem("&Options", options) + self.ld_id = options.insertItem("Loop driven", self.loopDriven, + QKeySequence("Alt+L")) + self.td_id = options.insertItem("Timer driven", self.timerDriven, + QKeySequence("Alt+T")) + options.insertSeparator() + self.dl_id = options.insertItem("Default label", self.defaultLabel, + QKeySequence("Alt+D")) + self.cl_id = options.insertItem("Custom label", self.customLabel, + QKeySequence("Alt+C")) + options.insertSeparator() + self.md_id = options.insertItem("No minimum duration", + self.toggleMinimumDuration, + QKeySequence("Alt+M")) + options.setCheckable(True) + # default option settings + self.timerDriven() + self.customLabel() + self.toggleMinimumDuration() + self.resize(400, 300) + self.setEraseColor(Qt.black) + + def drawItemRects(self, id_): + r = 100 + for n in range(id_ - self.first_draw_item): + if not n % 3: + r *= 4 + else: + r *= 5 + return r + + def drawItemText(self, id_): + return QString("%d Rectangles" % self.drawItemRects(id_)) + + def enableDrawingItems(self, yes): + for i in range(self.first_draw_item, self.last_draw_item + 1): + self.menubar.setItemEnabled(i, yes) + + # slots + def doMenuItem(self, id_): + if id_ >= self.first_draw_item and id_ <= self.last_draw_item: + self.draw(self.drawItemRects(id_)) + + def timerDriven(self): + self.timer_driven = True + self.options.setItemChecked(self.td_id, True) + self.options.setItemChecked(self.ld_id, False) + + def loopDriven(self): + self.timer_driven = False + self.options.setItemChecked(self.ld_id, True) + self.options.setItemChecked(self.td_id, False) + + def defaultLabel(self): + self.default_label = True + self.options.setItemChecked(self.dl_id, True) + self.options.setItemChecked(self.cl_id, False) + + def customLabel(self): + self.default_label = False + self.options.setItemChecked(self.dl_id, False) + self.options.setItemChecked(self.cl_id, True) + + def toggleMinimumDuration(self): + self.options.setItemChecked(self.md_id, + not self.options.isItemChecked(self.md_id)) + + def stopDrawing(self): + self.got_stop = True + + def newProgressDialog(self, label, steps, modal): + d = QProgressDialog(label, "Cancel", steps, self, "progress", modal) + if self.options.isItemChecked(self.md_id): + d.setMinimumDuration(0) + if not self.default_label: + d.setLabel(AnimatedThingy(d, label)) + d.setCaption("Please Wait") + return d + + def draw(self, n): + if self.timer_driven: + if self.pb: + qWarning("This cannot happen!") + return + + self.rects = n + self.pb = self.newProgressDialog("Drawing rectangles.\n" + "Using timer event.", n, False) + self.connect(self.pb, SIGNAL("cancelled()"), self.stopDrawing) + self.enableDrawingItems(False) + self.startTimer(0) + self.got_stop = False + else: # loop driven with modal progress dialog + lpb = self.newProgressDialog("Drawing rectangles.\n" + "Using loop.", n, True) + p = QPainter(self) + for i in range(n): + lpb.setProgress(i) + if lpb.wasCancelled(): + break + self._draw(p) + self._clear(p) + lpb.cancel() + del lpb + + def timerEvent(self, e): + if not self.got_stop: + self.pb.setProgress(self.pb.totalSteps() - self.rects) + self.rects -= 1 + p = QPainter(self) + self._draw(p) + + if not self.rects or self.got_stop: + if not self.got_stop: + self.pb.setProgress(self.pb.totalSteps()) + self._clear(p) + self.enableDrawingItems(True) + self.killTimers() + self.pb.cancel() + del self.pb + self.pb = None + + def _draw(self, p): + ww = self.width() + wh = self.height() + if ww > 8 and wh > 8: + c = QColor(randint(0, 255), randint(0, 255), randint(0, 255)) + x = randint(0, ww - 8) + y = randint(0, wh - 8) + w = randint(0, ww - x) + h = randint(0, wh - y) + p.fillRect(x, y, w, h, QBrush(c)) + + def _clear(self, p): + p.fillRect(0, 0, self.width(), self.height(), QBrush(self.eraseColor())) + + +if __name__ == "__main__": + app = QApplication(sys.argv) + try: + n = int(sys.argv[1]) + except: + n = 1 + wlst = [] # keep a ref around + for i in range(n): + cpuw = CPUWaster() + if i == 0: + app.setMainWidget(cpuw) + cpuw.show() + wlst.append(cpuw) + app.exec_loop() diff --git a/examples3/progressbar.py b/examples3/progressbar.py new file mode 100755 index 0000000..beca2b6 --- /dev/null +++ b/examples3/progressbar.py @@ -0,0 +1,155 @@ +#!/usr/bin/env python + +"""*********************************************************************** +** $Id: progressbar.py,v 1.1 2003/06/10 14:51:24 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +**************************************************************************""" + +#import pdb +import sys +from qt import * + +FALSE = 0 +TRUE = 1 + +class ProgressBar( QButtonGroup ): + # Constructor + # Creates child widgets of the ProgressBar widget + def __init__( self, parent=None, name=None ): + QButtonGroup.__init__( self, 0, Qt.Horizontal, "Progress Bar", parent, name ) + + self.timer = QTimer() + + self.setMargin( 10 ) + toplayout = QGridLayout( self.layout(), 2, 2, 5) + + self.setRadioButtonExclusive( TRUE ) + + # insert three radiobuttons which the user can use + # to set the speed of the progress and two pushbuttons + # to start/pause/continue and reset the progress + self.slow = QRadioButton( "&Slow", self ) + self.normal = QRadioButton( "&Normal", self ) + self.fast = QRadioButton( "&Fast", self ) + vb1 = QVBoxLayout( ) + toplayout.addLayout( vb1, 0, 0 ) + vb1.addWidget( self.slow ) + vb1.addWidget( self.normal ) + vb1.addWidget( self.fast ) + + # two push buttons, one for start, for for reset. + self.start = QPushButton( "&Start", self ) + self.reset = QPushButton( "&Reset", self ) + + vb2 = QVBoxLayout() + toplayout.addLayout( vb2, 0, 1 ) + vb2.addWidget( self.start ) + vb2.addWidget( self.reset ) + + # Create the progressbar + self.progress = QProgressBar( 100, self ) + #self.progress.setStyle( QMotifStyle() ) + toplayout.addMultiCellWidget( self.progress, 1, 1, 0, 1 ) + + # connect the clicked() SIGNALs of the pushbuttons to SLOTs + self.connect( self.start, SIGNAL("clicked()"), self.slotStart ) + self.connect( self.reset, SIGNAL("clicked()"), self.slotReset ) + + # connect the timeout() SIGNAL of the progress-timer to a SLOT + self.connect( self.timer, SIGNAL("timeout()"), self.slotTimeout ) + # Let's start with normal speed... + self.normal.setChecked( TRUE ) + + # some contraints + self.start.setFixedWidth( 80 ) + self.setMinimumWidth( 300 ) + + # SLOT slotStart + # This SLOT is called if the user clicks start/pause/continue button + def slotStart( self ): + # If the progress bar is at the beginning... + if self.progress.progress() == -1 : + # ...set according to the checked speed-radiobutton the + # the number of steps which are needed to complete the process + if self.slow.isChecked(): + self.progress.setTotalSteps( 10000 ) + elif self.normal.isChecked() : + self.progress.setTotalSteps( 1000 ) + else : + self.progress.setTotalSteps( 50 ) + + # disable the speed-radiobuttons + self.slow.setEnabled( FALSE ) + self.normal.setEnabled( FALSE ) + self.fast.setEnabled( FALSE ) + + # If the progress is not running... + if not self.timer.isActive() : + # ...start the timer (and so the progress) with a interval of 1 ms... + self.timer.start( 1 ) + # ...and rename the start/pause/continue button to Pause + self.start.setText( "&Pause" ) + else : # if the prgress is running... + # ...stop the timer (and so the prgress)... + self.timer.stop() + # ...and rename the start/pause/continue button to Continue + self.start.setText( "&Continue" ) + + # SLOT slotReset + # This SLOT is called when the user clicks the reset button + def slotReset( self ): + # stop the timer and progress + self.timer.stop() + + # rename the start/pause/continue button to Start... + self.start.setText( "&Start" ) + # ...and enable this button + self.start.setEnabled( TRUE ) + + # enable the speed-radiobuttons + self.slow.setEnabled( TRUE ) + self.normal.setEnabled( TRUE ) + self.fast.setEnabled( TRUE ) + + # reset the progressbar + self.progress.reset() + + # SLOT slotTimeout + # This SLOT is called each ms when the timer is + # active (== progress is running) + def slotTimeout( self ): + p = self.progress.progress() + + # If the progress is complete... + if p == self.progress.totalSteps() : + # ...rename the start/pause/continue button to Start... + self.start.setText( "&Start" ) + # ...and disable it... + self.start.setEnabled( FALSE ) + # ...and return + return + + # If the process is not complete increase it + p += 1 + self.progress.setProgress( p ) + + + #QPushButton *start, *pause, *reset; + +def main( args ): + a = QApplication( args ) + + progressbar = ProgressBar() + progressbar.setCaption("Qt Example - ProgressBar") + a.setMainWidget(progressbar) + progressbar.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/qdir.py b/examples3/qdir.py new file mode 100755 index 0000000..0da10eb --- /dev/null +++ b/examples3/qdir.py @@ -0,0 +1,323 @@ +#!/usr/bin/env python +# +# 2005-02-12 initial version hp + +import os +import pickle +from qt import * +from dirview import Directory, DirectoryView + +bookmarks = [ + "22 14 8 1", + "# c #000080", + "a c #585858", + "b c #000000", + "c c #ffffff", + "d c #ffffff", + "e c #ffffff", + "f c #000000", + ". c None", + "...bb.................", + "..bacb....bbb.........", + "..badcb.bbccbab.......", + "..bacccbadccbab.......", + "..baecdbcccdbab.......", + "..bacccbacccbab.......", + "..badcdbcecdfab.......", + "..bacecbacccbab.......", + "..baccdbcccdbab.......", + "...badcbacdbbab.......", + "....bacbcbbccab.......", + ".....babbaaaaab.......", + ".....bbabbbbbbb.......", + "......bb.............." +] + +home = [ + "16 15 4 1", + "# c #000000", + "a c #ffffff", + "b c #c0c0c0", + ". c None", + ".......##.......", + "..#...####......", + "..#..#aabb#.....", + "..#.#aaaabb#....", + "..##aaaaaabb#...", + "..#aaaaaaaabb#..", + ".#aaaaaaaaabbb#.", + "###aaaaaaaabb###", + "..#aaaaaaaabb#..", + "..#aaa###aabb#..", + "..#aaa#.#aabb#..", + "..#aaa#.#aabb#..", + "..#aaa#.#aabb#..", + "..#aaa#.#aabb#..", + "..#####.######.." +] + + +class PixmapView(QScrollView): + def __init__(self, parent): + QScrollView.__init__(self, parent) + self.pixmap = None + self.viewport().setBackgroundMode(self.PaletteBase) + + def setPixmap(self, pix): + self.pixmap = pix + self.resizeContents(pix.size().width(), pix.size().height()) + self.viewport().repaint(False) + + def drawContents(self, p, cx, cy, cw, ch): + p.fillRect(cx, cy, cw, ch, self.colorGroup().brush(QColorGroup.Base)) + p.drawPixmap(0, 0, self.pixmap) + + +class Preview(QWidgetStack): + def __init__(self, parent): + QWidgetStack.__init__(self, parent) + self.normalText = QMultiLineEdit(self) + self.normalText.setReadOnly(True) + self.html = QTextView(self) + self.pixmap = PixmapView(self) + self.raiseWidget(self.normalText) + + def showPreview(self, url, size): + if url.isLocalFile(): + path = url.path() + fi = QFileInfo(path) + if fi.isFile() and fi.size() > size * 1000: + self.normalText.setText( + "The File\n%s\nis too large, so I don't show it!" % path) + self.raiseWidget(self.normalText) + return + pix = QPixmap(path) + if pix.isNull(): + if fi.isFile(): + err = False + try: + text = open(path.latin1(), "r").read() + except IOError, msg: + text = QString(str(msg)) + err = True + if not err and fi.extension().lower().contains("htm"): + url = self.html.mimeSourceFactory().makeAbsolute( + path, self.html.context()) + self.html.setText(text, url) + self.raiseWidget(self.html) + return + else: + self.normalText.setText(text) + self.raiseWidget(self.normalText) + return + else: + self.normalText.setText("") + self.raiseWidget(self.normalText) + else: + self.pixmap.setPixmap(pix) + self.raiseWidget(self.pixmap) + else: + self.normalText.setText("I only show local files!") + self.raiseWidget(self.normalText) + + +# We can't instantiate QFilePreview directly because it is abstract. Note that +# the previewUrl() abstract is patched in later to work around the fact that +# you can't multiply inherit from more than one wrapped class. +class FilePreview(QFilePreview): + pass + + +class PreviewWidget(QVBox): + def __init__(self, parent): + QVBox.__init__(self, parent) + self.setSpacing( 5 ) + self.setMargin( 5 ) + row = QHBox(self) + row.setSpacing(5) + QLabel("Only show files smaller than: ", row) + self.sizeSpinBox = QSpinBox(1, 10000, 1, row) + self.sizeSpinBox.setSuffix(" KB") + self.sizeSpinBox.setValue(128) + row.setFixedHeight(10 + self.sizeSpinBox.sizeHint().height()) + self.__preview = Preview(self) + # workaround sip inability of multiple inheritance + # create a local QFilePreview instance and redirect + # the method, which is called on preview, to us + self.preview = FilePreview() + self.preview.previewUrl = self.previewUrl + + def previewUrl(self, url): + self.__preview.showPreview(url, self.sizeSpinBox.value()) + + +class CustomFileDialog(QFileDialog): + def __init__(self, preview = False): + QFileDialog.__init__(self, None, None, True) + self.bookmarkFile = ".pybookmarks" + self.bookmarkList = [] + if os.path.exists(self.bookmarkFile): + try: + self.bookmarkList = pickle.loads(open(self.bookmarkFile, "rb").read()) + except IOError, msg: + print msg + self.setDir("/") + self.dirView = DirectoryView(self, None, True) + self.dirView.addColumn("") + self.dirView.header().hide() + root = Directory(self.dirView, "/") + root.setOpen(True) + self.dirView.setFixedWidth(200) + self.addLeftWidget(self.dirView) + p = QPushButton(self) + p.setPixmap(QPixmap(bookmarks)) + QToolTip.add(p, "Bookmarks") + self.bookmarkMenu = QPopupMenu(self) + self.connect(self.bookmarkMenu, SIGNAL("activated(int)"), + self.bookmarkChosen) + self.addId = self.bookmarkMenu.insertItem("Add bookmark") + self.bookmarkMenu.insertSeparator() + for l in self.bookmarkList: + self.bookmarkMenu.insertItem(l) + p.setPopup(self.bookmarkMenu) + self.addToolButton(p, True) + self.connect(self.dirView, PYSIGNAL("folderSelected(const QString &)"), + self.setDir2) + self.connect(self, SIGNAL("dirEntered(const QString &)"), + self.dirView.setDir) + b = QToolButton(self) + QToolTip.add(b, "Go Home!") + b.setPixmap(QPixmap(home)) + self.connect(b, SIGNAL("clicked()"), self.goHome) + self.addToolButton(b) + + if preview: + self.setContentsPreviewEnabled(True) + pw = PreviewWidget(self) + self.setContentsPreview(pw, pw.preview) + self.setViewMode(QFileDialog.List) + self.setPreviewMode(QFileDialog.Contents) + + w = self.width() + h = self.height() + if preview: + self.resize(w + w / 2, h + h / 3) + else: + self.resize(w + w / 3, h + h / 4) + + def done(self, r): + if self.bookmarkList: + try: + open(self.bookmarkFile, "wb").write(pickle.dumps(self.bookmarkList)) + except IOError, msg: + print msg + return QFileDialog.done(self, r) + + def showEvent(self, e): + QFileDialog.showEvent(self, e) + self.dirView.setDir(self.dirPath()) + + def setDir2(self, path): + self.blockSignals(True) + self.setDir(path) + self.blockSignals(False) + + def bookmarkChosen(self, i): + if i == self.addId: + # keep bookmarks pythonic + dp = self.dirPath().latin1() + if dp not in self.bookmarkList: + self.bookmarkList.append(dp) + self.bookmarkMenu.insertItem(dp) + else: + self.setDir(self.bookmarkMenu.text(i)) + + def goHome(self): + if os.getenv("HOME"): + self.setDir(os.getenv("HOME")) + else: + self.setDir("/") + + +if __name__ == '__main__': + import sys + import getopt + + def usage(msg = None): + if msg: + print >> sys.stderr, msg + print >> sys.stderr, """\ +usage: qdir [--any | --dir | --custom] [--preview] [--default f] {--filter f} [caption ...] + --any Get any filename, need not exist. + --dir Return a directory rather than a file. + --custom Opens a customized QFileDialog with + dir browser, bookmark menu, etc. + --preview Show a preview widget. + --default f Start from directory/file f. + --filter f eg. '*.gif' '*.bmp' + caption ... Caption for dialog. +""" + sys.exit(1) + + def main(): + options = ["help", "any", "dir", "custom", "preview", "default=", "filter="] + mode = QFileDialog.ExistingFile + preview = False + custom = False + start = None + filter = QString.null + app = QApplication(sys.argv) + + try: + optlist, args = getopt.getopt(sys.argv[1:], "h", options) + except getopt.error, msg: + usage(msg) + + for opt, par in optlist: + if opt in ("-h", "--help"): + usage() + elif opt == "--any": + mode = QFileDialog.AnyFile + elif opt == "--dir": + mode = QFileDialog.Directory + elif opt == "--default": + start = par + elif opt == "--filter": + filter = par + elif opt == "--preview": + preview = True + elif opt == "--custom": + custom = True + if args: + caption = " ".join(args) + elif mode == QFileDialog.Directory: + caption = "Choose directory..." + else: + caption = "Choose file..." + if not start: + start = QDir.currentDirPath() + if not custom: + fd = QFileDialog(QString.null, filter, None, None, True) + fd.setMode(mode) + if preview: + fd.setContentsPreviewEnabled(True) + pw = PreviewWidget(fd) + fd.setContentsPreview(pw, pw.preview) + fd.setViewMode(QFileDialog.List) + fd.setPreviewMode(QFileDialog.Contents) + w = fd.width() + h = fd.height() + fd.resize(w + w / 3, h + h / 4) + fd.setCaption(caption) + fd.setSelection(start) + if fd.exec_loop() == QDialog.Accepted: + print "%s\n" % fd.selectedFile().latin1() + return 0 + else: + return 1 + else: + fd = CustomFileDialog(preview) + fd.exec_loop() + return 1 + + sys.exit(main()) diff --git a/examples3/qmag.py b/examples3/qmag.py new file mode 100755 index 0000000..f27da2c --- /dev/null +++ b/examples3/qmag.py @@ -0,0 +1,233 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: qmag.py,v 1.1 2002/06/20 18:52:31 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +from qt import * + +TRUE = 1 +FALSE = 0 + +zoomfactors = ["100%","200%","300%","400%","500%","600%","700%","800%","1600%"] + +refreshrates = [ + "No autorefresh", "50 per second", "4 per second", "3 per second", + "2 per second", "Every second", "Every two seconds", "Every three seconds", + "Every five seconds", "Every ten seconds"] + +timer = (0, 20, 250, 333, 500, 1000, 2000, 3000, 5000, 10000) + +class MagWidget(QWidget): + def __init__(self, qApp, parent = None, name = None): + self.qApp = qApp + QWidget.__init__(self, parent, name) + self.pm = QPixmap() # pixmap magnified + self.p = QPixmap() # pixmap + self.image = QImage() # image of pixmap (for RGB) + self.z = 0 # zoom factor + self.r = 0 # autorefresh rate (index into refreshrates) + self.grabbing = FALSE # TRUE if currently grabbing + self.grabx = -1 + self.graby = -1 + + self.zoom = QComboBox(FALSE, self) + self.zoom.insertStrList(zoomfactors, len(zoomfactors)) + self.connect(self.zoom, SIGNAL("activated(int)"), + self.setZoom) + + self.refresh = QComboBox(FALSE, self) + self.refresh.insertStrList(refreshrates, len(refreshrates)) + self.connect(self.refresh, SIGNAL("activated(int)"), + self.setRefresh) + + x = 0 + w = 0 + h = 20 + for s in zoomfactors: + cw = self.zoom.fontMetrics().width(s) + w = max(cw, w) + self.zoom.setGeometry(x, 2, w + 30, h) + + x = w + 34 + w = 0 + for s in refreshrates: + cw = self.refresh.fontMetrics().width(s) + w = max(cw, w) + self.refresh.setGeometry(x, 2, w + 30, h) + + self.saveButton = QPushButton(self) + self.connect(self.saveButton, SIGNAL("clicked()"), self.save) + self.saveButton.setText("Save") + self.saveButton.setGeometry(x + w + 30 + 2, 2, + 10 + self.saveButton.fontMetrics().width("Save"), h) + + self.quitButton = QPushButton(self) + self.connect(self.quitButton, SIGNAL("clicked()"), self.qApp, SLOT("quit()")) + self.quitButton.setText("Quit") + self.quitButton.setGeometry(self.saveButton.geometry().right() + 2, 2, + 10 + self.quitButton.fontMetrics().width("Quit"), h) + + self.rgb = QLabel(self) + self.rgb.setText("") + self.rgb.setAlignment(Qt.AlignVCenter) + self.rgb.resize(self.width(), self.rgb.fontMetrics().height() + 4) + + self.yoffset = self.zoom.height() + 4 + self.rgb.height() + self.setMinimumSize(self.quitButton.geometry().topRight().x() + 2, + self.yoffset + 20) + w = self.quitButton.geometry().topRight().x() + 2 + self.resize(w, w) + + self.setMouseTracking(TRUE) + self.grabx = self.qApp.desktop().width() / 2 + self.graby = self.qApp.desktop().height() / 2 + self.grabAround(QPoint(self.grabx, self.graby)) + + #self.zoom.setCurrentItem(1) # grabAround sets zoom factor + #self.setZoom(1) + self.refresh.setCurrentItem(5) + self.setRefresh(5) + + def setZoom(self, index): + if index == 8: + self.z = 16 + else: + self.z = index + 1 + self.grab() + + def setRefresh(self, index): + self.r = index + self.killTimers() + if index and not self.grabbing: + #print "st:", timer[index] + self.startTimer(timer[index]) + + def save(self): + if not self.p.isNull(): + self.killTimers() + fn = QFileDialog.getSaveFileName() + if not fn.isEmpty(): + self.p.save(fn, "BMP") + if self.r: + self.startTimer(timer[self.r]) + + def grab(self): + if not self.isVisible() or self.grabx < 0 or self.graby < 0: + return + + w = (self.width() + self.z - 1) / self.z + h = (self.height() + self.z - 1 - self.yoffset) / self.z + + if w < 1 or h < 1: + return + + x = self.grabx - w / 2 + y = self.graby - h / 2 + + if x + w > QApplication.desktop().width(): + x = QApplication.desktop().width() - w + elif x < 0: + x = 0 + + if y + h > QApplication.desktop().height(): + y = QApplication.desktop().height() - h + elif y < 0: + y = 0 + + self.p = QPixmap.grabWindow(QApplication.desktop().winId(), x, y, w, h) + self.image = self.p.convertToImage() + m = QWMatrix() + #print "z:", self.z + m.scale(float(self.z), float(self.z)) + self.pm = self.p.xForm(m) + self.repaint(FALSE) + + def paintEvent(self, e): + if not self.pm.isNull(): + paint = QPainter(self) + paint.drawPixmap(0, self.zoom.height() + 4, self.pm, + 0, 0, self.width(), self.height() - self.yoffset) + + def mousePressEvent(self, e): + if not self.grabbing: + self.grabbing = TRUE + self.killTimers() + self.grabMouse(Qt.crossCursor) + self.grabx = -1 + self.graby = -1 + else: + self.grabx = self.mapToGlobal(e.pos()).x() + self.graby = self.mapToGlobal(e.pos()).y() + + def mouseReleaseEvent(self, e): + if self.grabbing and self.grabx >= 0 and self.graby >= 0: + self.grabbing = FALSE + self.grabAround(e.pos()) + self.releaseMouse() + + def grabAround(self, pos): + rx = self.mapToGlobal(pos).x() + ry = self.mapToGlobal(pos).y() + w = abs(rx - self.grabx) + h = abs(ry - self.graby) + if w > 10 and h > 10: + pz = 1 + while w*pz*h*pz < self.width()*(self.height()-self.yoffset) and \ + w*pz < QApplication.desktop().width() and \ + h*pz < QApplication.desktop().height(): + pz += 1 + if (w*pz*h*pz - self.width()*(self.height()-self.yoffset)) > \ + (self.width()*(self.height()-self.yoffset) - w*(pz-1)*h*(pz-1)): + pz -= 1 + if pz < 1: + pz = 1 + elif pz > 8: + pz = 8 + self.zoom.setCurrentItem(pz-1) + self.z = pz + self.grabx = min(rx, self.grabx) + w / 2 + self.graby = min(ry, self.graby) + h / 2 + #self.resize(w*self.z, h*self.z*self.yoffset) + self.grab() + + def mouseMoveEvent(self, e): + if self.grabbing or self.pm.isNull() or \ + e.pos().y() > self.height() - self.zoom.fontMetrics().height() - 4 or \ + e.pos().y() < self.zoom.height() + 4: + self.rgb.setText("") + else: + x = e.pos().x() / self.z + y = (e.pos().y() - self.zoom.height() - 4) / self.z + pixelinfo = "" + if self.image.valid(x, y): + px = self.image.pixel(x, y) + pixelinfo = "%3d,%3d,%3d #%02x%02x%02x" % ( + qRed(px), qGreen(px), qBlue(px), + qRed(px), qGreen(px), qBlue(px)) + self.rgb.setText("x=%d, y=%d %s" % \ + (x + self.grabx, y + self.graby, pixelinfo)) + + def focusOutEvent(self, e): + self.rgb.setText("") + + def timerEvent(self, e): + self.grab() + + def resizeEvent(self, e): + self.rgb.setGeometry(0, self.height() - self.rgb.height(), + self.width(), self.rgb.height()) + +if __name__=='__main__': + app = QApplication( sys.argv ) + m = MagWidget(app) + app.setMainWidget(m) + m.show() + app.exec_loop() diff --git a/examples3/qt.png b/examples3/qt.png Binary files differnew file mode 100644 index 0000000..ca630a5 --- /dev/null +++ b/examples3/qt.png diff --git a/examples3/qtlogo.png b/examples3/qtlogo.png Binary files differnew file mode 100644 index 0000000..0dc05a0 --- /dev/null +++ b/examples3/qtlogo.png diff --git a/examples3/rangecontrols.py b/examples3/rangecontrols.py new file mode 100755 index 0000000..a47b8ff --- /dev/null +++ b/examples3/rangecontrols.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: rangecontrols.py,v 1.1 2003/07/01 14:18:37 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +INT_MAX = sys.maxint + +class RangeControls( QVBox ): + def __init__( self, parent=None, name=None ): + QVBox.__init__( self, parent, name ) + + row1 = QHBox( self ) + cell2 = QVBox( row1 ) + cell2.setMargin( 10 ) + cell2.setFrameStyle( QFrame.WinPanel | QFrame.Sunken ) + + QWidget( cell2 ) + + label1 = QLabel( QString( "Enter a value between\n%1 and %2:" ).arg( -INT_MAX ).arg( INT_MAX ), cell2 ) + label1.setMaximumHeight( label1.sizeHint().height() ) + sb1 = QSpinBox( -INT_MAX, INT_MAX, 1, cell2 ) + sb1.setValue( 0 ) + + label2 = QLabel( "Enter a zoom value:", cell2 ) + label2.setMaximumHeight( label2.sizeHint().height() ) + sb2 = QSpinBox( 0, 1000, 10, cell2 ) + sb2.setSuffix( " %" ) + sb2.setSpecialValueText( "Automatic" ) + + label3 = QLabel( "Enter a price:", cell2 ) + label3.setMaximumHeight( label3.sizeHint().height() ) + sb3 = QSpinBox( 0, INT_MAX, 1, cell2 ) + sb3.setPrefix( "$" ) + sb3.setValue( 355 ) + + QWidget( cell2 ) + + row2 = QHBox( self ) + + cell3 = QVBox( row2 ) + cell3.setMargin( 10 ) + cell3.setFrameStyle( QFrame.WinPanel | QFrame.Sunken ) + hslider = QSlider( 0, 64, 1, 33, Qt.Horizontal, cell3 ) + lcd2 = QLCDNumber( 2, cell3 ) + lcd2.display( 33 ) + lcd2.setSegmentStyle( QLCDNumber.Filled ) + self.connect( hslider, SIGNAL("valueChanged( int )"), lcd2, SLOT("display( int )") ) + + cell4 = QHBox( row2 ) + cell4.setFrameStyle( QFrame.WinPanel | QFrame.Sunken ) + cell4.setMargin( 10 ) + vslider = QSlider( 0, 64, 1, 8, Qt.Vertical, cell4 ) + lcd3 = QLCDNumber( 3, cell4 ) + lcd3.display( 8 ) + self.connect( vslider, SIGNAL("valueChanged( int )"), lcd3, SLOT("display( int )") ) + +def main( args ): + a = QApplication( args ) + + rangecontrols = RangeControls() + rangecontrols.resize( 500, 300 ) + rangecontrols.setCaption( "Qt Example - Range Control Widgets" ); + a.setMainWidget( rangecontrols ) + rangecontrols.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/richtext.py b/examples3/richtext.py new file mode 100755 index 0000000..592213d --- /dev/null +++ b/examples3/richtext.py @@ -0,0 +1,136 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: richtext.py,v 1.1 2003/07/01 14:18:37 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +sayings = [ + "<b>Saying 1:</b><br>" + "<hr><br><br>" + "<big>Evil is that which one believes of others. It is a sin to believe evil " + "of others, but it is seldom a mistake.</big><br><br>" + "<center><i>-- H.L. Mencken</i></center>", + + "<b>Saying 2:</b><br>" + "<hr><br><br>" + "<big>A well-used door needs no oil on its hinges.<br>" + "A swift-flowing steam does not grow stagnant.<br>" + "Neither sound nor thoughts can travel through a vacuum.<br>" + "Software rots if not used.<br><br>" + "These are great mysteries.</big><br><br>" + "<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>", + + "<b>Saying 3:</b><br>" + "<hr><br><br>" + "<big>Show business is just like high school, except you get paid.</big><br><br>" + "<center><i>-- Martin Mull</i></center>", + + "<b>Saying 4:</b><br>" + "<hr><br><br>" + "<big><b>The Least Successful Executions</b><br>" + "<twocolumn><p> History has furnished us with two executioners worthy of attention. " + "The first performed in Sydney in Australia. In 1803 three attempts were " + "made to hang a Mr. Joseph Samuels. On the first two of these the rope " + "snapped, while on the third Mr. Samuels just hung there peacefully until he " + "and everyone else got bored. Since he had proved unsusceptible to capital " + "punishment, he was reprieved.</p>" + "<p> The most important British executioner was Mr. James Berry who " + "tried three times in 1885 to hang Mr. John Lee at Exeter Jail, but on each " + "occasion failed to get the trap door open.<!p>" + "<p> In recognition of this achievement, the Home Secretary commuted " + "Lee's sentence to \"life\" imprisonment. He was released in 1917, emigrated " + "to America and lived until 1933.</p></twocolumn></big><br><br>" + "<center><i>-- Stephen Pile, \"The Book of Heroic Failures\"</i></center>", + + "<b>Saying 5:</b><br>" + "<hr><br><br>" + "<big>If you can, help others. If you can't, at least don't hurt others.</big><br><br>" + "<center><i>-- the Dalai Lama</i></center>", + + "<b>Saying 6:</b><br>" + "<hr><br><br>" + "<big>Television has brought back murder into the home -- where it belongs.</big><br><br>" + "<center><i>-- Alfred Hitchcock</i></center>", + + "<b>Saying 7:</b><br>" + "<hr><br><br>" + "<big>I don't know who my grandfather was; I am much more concerned to know " + "what his grandson will be.</big><br><br>" + "<center><i>-- Abraham Lincoln</i></center>", + + 0 +] + +class MyRichText( QVBox ): + def __init__( self, parent = None, name = None ): + QVBox.__init__( self, parent, name ) + + self.setMargin( 5 ) + + self.view = QTextView( self ) + #self.view.setText( "This is a <b>Test</b> with <i>italic</i> <u>stuff</u>" ) + paper = QBrush() + paper.setPixmap( QPixmap( "marble.png" ) ) + if paper.pixmap() != 0 : + self.view.setPaper( paper ) + else : + self.view.setPaper( white ) + + self.view.setText( sayings[0] ) + self.view.setMinimumSize( 450, 250 ) + + buttons = QHBox( self ) + buttons.setMargin( 5 ) + + self.bClose = QPushButton( "&Close", buttons ) + self.bPrev = QPushButton( "<< &Prev", buttons ) + self.bNext = QPushButton( "&Next >>", buttons ) + + self.bPrev.setEnabled( False ) + + self.connect( self.bClose, SIGNAL("clicked()"), qApp, SLOT("quit()") ) + self.connect( self.bPrev, SIGNAL("clicked()"), self.prev ) + self.connect( self.bNext, SIGNAL("clicked()"), self.next ) + + self.num = 0 + + def prev( self ): + if self.num <= 0 : + return + self.num -= 1 + self.view.setText( sayings[self.num] ) + if self.num == 0 : + self.bPrev.setEnabled( False ) + self.bNext.setEnabled( True ) + + def next( self ): + self.num += 1 + if not sayings[self.num]: + return + self.view.setText( sayings[self.num] ) + if not sayings[self.num + 1]: + self.bNext.setEnabled( False ) + self.bPrev.setEnabled( True ) + +def main( args ): + a = QApplication(sys.argv) # application object + + richtext = MyRichText() + richtext.resize( 450, 350 ); + richtext.setCaption( "Qt Example - Richtext" ) + a.setMainWidget( richtext ) + richtext.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/secret.py b/examples3/secret.py new file mode 100644 index 0000000..d6d2b6d --- /dev/null +++ b/examples3/secret.py @@ -0,0 +1,65 @@ +# This is part of the dragdrop example. + + +from 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 QString("The secret number is "+str(ord(payload)) ) + + return None + + +class SecretDrag(QStoredDrag): + def __init__(self, secret, parent=None, name=None): + QStoredDrag.__init__(self, 'secret/magic', parent, name) + data = QByteArray(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(QLabel): + def __init__(self, secret, parent=None, name=None): + QLabel.__init__(self, "Secret", parent, name) + self.setEraseColor( Qt.blue.light() ) + self.setFrameStyle( QLabel.Box | QLabel.Sunken ) + self.setMinimumHeight( self.sizeHint().height()*2 ) + self.setAlignment( QLabel.AlignCenter ) + self.mySecret = secret + + def mousePressEvent(self, e): + sd = SecretDrag( self.mySecret, self ) + sd.setPixmap(QPixmap(picture_xpm),QPoint(8,8)) + sd.dragCopy() + self.mySecret = self.mySecret + 1 diff --git a/examples3/semaphore.py b/examples3/semaphore.py new file mode 100755 index 0000000..ac8b231 --- /dev/null +++ b/examples3/semaphore.py @@ -0,0 +1,203 @@ +#!/usr/bin/env python +# +# A port of the semaphore example from Qt. + + +import sys + +# Check if thread support was enabled. +try: + from qt import QThread +except: + print "Thread support not enabled" + sys.exit(1) + +from qt import * + + +# The semaphore instances. +yellowSem = None +greenSem = None + + +class YellowThread(QThread): + def __init__(self,o): + QThread.__init__(self) + + self.receiver = o + self.stopped = 0 + self.mutex = QMutex() + + def run(self): + global yellowSem, greenSem + + for i in range(20): + yellowSem += 1 + + event = QCustomEvent(12345) + event.setData(QString("Yellow!")) + QThread.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 = QCustomEvent(12346) + event.setData(QString("Yellow!")) + QThread.postEvent(self.receiver,event) + + greenSem -= 1 + + def stop(self): + self.mutex.lock() + self.stopped = 1 + self.mutex.unlock() + + +class GreenThread(QThread): + def __init__(self,o): + QThread.__init__(self) + + self.receiver = o + self.stopped = 0 + self.mutex = QMutex() + + def run(self): + global yellowSem, greenSem + + for i in range(20): + greenSem += 1 + + event = QCustomEvent(12345) + event.setData(QString("Green!")) + QThread.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 = QCustomEvent(12346) + event.setData(QString("Green!")) + QThread.postEvent(self.receiver,event) + self.msleep(10) + + yellowSem -= 1 + + def stop(self): + self.mutex.lock() + self.stopped = 1 + self.mutex.unlock() + + +class SemaphoreExample(QWidget): + def __init__(self): + QWidget.__init__(self) + + self.yellowThread = YellowThread(self) + self.greenThread = GreenThread(self) + + global yellowSem, greenSem + yellowSem = QSemaphore(1) + greenSem = QSemaphore(1) + + self.button = QPushButton("&Ignition!",self) + self.connect(self.button,SIGNAL("clicked()"),self.startExample) + + self.mlineedit = QMultiLineEdit(self) + self.label = QLabel(self) + + vbox = QVBoxLayout(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(): + QMessageBox.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.setEraseColor(Qt.green) + else: + self.label.setEraseColor(Qt.yellow) + + self.label.setText(s) + + del s + elif event.type() == 12346: + s = event.data() + + QMessageBox.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 = QApplication(sys.argv) +se = SemaphoreExample() +app.setMainWidget(se) +se.show() + +sys.exit(app.exec_loop()) diff --git a/examples3/smalltable.py b/examples3/smalltable.py new file mode 100755 index 0000000..83e74bf --- /dev/null +++ b/examples3/smalltable.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: smalltable.py,v 1.1 2002/06/19 07:56:07 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +import os +from qt import * +from qttable import * + +TRUE = 1 +FALSE = 0 + +numRows = 30 +numCols = 10 + +if __name__ == '__main__': + app = QApplication(sys.argv) + + table = QTable(numRows, numCols) + + header = table.horizontalHeader() + + header.setLabel(0, "Tiny", 40) + header.setLabel(1, "Checkboxes") + header.setLabel(5, "Combos") + header.setMovingEnabled(TRUE) + + img = QImage("trolltech.bmp") + pix = QPixmap(img.scaleHeight(table.rowHeight(3))) + table.setPixmap(3, 2, pix) + table.setText(3, 2, "A Pixmap") + + comboEntries = QStringList("one") + comboEntries.append("two") + comboEntries.append("three") + comboEntries.append("four") + + for i in range(numRows): + item = QComboTableItem(table, comboEntries, FALSE) + item.setCurrentItem(i % 4) + table.setItem(i, 5, item) + + for i in range(numRows): + table.setItem(i, 1, QCheckTableItem(table, "Check me")) + + table.setCaption("Small table example") + table.show() + app.setMainWidget(table) + app.exec_loop() diff --git a/examples3/splitter.py b/examples3/splitter.py new file mode 100755 index 0000000..3cee9cf --- /dev/null +++ b/examples3/splitter.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import sys +from qt import * + +class Test(QWidget): + def __init__(self, parent=None, name='Test', f=0): + QWidget.__init__(self, parent, name, f) + + def paintEvent(self, e): + p = QPainter(self) + p.setClipRect(e.rect()) + d = 1000 + x1 = 0 + x2 = self.width() - 1 + y1 = 0 + y2 = self.height() - 1 + + x = (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 = (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 = QApplication(sys.argv) + + s1 = QSplitter(Qt.Vertical, None, "main") + s2 = QSplitter(Qt.Horizontal, s1, "top") + + t1 = Test(s2) + t1.setEraseColor(Qt.blue.light(180)) + t1.setMinimumSize(50,0) + + t2 = Test(s2) + t2.setEraseColor(Qt.green.light(180)) + s2.setResizeMode(t2, QSplitter.KeepSize) + s2.moveToFirst(t2) + + s3 = QSplitter(Qt.Horizontal, s1, "bottom") + + t3 = Test(s3) + t3.setEraseColor(Qt.red) + t4 = Test(s3) + t4.setEraseColor(Qt.white) + + t5 = Test(s3) + t5.setMaximumHeight(250) + t5.setMinimumSize(80,50) + t5.setEraseColor(Qt.yellow) + + s1.setOpaqueResize(1) + s2.setOpaqueResize(1) + s3.setOpaqueResize(1) + + a.setMainWidget(s1) + s1.show() + a.exec_loop() diff --git a/examples3/tabdialog.py b/examples3/tabdialog.py new file mode 100755 index 0000000..0d37cc5 --- /dev/null +++ b/examples3/tabdialog.py @@ -0,0 +1,116 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: tabdialog.py,v 1.1 2003/07/01 14:18:37 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * + +class TabDialog( QTabDialog ): + def __init__( self, parent=None, name=None, filename=None ): + QTabDialog.__init__( self, parent, name ) + self.filename = QString( filename ) + self.fileinfo = QFileInfo( filename ) + self.setupTab1() + self.setupTab2() + self.setupTab3() + self.connect( self, SIGNAL("applyButtonPressed()"), qApp, SLOT("quit()" ) ) + + def setupTab1( self ): + tab1 = QVBox( self ) + tab1.setMargin( 5 ) + + QLabel( "Filename:", tab1 ) + fname = QLineEdit( self.filename, tab1 ) + fname.setFocus() + + QLabel( "Path:", tab1 ) + path = QLabel( self.fileinfo.dirPath( True ), tab1 ) + path.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + QLabel( "Size:", tab1 ) + size = QLabel( QString( "%1 KB" ).arg( self.fileinfo.size() ), tab1 ) + size.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + QLabel( "Last Read:", tab1 ) + lread = QLabel( self.fileinfo.lastRead().toString(), tab1 ) + lread.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + QLabel( "Last Modified:", tab1 ) + lmodif = QLabel( self.fileinfo.lastModified().toString(), tab1 ) + lmodif.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + self.addTab( tab1, "General" ) + + def setupTab2( self ): + tab2 = QVBox( self ) + tab2.setMargin( 5 ) + + bg = QButtonGroup( 1, QGroupBox.Horizontal, "Permissions", tab2 ) + + readable = QCheckBox( "Readable", bg ) + if self.fileinfo.isReadable() : + readable.setChecked( True ) + + writable = QCheckBox( "Writeable", bg ) + if self.fileinfo.isWritable() : + writable.setChecked( True ) + + executable = QCheckBox( "Executable", bg ) + if self.fileinfo.isExecutable() : + executable.setChecked( True ) + + bg2 = QButtonGroup( 2, QGroupBox.Horizontal, "Owner", tab2 ) + + QLabel( "Owner", bg2 ) + owner = QLabel( self.fileinfo.owner(), bg2 ) + owner.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + QLabel( "Group", bg2 ) + group = QLabel( self.fileinfo.group(), bg2 ) + group.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + + self.addTab( tab2, "Permissions" ) + + def setupTab3( self ): + tab3 = QVBox( self ) + tab3.setMargin( 5 ) + tab3.setSpacing( 5 ) + + QLabel( QString( "Open %1 with:" ).arg( self.filename ), tab3 ) + + prgs = QListBox( tab3 ) + for i in range( 0, 30, 1 ) : + prg = QString( "Application %1" ).arg( i ) + prgs.insertItem( prg ) + prgs.setCurrentItem( 3 ) + + QCheckBox( QString( "Open files with the extension '%1' always with this application" ).arg( self.fileinfo.extension() ), tab3 ) + + self.addTab( tab3, "Applications" ) + +def main( args ): + a = QApplication(sys.argv) + #sys.argv.append("tabdialog.py") # to test uncomment this line + if len(sys.argv) < 2: + filename = QString(".") + else: + filename = QString(sys.argv[1]) + + tabdialog = TabDialog( None, "tabdialog", filename ) + tabdialog.resize( 450, 350 ); + tabdialog.setCaption( "Qt Example - Tabbed Dialog" ) + a.setMainWidget( tabdialog ) + tabdialog.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/tablestatistics.py b/examples3/tablestatistics.py new file mode 100755 index 0000000..49f82ae --- /dev/null +++ b/examples3/tablestatistics.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python + +#**************************************************************************** +#** $Id: tablestatistics.py,v 1.1 2002/06/19 07:56:07 phil Exp $ +#** +#** Copyright (C) 1992-1998 Troll Tech AS. All rights reserved. +#** +#** This file is part of an example program for PyQt. This example +#** program may be used, distributed and modified without limitation. +#** +#*****************************************************************************/ + +import sys +import os +from qt import * +from qttable import * + +TRUE = 1 +FALSE = 0 + +# column constants +TB_FILE = 0 +TB_SIZE = 1 +TB_FLAG = 2 +TB_COLS = 3 + +dirs = ( + "kernel", + "tools", + "widgets", + "dialogs", + "xml", + "table", + "network", + "opengl", + "canvas", +) + +class Table(QTable): + def __init__(self): + QTable.__init__(self, 0, TB_COLS) + self.setSorting(TRUE) + self.horizontalHeader().setLabel(TB_FILE, self.tr("File")) + self.horizontalHeader().setLabel(TB_SIZE, self.tr("Size (bytes)")) + self.horizontalHeader().setLabel(TB_FLAG, self.tr("Use in Sum")) + self.initTable() + self.adjustColumn(TB_FILE) + + # if the user edited something we might need to recalculate the sum + self.connect(self, SIGNAL("valueChanged(int, int)"), self.recalcSum) + + def initTable(self): + # read all the Qt source and header files into a list + all = [] + qtdir = os.getenv("QTDIR") + for i in dirs: + dir = QDir(os.path.join(qtdir, "src", i)) + lst = QStringList(dir.entryList("*.cpp; *.h")) + for f in lst: + if f.contains("moc"): + continue + all.append(os.path.join(i, str(f))) + + # set the number of rows we'll need for the table + self.setNumRows(len(all) + 1) + + i = 0 + sum = 0L + # insert the data into the table + for it in all: + self.setText(i, TB_FILE, it) + f = QFile(os.path.join(qtdir, "src", str(it))) + self.setText(i, TB_SIZE, str(f.size())) + ci = ComboItem(self, QTableItem.WhenCurrent) + self.setItem(i, TB_FLAG, ci) + i = i + 1 + sum += f.size() + self.displaySum(sum) + + def recalcSum(self, dummy, col): + # only recalc if a value in the second or third column changed + if col < TB_SIZE or col > TB_FLAG: + return + + sum = 0L + for i in range(self.numRows()-1): + if str(self.text(i, TB_FLAG)) == "No": + continue + sum += long(str(self.text(i, TB_SIZE))) + self.displaySum(sum) + + def displaySum(self, sum): + # insert calculated data + i1 = TableItem(self, QTableItem.Never, self.tr("Sum")) + self.setItem(self.numRows()-1, TB_FILE, i1) + i2 = TableItem(self, QTableItem.Never, str(sum)) + self.setItem(self.numRows()-1, TB_SIZE, i2) + + def sortColumn(self, col, ascending, wholeRows): + # sum row should not be sorted, so get rid of it for now + self.clearCell(self.numRows()-1, TB_FILE) + self.clearCell(self.numRows()-1, TB_SIZE) + # do sort + QTable.sortColumn(self, col, ascending, TRUE) + # re-insert sum row + self.recalcSum(0, TB_SIZE) + + +class TableItem(QTableItem): + def __init__(self, *args): + apply(QTableItem.__init__, (self,) + args) + + def paint(self, p, cg, cr, selected): + g = QColorGroup(cg) + # last row is the sum row - we want to make it more visible by + # using a red background + if self.row() == self.table().numRows()-1: + g.setColor(QColorGroup.Base, QColor("red")) + QTableItem.paint(self, p, g, cr, selected) + + +class ComboItem(QTableItem): + def __init__(self, t, et): + QTableItem.__init__(self, t, et, "Yes") + self.cb = None + # we do not want this item to be replaced + self.setReplaceable(FALSE) + + def createEditor(self): + # create an editor - a combobox in our case + self.cb = QComboBox(self.table().viewport()) + QObject.connect(self.cb, SIGNAL("activated(int)"), + self.table(), SLOT("doValueChanged()")) + self.cb.insertItem("Yes") + self.cb.insertItem("No") + # and initialize it + if str(self.text()) == "No": + self.cb.setCurrentItem(1) + else: + self.cb.setCurrentItem(0) + return self.cb + + def setContentFromEditor(self, w): + # the user changed the value of the combobox, so synchronize the + # value of the item (its text), with the value of the combobox + if w.inherits("QComboBox"): + self.setText(w.currentText()) + else: + QTableItem.setContentFromEditor(self, w) + + def setText(self, s): + # initialize the combobox from the text + if self.cb: + if str(s) == "No": + self.cb.setCurrentItem(1) + else: + self.cb.setCurrentItem(0) + QTableItem.setText(self, s) + + +if __name__ == '__main__': + app = QApplication(sys.argv) + + t = Table() + t.setCaption("Statistics") + t.show() + app.setMainWidget(t) + app.exec_loop() diff --git a/examples3/tooltip.py b/examples3/tooltip.py new file mode 100755 index 0000000..7eadb7f --- /dev/null +++ b/examples3/tooltip.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python + +"""************************************************************************** +** $Id: tooltip.py,v 1.1 2003/07/01 14:18:37 phil Exp $ +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +***************************************************************************""" + +import sys +from qt import * +from random import random + +class DynamicTip( QToolTip ): + def __init__( self, parent ): + QToolTip.__init__( self, parent ) + + def maybeTip( self, pos ): + #if not self.parent.inherits( "TellMe" ): + if QToolTip(self).parentWidget().inherits( "TellMe" ) : + return + r = QRect( QToolTip(self).parentWidget().tip(pos) ) + if not r.isValid(): + return + + s = QString( "position: %d,%d" % (r.center().x(), r.center().y()) ) + QToolTip(self).tip( r, s ) + + +class TellMe( QWidget ): + def __init__( self, parent=None, name=None ): + QWidget.__init__( self, parent, name ) + + self.setMinimumSize( 30, 30 ) + self.r1 = self.randomRect() + self.r2 = self.randomRect() + self.r3 = self.randomRect() + + self.t = DynamicTip( self ) + + QToolTip.add( self, self.r3, "this color is called red" ) # <- helpful + + def paintEvent( self, e ): + + p = QPainter( self ) + + # I try to be efficient here, and repaint only what's needed + if e.rect().intersects( self.r1 ): + p.setBrush( Qt.blue ) + p.drawRect( self.r1 ) + + if e.rect().intersects( self.r2 ): + p.setBrush( Qt.blue ) + p.drawRect( self.r2 ) + + if e.rect().intersects( self.r3 ): + p.setBrush( Qt.red ) + p.drawRect( self.r3 ) + + def mousePressEvent( self, e ): + + if self.r1.contains( e.pos() ): + self.r1 = self.randomRect() + if self.r2.contains( e.pos() ): + self.r2 = self.randomRect() + self.repaint() + + def resizeEvent( self, e ): + + if not self.rect().contains( self.r1 ): + self.r1 = self.randomRect() + if not self.rect().contains( self.r2 ): + self.r2 = self.randomRect() + + def randomRect( self ): + return QRect( random() * (self.width() - 20), random() * (self.height() - 20), 20, 20 ) + + def tip( self, p ): + + if self.r1.contains( p ): + return self.r1 + elif self.r2.contains( p ): + return self.r2 + else: + return QRect( 0,0, -1,-1 ) + + def __del__( self ): + del self.t + self.t = None + +def main( args ): + a = QApplication( args ) + + mw = TellMe() + mw.setCaption( "Qt Example - Dynamic Tool Tips" ) + a.setMainWidget( mw ) + mw.show() + + a.exec_loop() + +if __name__=="__main__": + main(sys.argv) diff --git a/examples3/trolltech.bmp b/examples3/trolltech.bmp Binary files differnew file mode 100644 index 0000000..220861e --- /dev/null +++ b/examples3/trolltech.bmp diff --git a/examples3/trolltech.gif b/examples3/trolltech.gif Binary files differnew file mode 100644 index 0000000..f674369 --- /dev/null +++ b/examples3/trolltech.gif diff --git a/examples3/tt-logo.png b/examples3/tt-logo.png Binary files differnew file mode 100644 index 0000000..a0d9e34 --- /dev/null +++ b/examples3/tt-logo.png diff --git a/examples3/tut1.py b/examples3/tut1.py new file mode 100755 index 0000000..982e984 --- /dev/null +++ b/examples3/tut1.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +# Qt tutorial 1. + +import sys +import qt + + +a = qt.QApplication(sys.argv) + +hello = qt.QPushButton("Hello world!", None) +hello.resize(100, 30) + +a.setMainWidget(hello) +hello.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut10.py b/examples3/tut10.py new file mode 100755 index 0000000..182d04d --- /dev/null +++ b/examples3/tut10.py @@ -0,0 +1,145 @@ +#!/usr/bin/env python + +# Qt tutorial 10. + +import sys +import qt + + +class LCDRange(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.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(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.ang = 45 + self.f = 0 + self.setPalette(qt.QPalette(qt.QColor(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(qt.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(qt.PYSIGNAL("forceChanged(int)"), (self.f, )) + + def paintEvent(self, ev): + if not ev.rect().intersects(self.cannonRect()): + return + + cr = self.cannonRect() + pix = qt.QPixmap(cr.size()) + pix.fill(self, cr.topLeft()) + + p = qt.QPainter(pix) + + p.setBrush(qt.Qt.blue) + p.setPen(qt.Qt.NoPen) + + p.translate(0, pix.height() - 1) + p.drawPie(qt.QRect(-35, -35, 70, 70), 0, 90 * 16) + p.rotate(-self.ang) + p.drawRect(qt.QRect(33, -4, 15, 8)) + p.end() + + p.begin(self) + p.drawPixmap(cr.topLeft(), pix) + + def cannonRect(self): + r = qt.QRect(0, 0, 50, 50) + r.moveBottomLeft(self.rect().bottomLeft()) + return r + + def sizePolicy(self): + return qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) + + +class MyWidget(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + quit = qt.QPushButton("&Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.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, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setAngle) + self.connect(self.cannonField, qt.PYSIGNAL("angleChanged(int)"), self.angle.setValue) + + self.connect(self.force, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setForce) + self.connect(self.cannonField, qt.PYSIGNAL("forceChanged(int)"), self.force.setValue) + + grid = qt.QGridLayout(self, 2, 2, 10) + + grid.addWidget(quit, 0, 0) + grid.addWidget(self.cannonField, 1, 1) + grid.setColStretch(1, 10) + + leftBox = qt.QVBoxLayout() + + grid.addLayout(leftBox, 1, 0) + + leftBox.addWidget(self.angle) + leftBox.addWidget(self.force) + + self.angle.setValue(60) + self.force.setValue(25) + self.angle.setFocus() + + +qt.QApplication.setColorSpec(qt.QApplication.CustomColor) +a = qt.QApplication(sys.argv) + +w = MyWidget() +w.setGeometry(100, 100, 500, 355) +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut11.py b/examples3/tut11.py new file mode 100755 index 0000000..95d5066 --- /dev/null +++ b/examples3/tut11.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python + +# Qt tutorial 11. + +import sys +import math +import qt + + +class LCDRange(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.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(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.ang = 45 + self.f = 0 + self.timerCount = 0 + + self.autoShootTimer = qt.QTimer(self, "movement handler") + self.connect(self.autoShootTimer, qt.SIGNAL("timeout()"), self.moveShot) + + self.shoot_ang = 0 + self.shoot_f = 0 + + self.setPalette(qt.QPalette(qt.QColor(250, 250, 200))) + + self.barrelRect = qt.QRect(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(qt.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(qt.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 = qt.QRegion(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(qt.QRegion(shotR)) + + self.repaint(r) + + def paintEvent(self, ev): + updateR = ev.rect() + p = qt.QPainter(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(qt.Qt.black) + p.setPen(qt.Qt.NoPen) + p.drawRect(self.shotRect()) + + def paintCannon(self, p): + cr = self.cannonRect() + pix = qt.QPixmap(cr.size()) + pix.fill(self, cr.topLeft()) + + tmp = qt.QPainter(pix) + tmp.setBrush(qt.Qt.blue) + tmp.setPen(qt.Qt.NoPen) + + tmp.translate(0, pix.height() - 1) + tmp.drawPie(qt.QRect(-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 = qt.QRect(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 = qt.QRect(0, 0, 6, 6) + r.moveCenter(qt.QPoint(x, self.height() - 1 - y)) + return r + + def sizePolicy(self): + return qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) + + +class MyWidget(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + quit = qt.QPushButton("&Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.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, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setAngle) + self.connect(self.cannonField, qt.PYSIGNAL("angleChanged(int)"), self.angle.setValue) + + self.connect(self.force, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setForce) + self.connect(self.cannonField, qt.PYSIGNAL("forceChanged(int)"), self.force.setValue) + + shoot = qt.QPushButton("&Shoot", self, "shoot") + shoot.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(shoot, qt.SIGNAL("clicked()"), self.cannonField.shoot) + + grid = qt.QGridLayout(self, 2, 2, 10) + + grid.addWidget(quit, 0, 0) + grid.addWidget(self.cannonField, 1, 1) + grid.setColStretch(1, 10) + + leftBox = qt.QVBoxLayout() + grid.addLayout(leftBox, 1, 0) + leftBox.addWidget(self.angle) + leftBox.addWidget(self.force) + + topBox = qt.QHBoxLayout() + grid.addLayout(topBox, 0, 1) + topBox.addWidget(shoot) + topBox.addStretch(1) + + self.angle.setValue(60) + self.force.setValue(25) + self.angle.setFocus() + + +qt.QApplication.setColorSpec(qt.QApplication.CustomColor) +a = qt.QApplication(sys.argv) + +w = MyWidget() +w.setGeometry(100, 100, 500, 355) +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut12.py b/examples3/tut12.py new file mode 100755 index 0000000..818afd3 --- /dev/null +++ b/examples3/tut12.py @@ -0,0 +1,253 @@ +#!/usr/bin/env python + +# Qt tutorial 12. + +import sys +import math +import random +import qt + + +class LCDRange(qt.QVBox): + def __init__(self, s=None, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + + self.label = qt.QLabel(" ", self, "label") + self.label.setAlignment(qt.Qt.AlignCenter) + + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.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(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.ang = 45 + self.f = 0 + self.timerCount = 0 + + self.autoShootTimer = qt.QTimer(self, "movement handler") + self.connect(self.autoShootTimer, qt.SIGNAL("timeout()"), self.moveShot) + + self.shoot_ang = 0 + self.shoot_f = 0 + self.target = qt.QPoint(0, 0) + + self.setPalette(qt.QPalette(qt.QColor(250, 250, 200))) + + self.barrelRect = qt.QRect(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(qt.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(qt.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 = qt.QRegion(self.targetRect()) + self.target = qt.QPoint(random.randint(200, 390), random.randint(10, 265)) + self.repaint(r.unite(qt.QRegion(self.targetRect()))) + + def moveShot(self): + r = qt.QRegion(self.shotRect()) + self.timerCount = self.timerCount + 1 + + shotR = self.shotRect() + + if shotR.intersects(self.targetRect()): + self.autoShootTimer.stop() + self.emit(qt.PYSIGNAL("hit()"), ()) + elif shotR.x() > self.width() or shotR.y() > self.height(): + self.autoShootTimer.stop() + self.emit(qt.PYSIGNAL("missed()"), ()) + else: + r = r.unite(qt.QRegion(shotR)) + + self.repaint(r) + + def paintEvent(self, ev): + updateR = ev.rect() + p = qt.QPainter(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(qt.Qt.black) + p.setPen(qt.Qt.NoPen) + p.drawRect(self.shotRect()) + + def paintTarget(self, p): + p.setBrush(qt.Qt.red) + p.setPen(qt.Qt.black) + p.drawRect(self.targetRect()) + + def paintCannon(self, p): + cr = self.cannonRect() + pix = qt.QPixmap(cr.size()) + pix.fill(self, cr.topLeft()) + + tmp = qt.QPainter(pix) + tmp.setBrush(qt.Qt.blue) + tmp.setPen(qt.Qt.NoPen) + + tmp.translate(0, pix.height() - 1) + tmp.drawPie(qt.QRect(-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 = qt.QRect(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 = qt.QRect(0, 0, 6, 6) + r.moveCenter(qt.QPoint(x, self.height() - 1 - y)) + return r + + def targetRect(self): + r = qt.QRect(0, 0, 20, 10) + r.moveCenter(qt.QPoint(self.target.x(), self.height() - 1 - self.target.y())) + return r + + def sizePolicy(self): + return qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) + + +class MyWidget(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + quit = qt.QPushButton("&Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.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, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setAngle) + self.connect(self.cannonField, qt.PYSIGNAL("angleChanged(int)"), self.angle.setValue) + + self.connect(self.force, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setForce) + self.connect(self.cannonField, qt.PYSIGNAL("forceChanged(int)"), self.force.setValue) + + shoot = qt.QPushButton("&Shoot", self, "shoot") + shoot.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(shoot, qt.SIGNAL("clicked()"), self.cannonField.shoot) + + grid = qt.QGridLayout(self, 2, 2, 10) + + grid.addWidget(quit, 0, 0) + grid.addWidget(self.cannonField, 1, 1) + grid.setColStretch(1, 10) + + leftBox = qt.QVBoxLayout() + grid.addLayout(leftBox, 1, 0) + leftBox.addWidget(self.angle) + leftBox.addWidget(self.force) + + topBox = qt.QHBoxLayout() + grid.addLayout(topBox, 0, 1) + topBox.addWidget(shoot) + topBox.addStretch(1) + + self.angle.setValue(60) + self.force.setValue(25) + self.angle.setFocus() + + +qt.QApplication.setColorSpec(qt.QApplication.CustomColor) +a = qt.QApplication(sys.argv) + +w = MyWidget() +w.setGeometry(100, 100, 500, 355) +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut13.py b/examples3/tut13.py new file mode 100755 index 0000000..a973ea7 --- /dev/null +++ b/examples3/tut13.py @@ -0,0 +1,330 @@ +#!/usr/bin/env python + +# Qt tutorial 13. + +import sys +import math +import random +import qt + + +class LCDRange(qt.QWidget): + def __init__(self, s=None, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + + self.label = qt.QLabel(" ", self, "label") + self.label.setAlignment(qt.Qt.AlignCenter) + + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.PYSIGNAL("valueChanged(int)")) + + self.setFocusProxy(self.slider) + + l = qt.QVBoxLayout(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(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.ang = 45 + self.f = 0 + self.timerCount = 0 + + self.autoShootTimer = qt.QTimer(self, "movement handler") + self.connect(self.autoShootTimer, qt.SIGNAL("timeout()"), self.moveShot) + + self.shoot_ang = 0 + self.shoot_f = 0 + self.target = qt.QPoint(0, 0) + self.gameEnded = 0 + + self.setPalette(qt.QPalette(qt.QColor(250, 250, 200))) + + self.barrelRect = qt.QRect(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(qt.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(qt.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(qt.PYSIGNAL("canShoot(bool)"), (0, )) + + def newTarget(self): + r = qt.QRegion(self.targetRect()) + self.target = qt.QPoint(random.randint(200, 390), random.randint(10, 265)) + self.repaint(r.unite(qt.QRegion(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(qt.PYSIGNAL("canShoot(bool)"), (1, )) + + def moveShot(self): + r = qt.QRegion(self.shotRect()) + self.timerCount = self.timerCount + 1 + + shotR = self.shotRect() + + if shotR.intersects(self.targetRect()): + self.autoShootTimer.stop() + self.emit(qt.PYSIGNAL("hit()"), ()) + self.emit(qt.PYSIGNAL("canShoot(bool)"), (1, )) + elif shotR.x() > self.width() or shotR.y() > self.height(): + self.autoShootTimer.stop() + self.emit(qt.PYSIGNAL("missed()"), ()) + self.emit(qt.PYSIGNAL("canShoot(bool)"), (1, )) + else: + r = r.unite(qt.QRegion(shotR)) + + self.repaint(r) + + def paintEvent(self, ev): + updateR = ev.rect() + p = qt.QPainter(self) + + if self.gameEnded: + p.setPen(qt.Qt.black) + p.setFont(qt.QFont("Courier", 48, qt.QFont.Bold)) + p.drawText(self.rect(), qt.Qt.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(qt.Qt.black) + p.setPen(qt.Qt.NoPen) + p.drawRect(self.shotRect()) + + def paintTarget(self, p): + p.setBrush(qt.Qt.red) + p.setPen(qt.Qt.black) + p.drawRect(self.targetRect()) + + def paintCannon(self, p): + cr = self.cannonRect() + pix = qt.QPixmap(cr.size()) + pix.fill(self, cr.topLeft()) + + tmp = qt.QPainter(pix) + tmp.setBrush(qt.Qt.blue) + tmp.setPen(qt.Qt.NoPen) + + tmp.translate(0, pix.height() - 1) + tmp.drawPie(qt.QRect(-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 = qt.QRect(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 = qt.QRect(0, 0, 6, 6) + r.moveCenter(qt.QPoint(x, self.height() - 1 - y)) + return r + + def targetRect(self): + r = qt.QRect(0, 0, 20, 10) + r.moveCenter(qt.QPoint(self.target.x(), self.height() - 1 - self.target.y())) + return r + + def isShooting(self): + return self.autoShootTimer.isActive() + + def sizePolicy(self): + return qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) + + +class GameBoard(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + quit = qt.QPushButton("&Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.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, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setAngle) + self.connect(self.cannonField, qt.PYSIGNAL("angleChanged(int)"), self.angle.setValue) + + self.connect(self.force, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setForce) + self.connect(self.cannonField, qt.PYSIGNAL("forceChanged(int)"), self.force.setValue) + + self.connect(self.cannonField, qt.PYSIGNAL("hit()"), self.hit) + self.connect(self.cannonField, qt.PYSIGNAL("missed()"), self.missed) + + self.shoot = qt.QPushButton("&Shoot", self, "shoot") + self.shoot.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(self.shoot, qt.SIGNAL("clicked()"), self.fire) + self.connect(self.cannonField, qt.PYSIGNAL("canShoot(bool)"), self.shoot, qt.SLOT("setEnabled(bool)")) + + restart = qt.QPushButton("&New Game", self, "newgame") + restart.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(restart, qt.SIGNAL("clicked()"), self.newGame) + + self.hits = qt.QLCDNumber(2, self, "hits") + self.shotsLeft = qt.QLCDNumber(2, self, "shotsleft") + hitsL = qt.QLabel("HITS", self, "hitsLabel") + shotsLeftL = qt.QLabel("SHOTS LEFT", self, "shotsleftLabel") + + grid = qt.QGridLayout(self, 2, 2, 10) + grid.addWidget(quit, 0, 0) + grid.addWidget(self.cannonField, 1, 1) + grid.setColStretch(1, 10) + + leftBox = qt.QVBoxLayout() + grid.addLayout(leftBox, 1, 0) + leftBox.addWidget(self.angle) + leftBox.addWidget(self.force) + + topBox = qt.QHBoxLayout() + 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() + + +qt.QApplication.setColorSpec(qt.QApplication.CustomColor) +a = qt.QApplication(sys.argv) + +gb = GameBoard() +gb.setGeometry(100, 100, 500, 355) +a.setMainWidget(gb) +gb.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut14.py b/examples3/tut14.py new file mode 100755 index 0000000..f046757 --- /dev/null +++ b/examples3/tut14.py @@ -0,0 +1,378 @@ +#!/usr/bin/env python + +# Qt tutorial 14. + +import sys +import math +import random +import qt + + +class LCDRange(qt.QWidget): + def __init__(self, s=None, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + + self.label = qt.QLabel(" ", self, "label") + self.label.setAlignment(qt.Qt.AlignCenter) + + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.PYSIGNAL("valueChanged(int)")) + + self.setFocusProxy(self.slider) + + l = qt.QVBoxLayout(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(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.ang = 45 + self.f = 0 + self.timerCount = 0 + + self.autoShootTimer = qt.QTimer(self, "movement handler") + self.connect(self.autoShootTimer, qt.SIGNAL("timeout()"), self.moveShot) + + self.shoot_ang = 0 + self.shoot_f = 0 + self.target = qt.QPoint(0, 0) + self.gameEnded = 0 + self.barrelPressed = 0 + + self.setPalette(qt.QPalette(qt.QColor(250, 250, 200))) + + self.barrelRect = qt.QRect(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(qt.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(qt.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(qt.PYSIGNAL("canShoot(bool)"), (0, )) + + def newTarget(self): + r = qt.QRegion(self.targetRect()) + self.target = qt.QPoint(random.randint(200, 390), random.randint(10, 265)) + self.repaint(r.unite(qt.QRegion(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(qt.PYSIGNAL("canShoot(bool)"), (1, )) + + def moveShot(self): + r = qt.QRegion(self.shotRect()) + self.timerCount = self.timerCount + 1 + + shotR = self.shotRect() + + if shotR.intersects(self.targetRect()): + self.autoShootTimer.stop() + self.emit(qt.PYSIGNAL("hit()"), ()) + self.emit(qt.PYSIGNAL("canShoot(bool)"), (1, )) + elif shotR.x() > self.width() or shotR.y() > self.height() or shotR.intersects(self.barrierRect()): + self.autoShootTimer.stop() + self.emit(qt.PYSIGNAL("missed()"), ()) + self.emit(qt.PYSIGNAL("canShoot(bool)"), (1, )) + else: + r = r.unite(qt.QRegion(shotR)) + + self.repaint(r) + + def mousePressEvent(self, ev): + if ev.button() != qt.Qt.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() == qt.Qt.LeftButton: + self.barrelPressed = 0 + + def paintEvent(self, ev): + updateR = ev.rect() + p = qt.QPainter(self) + + if self.gameEnded: + p.setPen(qt.Qt.black) + p.setFont(qt.QFont("Courier", 48, qt.QFont.Bold)) + p.drawText(self.rect(), qt.Qt.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(qt.Qt.black) + p.setPen(qt.Qt.NoPen) + p.drawRect(self.shotRect()) + + def paintTarget(self, p): + p.setBrush(qt.Qt.red) + p.setPen(qt.Qt.black) + p.drawRect(self.targetRect()) + + def paintBarrier(self, p): + p.setBrush(qt.Qt.yellow) + p.setPen(qt.Qt.black) + p.drawRect(self.barrierRect()) + + def paintCannon(self, p): + cr = self.cannonRect() + pix = qt.QPixmap(cr.size()) + pix.fill(self, cr.topLeft()) + + tmp = qt.QPainter(pix) + tmp.setBrush(qt.Qt.blue) + tmp.setPen(qt.Qt.NoPen) + + tmp.translate(0, pix.height() - 1) + tmp.drawPie(qt.QRect(-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 = qt.QRect(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 = qt.QRect(0, 0, 6, 6) + r.moveCenter(qt.QPoint(x, self.height() - 1 - y)) + return r + + def targetRect(self): + r = qt.QRect(0, 0, 20, 10) + r.moveCenter(qt.QPoint(self.target.x(), self.height() - 1 - self.target.y())) + return r + + def barrierRect(self): + return qt.QRect(145, self.height() - 100, 15, 100) + + def barrelHit(self, p): + mtx = qt.QWMatrix() + 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 qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) + + +class GameBoard(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + quit = qt.QPushButton("&Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.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 = qt.QVBox(self, "cannonFrame") + box.setFrameStyle(qt.QFrame.WinPanel | qt.QFrame.Sunken) + + self.cannonField = CannonField(box, "cannonField") + + self.connect(self.angle, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setAngle) + self.connect(self.cannonField, qt.PYSIGNAL("angleChanged(int)"), self.angle.setValue) + + self.connect(self.force, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setForce) + self.connect(self.cannonField, qt.PYSIGNAL("forceChanged(int)"), self.force.setValue) + + self.connect(self.cannonField, qt.PYSIGNAL("hit()"), self.hit) + self.connect(self.cannonField, qt.PYSIGNAL("missed()"), self.missed) + + self.shoot = qt.QPushButton("&Shoot", self, "shoot") + self.shoot.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(self.shoot, qt.SIGNAL("clicked()"), self.fire) + self.connect(self.cannonField, qt.PYSIGNAL("canShoot(bool)"), self.shoot, qt.SLOT("setEnabled(bool)")) + + restart = qt.QPushButton("&New Game", self, "newgame") + restart.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(restart, qt.SIGNAL("clicked()"), self.newGame) + + self.hits = qt.QLCDNumber(2, self, "hits") + self.shotsLeft = qt.QLCDNumber(2, self, "shotsleft") + hitsL = qt.QLabel("HITS", self, "hitsLabel") + shotsLeftL = qt.QLabel("SHOTS LEFT", self, "shotsleftLabel") + + accel = qt.QAccel(self) + accel.connectItem(accel.insertItem(qt.Qt.Key_Enter), self.fire) + accel.connectItem(accel.insertItem(qt.Qt.Key_Return), self.fire) + accel.connectItem(accel.insertItem(qt.Qt.CTRL + qt.Qt.Key_Q), qt.qApp, qt.SLOT("quit()")) + + grid = qt.QGridLayout(self, 2, 2, 10) + grid.addWidget(quit, 0, 0) + grid.addWidget(box, 1, 1) + grid.setColStretch(1, 10) + + leftBox = qt.QVBoxLayout() + grid.addLayout(leftBox, 1, 0) + leftBox.addWidget(self.angle) + leftBox.addWidget(self.force) + + topBox = qt.QHBoxLayout() + 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() + + +qt.QApplication.setColorSpec(qt.QApplication.CustomColor) +a = qt.QApplication(sys.argv) + +gb = GameBoard() +gb.setGeometry(100, 100, 500, 355) +a.setMainWidget(gb) +gb.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut2.py b/examples3/tut2.py new file mode 100755 index 0000000..8b6a076 --- /dev/null +++ b/examples3/tut2.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +# Qt tutorial 2. + +import sys +import qt + + +a = qt.QApplication(sys.argv) + +quit = qt.QPushButton("Quit", None) +quit.resize(75, 30) +quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + +qt.QObject.connect(quit, qt.SIGNAL("clicked()"), a, qt.SLOT("quit()")) + +a.setMainWidget(quit) +quit.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut3.py b/examples3/tut3.py new file mode 100755 index 0000000..9b73954 --- /dev/null +++ b/examples3/tut3.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +# Qt tutorial 3. + +import sys +import qt + + +a = qt.QApplication(sys.argv) + +box = qt.QVBox() +box.resize(200, 120) + +quit = qt.QPushButton("Quit", box) +quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + +qt.QObject.connect(quit, qt.SIGNAL("clicked()"), a, qt.SLOT("quit()")) + +a.setMainWidget(box) +box.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut4.py b/examples3/tut4.py new file mode 100755 index 0000000..9ad05c7 --- /dev/null +++ b/examples3/tut4.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +# Qt tutorial 4. + +import sys +import qt + + +class MyWidget(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.setMinimumSize(200, 120) + self.setMaximumSize(200, 120) + + quit = qt.QPushButton("Quit", self, "quit") + quit.setGeometry(62, 40, 75, 30) + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.SLOT("quit()")) + + +a = qt.QApplication(sys.argv) + +w = MyWidget() +w.setGeometry(100, 100, 200, 120) +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut5.py b/examples3/tut5.py new file mode 100755 index 0000000..88a2447 --- /dev/null +++ b/examples3/tut5.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +# Qt tutorial 5. + +import sys +import qt + + +class MyWidget(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + quit = qt.QPushButton("Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.SLOT("quit()")) + + lcd = qt.QLCDNumber(2, self, "lcd") + + slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + slider.setRange(0, 99) + slider.setValue(0) + + self.connect(slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + + +a = qt.QApplication(sys.argv) + +w = MyWidget() +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut6.py b/examples3/tut6.py new file mode 100755 index 0000000..785edfe --- /dev/null +++ b/examples3/tut6.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +# Qt tutorial 6. + +import sys +import qt + + +class LCDRange(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + slider.setRange(0, 99) + slider.setValue(0) + self.connect(slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + + +class MyWidget(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + quit = qt.QPushButton("Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.SLOT("quit()")) + + grid = qt.QGrid(4, self) + + for c in range(4): + for r in range(4): + LCDRange(grid) + + +a = qt.QApplication(sys.argv) + +w = MyWidget() +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut7.py b/examples3/tut7.py new file mode 100755 index 0000000..400505e --- /dev/null +++ b/examples3/tut7.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# Qt tutorial 7. + +import sys +import qt + + +class LCDRange(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.PYSIGNAL("valueChanged(int)")) + + def value(self): + return self.slider.value() + + def setValue(self, value): + self.slider.setValue(value) + + +class MyWidget(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + quit = qt.QPushButton("Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.SLOT("quit()")) + + grid = qt.QGrid(4, self) + + self.lcdlist = [] + previous = None + + for r in range(4): + for c in range(4): + lr = LCDRange(grid) + + if previous: + self.connect(lr, qt.PYSIGNAL("valueChanged(int)"), previous.setValue) + + previous = lr + self.lcdlist.append(lr) + + +a = qt.QApplication(sys.argv) + +w = MyWidget() +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut8.py b/examples3/tut8.py new file mode 100755 index 0000000..f7dd156 --- /dev/null +++ b/examples3/tut8.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python + +# Qt tutorial 8. + +import sys +import qt + + +class LCDRange(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.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(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.ang = 45 + self.setPalette(qt.QPalette(qt.QColor(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(qt.PYSIGNAL("angleChanged(int)"), (self.ang, )) + + def paintEvent(self, ev): + p = qt.QPainter(self) + p.drawText(200, 200, "Angle = %d" % (self.ang)) + + def sizePolicy(self): + return qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) + + +class MyWidget(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + quit = qt.QPushButton("Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.SLOT("quit()")) + + self.angle = LCDRange(self, "angle") + self.angle.setRange(5, 70) + + self.cannonField = CannonField(self, "cannonField") + + self.connect(self.angle, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setAngle) + self.connect(self.cannonField, qt.PYSIGNAL("angleChanged(int)"), self.angle.setValue) + + grid = qt.QGridLayout(self, 2, 2, 10) + + grid.addWidget(quit, 0, 0) + grid.addWidget(self.angle, 1, 0, qt.Qt.AlignTop) + grid.addWidget(self.cannonField, 1, 1) + grid.setColStretch(1, 10) + + self.angle.setValue(60) + self.angle.setFocus() + + +a = qt.QApplication(sys.argv) + +w = MyWidget() +w.setGeometry(100, 100, 500, 355) +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/tut9.py b/examples3/tut9.py new file mode 100755 index 0000000..aba7ddc --- /dev/null +++ b/examples3/tut9.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python + +# Qt tutorial 9. + +import sys +import qt + + +class LCDRange(qt.QVBox): + def __init__(self, parent=None, name=None): + qt.QVBox.__init__(self, parent, name) + + lcd = qt.QLCDNumber(2, self, "lcd") + self.slider = qt.QSlider(qt.Qt.Horizontal, self, "slider") + self.slider.setRange(0, 99) + self.slider.setValue(0) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), lcd, qt.SLOT("display(int)")) + self.connect(self.slider, qt.SIGNAL("valueChanged(int)"), self, qt.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(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + self.ang = 45 + self.setPalette(qt.QPalette(qt.QColor(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(qt.PYSIGNAL("angleChanged(int)"), (self.ang, )) + + def paintEvent(self, ev): + p = qt.QPainter(self) + + p.setBrush(qt.Qt.blue) + p.setPen(qt.Qt.NoPen) + + p.translate(0, self.rect().bottom()) + p.drawPie(qt.QRect(-35, -35, 70, 70), 0, 90 * 16) + p.rotate(-self.ang) + p.drawRect(qt.QRect(33, -4, 15, 8)) + + def sizePolicy(self): + return qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) + + +class MyWidget(qt.QWidget): + def __init__(self, parent=None, name=None): + qt.QWidget.__init__(self, parent, name) + + quit = qt.QPushButton("&Quit", self, "quit") + quit.setFont(qt.QFont("Times", 18, qt.QFont.Bold)) + self.connect(quit, qt.SIGNAL("clicked()"), qt.qApp, qt.SLOT("quit()")) + + self.angle = LCDRange(self, "angle") + self.angle.setRange(5, 70) + + self.cannonField = CannonField(self, "cannonField") + + self.connect(self.angle, qt.PYSIGNAL("valueChanged(int)"), self.cannonField.setAngle) + self.connect(self.cannonField, qt.PYSIGNAL("angleChanged(int)"), self.angle.setValue) + + grid = qt.QGridLayout(self, 2, 2, 10) + + grid.addWidget(quit, 0, 0) + grid.addWidget(self.angle, 1, 0, qt.Qt.AlignTop) + grid.addWidget(self.cannonField, 1, 1) + grid.setColStretch(1, 10) + + self.angle.setValue(60) + self.angle.setFocus() + + +qt.QApplication.setColorSpec(qt.QApplication.CustomColor) +a = qt.QApplication(sys.argv) + +w = MyWidget() +w.setGeometry(100, 100, 500, 355) +a.setMainWidget(w) +w.show() +sys.exit(a.exec_loop()) diff --git a/examples3/webbrowser/mainwindow.py b/examples3/webbrowser/mainwindow.py new file mode 100644 index 0000000..6afdfc8 --- /dev/null +++ b/examples3/webbrowser/mainwindow.py @@ -0,0 +1,1097 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'mainwindow.ui' +# +# Created: Sun Dec 5 14:50:47 2004 +# by: The PyQt User Interface Compiler (pyuic) snapshot-20041203 +# +# WARNING! All changes made in this file will be lost! + + +from qt import * +from qtaxcontainer import QAxWidget + +image0_data = [ +"32 32 3 1", +". c None", +"a c #000080", +"# c #808080", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +".......#aaaaaaaaa...............", +"......#aaaaaaaaaaa.........a....", +".....#aaa.......aaa.......aa....", +"....#aaa.........aaaa....aaa....", +"....aaa...........aaaa..aaaa....", +"....aa..............aaaaaaaa....", +"....aa...............aaaaaaa....", +"....aa...............aaaaaaa....", +"....aa..............aaaaaaaa....", +"....aa.............aaaaaaaaa....", +"....#aa...........aaaaaaaaaa....", +".....#aa.........aaaaaaaaaaa....", +"......aa#.......................", +".......aa#......................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................" +] +image1_data = [ +"32 32 142 2", +"Qt c None", +"#O c #0010f7", +"#P c #0021ef", +"#R c #0021f7", +"#S c #0021ff", +"#T c #0029ff", +"ah c #0031ff", +"#N c #0829f7", +"#x c #0831ff", +"#C c #0839ff", +"#E c #1029e7", +"#r c #1039ff", +"#o c #1042ff", +"#Q c #1831de", +"ak c #1831e7", +"#k c #1842ff", +"#H c #184aff", +"aj c #2139e7", +"#s c #2142de", +"#G c #214aff", +".9 c #2152ff", +"#2 c #2939c6", +"ag c #2939d6", +"a# c #2942ce", +"#p c #2942de", +"#U c #2952ff", +"ae c #295aff", +"#y c #3152de", +".2 c #3152e7", +"#I c #315aff", +"#z c #3163ff", +"#1 c #394abd", +"#L c #394ade", +"#B c #3963ff", +"#w c #396bff", +"#V c #4252d6", +"#l c #4252de", +"#W c #4263ef", +"#q c #426bff", +".1 c #4273ff", +"#5 c #4a5ad6", +"#J c #4a73ff", +"#K c #4a7bff", +"ac c #4a84ff", +"ab c #5263c6", +".T c #5263ce", +".M c #5273d6", +".c c #5273e7", +".U c #527bde", +"#t c #527bf7", +"#A c #5284ff", +"#X c #5a63ad", +".V c #5a84ef", +"#F c #5a84ff", +"#v c #5a8cff", +"ad c #636bbd", +".e c #637bc6", +".W c #637bce", +".3 c #637bd6", +".Q c #6384de", +".5 c #638cef", +"#b c #638cff", +"#j c #6394ff", +"af c #6b73bd", +"#0 c #6b73c6", +".S c #6b84ce", +"#u c #6b94ff", +".C c #6b9cff", +"ai c #737bce", +".z c #7384b5", +".j c #7384c6", +"#6 c #738cce", +".4 c #738cd6", +".b c #739ce7", +".I c #73a5ff", +"#n c #73adff", +"#Z c #7b84b5", +".R c #7b8cbd", +".J c #7b94bd", +".n c #7ba5e7", +".P c #7badff", +"#c c #7bb5ff", +"#M c #84849c", +"#3 c #8484ad", +".i c #848cc6", +"al c #8494bd", +"aa c #849cc6", +".y c #84adff", +".O c #84b5ff", +"#a c #84bdff", +".t c #8c94ad", +".a c #8c94b5", +".D c #8c9cbd", +".m c #8c9cce", +".A c #8ca5ef", +".f c #8cadf7", +".H c #8cbdff", +"#D c #9494a5", +"#8 c #9494bd", +"#9 c #9494c6", +"a. c #949cbd", +".r c #94c6ff", +"#d c #94ceff", +"#4 c #9ca5ad", +"#7 c #9ca5b5", +".u c #9cbdf7", +".6 c #9cc6ff", +".0 c #9cceff", +".x c #9cd6ff", +".L c #a5a5b5", +"#Y c #a5a5bd", +"#e c #a5ceff", +"## c #a5d6ff", +".X c #adadb5", +".k c #adc6ff", +"#i c #add6ff", +".E c #b5b5b5", +".d c #b5b5bd", +".K c #b5bdc6", +".F c #b5ceff", +".N c #b5d6ff", +".B c #b5deff", +".s c #bdbdbd", +".# c #bdbdc6", +"#. c #bdd6ff", +".G c #bde7ff", +"#h c #c6e7ff", +"#f c #c6efff", +".w c #c6f7ff", +".h c #ced6ff", +".Y c #cee7ff", +".q c #ceefff", +".Z c #cef7ff", +".l c #d6efff", +".8 c #d6f7ff", +".o c #deefff", +".7 c #def7ff", +"#m c #deffff", +"#g c #e7ffff", +".v c #efffff", +".p c #f7ffff", +".g c #ffffff", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQt.#.a.b.c.aQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQt.d.e.f.g.h.iQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.d.j.k.g.g.l.mQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQt.a.n.o.g.p.q.r.mQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQt.s.t.u.g.g.v.w.x.y.mQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQt.z.A.g.g.v.B.x.r.C.DQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQt.E.a.F.g.g.v.G.r.H.H.I.JQtQtQtQtQtQtQtQtQtQt.s.s.K.K.KQtQt", +"QtQt.L.M.N.g.g.q.x.H.O.y.P.P.Q.LQtQtQt.s.s.K.a.R.S.T.U.V.V.Q.W.X", +"Qt.#.Q.Y.g.g.Z.0.O.y.P.P.P.P.1.2.3.4.S.e.c.5.f.6.N.l.7.8.Z.0.9.T", +".s.W#..g.p.Z###a.O.P.P.I.I.P#b#c#d#e.B#f#g.7.8.8.q#h#i.r.H#j#k#l", +".e#e.g#m.G#d.O.y.P.I.I.I.I.I.I.H.6####.0.r.H#a.O#c.I#n.I#j.1#o#p", +".5.p#f.x.0.O.y.P.I.I.I.I.I.I.I.I.I.I.I.I.I.I.I.I.I.C.C.C#b#q#r#s", +"#t##.r.H.O#c.P.I.I.I.I.I.I.C.I.C.C.I.C.I.C.C.C.C#u.C#j#j#v#w#x#p", +"#y#z#j.I.I.P.I.I.C.C.C.I.I.C.C#j#b#v#v#b#j#j#j#b#j#v#b#v#A#B#C#p", +"#D#E#k#q#A#j.C.I.C.I.C.C.C.I#F#G#k#k#H#G#I#B.1.1#J#K#K.1#q#z#x#L", +".s#M#N#r#z#K#b#u.C#u.C.C.I.I#B#O#P#Q#E#P#R#S#T#x#r#r#H.9#U#G#T#V", +"QtQt.z#N#r#I.1#v#j#u#j.C#u.I#W#X#D.s#Y#D#Z#0#1#2#Q#P#P#N#N#T#E#3", +"QtQt.s#4#5#x#H#B#K#v#j#j#j#j#6QtQtQtQtQtQtQt.s.s.d.X#7#8#9a..X.s", +"QtQtQtQt.da##S#k#z#J#v#b#j#vaaQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQt.Eab#x#o#I#K#v#vac.iQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQt.sad#E#rae#q#K#wafQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQt.#.Lagah#k#U#kafQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQt#4#Q#T#xahaiQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQt#4adajakalQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt" +] +image2_data = [ +"32 32 142 2", +"Qt c None", +"#Y c #0018e7", +"aa c #0018ef", +"#E c #0018ff", +"#Q c #0021ef", +"#K c #0021ff", +"a# c #0029ff", +"a. c #0829ff", +"#P c #0831ff", +"#4 c #1021d6", +"#R c #1021de", +"#L c #1029d6", +"#V c #1029e7", +"#n c #1039f7", +"#W c #1039ff", +"#O c #1042ff", +"ah c #1831ce", +"#y c #1842ff", +"aj c #2131c6", +"#S c #2131ce", +"#z c #2139de", +".0 c #2142de", +"ai c #2142e7", +".t c #214aef", +"#D c #214aff", +".x c #2152ff", +"al c #2939de", +"#d c #294ae7", +"#I c #2952ff", +"#J c #295aff", +"#T c #3142bd", +"#N c #315aff", +"#s c #3163ff", +"#F c #394ac6", +"#G c #3952d6", +"ag c #395ae7", +".B c #3963f7", +"ae c #3963ff", +".g c #396bff", +"#U c #424ab5", +"#2 c #4252b5", +".J c #425ace", +"#A c #4263de", +".b c #426be7", +"#p c #426bef", +"#x c #426bff", +".n c #4273ff", +".o c #4a63ce", +"#t c #4a6be7", +".Q c #4a73de", +"#3 c #4a73ff", +"#C c #4a7bff", +"#Z c #525abd", +".1 c #526bbd", +".W c #526bc6", +".R c #526bce", +".P c #527be7", +"#w c #5284ff", +"#m c #528cff", +"ac c #5a63bd", +"ak c #5a6bbd", +".O c #5a7bf7", +"#H c #5a84ff", +"#9 c #5a8cff", +"af c #636bb5", +".h c #636bbd", +"ab c #6384ef", +"#v c #638cff", +".w c #6394ff", +".s c #639cff", +"#M c #6b73b5", +".C c #6b73bd", +"#u c #6b9cff", +".c c #737bb5", +".S c #7384ce", +".N c #738ce7", +".a c #7394de", +".8 c #7394ef", +"#8 c #739cf7", +"#B c #739cff", +".A c #73a5ff", +"#0 c #7b84b5", +".T c #7b8cbd", +".9 c #7b94c6", +"#. c #7b94d6", +".7 c #7ba5ff", +".X c #7badff", +".I c #7bb5ff", +"#5 c #848ca5", +".y c #848cad", +".M c #8494b5", +"## c #849cd6", +"#c c #84adff", +".G c #84b5ff", +".Z c #84bdff", +"#o c #8c8cad", +"#a c #8ca5ce", +".Y c #8cb5ff", +".H c #8cbdff", +"#1 c #9494a5", +".U c #9494ad", +"#7 c #949cad", +"#b c #94ade7", +".z c #94c6ff", +".v c #94ceff", +".j c #9c9cad", +".u c #9ca5ad", +"#r c #9cc6ff", +".m c #9cceff", +".d c #a5a5a5", +"#6 c #a5a5ad", +".V c #a5a5b5", +".K c #a5adb5", +".2 c #a5ceff", +".r c #a5d6ff", +".L c #adadad", +".i c #adadb5", +".p c #adadbd", +".q c #addeff", +"#e c #ade7ff", +"#X c #b5b5b5", +".D c #b5b5bd", +".E c #b5b5c6", +".F c #b5bdc6", +".f c #b5deff", +"#q c #b5efff", +".# c #bdbdbd", +"ad c #bdbdc6", +".6 c #bddeff", +"#i c #bde7ff", +"#h c #bdefff", +"#g c #c6f7ff", +"#l c #cee7ff", +"#j c #cef7ff", +"#f c #ceffff", +".k c #d6efff", +"#k c #d6f7ff", +".l c #d6ffff", +".e c #deefff", +".5 c #e7ffff", +".4 c #efffff", +".3 c #f7ffff", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.#.a.b.c.#QtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.d.e.f.g.h.iQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.j.k.l.m.n.o.pQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.d.f.q.r.m.s.t.cQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.u.q.v.m.r.m.w.x.y.#QtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.u.z.z.z.z.m.m.A.B.C.DQtQtQtQt", +"QtQt.#.E.F.#.#QtQtQtQtQtQtQtQtQtQt.j.G.H.z.H.z.m.m.I.n.J.KQtQtQt", +".L.M.N.O.P.Q.R.S.T.U.E.#.#QtQtQt.V.W.X.H.Y.H.H.z.z.z.Z.g.0.VQtQt", +".1.2.3.4.5.k.6.2.Y.7.8.a.9#.###a#b.Y.G.G.G.G.Y.G.Y.H.z#c.n#d.u.#", +".b#e#f#g#h#i.f#h#g#g#j#k#k#k.e.4.4#l#c.X.G.G.G.G.G.G.G.H.H#m#n#o", +"#p.m#q.r.m.m.m.z#r.m.z.m.r.q.q.q.m.H.G.G.X#c.G.G.G.X.X.X.X.7#s.J", +"#t.v.q.m.z.H.H.H.H.H.Z.Y.G.G.G.G.G.G.G.X#c.I#c.X.X.X.A.A#u#u.n#d", +"#t.H.r.z.Y.G#c.X.X.X.7.X.X.X.X.X.X.X.X.X.X.X.X.X.7.A#u#v#w#x#y#z", +"#A.I.m.H.X.X.X.A.A#B.A#B#u#u#u#u#B.X#c.X.X.X.X.A.A#u.w#C.g#D#E#F", +"#G.s.G.A.w#v#H#w#C.n#x#s#I#y#y#y#J#H.X.7.X.X.7.A#u.w#w#J#y#K#L.U", +"#M.x.n#N#D#O#P#K#K#Q#Q#R#S#T#U#U#V#W.A.X.A.A#B#u.w.n#D#P#E#L.VQt", +"#X.h#V#Q#Y#R#S#U#Z#0#1.p.#.#.#.#.V#2.s.7.A#u#u.w#3#D#P#E#4#5QtQt", +"QtQt#6#1#7.D.#.#QtQtQtQtQtQtQtQtQt#6#8#B#u.w#9#s#ya.#E#F.V.#QtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.#.8#9#H#w#s#Wa#aa#2#XQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.#ab#w#C#N#W#K#Eac.#QtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtad.Pae#J#Wa##Vaf#XQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.#ag#W#P#Eah#6QtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.#ai#K#Eaj.jQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.#akalak.iQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt" +] +image3_data = [ +"25 25 2 1", +"# c #000000", +". c #ffffff", +".........................", +".........................", +".........................", +".........######..........", +".......##########........", +"......####....####.......", +".....###........###......", +"....#####........###.....", +"....##.###........##.....", +"...###..###.......###....", +"...##....###.......##....", +"...##.....###......##....", +"...##......###.....##....", +"...##.......###....##....", +"...###.......###..###....", +"....##........###.##.....", +"....###........#####.....", +".....###........###......", +"......####....####.......", +".......##########........", +".........######..........", +".........................", +".........................", +".........................", +"........................." +] +image4_data = [ +"32 32 3 1", +". c None", +"# c #000080", +"a c #808080", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"...............#########a.......", +"....#.........###########a......", +"....##.......###.......###a.....", +"....###....####.........###a....", +"....####..####...........###....", +"....########..............##....", +"....#######...............##....", +"....#######...............##....", +"....########..............##....", +"....#########.............##....", +"....##########...........##a....", +"....###########.........##a.....", +".......................a##......", +"......................a##.......", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................", +"................................" +] +image5_data = [ +"32 32 211 2", +"Qt c None", +"aJ c #000000", +"#W c #080800", +"#N c #100800", +"#V c #101000", +"#E c #101008", +"#M c #181000", +"#L c #181800", +"#D c #181808", +"#F c #181810", +"as c #211800", +"#K c #211808", +"#J c #212110", +"#G c #212118", +"#q c #212121", +"an c #292100", +"#I c #292110", +"aN c #292910", +"#H c #292918", +"#y c #292921", +"aF c #312900", +"#C c #312918", +"#i c #312929", +".0 c #313131", +"#7 c #393100", +"#U c #393108", +"aG c #393931", +".M c #393939", +"#u c #423939", +"#c c #424a42", +"aE c #4a4200", +"aY c #4a4210", +".V c #4a4239", +"#B c #4a4a39", +".m c #4a4a42", +"aP c #4a5218", +".G c #4a5252", +".z c #4a5a52", +"aO c #524200", +"am c #524a00", +"#T c #524a08", +"#p c #524a4a", +".s c #525252", +"#a c #525a52", +".7 c #52635a", +"#b c #526363", +"az c #5a4a00", +"#6 c #5a5208", +"aw c #5a5210", +".Z c #5a524a", +".L c #5a5a52", +".y c #5a5a5a", +".F c #5a635a", +"#S c #635208", +"ax c #635a10", +".U c #635a52", +".r c #635a5a", +"aZ c #636321", +"## c #63635a", +".A c #636363", +"#h c #636b6b", +"aL c #637329", +"af c #6b5a00", +".6 c #6b635a", +"#o c #6b6363", +".E c #6b6b63", +"a4 c #6b7321", +"aS c #6b7329", +"aR c #6b7331", +"aX c #736300", +"al c #736308", +"#R c #736b10", +".T c #736b63", +"a5 c #737329", +".i c #73736b", +".K c #737373", +"a7 c #737b29", +"#g c #737b73", +"a9 c #7b7318", +"#A c #7b7373", +"a8 c #7b7b21", +"aV c #7b7b29", +"aQ c #7b7b5a", +".J c #7b7b73", +".1 c #7b7b7b", +"b# c #7b8431", +"a3 c #7b844a", +".8 c #7b847b", +"ay c #847308", +"#5 c #847310", +"aT c #847b21", +"b. c #847b29", +".S c #847b73", +".d c #847b7b", +"aW c #848421", +"a1 c #848429", +"a0 c #848431", +"bq c #84844a", +".H c #848484", +"ae c #8c7b08", +"ak c #8c7b10", +"#j c #8c8484", +"ba c #8c8c63", +"a2 c #8c8c7b", +".x c #8c8c84", +".2 c #8c948c", +".9 c #8cada5", +"aC c #947b08", +".Y c #947b73", +"aK c #948c10", +"#Q c #948c18", +"a6 c #948c29", +"#m c #948c84", +"bp c #949442", +"aH c #949484", +".D c #94948c", +".n c #949494", +"bn c #949c4a", +"bl c #949c5a", +"bj c #949c63", +".u c #949c94", +".v c #94a59c", +"aI c #9c8c10", +"#4 c #9c8c18", +"#O c #9c8c29", +"aM c #9c9418", +"#r c #9c948c", +"bo c #9c9c4a", +"bm c #9c9c52", +"bk c #9c9c5a", +"bh c #9c9c6b", +".k c #9c9c94", +".a c #9c9c9c", +"bi c #9ca56b", +"bf c #9ca573", +".h c #9ca59c", +"#f c #9ca5a5", +".B c #9cbdb5", +"#P c #a59400", +"aB c #a59418", +"#k c #a5948c", +"ar c #a59c29", +".N c #a59c8c", +".P c #a59c94", +".W c #a59c9c", +"bg c #a5a573", +"bd c #a5a584", +".q c #a5a59c", +".c c #a5a5a5", +"be c #a5ad7b", +".o c #a5ada5", +".C c #a5adad", +".I c #a5b5ad", +"#d c #a5bdb5", +".w c #a5c6bd", +"ad c #ad9c10", +"aj c #ad9c18", +"#w c #ad9c94", +".f c #ada59c", +"bc c #adad7b", +"bb c #adad84", +".# c #adada5", +".t c #adadad", +".4 c #adb5ad", +"ai c #b5a518", +"aq c #b5a529", +"aD c #b5a542", +"ao c #b5a54a", +".O c #b5a594", +"#v c #b5a59c", +"at c #b5ad52", +"#z c #b5ad9c", +".5 c #b5ada5", +".j c #b5b5ad", +".e c #b5b5b5", +".3 c #b5bdb5", +".Q c #b5bdbd", +"#e c #b5cec6", +"#8 c #bda539", +"#x c #bda59c", +"#3 c #bdad29", +"#X c #bdad31", +"ag c #bdad42", +"#n c #bdb5ad", +".b c #bdbdbd", +".X c #bdcec6", +"aU c #c6b510", +"#. c #c6c6bd", +".p c #c6cece", +".g c #c6ded6", +"ac c #cebd31", +"#l c #ced6ce", +"#s c #ced6d6", +"#t c #cedede", +"#9 c #d6c610", +"#2 c #d6c631", +"ap c #dec608", +"ah c #dece10", +"ab c #dece31", +".l c #deefe7", +".R c #deefef", +"au c #e7ce08", +"a. c #e7d621", +"a# c #e7d631", +"aa c #e7d639", +"#1 c #e7de39", +"#Y c #efde10", +"av c #efde21", +"aA c #efde29", +"#Z c #f7e729", +"#0 c #f7e739", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQt.#.aQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQt.b.c.d.eQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQt.f.g.h.i.bQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQt.j.k.l.e.m.nQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQt.b.a.o.p.q.r.s.tQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQt.u.v.w.k.x.y.z.A.bQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQt.t.k.B.C.k.D.E.F.G.HQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQt.b.#.#.o.I.b.c.J.K.L.M.tQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQt.a.N.O.P.Q.R.o.S.T.U.V.s.bQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQt.t.N.P.W.k.X.R.P.Y.i.A.Z.0.1QtQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.b.x.2.w.3.4.I.j.#.5.6.L.F.7.0.cQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.n.8.9.p#..o.4.x.x.x##.s#a#b.s#c.bQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQt.t.D.##d#e.h#f.o.P.2.2#g###h.A.z#i.KQtQtQtQtQtQtQt", +"QtQtQtQtQtQt.b#j.P.f.P#k.q.4.X#l#m#n.n#o.J.6#p#i#q.cQtQtQtQtQtQt", +"QtQtQtQtQtQt.W#m#k.O#m#r.5.k#s#t#m.q#r.U.E.T#p#u#i.M.eQtQtQtQtQt", +"QtQtQtQtQt.b.x#r.o.t#v.f.o.4.l#l#w#x.f.i#o.E###a.m#y.nQtQtQtQtQt", +"QtQtQtQtQt.b.e.c#d.o#z.u.q#f.I.q.#.#.2#A.U.m#B#h.h.j.bQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.b#C#D#E#F#G#G#G#H#I#J#K#L#M#N.iQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.b#O#P#Q#R#S#T#U#L#M#V#W#N#V#V.iQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.b#X#Y#Z#0#0#1#2#3#4#5#6#7#M#V#AQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.b#8#9a.a#aaaaabac#3adaeaf#7#M.JQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.bagaha.a##1aaaa#2aiajakalaman#AQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtaoapa.a#aaaqaraq#3aj#5afamas.JQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtatauava#aw#V#W#Max#4ayafazan.JQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtatahaAaB#W#N#M#V#V#RaCalazas.JQtQtQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQt.baDap#Z#Q#N#M#V#M#N#6akafaEaFaG.E#h.JQtQtQtQtQt", +"QtQtQtQtQtQtQtQtaHaIahaAaB#W#W#N#WaJ#6aKalamaF#WaJaJ#yQtQtQtQtQt", +"QtQtQtQtQtQtQt.qaLaIahavaM#WaJ#W#DaN#RaealaOan#NaNaPaQQtQtQtQtQt", +"QtQtQtQtQtQt.jaRaSaTaUavaB#WaNaPaLaVaWaeaX#6aYaZa0a1a2QtQtQtQtQt", +"QtQtQtQtQt.ba3a4a5a5aVa6a1aZa7aSaSa5a8a9a4a5b.b#a5a5.kQtQtQtQtQt", +"QtQtQtQtQtbaa7a7aVa0b.b#a7b#a0a7a7a7aSaSa7b.aVa0aVaR.#QtQtQtQtQt", +"QtQtQtQtQtbbbcbdbebebfbgbhbhbibjbjbkbkblbmbmbnbobpbq.bQtQtQtQtQt" +] +image6_data = [ +"22 22 165 2", +"Qt c None", +".h c #000000", +".o c #010101", +"aF c #030303", +"#n c #060606", +".H c #080808", +".r c #0c0c0c", +".q c #121212", +"#V c #124e7f", +"#m c #131313", +".G c #161615", +"aI c #172cac", +".6 c #181818", +"aH c #1841b2", +".p c #191919", +"#8 c #1928ba", +"#W c #1929ba", +"aj c #192aba", +"av c #1a31c2", +"aE c #1b1b1b", +"aD c #1b2bc8", +"at c #1c79d2", +"ah c #1c7dd4", +"aA c #1d1d1d", +"aC c #1d7ad7", +"#6 c #1d7eda", +".5 c #1e1e1e", +"#7 c #1e8ae0", +"ai c #1e8de0", +"au c #1e90e0", +".g c #242424", +"#5 c #313b6c", +"aB c #343d8d", +"#3 c #393939", +".f c #3d3d3d", +"ak c #433967", +"#C c #434442", +"aw c #443c6e", +"#l c #454643", +"as c #454fa3", +".4 c #474845", +"#R c #474846", +".e c #484848", +"aG c #4856a0", +".d c #4a4a4a", +"#9 c #4c416a", +".c c #4c4c4c", +"ag c #4c5cae", +"#X c #4d4669", +"#z c #4dc2b2", +"#P c #4e445a", +"#G c #53504e", +".l c #545454", +".b c #555555", +"#Q c #595274", +"#i c #62b2a2", +".a c #676767", +"#j c #69b6a3", +".F c #6f6f6a", +".K c #6f8b89", +"ax c #747474", +"#a c #76a1a0", +".# c #797979", +"#A c #7bd7e8", +"ay c #7d7d7d", +"#U c #7e7d73", +".I c #808080", +".O c #81a3b8", +"az c #828282", +"#y c #82d1c0", +"#S c #848484", +"#O c #857e7c", +"#F c #86add2", +"#k c #86cdda", +"#N c #89b1bd", +"#h c #8acec3", +"#o c #8c8c8c", +"#L c #8cbbca", +"al c #8d8d8d", +".s c #8f8f8f", +"#H c #909090", +"#K c #90bac9", +"#M c #91c4cf", +"#t c #929292", +".X c #94c2cf", +".N c #94c2d0", +".W c #959595", +"#B c #96b9cb", +".3 c #97bede", +".L c #98c2ce", +".P c #9b9b9b", +"a. c #9c9c9c", +"am c #9d9d9d", +"#s c #9dbdc4", +"#b c #9e9e9e", +"#Y c #a0a0a0", +"an c #a6a6a6", +"#v c #a6d1d6", +".Z c #a7a1a1", +"#I c #a7a7a7", +"#D c #a7edde", +".M c #a8d8e5", +"#u c #aeaeae", +"ac c #b1b1b1", +"a# c #b2b2b2", +".2 c #b5cbd6", +".V c #b6b6b6", +"ar c #b7b7b7", +"#Z c #b8b8b8", +"#2 c #bababa", +".Q c #babbb9", +"aq c #bbbbbb", +"#c c #bcbcbc", +".8 c #bfbfbf", +"ap c #c0c0c0", +".1 c #c1d9d2", +"aa c #c8c8c8", +"ab c #cacaca", +"ao c #cbcbcb", +".Y c #ccf8f1", +"#J c #cdcdcd", +".R c #cecece", +"#p c #d1f9f4", +"#4 c #d5d5d5", +"#w c #d5ece4", +".9 c #d5f6f5", +"#0 c #d6d6d6", +".U c #d7d7d7", +"af c #d8d8d8", +".x c #dadada", +".y c #dbdbdb", +".w c #dcdcdc", +"#e c #dcf7f4", +"#1 c #dddddd", +"ae c #dedede", +".E c #dfdfdf", +".z c #e0e0e0", +"#g c #e0ebe4", +"#q c #e1edea", +"#d c #e2e2e2", +"#x c #e2ebe2", +".0 c #e2eee5", +".v c #e3e3e3", +"## c #e3e7d5", +"#r c #e4ebd9", +"#E c #e4f2ec", +".u c #e5e5e5", +".S c #e7e7e7", +".k c #e9e9e9", +".A c #ebebeb", +".D c #ededed", +".t c #f0f0f0", +"#T c #f4f4f4", +".n c #f6f6f6", +".C c #f7f7f7", +"#f c #f8f5f2", +".m c #f8f8f8", +".7 c #f9f9f9", +"ad c #fafafa", +"#. c #fbf0eb", +".J c #fbfbfb", +".T c #fcfcfc", +".B c #fdfdfd", +".j c #fefefe", +".i c #ffffff", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt", +"QtQtQtQtQt.#.a.b.c.d.d.e.f.g.hQtQtQtQtQtQtQt", +"QtQtQtQt.#.i.i.i.i.i.i.i.i.i.h.hQtQtQtQtQtQt", +"QtQtQtQt.a.j.j.j.j.j.j.i.i.i.h.k.hQtQtQtQtQt", +"QtQtQtQt.l.m.n.o.p.q.r.s.j.i.h.t.u.hQtQtQtQt", +"QtQtQtQt.e.v.w.x.y.z.A.n.B.B.h.C.D.E.hQtQtQt", +"QtQtQt.h.h.h.h.h.F.G.H.I.n.J.h.h.h.h.h.hQtQt", +"QtQt.h.K.L.M.N.O.h.P.Q.R.S.n.T.j.U.V.W.hQtQt", +"Qt.h.X.Y.Z.0.1.2.3.h.4.5.6.q.r.s.7.v.8.hQtQt", +"Qt.h.9#..###.F.F.F#a.h#b#c#d.m.j.7.v#c.hQtQt", +"Qt.h#e#f.a#g#h#i#j#k.h#l#m.r#n#o.7.v#c.hQtQt", +"Qt.h#p#q.a#r.F.F.F#s.h#t#u.x.n.j.7.v#c.hQtQt", +"Qt.h#v#w.##x#y#z#A#B.h#C#m#m.q#o.7.v#c.hQtQt", +"QtQt.h#D.Z#E.F.F#F.h#G#H#I#J.A.7.m.v#c.hQtQt", +"QtQtQt.h#K#L#M#N.h#O#P#Q#R#m.q#S#T#d#c.hQtQt", +"QtQtQtQt.h.h.h.h.Z#U#V#W#X#Y#Z#0.S#1#2.hQtQt", +"QtQtQtQt#3.t.v.x#4#5#6#7#8#9a.a#aaabac.hQtQt", +"QtQtQtQt.6ad.kae.yafagahaiajakalamana..oQtQt", +"QtQtQtQt.haeaoapaqaqarasatauavawaxayaz.oQtQt", +"QtQtQtQtQt.h.h.h.h.haA.oaBaCaiaD.HaEaFQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtaGaHaIQtQtQtQtQtQt", +"QtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQtQt" +] + +class MainWindow(QMainWindow): + def __init__(self,parent = None,name = None,fl = 0): + QMainWindow.__init__(self,parent,name,fl) + self.statusBar() + + self.image0 = QPixmap(image0_data) + self.image1 = QPixmap(image1_data) + self.image2 = QPixmap(image2_data) + self.image3 = QPixmap(image3_data) + self.image4 = QPixmap(image4_data) + self.image5 = QPixmap(image5_data) + self.image6 = QPixmap(image6_data) + + if not name: + self.setName("MainWindow") + + + self.setCentralWidget(QWidget(self,"qt_central_widget")) + MainWindowLayout = QHBoxLayout(self.centralWidget(),0,6,"MainWindowLayout") + + self.Frame3 = QFrame(self.centralWidget(),"Frame3") + self.Frame3.setFrameShape(QFrame.StyledPanel) + self.Frame3.setFrameShadow(QFrame.Sunken) + Frame3Layout = QVBoxLayout(self.Frame3,1,0,"Frame3Layout") + + self.WebBrowser = QAxWidget(self.Frame3,"WebBrowser") + self.WebBrowser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}") + self.WebBrowser.setFocusPolicy(QAxWidget.StrongFocus) + Frame3Layout.addWidget(self.WebBrowser) + MainWindowLayout.addWidget(self.Frame3) + + self.actionGo = QAction(self,"actionGo") + self.actionGo.setIconSet(QIconSet(self.image0)) + self.actionBack = QAction(self,"actionBack") + self.actionBack.setIconSet(QIconSet(self.image1)) + self.actionForward = QAction(self,"actionForward") + self.actionForward.setIconSet(QIconSet(self.image2)) + self.actionStop = QAction(self,"actionStop") + self.actionStop.setIconSet(QIconSet(self.image3)) + self.actionRefresh = QAction(self,"actionRefresh") + self.actionRefresh.setIconSet(QIconSet(self.image4)) + self.actionHome = QAction(self,"actionHome") + self.actionHome.setIconSet(QIconSet(self.image5)) + self.actionFileClose = QAction(self,"actionFileClose") + self.FileNewGroup = QActionGroup(self,"FileNewGroup") + self.FileNewGroup.setUsesDropDown(1) + self.actionNewWindow = QAction(self.FileNewGroup,"actionNewWindow") + self.actionSearch = QAction(self,"actionSearch") + self.actionSearch.setIconSet(QIconSet(self.image6)) + self.actionAbout = QAction(self,"actionAbout") + self.actionAboutQt = QAction(self,"actionAboutQt") + + + self.Toolbar = QToolBar(QString(""),self,Qt.DockTop) + + self.actionBack.addTo(self.Toolbar) + self.actionForward.addTo(self.Toolbar) + self.actionStop.addTo(self.Toolbar) + self.actionRefresh.addTo(self.Toolbar) + self.actionHome.addTo(self.Toolbar) + self.Toolbar.addSeparator() + self.actionSearch.addTo(self.Toolbar) + self.Toolbar_2 = QToolBar(QString(""),self,Qt.DockTop) + + self.Toolbar_2.setHorizontallyStretchable(1) + + self.lblAddress = QLabel(self.Toolbar_2,"lblAddress") + + self.addressEdit = QLineEdit(self.Toolbar_2,"addressEdit") + self.actionGo.addTo(self.Toolbar_2) + + + self.menubar = QMenuBar(self,"menubar") + + + self.PopupMenu = QPopupMenu(self) + self.FileNewGroup_2 = QPopupMenu(self) + self.PopupMenu.setAccel(QString.null,self.PopupMenu.insertItem(self.FileNewGroup.iconSet(),self.__tr("New"),self.FileNewGroup_2)) + self.actionNewWindow.addTo(self.FileNewGroup_2) + self.PopupMenu.insertSeparator() + self.actionFileClose.addTo(self.PopupMenu) + self.menubar.insertItem(QString(""),self.PopupMenu,1) + + self.unnamed = QPopupMenu(self) + self.actionAbout.addTo(self.unnamed) + self.actionAboutQt.addTo(self.unnamed) + self.menubar.insertItem(QString(""),self.unnamed,2) + + + self.languageChange() + + self.resize(QSize(812,605).expandedTo(self.minimumSizeHint())) + self.clearWState(Qt.WState_Polished) + + self.connect(self.actionHome,SIGNAL("activated()"),self.WebBrowser,SLOT("GoHome()")) + self.connect(self.actionRefresh,SIGNAL("activated()"),self.WebBrowser,SLOT("Refresh()")) + self.connect(self.actionStop,SIGNAL("activated()"),self.WebBrowser,SLOT("Stop()")) + self.connect(self.actionForward,SIGNAL("activated()"),self.WebBrowser,SLOT("GoForward()")) + self.connect(self.actionBack,SIGNAL("activated()"),self.WebBrowser,SLOT("GoBack()")) + self.connect(self.actionGo,SIGNAL("activated()"),self.go) + self.connect(self.actionFileClose,SIGNAL("activated()"),self.close) + self.connect(self.actionSearch,SIGNAL("activated()"),self.WebBrowser,SLOT("GoSearch()")) + self.connect(self.addressEdit,SIGNAL("returnPressed()"),self.go) + self.connect(self.WebBrowser,SIGNAL("NavigateComplete(const QString&)"),self.addressEdit.setText) + self.connect(self.WebBrowser,SIGNAL("TitleChange(const QString&)"),self.setTitle) + self.connect(self.WebBrowser,SIGNAL("NavigateComplete(const QString&)"),self.navigateComplete) + self.connect(self.WebBrowser,SIGNAL("CommandStateChange(int,bool)"),self.setCommandState) + self.connect(self.WebBrowser,SIGNAL("BeforeNavigate(const QString&,int,const QString&,const QVariant&,const QString&,bool&)"),self.navigateBegin) + self.connect(self.actionStop,SIGNAL("activated()"),self.navigateComplete) + self.connect(self.actionNewWindow,SIGNAL("activated()"),self.newWindow) + self.connect(self.actionAbout,SIGNAL("activated()"),self.aboutSlot) + self.connect(self.actionAboutQt,SIGNAL("activated()"),self.aboutQtSlot) + + self.init() + + + def languageChange(self): + self.setCaption(self.__tr("Qt WebBrowser")) + self.WebBrowser.setControl(self.__tr("{8856F961-340A-11D0-A96B-00C04FD705A2}")) + self.actionGo.setText(self.__tr("Go")) + self.actionGo.setMenuText(self.__tr("Go")) + self.actionBack.setText(self.__tr("Back")) + self.actionBack.setAccel(self.__tr("Backspace")) + self.actionBack.setMenuText(self.__tr("Back")) + self.actionForward.setText(self.__tr("Forward")) + self.actionForward.setMenuText(self.__tr("Forward")) + self.actionStop.setText(self.__tr("Stop")) + self.actionStop.setMenuText(self.__tr("Stop")) + self.actionRefresh.setText(self.__tr("Refresh")) + self.actionRefresh.setMenuText(self.__tr("Refresh")) + self.actionHome.setText(self.__tr("Home")) + self.actionHome.setMenuText(self.__tr("Home")) + self.actionFileClose.setText(self.__tr("Close")) + self.actionFileClose.setMenuText(self.__tr("C&lose")) + self.FileNewGroup.setText(self.__tr("New")) + self.actionNewWindow.setText(self.__tr("Window")) + self.actionNewWindow.setAccel(self.__tr("Ctrl+N")) + self.actionNewWindow.setMenuText(self.__tr("Window")) + self.FileNewGroup.setMenuText(self.__tr("New")) + self.actionSearch.setText(self.__tr("Search")) + self.actionSearch.setMenuText(self.__tr("Search")) + self.actionAbout.setText(self.__tr("About")) + self.actionAbout.setMenuText(self.__tr("About")) + self.actionAboutQt.setText(self.__tr("About Qt")) + self.actionAboutQt.setMenuText(self.__tr("About Qt")) + self.Toolbar.setLabel(self.__tr("Toolbar")) + self.Toolbar_2.setLabel(self.__tr("Toolbar_2")) + self.lblAddress.setText(self.__tr("Address")) + self.PopupMenu.changeItem(self.PopupMenu.idAt(0),self.__tr("New")) + if self.menubar.findItem(1): + self.menubar.findItem(1).setText(self.__tr("&File")) + if self.menubar.findItem(2): + self.menubar.findItem(2).setText(self.__tr("&Help")) + + + def go(self): + print "MainWindow.go(): Not implemented yet" + + def newWindow(self): + print "MainWindow.newWindow(): Not implemented yet" + + def setProgress(self,a0,a1): + print "MainWindow.setProgress(int,int): Not implemented yet" + + def init(self): + pass + + def setTitle(self,a0): + print "MainWindow.setTitle(const QString&): Not implemented yet" + + def setCommandState(self,a0,a1): + print "MainWindow.setCommandState(int,bool): Not implemented yet" + + def navigateComplete(self): + print "MainWindow.navigateComplete(): Not implemented yet" + + def navigateBegin(self): + print "MainWindow.navigateBegin(): Not implemented yet" + + def aboutSlot(self): + print "MainWindow.aboutSlot(): Not implemented yet" + + def aboutQtSlot(self): + print "MainWindow.aboutQtSlot(): Not implemented yet" + + def __tr(self,s,c = None): + return qApp.translate("MainWindow",s,c) diff --git a/examples3/webbrowser/mainwindow.ui b/examples3/webbrowser/mainwindow.ui new file mode 100644 index 0000000..1689e8a --- /dev/null +++ b/examples3/webbrowser/mainwindow.ui @@ -0,0 +1,410 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
+<class>MainWindow</class>
+<widget class="QMainWindow">
+ <property name="name">
+ <cstring>MainWindow</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>812</width>
+ <height>605</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>Qt WebBrowser</string>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <widget class="QFrame">
+ <property name="name">
+ <cstring>Frame3</cstring>
+ </property>
+ <property name="frameShape">
+ <enum>StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>Sunken</enum>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>1</number>
+ </property>
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <widget class="QAxWidget">
+ <property name="name">
+ <cstring>WebBrowser</cstring>
+ </property>
+ <property name="focusPolicy">
+ <enum>StrongFocus</enum>
+ </property>
+ <property name="control">
+ <string>{8856F961-340A-11D0-A96B-00C04FD705A2}</string>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ </hbox>
+</widget>
+<menubar>
+ <property name="name">
+ <cstring>menubar</cstring>
+ </property>
+ <item text="&File" name="PopupMenu">
+ <action name="FileNewGroup"/>
+ <item text="New" name="FileNewGroup_2" accel="">
+ <action name="actionNewWindow"/>
+ </item>
+ <separator/>
+ <action name="actionFileClose"/>
+ </item>
+ <item text="&Help" name="unnamed">
+ <action name="actionAbout"/>
+ <action name="actionAboutQt"/>
+ </item>
+</menubar>
+<toolbars>
+ <toolbar dock="2">
+ <property name="name">
+ <cstring>Toolbar</cstring>
+ </property>
+ <property name="label">
+ <string>Toolbar</string>
+ </property>
+ <action name="actionBack"/>
+ <action name="actionForward"/>
+ <action name="actionStop"/>
+ <action name="actionRefresh"/>
+ <action name="actionHome"/>
+ <separator/>
+ <action name="actionSearch"/>
+ </toolbar>
+ <toolbar dock="2">
+ <property name="name">
+ <cstring>Toolbar_2</cstring>
+ </property>
+ <property name="horizontallyStretchable">
+ <bool>true</bool>
+ </property>
+ <property name="label">
+ <string>Toolbar_2</string>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>lblAddress</cstring>
+ </property>
+ <property name="text">
+ <string>Address</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit">
+ <property name="name">
+ <cstring>addressEdit</cstring>
+ </property>
+ </widget>
+ <action name="actionGo"/>
+ </toolbar>
+</toolbars>
+<customwidgets>
+</customwidgets>
+<actions>
+ <action>
+ <property name="name">
+ <cstring>actionGo</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>image0</iconset>
+ </property>
+ <property name="text">
+ <string>Go</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionBack</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>image1</iconset>
+ </property>
+ <property name="text">
+ <string>Back</string>
+ </property>
+ <property name="accel">
+ <string>Backspace</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionForward</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>image2</iconset>
+ </property>
+ <property name="text">
+ <string>Forward</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionStop</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>image3</iconset>
+ </property>
+ <property name="text">
+ <string>Stop</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionRefresh</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>image4</iconset>
+ </property>
+ <property name="text">
+ <string>Refresh</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionHome</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>image5</iconset>
+ </property>
+ <property name="text">
+ <string>Home</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionFileClose</cstring>
+ </property>
+ <property name="text">
+ <string>Close</string>
+ </property>
+ <property name="menuText">
+ <string>C&lose</string>
+ </property>
+ </action>
+ <actiongroup>
+ <property name="name">
+ <cstring>FileNewGroup</cstring>
+ </property>
+ <property name="text">
+ <string>New</string>
+ </property>
+ <property name="usesDropDown">
+ <bool>true</bool>
+ </property>
+ <action>
+ <property name="name">
+ <cstring>actionNewWindow</cstring>
+ </property>
+ <property name="text">
+ <string>Window</string>
+ </property>
+ <property name="accel">
+ <string>Ctrl+N</string>
+ </property>
+ </action>
+ </actiongroup>
+ <action>
+ <property name="name">
+ <cstring>actionSearch</cstring>
+ </property>
+ <property name="iconSet">
+ <iconset>image6</iconset>
+ </property>
+ <property name="text">
+ <string>Search</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionAbout</cstring>
+ </property>
+ <property name="text">
+ <string>About</string>
+ </property>
+ </action>
+ <action>
+ <property name="name">
+ <cstring>actionAboutQt</cstring>
+ </property>
+ <property name="text">
+ <string>About Qt</string>
+ </property>
+ </action>
+</actions>
+<images>
+ <image name="image0">
+ <data format="XPM.GZ" length="1241">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232365200210543251d2e253d856405bffcbc54103b11c8563600020b03105719c4b530b08072f50880513560a09c080338d5209420294a4451a38c90426621ab5146d10de524a2aa417505445122861a547722bb0c971a3d2aa921c2ae446c6a9431fc85a9064551220e354009653dec00294e712a1ac4e97078a9a9b5e6020013b3f563</data>
+ </image>
+ <image name="image1">
+ <data format="XPM.GZ" length="4494">789ce596497332470c86effe15947573a5f4c1cc30cc542a07ef60bc808dd7540e3d9b6df006186c93ca7f8fba2535ce57be98dc9292313c487a2575f7ccf063a376d53baa6dfc589bbe9ad7fbbc96df99496da3983d3e7efcfec76f7faead87418dfe1a51500bd67f595befbfd6f2daf1f35369014e08a05e6fd4ab96e31e73d0282bc7a7cae23ff3ccfe8170ca6cee9843f51f3b4ec8cff9efccdebf2d2cf9b06bb9417a25c74f98bdff99390a84fb8e49af70f39891b2e40bfbf8b6b0917e87968346a8f5a6cc51c07ab02f2cf1983237552f709c86691e3bbd5be5821998a32067bd1765d13f67563d530a4b3df8b01c523d8ec74059faed086bfc82390e851b8ed3c86485e34365a9bfc5ece3df8433e10bcb5140f5dd3cf0e099f32f99e350cecb5858f2b1c1dc52fda663d334a277c0ecfd5d61c9373973120967969b548fd71b079e797d8e985b21eb63aecceb85e7c299f4ffaa2ce7739359ebc195631387c6ad1f5e302791ccbba72cf173e15cfa2d2cc7619cf1fa63c9dccaa4ff4bcfdc7fa82cfdf7999348f6bf299c4bfd4c59ea0f99535dafca71d60a65ffebca52ff8c3989e47cce98351fb785759e7bcbad65bf0be624ca9a8e87caac0fb1702ef191b2cc9731a7b9ec4f87d934659e27e142f8c671e6eb9d0ae7b2be07cc6924ccf999698a7e4f58f572e64cebb9f393444994e68e4365d9ff7be15caef70766ad678cb0f8f18359ebe109b3af27f199fadd794cf254eb196599774758e77d5496f5dd64a67959af122ef87c639b59eb81d34ba97fe3f4215196f3922acbbc28acf527cc792c7a857029ecf63bcded05efb8a52cf3cc9833ed2f66563dac0b8b1ebe3317ea77f73352173db8f6ccf54a66df0f30fb7c777d9bc214d2cf88d9cf73cfece3ddf3296b66da7fe199d7a32b5cc8feef31fbfe8f99bdde96b0faddf3272bac390665b99e90d9e7ef33972de9d73d7ff3d873255c49fc1b73257ee4f8d2eb5d336b3e8e8535ff86d9e7bbf35f2cf51366ef77cfeb6299df62563f3c0a8b1fdcf3d3569778773f756e66f7fcac967e175f797ffff5dfd9ff4103010d6698a35955030b2cb1c25bbcc3fbd5344861882352b8c5077c5c45836678c267ca7fc1314ebeaf81537cc599eb608e6ff88e1f2b682c705314b6486182dbb8f31d0ddca529f644619ff2db641d3cf82a8bfa9d62d7da670d3cc4233c760a63eaa08d2734478fac8f87ffc833788a6738c073bc20ebe3255eb1069d863e5e3b851bacfb7c6b0d0c30c488f24a3a2d4ddaf1986a3d600b13179be280ef597809e876e206000c69d8ec0e590f32c8a18012b7a0825b9799e018eee0de4e0b4318c103ff2ea2985b78c47d28a487ce276b634cca40356d1655801c3bf044af2136e0195ef8b711be4045ab50ff42e16bdbb6463d8e610253fe3d4855ec3ed80abd9f62397ef9c9e6cee835249bc31bbc731ff0010beacbcdbfaca29f2836a3e839fd1f3acb5cb6fd6e13b6605b34766097d6664cdf0d7faad9813dd827df08daf4de812ddaa7061c4017baf43ea6daef70c8fb0247704c932dc897b94e67da09553a811ef4a94a0f4ee10c069435216b630ae7a43b800b7fc6164ea543ea73ea75663b22a50e5cc215ec50956beaf606ead08080147b64c76403d20ebdc6142268528d3655ee3a1db6f88b535ee015b42081d4205ee1f4f335878501ea7644331dc81acecdb7ef63b86b32eae59956cff63237f92af7319c9a82669c989256bd0b6fa6fabe86bbfe0ecdadb9a399ce61b49a86355adfbedd45736756bc27b30afd161a9a9179585de33bf69fd2f8ebd7b5bf014644b906</data>
+ </image>
+ <image name="image2">
+ <data format="XPM.GZ" length="4494">789ce5965b4f23471085dff915d6d6db2aaac5e3b92aca037703cbc55c8c21ca43cf8c8d0dd85c6c307694ff9eeaaed3bd68771f968d14298a0a109fabebd4e99a9ef17cfad8e81d1f343e7e5a99cecc6c5435aaa1796a7cac9fc7e3c5ef7ffcf6e7ca8756d4909f661c35a20fbfac7ce8cc1a55e3f07ed2b7409702b4badaccfb996563020f5c7ecbf340b9a31c3591dff7ac7943e002cc8e73cf74acdcc27a8a2d37a5be4e1d9f04567f9fc105f25dcfea9726caad62a07c1158f58f94e3087e868ea57fa5fa0be590bfb11c3525affd4e03ebfa25b8507fbcaa1c47ca66e459fdf10c6c30af4dcfda8f5f9513dfffce71e1f5a956967adddfaeb25f4f7b60e8d199e596f42f6bc787ca213f554e5be06dc7a28ffdee282791cedb5c83d19fd795a55ecf4b3fb0ee07ebd312fae796e3283665e238524e2265de031bcc774d396d61be25b8c4fe1f02abfeab67f49f2867decfbd6393b6a03f03438f3bca19fa51cb33fc6f80fd7eae2c27e257e7cb4de5b4045f78d679f24960ddcfb172e6f73357ce63e88fc115ce43e558fcabbeb905fb7e47cae24ff5daca41af007bbd81e5b425f53aff6160d52f95f318f37d01a39ee7ca05f4790a469e0e1c97590bfa1b81f53c3e2bfbf5ecf697b532efe754398f31af437085eb65948b18e723f70cbf9e2bcc633db0f65b533609fcbafb372bf318fdcfc015e65b281731ee0ff6acf70767ca5e8f7be01abcab5cfa7e89e53cce2ba3fd1681b5df8172013f44e00acfbf4a39e8ef287b7dbe02234feefce795d727a36c12ccf75239d4b7c1bede9def42fcc0ef7960d5cbc05ebf543635aed752b94aa1ff02ee83ddf3b6a87c3d3f2b9b047a4fcaa17e0cf6f5eef928ab13f5476960d5eb7ac6f5dd07d7e04839e83d29d7be9ffbfe31b50dc723cfa87f08acf947e51a7ad457ee6760773ecaa4f47e36036bfd96673c3fb6c13578a01cf41f9505d5af3b2f655dc28fa93da33e550ef523e5e06f08861eb9e7b94cdfe7ddf753d50feb6f94437e00f67edcf3aa4e831ed8afe73bb05fefe655f7c37edcfd62bb81ddfb82935776cfeb41c87766ff2cfe7f1a4c6cb8e48ae91f68d4dce7015ff390473fad71c3b77cc7639ef03d3ffcb48f013ff293a84c79c6d54f693c8bc28b28589539bff2e2ed647e586389184bacf13a6ff0e6d71a32f92dde96bfdf9dbccc6387dba2d086caae4c668ff7bf68f0673ee0433ee263eef0099ff2199f8b62d0e32e5f704fea2fe5b70d3f57729556b91b349a1c718b634e64faa9fc7fc919e772220a91213254ca273b884bf72b4a54f1846ad925e93b1af56940d734a4110fe4efb5c40dddda907311734c7752d10b3a1ae289c634a17b7dafe331e995b3b124fbdfd25d85471763596fab7aa2a4f53d444653ded3773bb96e8faeae1de2ea8dff9da0b0ebfcd858e3357aa667bb1f68b4a5e7d256853559e8f56d64aefe85e6f44a0b5aea3bac5c2bebf74b8775fb6bfbb858771e7a6f1df09c36f89a36698bb6f53d5c4ef08ee4e6a2dd269b9d488729ed4a171b7bd40ece3228cce5d305edd3673ed7773139bd133a14d5233a96cff7a9237142a77446e7125dba900e70681564f5a6acdc1285ae9e0feaf150d675e8d2d59dd315ad52931fec2973d1a5489c6698e29c5a508829797bd629a52665bcf9fdd32ed95c1d50217b5c18b67390f34befb8e78873a9b6b39ad285216328a2de3bef5b32a59db5ccec42a6b565aaf7dffba6e663d3972b211ea86b065f3cbccbc7b53890399a21a55f677f5863e4f670c337df667f58e3d6dc99dbef3dd5ff6bdf73ff82c65fbfaefc0d4fb5b868</data>
+ </image>
+ <image name="image3">
+ <data format="XPM.GZ" length="802">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232325500210543251d2e25658564056503300071f540dc3430007371012a492a830156496538c094848922c9c2259134c099304914e3604c8424aa5e6449b0044216ca824ba2da8b4512218b4d122e8b55520fee5974072164511da487ea490c7f22cba249e20d3efc018f3fcae0d2702eb5d2106992b5d65c00b9a48974</data>
+ </image>
+ <image name="image4">
+ <data format="XPM.GZ" length="1241">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade65232365200210543251d2e253d856405bffcbc54105b19c8563600020b03103711c4b530b08072f50880513524ab518681443435ca984ae08ae06a94114a10ac443435ca3043904d4c4453a38ca604ae11590d9a0ab80bd0d46078914c35c4d885a608871a547f61f81d5d117a1862018930e5b8d5c0950c741a1b1e6a6aadb90086a9d853</data>
+ </image>
+ <image name="image5">
+ <data format="XPM.GZ" length="5598">789ca5985973db480ec7dff3295cc15b6a0b2351a428d6d63ef83e255bbe647b6a1fd02465dd872d9f53f3dd076c005dc926ce6a32eed8553f37fadf7fa0c1a69cdfbe6cdc9cb537befcf6e97145ab61be910fe861e34bf1349dbefdfedffffcf1e97323dae07f51bdbe117dfed7a7cfddd546bed199cfca0ae888016afeab62e8796ef110ee545caf05be16ae5bfc6ee096e7b6e756983f51b6f53b81257ecfb8eee7e9b162f66af1c78125fe48987f23f3fb81657e691cd5bddecc7316d555efd058f7eb2867aa771058f4de8c55cffb6dd4a34cf5b68d357e681c6515634db81a7e3ef59c35cccf5560bf9ef6953389c77660af074f15c751e05c38a6d81f2ef9f3a848f4e9d658f2c36b635dbfa54cc2383556bd33e12492fc70df38f1f3f8ae4cc2745a711285fda7caa4f95e06967a2d8c63f27a8fc2a60fa4acfa980a371b898f0767dc6cf8fdbc9f84c27e4de124d2fabe186b3dee8c75ff1365dbef2db0ccef0987fd2f2a6632fd576552fd2b63d57b08ecd7d39d70b321fd0560acfb6d1a4b7e3050764de7d79f08a70de937ea7b7689e68f4de1e0776e2c7ab8abecb47eb170aa7ee822b0e89f1b4b7fd24dc529abe9794f02cbf99e2b3badc7a5b1ee97089b3e0e8d253f3c364e253e5576120ff7c63a9f7966d2e771d358e75bca4ef3bb0e2cf9758db5fe47c6b21eeb81bd3f07c2ad58ebd130d67e6a194b3cf97e62b2fa24c67a1f5d2aab3f8781a53e17c6eaa7082cfa3de156acf9d5034b7e3563f1eb96c6eaf7c0b815fbf8d2739e3aedefb1b1de9723618b77a49cebf946c6e20f5f8d251e753e8b5bb9e74c980a4afc7a7fbf66b1ed8fb7c67a9ec7c2ad5cfd74038bdfa6b1f6cbd458fd2e84b358efbb0363f5b71358fccd8c33596f9c4bfddcc458fac78d8cf5797b3296f5f82c4c49e6f5c9bf9fb23ce41307967e3935d6f36c0b67b1ce3f188b5f3757367f5363b98fdc38b0cc0f8cf5f90bf3ea97028bfe50981289777d63edcf81b1c4439897f3c52d615738cfe0df371c1deb7db265acf98d8d253f7a50d67a60c758cfcbf4cc7f2fb0f8bf1736bfae30d6f35f1a4b3ce6c6e2df95ca85f6f7dc58f3db0e5c783e14e6ebc533e87e963fbe0873f9fd3cc97c91693fd028b0d4e3c558f3eb0b9b5f972bab3fe78c353f3056bfabc0e2371636bfe4cf9b29d1e76b69acfdb863accfd33cb0dc2fa7c6e2179e03cb79ae940b7dffbf1b6bfd1363f53b12367f581a6b3d1bca56df6e60a9bfc6e765def4ecef6bc7eafaf9e8d558fbb7a15ce87d7263acf7ffbdb1e40f33e1e0cf29ebfea8eb6d7ff29f17f8f4137dfe51d8fa0117ca65ee3fbfe3bd705116b2de9f775e3af50313e1a229f1f0682cf1b052e6e1d9dfbf1cddd4fd2363cdcfef5fb05b7d1f0c944bed4f67ac9f5f27c265bf4c3d9f07eefb787f1f96695eaa1e0a174d7d7f81b1ee4f81a5fe75e552d9bf1fca7e617e9e8d556f33b0c4fbcf5ffdb44c956bc6a2d75dfd6c2020fd3ce2ff69a0c31c0b2cff91461fef71804374bfaa81231ce3044b9ce2ecd734380fc2392e70890ff888bfa6f184cff8c24e5ef10ddf71f3a37c3ed6c015afdec26dfeb983bbb887fb78f0f734380fe031c7437f3247788c27d8fe713e1f6a1076f014cfb08be7ac7481977885d75c951fe4f3630dcea3c3eb7b9cc70d6b9ce12d9fee26de610debeb69b0fb578cb89a0d8c399711e794609373d9c39455f2b53466d8c20c17809c45cc7a3c00f011081cffccff379fef35388f1d0428a0c401f459e58c3d45700f0003cee71d8678fc730d7430e2557d3c8331f7568c37308129cc7006733e9d262c6008cb6ff3f94ea3c72bc678ca3f1fb80a637884154c71c974c55d72c91a4feca4fdf553f8ad46554d8e9ee30a9eb1efab31611f2ff0ca346427bb9c11e114debe7e7ebed328318702e7f0ce9dbee47a1c724655b745b0c94ea6b0c55519f059b98f73d19a6cc30eecc21eecfb7100877004c770026de8e070bdfe805338832e9cc3055cc2955f7b0d3de8f0cfebb5356ee016eea0c6a30e11342086049a907aadcd35355a90111250f5e5288706bfdb4bea572a78b49e06ddd3a0d2807a2502110d6944639ad09466ebf9e8ae684e0bf5b1a4075ab28f11ffa1df678dc7f57cb0c68a9ee899355e7c2ddbf40a31bdb1c63bcdfe86c6803669cb9f4555c76b38a76dcee57d5d1f5c8f1d5af0b9745581bb029a5c8f3eedd21eed73b70ebe56fa91061dd061f05139e9d1116b1cfb9aee55c4fcf6330d5cd289d778a6b65fdd831dea702e256b9cf2b974a84367d4fd580347744e17744957acc13e7cfc095d538f356ed8cd2ddd518dea147da4c1956890ffcf295ed5e4c83b4a59f182b9455935e3b801ab791c7fa4e188d7a4bcbee66353feaef9df8852ca2f3e9ee3ef73840f359cabfec22979f4ddbd1bf018ba118f318f899bf298b9b95bb8e537cffe9ffffef4171c39a0bf</data>
+ </image>
+ <image name="image6">
+ <data format="XPM.GZ" length="3742">789c8d96c9521c490c86ef3c458775734cc8ddd5b5c6c41c303b180cc60b66620eaacc2c9aa5599b7562de7da45fc5180c8e98fa39f091522e4a49c9bbb783bdedcdc1db77735733991d864198c8e5e06dbc9e4eeffffceb8fbfe7de64d9407f466531c8defc36f76667360883adb3d364c013051ae2039f8147266359068f4dc6740a2e4db05f05d726f0253898c017c6a3cc04ffafce79aa3af0143c36c17e055caa0aacbf06aeb2203e5f09ae4d185f75ce472de6e7737063c2fcb57356b702fed673e32c473d4bcf3760198f02e69325706b022f3a676df0f567e05035d1ed273dc79883e7c1d1045e70ae2456d84fd9738a589f0b703261bc72ae25e17ee4b0e7d8f3b5733374e603e32c37c11ff36970db12f193f7e07c1c6bec87c6e0c604ff0e1c4db03f36cec7e3a6f4fd2e38e779eee7bd05e7e350fa7e4fc0455ee6b84fb9eab913bfdf1c5ce5758efba54fffb1e75302d726f8af3817a5f8f922584cf06fc0211f951ebfd0b30afe07ce4510dfdf1e38e665e9f9f1e01c32cf1fda06a73c2f7c7eac5f8c8b61eef582f315b909dc82f1c17e07dc1459e5f1c77d953abb787e0ab832611cf957366dd9c707f556762a3fcf8673ddd6d8afdc1957b909fe98af2a65d4c787c08d09e3c8bfaad504f378de83a309e35fc049d9d747bda19c7dbe8f602d88d6fd11af3a33c1ffde398e02ec69178c0b04bb7fa12be03e08e7ab4b895e2f74ec1ca2e73f6d811b2d37df1feaa9969082f71ff4a73a98c01f9cdb3678fde27eea58f7f9cdc8bfba33c11efda2199ac01bcead048fd72678a4e9e3f6a86f6d172acc87fc69f290f9386f3d72f478a1bf348509fea8b7a66c9b80fec1a8b7a66a53f47cc2fe9b5ae77346fe35ad09e761703081d12f9b68c2fc57ce6d0c1e6fe463934ce0efc63234c11ffd5b4a13c66f9cb53d79fded832bcd27f47f5aeb59055e744eb1df3fe2251aeee4e7453f9264c27aa847b44f7f4f909fda3efb7ae30c5c84b65f1fef435b9a608ff7a4ad4c981ffb6b6b13d8fda5edfb37eff4dcb65e2f787f5a7cb0f7fd0413ecf13eb49d09f6783ff07cf97d8ec0a3f8d8df516f483faf07c45b1f27e9f30ff989e9fdbe11ff1034fd3c9eebe068c238fa9f6677f2fb27ac1f475dd3f97da25fc6c204be755673ef3f8db3360c1f1f824b13c651df2877c44fd0df511efe5ea39f44318151cf9a4e2ab0af870d63fee4dc55fdfe109f880ff3fb788a8ff98df733762630fa471aa6febda2839e5b3f0fe1bef4f18bc9fb01fa7dca4ce0bb9e5b671ef69c3cff18f99cc626d853cf551f3fe453ca531bbdde979cbb2c793e207f536102a39fa5ca0446bf4279f97b89feaabb5181511f38bedf2ffa47373461bdcfe0dc8471d46387860fc6fbaad155c11ef7a5d953747ede69cf2a30fe3fd06c5121fe88572726f8a37f68720ffbfdadf7ac02fb7e82098c7e85ebf2fde37dea92098cf7acc367bc33fbff7a6ecfc4c22d078eaac41d1ff0e4d7f66a7df84293e71ecfec858f9ee8d1fef8a9c733fb139ef2299ff1395ff0255fc167c233befee1f1cc3ef10ddff21ddff303cfabe77bd584177891971e3d7ed8db4e7b2df30aaff29a7aac3ff9ebe4a9bdf2067fe04ddee28ffafb36eff027de558fcfbaab2ffc95bf3db5578b3dfecefb3ce411673c56ceb9e0b23f47a5fbac7fb26f889988742f2a129e504b81a246e0c8ec293cb7a7441d0b1dd0840ee9883486744253bea4533a7bd5fe9c2ed4feb29fff4aff32a36b8dd5e92fe6bfa15bddcf1dddd303cd93c6911668aa2b5cbc363f3c16799f9630fbb2d20aadd21aadeb3d547a8617f6f0d8a00fb4495bfadb47daa61dfa84f977e933c597f64f6e6c9fbed057fa467bf49df669c8bb34a2eca53d8d35576ef88e722aa8a48a6a6a448320a20fd36bf3eb7f407c2c89efb5500f6422877224c77222533915e6b397fbd117f54ccee54275295732936bb9915bb9937b797869ff34e7649ecfe4bd2ce81a8bbc2a4bb2fc5a3dfe2c59915559fb75fdfe8f7affe7f7b97f011cdd9635</data>
+ </image>
+</images>
+<connections>
+ <connection>
+ <sender>actionHome</sender>
+ <signal>activated()</signal>
+ <receiver>WebBrowser</receiver>
+ <slot>GoHome()</slot>
+ </connection>
+ <connection>
+ <sender>actionRefresh</sender>
+ <signal>activated()</signal>
+ <receiver>WebBrowser</receiver>
+ <slot>Refresh()</slot>
+ </connection>
+ <connection>
+ <sender>actionStop</sender>
+ <signal>activated()</signal>
+ <receiver>WebBrowser</receiver>
+ <slot>Stop()</slot>
+ </connection>
+ <connection>
+ <sender>actionForward</sender>
+ <signal>activated()</signal>
+ <receiver>WebBrowser</receiver>
+ <slot>GoForward()</slot>
+ </connection>
+ <connection>
+ <sender>actionBack</sender>
+ <signal>activated()</signal>
+ <receiver>WebBrowser</receiver>
+ <slot>GoBack()</slot>
+ </connection>
+ <connection>
+ <sender>actionGo</sender>
+ <signal>activated()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>go()</slot>
+ </connection>
+ <connection>
+ <sender>actionFileClose</sender>
+ <signal>activated()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>close()</slot>
+ </connection>
+ <connection>
+ <sender>actionSearch</sender>
+ <signal>activated()</signal>
+ <receiver>WebBrowser</receiver>
+ <slot>GoSearch()</slot>
+ </connection>
+ <connection>
+ <sender>addressEdit</sender>
+ <signal>returnPressed()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>go()</slot>
+ </connection>
+ <connection>
+ <sender>WebBrowser</sender>
+ <signal>NavigateComplete(const QString&)</signal>
+ <receiver>addressEdit</receiver>
+ <slot>setText(const QString&)</slot>
+ </connection>
+ <connection>
+ <sender>WebBrowser</sender>
+ <signal>TitleChange(const QString&)</signal>
+ <receiver>MainWindow</receiver>
+ <slot>setTitle(const QString&)</slot>
+ </connection>
+ <connection>
+ <sender>WebBrowser</sender>
+ <signal>NavigateComplete(const QString&)</signal>
+ <receiver>MainWindow</receiver>
+ <slot>navigateComplete()</slot>
+ </connection>
+ <connection>
+ <sender>WebBrowser</sender>
+ <signal>CommandStateChange(int,bool)</signal>
+ <receiver>MainWindow</receiver>
+ <slot>setCommandState(int,bool)</slot>
+ </connection>
+ <connection>
+ <sender>WebBrowser</sender>
+ <signal>BeforeNavigate(const QString&,int,const QString&,const QVariant&,const QString&,bool&)</signal>
+ <receiver>MainWindow</receiver>
+ <slot>navigateBegin()</slot>
+ </connection>
+ <connection>
+ <sender>actionStop</sender>
+ <signal>activated()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>navigateComplete()</slot>
+ </connection>
+ <connection>
+ <sender>actionNewWindow</sender>
+ <signal>activated()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>newWindow()</slot>
+ </connection>
+ <connection>
+ <sender>actionAbout</sender>
+ <signal>activated()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>aboutSlot()</slot>
+ </connection>
+ <connection>
+ <sender>actionAboutQt</sender>
+ <signal>activated()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>aboutQtSlot()</slot>
+ </connection>
+</connections>
+<forwards>
+ <forward>class QProgressBar</forward>
+</forwards>
+<variables>
+ <variable>QProgressBar *pb;</variable>
+</variables>
+<slots>
+ <slot>go()</slot>
+ <slot>newWindow()</slot>
+ <slot>setProgress( int a, int b )</slot>
+ <slot>init()</slot>
+ <slot>setTitle( const QString & title )</slot>
+ <slot>setCommandState( int cmd, bool on )</slot>
+ <slot>navigateComplete()</slot>
+ <slot>navigateBegin()</slot>
+ <slot>aboutSlot()</slot>
+ <slot>aboutQtSlot()</slot>
+</slots>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>qaxwidget.h</includehint>
+</includehints>
+</UI>
diff --git a/examples3/webbrowser/webbrowser.py b/examples3/webbrowser/webbrowser.py new file mode 100644 index 0000000..bd1462e --- /dev/null +++ b/examples3/webbrowser/webbrowser.py @@ -0,0 +1,91 @@ +# Copyright (C) 2001-2002 Trolltech AS. All rights reserved. +# Copyright (C) 2004 Riverbank Computing Ltd. All rights reserved. +# +# This file is part of an example program for the ActiveQt integration. +# This example program may be used, distributed and modified without +# limitation. + + +import sys +import qt +import qtaxcontainer + +import mainwindow + + +class MainWindowImpl(mainwindow.MainWindow): + def init(self): + self.pb = qt.QProgressBar(self.statusBar()) + self.pb.setPercentageVisible(False) + self.pb.hide() + self.statusBar().addWidget(self.pb, 0, True) + + self.connect(self.WebBrowser, qt.SIGNAL("ProgressChange(int,int)"), self.setProgress) + self.connect(self.WebBrowser, qt.SIGNAL("StatusTextChange(const QString&)"), self.statusBar(), qt.SLOT("message(const QString&)")) + + self.WebBrowser.dynamicCall("GoHome()"); + + self.subwindows = [] + + def go(self): + self.actionStop.setEnabled(True) + self.WebBrowser.dynamicCall("Navigate(const QString&)", qt.QVariant(self.addressEdit.text())) + + def setTitle(self, title): + self.setCaption("Qt WebBrowser - " + title.latin1()) + + def setProgress(self, a, b): + if a <= 0 or b <= 0: + self.pb.hide() + return + + self.pb.show() + self.pb.setTotalSteps(b) + self.pb.setProgress(a) + + def setCommandState(self, cmd, on): + if cmd == 1: + self.actionForward.setEnabled(on) + elif cmd == 2: + self.actionBack.setEnabled(on) + + def navigateBegin(self): + self.actionStop.setEnabled(True) + + def navigateComplete(self): + self.actionStop.setEnabled(False) + + def newWindow(self): + window = MainWindowImpl() + window.show() + + if self.addressEdit.text().isEmpty(): + return + + window.addressEdit.setText(self.addressEdit.text()) + window.actionStop.setEnabled(True) + window.go() + + self.subwindows += window + + def aboutSlot(self): + qt.QMessageBox.about(self, self.tr("About WebBrowser"), self.tr( +"""This Example has been created using the ActiveQt integration into Qt Designer. +It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX +control into a Qt application.""")) + + def aboutQtSlot(self): + qt.QMessageBox.aboutQt(self, self.tr("About Qt")) + + +def main(args): + a = qt.QApplication(args) + w = MainWindowImpl() + a.setMainWidget(w) + w.show() + + return a.exec_loop() + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/examples3/widgets.py b/examples3/widgets.py new file mode 100755 index 0000000..470f24e --- /dev/null +++ b/examples3/widgets.py @@ -0,0 +1,500 @@ +#!/usr/bin/env python + + +import sys, string +from qt import * + +# +## Constructs an analog clock widget that uses an internal QTimer. +# +def QMIN( x, y ): + if y > x: + return y + return x + +# +## Constructs an analog clock widget that uses an internal QTimer. +# + +class AnalogClock( QWidget ): + def __init__( self, *args ): + apply( QWidget.__init__, (self,) + args ) + self.time = QTime.currentTime() # get current time + internalTimer = QTimer( self ) # create internal timer + self.connect( internalTimer, SIGNAL("timeout()"), self.timeout ) + internalTimer.start( 5000 ) # emit signal every 5 seconds + +# +## The QTimer::timeout() signal is received by this slot. +# + + def timeout( self ): + new_time = QTime.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 = QTime.currentTime() # save current time + + pts = QPointArray() + paint = QPainter( self ) + paint.setBrush( self.foregroundColor() ) # fill with foreground color + + cp = QPoint( self.rect().center() ) # widget center point + d = QMIN( self.width(), self.height() ) # we want a circular clock + + matrix = QWMatrix() # 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( QLCDNumber ): + def __init__( self, *args ): + apply( QLCDNumber.__init__,(self,) + args ) + self.showingColon = 0 + self.setFrameStyle(QFrame.Panel | QFrame.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() == Qt.LeftButton: + self.showDate() + + def showDate( self ): + if self.showDateTimer != -1: + return + d = QDate.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(QTime.currentTime().toString())[:5]) #.left(5) + if not self.showingColon: + s[2] = ' ' + if s[0] == '0': + s[0] = ' ' + s = string.join(s,'') + self.display( s ) + + def QMIN( x, y ): + if y > x: + return y + return x + +TRUE = 1 +FALSE = 0 +MOVIEFILENAME = "trolltech.gif" + +# +# WidgetView contains lots of Qt widgets. +# + +class WidgetView ( QWidget ): + def __init__( self, *args ): + apply( QWidget.__init__, (self,) + args ) + + # Set the window caption/title + self.setCaption( "Qt Widgets Demo Application" ) + + # Install an application-global event filter + qApp.installEventFilter( self ) + + # Create a layout to position the widgets + self.topLayout = QVBoxLayout( self, 10 ) + + # Create a grid layout to hold most of the widgets + self.grid = QGridLayout( 6, 3 ) + + # This layout will get all of the stretch + self.topLayout.addLayout( self.grid, 10 ) + + # Create a menubar + self.menubar = QMenuBar( self ) + self.menubar.setSeparator( QMenuBar.InWindowsStyle ) + + # Create an easter egg + QToolTip.add( self.menubar, QRect( 0, 0, 2, 2 ), "easter egg" ) + + self.popup = QPopupMenu() + 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", qApp, SLOT("quit()"), Qt.CTRL+Qt.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 = QColor() + col.setRgb( 0xaa, 0xbe, 0xff ) + self.dclock.setPalette( QPalette( col ) ) + + # make tool tips for both of them + QToolTip.add( self.aclock, "custom widget: analog clock" ) + QToolTip.add( self.dclock, "custom widget: digital clock" ) + + # Create a push button. + self.pb = QPushButton( 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, Qt.AlignVCenter ) + self.connect( self.pb, SIGNAL("clicked()"), self.button1Clicked ) + QToolTip.add( self.pb, "push button 1" ) + self.pm = QPixmap() + self.pix = self.pm.load( "qt.png" ) # load pixmap for button 2 + if not self.pix: + QMessageBox.information( None, "Qt Widgets Example", + "Could not load the file \"qt.png\", which\n" + "contains an icon used...\n\n" + "The text \"line 42\" will be substituted.", + QMessageBox.Ok + QMessageBox.Default ) + + # Create a label containing a QMovie + self.movielabel = QLabel( self, "label0" ) + self.movie = QMovie( MOVIEFILENAME ) + self.movie.connectStatus( self.movieStatus ) + self.movie.connectUpdate( self.movieUpdate ) + self.movielabel.setFrameStyle( QFrame.Box | QFrame.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, Qt.AlignCenter ) + QToolTip.add( self.movielabel, "movie" ) + + # Create a group of check boxes + self.bg = QButtonGroup( self, "checkGroup" ) + self.bg.setTitle( "Check Boxes" ) + self.grid.addWidget( self.bg, 1, 0 ) + + # Create a layout for the check boxes + self.vbox = QVBoxLayout(self.bg, 10) + + self.vbox.addSpacing( self.bg.fontMetrics().height() ) + + self.cb = range(3) + self.cb[0] = QCheckBox( self.bg ) + self.cb[0].setText( "Read" ) + self.vbox.addWidget( self.cb[0] ) + self.cb[0].setMinimumSize( self.cb[0].sizeHint() ) + self.cb[1] = QCheckBox( self.bg ) + self.cb[1].setText( "Write" ) + self.vbox.addWidget( self.cb[1] ) + self.cb[1].setMinimumSize( self.cb[1].sizeHint() ) + self.cb[2] = QCheckBox( 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 ) + + QToolTip.add( self.cb[0], "check box 1" ) + QToolTip.add( self.cb[1], "check box 2" ) + QToolTip.add( self.cb[2], "check box 3" ) + + # Create a group of radio buttons + self.bg = QButtonGroup( self, "radioGroup" ) + self.bg.setTitle( "Radio buttons" ) + + self.grid.addWidget( self.bg, 1, 1 ) + + # Create a layout for the radio buttons + self.vbox = QVBoxLayout( self.bg, 10 ) + + self.vbox.addSpacing( self.bg.fontMetrics().height() ) + self.rb = QRadioButton( self.bg ) + self.rb.setText( "&AM" ) + self.rb.setChecked( TRUE ) + self.vbox.addWidget( self.rb ) + self.rb.setMinimumSize( self.rb.sizeHint() ) + QToolTip.add( self.rb, "radio button 1" ) + self.rb = QRadioButton( self.bg ) + self.rb.setText( "&FM" ) + self.vbox.addWidget( self.rb ) + self.rb.setMinimumSize( self.rb.sizeHint() ) + QToolTip.add( self.rb, "radio button 2" ) + self.rb = QRadioButton( 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 ) + QToolTip.add( self.rb, "radio button 3" ) + + # Create a list box + self.lb = QListBox( self, "listBox" ) + for i in range( 0, 100, 1 ): # fill list box + txt = QString() + 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 ) + QToolTip.add( self.lb, "list box" ) + + self.vbox = QVBoxLayout( 8 ) + self.grid.addLayout( self.vbox, 2, 1 ) + + # Create a slider + self.sb = QSlider( 0, 300, 1, 100, QSlider.Horizontal, self, "Slider" ) + self.sb.setTickmarks( QSlider.Below ) + self.sb.setTickInterval( 10 ) + self.sb.setFocusPolicy( QWidget.TabFocus ) + self.sb.setFixedHeight( self.sb.sizeHint().height() ) + self.vbox.addWidget( self.sb ) + + self.connect( self.sb, SIGNAL("valueChanged(int)"), self.sliderValueChanged ) + QToolTip.add( self.sb, "slider" ) + + # Create a combo box + self.combo = QComboBox( 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 ) + QToolTip.add( self.combo, "read-only combo box" ) + + # Create an editable combo box + self.edCombo = QComboBox( 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 QString &)"), self.edComboBoxItemActivated) + QToolTip.add( self.edCombo, "editable combo box" ) + + self.edCombo.setAutoCompletion( TRUE ) + + self.vbox.addStretch( 1 ) + + self.vbox = QVBoxLayout( 8 ) + self.grid.addLayout( self.vbox, 2, 2 ) + + # Create a spin box + self.spin = QSpinBox( 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 QString &)" ), self.spinBoxValueChanged ) + QToolTip.add( self.spin, "spin box" ) + self.vbox.addWidget( self.spin ) + + self.vbox.addStretch( 1 ) + + # Create a multi line edit + self.mle = QMultiLineEdit( 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 QMultiLineEdit widget,\n" + "useful for small multi-line\n" + "input fields.") + QToolTip.add( self.mle, "multi line editor" ) + + # Create a single line edit + self.le = QLineEdit( 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 QString &)"), self.lineEditTextChanged ) + QToolTip.add( self.le, "single line editor" ) + + # Create a horizontal line (sort of QFrame) above the message line + self.separator = QFrame( self, "separatorLine" ) + self.separator.setFrameStyle( QFrame.HLine | QFrame.Sunken ) + self.separator.setFixedHeight( self.separator.sizeHint().height() ) + self.grid.addMultiCellWidget( self.separator, 5, 5, 0, 2 ) + QToolTip.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 = QHBoxLayout() + self.topLayout.addLayout( self.hbox ) + self.msgLabel = QLabel( self, "msgLabel" ) + self.msgLabel.setText( "Message:" ) + self.msgLabel.setAlignment( Qt.AlignHCenter | Qt.AlignVCenter ) + self.msgLabel.setFixedSize( self.msgLabel.sizeHint() ) + self.hbox.addWidget( self.msgLabel ) + QToolTip.add( self.msgLabel, "label 1" ) + + self.msg = QLabel( self, "message" ) + self.msg.setFrameStyle( QFrame.Panel | QFrame.Sunken ) + self.msg.setAlignment( Qt.AlignCenter ) + self.msg.setFont( QFont( "times", 12, QFont.Bold ) ) + self.msg.setText( "Message" ) + self.msg.setFixedHeight( self.msg.sizeHint().height() ) + self.msg.setText( "" ) + self.hbox.addWidget( self.msg, 5 ) + QToolTip.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 == QMovie.SourceEmpty or s == QMovie.UnrecognizedFormat: + pm = QPixmap('tt-logo.png') + self.movielabel.setPixmap(pm) + self.movielabel.setFixedSize(pm.size()) + else: + if ( self.movielabel.movie() ): # for flicker-free animation: + self.movielabel.setBackgroundMode( QWidget.NoBackground ) + + def button1Clicked( self ): + self.msg.setText( "The first push button was clicked" ) + + def checkBoxClicked( self, id ): + 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): + self.msg.setText( "Editable Combo Box set to %s" % text ) + + def radioButtonClicked( self, id ): + self.msg.setText( "Radio button #%d clicked" % id ) + + def listBoxItemSelected( self, index ): + self.msg.setText( "List box item %d selected" % index ) + + def sliderValueChanged( self, value ): + self.msg.setText( "Movie set to %d%% of normal speed" % value ) + self.movie.setSpeed( value ) + + def comboBoxItemActivated( self, index ): + self.msg.setText( "Combo box item %d activated" % index ) + p = QApplication.palette() + if index == 0: + p.setColor( QColorGroup.Highlight, Qt.darkBlue ) + elif index == 1: + p.setColor( QColorGroup.Highlight, Qt.darkRed ) + elif index == 2: + p.setColor( QColorGroup.Highlight, Qt.darkGreen ) + elif index == 3: + p.setColor( QColorGroup.Highlight, Qt.blue ) + elif index == 4: + p.setColor( QColorGroup.Highlight, Qt.red ) + QApplication.setPalette( p, TRUE ) + + def lineEditTextChanged( self, newText ): + self.msg.setText("Line edit text: " + unicode(newText)) + + def spinBoxValueChanged( self, valueText ): + self.msg.setText("Spin box value: " + unicode(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 = QMouseEvent( event ) + # if (e.button() == Qt.RightButton) and (e.state() & Qt.ControlButton) != 0: + # txt = QString( "The clicked widget is a\n" ) + # txt = txt + QObect.className() + # txt = txt + "\nThe widget's name is\n" + # if QObject.name(): + # txt = txt + QObject.name() + # else: + # txt = txt + "<no name>" + # identify_now = FALSE # don't do it in message box + # QMessageBox.message( "Identify Widget", txt, 0, QObject ) + # identify_now = TRUE; # allow it again + # return FALSE # don't eat event + +################################################################################################ + +#QApplication.setColourSpec( QApplication.CustomColor ) +a = QApplication( sys.argv ) + +w = WidgetView() +a.setMainWidget( w ) +w.show() +a.exec_loop() |