diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-08-16 09:06:37 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-08-16 09:06:37 +0000 |
commit | 39d98386f72c65826e162e3e8fd36752ec469252 (patch) | |
tree | 5cec746207c4c892d064beafca1de94568a3aeb9 /examples/uimodules | |
download | pytde-39d98386f72c65826e162e3e8fd36752ec469252.tar.gz pytde-39d98386f72c65826e162e3e8fd36752ec469252.zip |
Move python-kde3 to the more correct python-trinity
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/python-trinity@1247483 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'examples/uimodules')
-rw-r--r-- | examples/uimodules/uidialogs.py | 232 | ||||
-rw-r--r-- | examples/uimodules/uimenus.py | 108 | ||||
-rw-r--r-- | examples/uimodules/uimisc.py | 239 | ||||
-rw-r--r-- | examples/uimodules/uiwidgets.py | 754 | ||||
-rw-r--r-- | examples/uimodules/uixml.py | 45 |
5 files changed, 1378 insertions, 0 deletions
diff --git a/examples/uimodules/uidialogs.py b/examples/uimodules/uidialogs.py new file mode 100644 index 0000000..0f86072 --- /dev/null +++ b/examples/uimodules/uidialogs.py @@ -0,0 +1,232 @@ +from qt import QVBox, QLabel, QLineEdit, QString, QPixmap, QPushButton, QColor, SIGNAL, QButtonGroup,\ + QRadioButton, Qt, QWidget + +from kdecore import KAccel, i18n + +from kdeui import KAboutDialog, KAboutKDE, KBugReport, KColorDialog, KDialog, KDialogBase, KFontDialog,\ + KPasswordDialog, KMessageBox, KLineEditDlg, KKeyDialog, KWizard + +# despite what the docs say, there is no enum (in 2.1.1 anyway) +# that contains these values +QuestionYesNo = 0 +WarningYesNo = 1 +WarningContinueCancel = 2 +WarningYesNoCancel = 3 +Information = 4 +Sorry = 5 +Error = 6 + +# Python 2.2.2 supplies these, but they're duplicated here +# for backward compatibility +False = 0 +True = 1 + +class CustomDlg (KDialog): + def __init__ (self, parent, name = "custom dlg", modal = False): + KDialog.__init__ (self, parent, name, modal) + + x = 20 + y = 10 + + rLbl = QLabel ("r", self) + gLbl = QLabel ("g", self) + bLbl = QLabel ("b", self) + self.rEd = QLineEdit ("64", self) + self.gEd = QLineEdit ("64", self) + self.bEd = QLineEdit ("64", self) + self.dlgBtn = QPushButton ("Set/Get Color", self) + self.okBtn = QPushButton ("OK", self) + self.canBtn = QPushButton ("Cancel", self) + + rLbl.setGeometry (x, y, 25, 20) + gLbl.setGeometry (x + 30, y, 25, 20) + bLbl.setGeometry (x + 60, y, 25, 20) + y = y + 20 + self.rEd.setGeometry (x, y, 25, 20) + self.gEd.setGeometry (x + 30, y, 25, 20) + self.bEd.setGeometry (x + 60, y, 25, 20) + y = y + 30 + self.dlgBtn.setGeometry (x, y, 90, 22) + y = y + 30 + self.okBtn.setGeometry (x, y, 40, 22) + self.canBtn.setGeometry (x + 50, y, 40, 22) + + self.connect (self.dlgBtn, SIGNAL ("clicked()"), self.dlgClicked) + self.connect (self.okBtn, SIGNAL ("clicked ()"), self.okClicked) + self.connect (self.canBtn, SIGNAL ("clicked ()"), self.cancelClicked) + + def dlgClicked (self): + # get some (numerical) color values from the original dialog + red = int (self.rEd.text ().latin1 ()) + green = int (self.gEd.text ().latin1 ()) + blue = int (self.bEd.text ().latin1 ()) + + # convert the numbers to a QColor + color = QColor (red, green, blue) + + # invoke the dialog (getColor is a 'static' call) + # initialize with the colors from above (in color) + # color will also hold the new value chosen in the + # KColorDialog + result = KColorDialog.getColor (color, self) + + # get the numerical color values back + red, green, blue = color.rgb () + + # update the QLineEdits in the original dialog + self.rEd.setText (str (red)) + self.gEd.setText (str (green)) + self.bEd.setText (str (blue)) + + def okClicked (self): + self.done (1) + + def cancelClicked (self): + self.done (0) + +class MessageDlg (KDialog): + def __init__ (self, parent, name = "message dlg", modal = False): + KDialog.__init__ (self, parent, name, modal) + + buttons = ["QuestionYesNo", "WarningYesNo", "WarningContiueCancel", "WarningYesNoCancel",\ + "Information", "Sorry", "Error"] + + n = len (buttons) + + grp = QButtonGroup (n, Qt.Vertical, "MessageBoxes", self, "button grp") + grp.setGeometry (10, 10, 200, 30*n) + for i in range (n): + QRadioButton (buttons [i], grp) + + self.connect (grp, SIGNAL ("clicked (int)"), self.launch) + + def launch (self, which): + if which == QuestionYesNo: + KMessageBox.questionYesNo (self, "This is a questionYesNo message box\nThere is also a list version of this dialog",\ + "questionYesNo") + + elif which == WarningYesNo: + KMessageBox.warningYesNo (self, "This is a warningYesNo message box", "warningYesNo") + + elif which == WarningContinueCancel: + KMessageBox.warningContinueCancel (self, "This is a warningContinueCancel message box", "warningContinueCancel"); + + elif which == WarningYesNoCancel: + KMessageBox.warningYesNoCancel (self, "This is a warningYesNoCancel message box", "warningYesNoCancel") + + elif which == Information: + KMessageBox.information (self, "This is an information message box", "Information") + + elif which == Sorry: + KMessageBox.sorry (self, "This is a 'sorry' message box", "Sorry") + + elif which == Error: + KMessageBox.error (self, "No - this isn't really an error\nIt's an error message box\n", "Error") + + +def dlgKAboutDialog (parent): + dlg = KAboutDialog (parent, 'about dialog', False) + dlg.setLogo (QPixmap ("pytestimage.png")) + dlg.setTitle ("UISampler for PyKDE") + dlg.setAuthor ("Jim Bublitz", "jbublitz@nwinternet.com", "http://www.riverbankcomputing.co.uk",\ + "\n\nPyKDE -- Python bindings\n\tfor KDE") + dlg.addContributor ("PyKDE list", "pykde@mats.gmd.de", QString.null, QString.null) + + dlg.show () + + +def dlgKBugReport (parent): + dlg = KBugReport (parent) + dlg.exec_loop () + +def dlgKAboutKDE (parent): + dlg = KAboutKDE (parent, "about kde", False) + dlg.show () + +def dlgKColorDialog (parent): + dlg = KColorDialog (parent, "color dlg", False) + dlg.show () + +def dlgKDialog (parent): + dlg = CustomDlg (parent) + dlg.show () + +def dlgKDialogBase (parent): + caption = "KDialogBase sample" + text_ = "This is a KDialogBase example" + dlg = KDialogBase (parent, "sample_dialog", False, caption,\ + KDialogBase.Ok | KDialogBase.Cancel, KDialogBase.Ok, True ) + + page = dlg.makeVBoxMainWidget(); + + # making 'page' the parent inserts the widgets in + # the VBox created above + label = QLabel( caption, page, "caption" ); + + lineedit = QLineEdit(text_, page, "lineedit" ); + lineedit.setMinimumWidth(dlg.fontMetrics().maxWidth()*20); + + # This tests some handwritten code in KDialogBase + label0 = QLabel ("Border widths", page) + a, b, c, d = dlg.getBorderWidths () + labelA = QLabel ("Upper Left X: " + str (a), page) + labelB = QLabel ("Upper Left Y: " + str (b), page) + labelC = QLabel ("Lower Right X: " + str (c), page) + labelD = QLabel ("Lower Right Y: " + str (d), page) + + dlg.show () + +def dlgKFontDialog (parent): + dlg = KFontDialog (parent, "font dlg", False, False) + dlg.show () + +def dlgKKeyDialog (parent): + # This really doesn't do anything except pop up the dlg + keys = KAccel (parent) + keys.insertItem( i18n( "Zoom in" ), "Zoom in", "+" ); + keys.readSettings(); + KKeyDialog.configureKeys (keys) + +def dlgKLineEditDlg (parent): + result, ok = KLineEditDlg.getText ("Enter text", "<Your input here>", parent) + print "result", result + print "ok", ok + + # pop up another dlg to show what happened in the KLineEditDlg + if ok: + result = result.latin1 () + KMessageBox.information (parent, "OK was pressed\nText: " + result, "KLineEditDlg result") + else: + result = "" + KMessageBox.information (parent, "Cancel pressed\nText: " + result, "KLineEditDlg result") + +def dlgKMessageBox (parent): + dlg = MessageDlg (parent) + dlg.show () + +def dlgKPasswordDialog (parent): + dlg = KPasswordDialog (KPasswordDialog.Password, "Enter password (just a test)") + dlg.exec_loop () + +def dlgKWizard (parent): + wiz = KWizard (parent) + + page1 = QWidget (wiz) + p1Lbl = QLabel ("This is page 1", page1) + p1Lbl.setGeometry (20, 20, 100, 20) + page2 = QWidget (wiz) + p2Lbl = QLabel ("This is page 2", page2) + p2Lbl.setGeometry (50, 20, 100, 20) + page3 = QWidget (wiz) + p3Lbl = QLabel ("This is page 3", page3) + p3Lbl.setGeometry (80, 20, 100, 20) + + wiz.addPage (page1, "Page 1") + wiz.addPage (page2, "Page 2") + wiz.addPage (page3, "Page 3") + wiz.show () + +if __name__ == "__main__": + print + print "Please run uisampler.py" + print
\ No newline at end of file diff --git a/examples/uimodules/uimenus.py b/examples/uimodules/uimenus.py new file mode 100644 index 0000000..19173b3 --- /dev/null +++ b/examples/uimodules/uimenus.py @@ -0,0 +1,108 @@ +import os + +from qt import QLabel + +from kdecore import KApplication + +class PageLaunch: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + launchLbl = QLabel ("Launching application ... please wait\n\nClose launched application to continue", self.page) + launchLbl.setGeometry (x, y, 300, 80) + launchLbl.show () + + self.page.show () + + KApplication.kApplication ().processEvents () + + +class PageNotImpl: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + niLbl = QLabel ("Nothing is currently implemented for this widget", self.page) + niLbl.setGeometry (x, y, 300, 20) + niLbl.show () + + +def menuKAccelGen (parent): + parent.currentPageObj = PageNotImpl (parent) + +def menuKAccelMenu (parent): + parent.currentPageObj = PageNotImpl (parent) + +def menuKAction (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKActionMenu (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKActionSeparator (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKContextMenuManager (parent): + pass + +def menuKDCOPActionProxy (parent): + pass + +def menuKHelpMenu (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKMenuBar (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKPanelApplet (parent): + parent.currentPageObj = PageNotImpl (parent) + +def menuKPanelExtension (parent): + parent.currentPageObj = PageNotImpl (parent) + +def menuKPanelMenu (parent): + parent.currentPageObj = PageNotImpl (parent) + +def menuKPopupFrame (parent): + pass + +def menuKPopupMenu (parent): + pass + +def menuKPopupTitle (parent): + pass + +def menuKStatusBar (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKStatusBarLabel (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKStdAction (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKToolBar (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python menudemo.py") + +def menuKWindowListMenu (parent): + pass + + +if __name__ == "__main__": + print + print "Please run uisampler.py" + print
\ No newline at end of file diff --git a/examples/uimodules/uimisc.py b/examples/uimodules/uimisc.py new file mode 100644 index 0000000..31f7c18 --- /dev/null +++ b/examples/uimodules/uimisc.py @@ -0,0 +1,239 @@ +import os, time + +from qt import QImage, QLabel, QPixmap, QPushButton, SIGNAL, QColor, QValidator + +from kdeui import KMessageBox, KDateValidator, KFloatValidator, KIntValidator, KLineEdit, KLed + + + +class Page3: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 15 + + green = QColor (0, 255, 0) + yellow = QColor (255, 255, 0) + red = QColor (255, 0, 0) + + ivLbl = QLabel ("KIntValidator", self.page) + ivLbl.setGeometry (x, y, 100, 20) + ivLbl.show () + + self.iv = KLineEdit (self.page) + self.iv.setGeometry (x, y + 20, 100, 20) + self.iv.show () + self.page.connect (self.iv, SIGNAL("textChanged (const QString &)"), self.ivChanged) + + self.ivVal = KIntValidator (self.page) + self.ivVal.setRange (20, 50) + + ivRngLbl = QLabel ("Range is 20 - 50", self.page) + ivRngLbl.setGeometry (x, y + 45, 100, 20) + ivRngLbl.show () + + ivAccLbl = QLabel ("Acceptable", self.page) + ivAccLbl.setGeometry (x + 125, y + 45, 85, 20) + ivAccLbl.show () + ivInterLbl = QLabel ("Intermediate", self.page) + ivInterLbl.setGeometry (x + 125, y + 20, 85, 20) + ivInterLbl.show () + ivInvalLbl = QLabel ("Invalid", self.page) + ivInvalLbl.setGeometry (x + 125, y - 5, 85, 20) + ivInvalLbl.show () + self.ivInvalLed = KLed (red, KLed.Off, KLed.Sunken, KLed.Circular,self.page) + self.ivInvalLed.setGeometry (x + 215, y - 5, 18, 18) + self.ivInvalLed.show () + self.ivInterLed = KLed (yellow, KLed.Off, KLed.Sunken, KLed.Circular,self.page) + self.ivInterLed.setGeometry (x + 215, y + 20, 18, 18) + self.ivInterLed.show () + self.ivAccLed = KLed (green, KLed.On, KLed.Sunken, KLed.Circular,self.page) + self.ivAccLed.setGeometry (x + 215, y + 45, 18, 18) + self.ivAccLed.show () + + y = y + 100 + + fvLbl = QLabel ("KFloatValidator", self.page) + fvLbl.setGeometry (x, y, 100, 20) + fvLbl.show () + + self.fv = KLineEdit (self.page) + self.fv.setGeometry (x, y + 20, 100, 20) + self.fv.show () + self.page.connect (self.fv, SIGNAL("textChanged (const QString &)"), self.fvChanged) + + self.fvVal = KFloatValidator (self.page) + self.fvVal.setRange (10.0, 40.0) + + fvRngLbl = QLabel ("Range is 10.0 - 40.0", self.page) + fvRngLbl.setGeometry (x, y + 45, 100, 20) + fvRngLbl.show () + + fvAccLbl = QLabel ("Acceptable", self.page) + fvAccLbl.setGeometry (x + 125, y + 45, 85, 20) + fvAccLbl.show () + fvInterLbl = QLabel ("Intermediate", self.page) + fvInterLbl.setGeometry (x + 125, y + 20, 95, 20) + fvInterLbl.show () + fvInvalLbl = QLabel ("Invalid", self.page) + fvInvalLbl.setGeometry (x + 125, y - 5, 85, 20) + fvInvalLbl.show () + self.fvInvalLed = KLed (red, KLed.Off, KLed.Sunken, KLed.Circular,self.page) + self.fvInvalLed.setGeometry (x + 215, y - 5, 18, 18) + self.fvInvalLed.show () + self.fvInterLed = KLed (yellow, KLed.Off, KLed.Sunken, KLed.Circular,self.page) + self.fvInterLed.setGeometry (x + 215, y + 20, 18, 18) + self.fvInterLed.show () + self.fvAccLed = KLed (green, KLed.On, KLed.Sunken, KLed.Circular,self.page) + self.fvAccLed.setGeometry (x + 215, y + 45, 18, 18) + self.fvAccLed.show () + + y = y + 100 + + dvLbl = QLabel ("KDateValidator", self.page) + dvLbl.setGeometry (x, y, 100, 20) + dvLbl.show () + + self.dv = KLineEdit (self.page) + self.dv.setGeometry (x, y + 20, 100, 20) + self.dv.show () +# self.page.connect (self.dv, SIGNAL("textChanged (const QString &)"), self.dvChanged) + + self.dvVal = KDateValidator (self.page) +# self.dvVal.setRange (10.0, 40.0) + +# dvRngLbl = QLabel ("Range is 10.0 - 40.0", self.page) +# dvRngLbl.setGeometry (x, y + 45, 100, 20) +# dvRngLbl.show () + + dvBtn = QPushButton ("Validate", self.page) + dvBtn.setGeometry (x, y + 45, 60, 22) + dvBtn.show () + self.page.connect (dvBtn, SIGNAL ("clicked ()"), self.dvChanged) + + dvNoteLbl = QLabel ("Format is locale dependent\nShort date only\nTry DD-MM-YY", self.page) + dvNoteLbl.setGeometry (x, y + 70, 150, 60) + dvNoteLbl.show () + + dvAccLbl = QLabel ("Acceptable", self.page) + dvAccLbl.setGeometry (x + 125, y + 45, 85, 20) + dvAccLbl.show () + dvInterLbl = QLabel ("Intermediate", self.page) + dvInterLbl.setGeometry (x + 125, y + 20, 85, 20) + dvInterLbl.show () + dvInvalLbl = QLabel ("Invalid", self.page) + dvInvalLbl.setGeometry (x + 125, y - 5, 85, 20) + dvInvalLbl.show () + self.dvInvalLed = KLed (red, KLed.Off, KLed.Sunken, KLed.Circular,self.page) + self.dvInvalLed.setGeometry (x + 215, y - 5, 18, 18) + self.dvInvalLed.show () + self.dvInterLed = KLed (yellow, KLed.Off, KLed.Sunken, KLed.Circular,self.page) + self.dvInterLed.setGeometry (x + 215, y + 20, 18, 18) + self.dvInterLed.show () + self.dvAccLed = KLed (green, KLed.On, KLed.Sunken, KLed.Circular,self.page) + self.dvAccLed.setGeometry (x + 215, y + 45, 18, 18) + self.dvAccLed.show () + + def ivChanged (self): + self.ivInvalLed.off () + self.ivInterLed.off () + self.ivAccLed.off () + + state, i = self.ivVal.validate (self.iv.text ()) + + if state == QValidator.Acceptable: + self.ivAccLed.on () + elif state == QValidator.Intermediate: + self.ivInterLed.on () + else: + self.ivInvalLed.on () + + def fvChanged (self): + self.fvInvalLed.off () + self.fvInterLed.off () + self.fvAccLed.off () + + state, i = self.fvVal.validate (self.fv.text ()) + + if state == QValidator.Acceptable: + self.fvAccLed.on () + elif state == QValidator.Intermediate: + self.fvInterLed.on () + else: + self.fvInvalLed.on () + + def dvChanged (self): + self.dvInvalLed.off () + self.dvInterLed.off () + self.dvAccLed.off () + + state, i = self.dvVal.validate (self.dv.text ()) + + if state == QValidator.Acceptable: + self.dvAccLed.on () + elif state == QValidator.Intermediate: + self.dvInterLed.on () + else: + self.dvInvalLed.on () + +class PageNotImpl: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + niLbl = QLabel ("Nothing is currently implemented for this widget", self.page) + niLbl.setGeometry (x, y, 300, 20) + niLbl.show () + +def miscKAlphaPainter (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKCModule (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKColor (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKColorDrag (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKCommand (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKCommandHistory (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKDockWindow (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKFloatValidator (parent): + parent.currentPageObj = Page3 (parent) + +def miscKDateValidator (parent): + parent.currentPageObj = Page3 (parent) + +def miscKIntValidator (parent): + parent.currentPageObj = Page3 (parent) + +def miscKPixmapIO (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKSharedPixmap (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscKSystemTray (parent): + KMessageBox.information (parent, "See the systray.py example in the templates/ subdirectories") + +def miscKThemeBase (parent): + parent.currentPageObj = PageNotImpl (parent) + +def miscQXEmbed (parent): + parent.currentPageObj = PageNotImpl (parent) + +if __name__ == "__main__": + print + print "Please run uisampler.py" + print
\ No newline at end of file diff --git a/examples/uimodules/uiwidgets.py b/examples/uimodules/uiwidgets.py new file mode 100644 index 0000000..b12df10 --- /dev/null +++ b/examples/uimodules/uiwidgets.py @@ -0,0 +1,754 @@ +import time, sys + +from qt import QLabel, QFrame, QColor, QPushButton, SIGNAL, QButtonGroup, QRadioButton, Qt, QString, QChar,\ + QWidget, QTimer + +from kdecore import KApplication +from kdeui import KEdit, KComboBox, KColorCombo, KEditListBox, KListBox, KLineEdit, KRestrictedLine,\ + KSqueezedTextLabel, KFontChooser, KButtonBox, KColorButton, KColorCells,\ + KColorPatch, KDualColorButton,\ + KRootPermsIcon, KWritePermsIcon, KCharSelect, KDialog, KLed, KRootPixmap,\ + KTabCtl, KProgress, KDatePicker, KDateTable, KGradientSelector, KHSSelector,\ + KIntNumInput, KDoubleNumInput, KPasswordEdit, KURLLabel, KPaletteTable,\ + KSeparator + +if sys.version [:6] < "2.2.2": + False = 0 + True = 1 + +class Page1: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + editLbl = QLabel ("KEdit", self.page) + editLbl.setGeometry (x, y, 50, 20) + editLbl.show () + + textList = ["Now is the winter of our discontent",\ + "made glorious summer by this sun of York;",\ + "and all the clouds that lour'd upon our house",\ + "in the deep bosom of the ocean buried."] + + parent.edit = KEdit (self.page) + parent.edit.setGeometry (x, y + 20, 300, 100) + for line in textList: + parent.edit.insertLine (line) + parent.edit.show () + + y = y + 125 + searchBtn = QPushButton ("Search", self.page) + replaceBtn = QPushButton ("Replace", self.page) + gotoBtn = QPushButton ("GoTo Line", self.page) + + searchBtn.setGeometry (x, y, 60, 22) + replaceBtn.setGeometry (x + 90, y, 60, 22) + gotoBtn.setGeometry (x + 180, y, 60, 22) + + self.page.connect (searchBtn, SIGNAL ("clicked ()"), parent.edit.search) + self.page.connect (replaceBtn, SIGNAL ("clicked ()"), parent.edit.replace) + self.page.connect (gotoBtn, SIGNAL ("clicked ()"), parent.edit.doGotoLine) + + searchBtn.show () + replaceBtn.show () + gotoBtn.show () + + y = y + 35 + + lineeditLbl = QLabel ("KLineEdit", self.page) + lineeditLbl.setGeometry (x, y, 70, 20) + lineeditLbl.show () + + lineedit = KLineEdit (self.page) + lineedit.setGeometry (x, y + 20, 100, 20) + lineedit.show () + + intLbl = QLabel ("KIntNumInput", self.page) + intLbl.setGeometry (x + 195, y + 35, 95, 20) + intLbl.show () + + intNum = KIntNumInput (5, self.page) + intNum.setGeometry (x + 195, y + 55, 175, 50) +# intNum.setSuffix (" GB") +# intNum.setPrefix ("hdc ") + intNum.setLabel ("Capacity") + intNum.setRange (0, 10, 1, True) + intNum.show () + + y = y + 50 + + dblLbl = QLabel ("KDoubleNumInput", self.page) + dblLbl.setGeometry (x + 195, y + 80, 115, 20) + dblLbl.show () + + dblNum = KDoubleNumInput (2.5, self.page) + dblNum.setGeometry (x + 195, y + 100, 175, 50) + dblNum.setLabel ("Variable") + dblNum.setRange (0.0, 10.0, 0.5, True) + dblNum.show () + + restricteditLbl = QLabel ("KRestrictedLine", self.page) + restricteditLbl.setGeometry (x, y, 95, 20) + restricteditLbl.show () + + self.restrictlineedit = KRestrictedLine (self.page) + self.restrictlineedit.setGeometry (x, y + 20, 100, 20) + self.restrictlineedit.show () + + buttons = ["Numbers Only", "Upper Case Only", "Lower Case Only"] + + n = len (buttons) + + self.validLbl = QLabel ("", self.page) + self.validLbl.setGeometry (x, y + 50, 250, 20) + self.validLbl.show () + + grp = QButtonGroup (n, Qt.Vertical, "Select valid chars", self.page, "button grp") + grp.setGeometry (x, y + 75, 150, 5+30*n) + for i in range (n): + QRadioButton (buttons [i], grp) + + grp.connect (grp, SIGNAL ("clicked (int)"), self.restrict) + + grp.find (0).setChecked (True) + self.restrict (0) + + grp.show () + + self.page.show () + kapp = KApplication.kApplication () + kapp.processEvents () + + y = y + 195 + sqzLbl = QLabel ("This text is too long to fit in the label below", self.page) + sqzLbl.setGeometry (x, y, 350, 20) + sqzLbl.show () + + sqzLbl1 = QLabel ("KSqueezedTxtLabel:", self.page) + sqzLbl1.setGeometry (x, y + 20, 120, 20) + sqzLbl1.show () + + squeeze = KSqueezedTextLabel ("This text is too long to fit in the label below", self.page) + squeeze.setGeometry (x + 125, y + 20, 125, 20) + squeeze.setBackgroundMode (QWidget.PaletteBase) + squeeze.show () + + def restrict (self, which): + r = {0: "0123456789", 1: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 2: "abcdefghijklmnopqrstuvwxyz"} + self.restrictlineedit.setValidChars (r [which]) + self.validLbl.setText ("Valid: " + self.restrictlineedit.validChars ().latin1 ()) + + +class Page2: + def __init__ (self, parent): + self.page = parent.addPage () + + x1 = 10 + y1 = 10 + x2 = 240 + y2 = 100 + + + + cbLbl = QLabel ("KComboBox", self.page) + cbLbl.setGeometry (x1, y1, 75, 20) + cbLbl.show () + + combo = KComboBox (self.page) + combo.insertStrList (["One", "Two", "Three"]) + combo.setGeometry (x1, y1 + 20, 100, 25) + combo.show () + + ccbLbl = QLabel ("KColorCombo", self.page) + ccbLbl.setGeometry (x2, y1, 100, 20) + ccbLbl.show () + + colorCombo = KColorCombo (self.page) + colorCombo.setGeometry (x2, y1 + 20, 100, 25) + colorCombo.show () + + editListBox = KEditListBox ("KEditListBox", self.page) + editListBox.setGeometry (x1, y2, 220, 175) + editListBox.insertStrList (["One", "Two", "Three"]) + editListBox.show () + + lbLbl = QLabel ("KListBox", self.page) + lbLbl.setGeometry (x2, y2, 100, 20) + lbLbl.show () + + listBox = KListBox (self.page) + listBox.setGeometry (x2, y2 + 20, 100, 100) + listBox.insertStrList (["One", "Two", "Three"]) + listBox.show () + +class Page3: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + fontLbl = QLabel ("KFontChooser", self.page) + fontLbl.setGeometry (x, y, 95, 20) + fontLbl.show () + + fontChoose = KFontChooser (self.page) + fontChoose.setGeometry (x, y + 20, 375, 300) + fontChoose.show () + + y = y + 330 + +class Page4: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + cbLbl = QLabel ("KColorButton", self.page) + cbLbl.setGeometry (x, y, 75, 20) + cbLbl.show () + + cb = KColorButton (self.page) + cb.setColor (QColor (255, 0, 0)) + cb.setGeometry (x, y + 20, 30, 30) + cb.show () + + ccbLbl = QLabel ("KColorCombo", self.page) + ccbLbl.setGeometry (x + 150, y, 100, 20) + ccbLbl.show () + + colorCombo = KColorCombo (self.page) + colorCombo.setGeometry (x + 150, y + 20, 100, 25) + colorCombo.show () + + y = y + 60 + + cpLbl = QLabel ("KColorPatch", self.page) + cpLbl.setGeometry (x, y, 75, 20) + cpLbl.show () + + cp = KColorPatch (self.page) + cp.setColor (QColor (255, 0, 0)) + cp.setGeometry (x, y + 20, 20, 20) + cp.show () + + x = x + 150 + + ccLbl = QLabel ("KColorCells", self.page) + ccLbl.setGeometry (x, y, 75, 20) + ccLbl.show () + + cc = KColorCells (self.page, 1, 5) + cc.setColor (0, QColor (0, 0, 0)) + cc.setColor (1, QColor (255, 0, 0)) + cc.setColor (2, QColor (0, 255, 0)) + cc.setColor (3, QColor (0, 0, 255)) + cc.setColor (4, QColor (255, 255, 255)) + cc.setGeometry (x, y + 20, 100, 20) + cc.show () + + x = 10 + y = y + 50 + + dcLbl = QLabel ("KDualColorButton", self.page) + dcLbl.setGeometry (x, y, 105, 20) + dcLbl.show () + + dc = KDualColorButton (QColor (255, 0, 0), QColor (0, 0, 0), self.page) + dc.setGeometry (x, y + 20, 40, 40) + dc.show () + + gsLbl = QLabel ("KGradientSelector", self.page) + gsLbl.setGeometry (x + 80, y + 30, 110, 20) + gsLbl.show () + + gs = KGradientSelector (self.page) + gs.setGeometry (x + 80, y + 50, 250, 20) + gs.setColors (QColor (255, 0, 0), QColor (255, 255, 0)) + gs.show () + + y = y + 80 + + hsLbl = QLabel ("KHSSelector", self.page) + hsLbl.setGeometry (x, y, 95, 20) + hsLbl.show () + + hs = KHSSelector (self.page) + hs.setGeometry (x, y + 20, 350, 80) + hs.show () + + y = y + 110 + + ptLbl = QLabel ("KPaletteTable", self.page) + ptLbl.setGeometry (x, y, 95, 20) + ptLbl.show () + + pt = KPaletteTable (self.page, 340, 24) + pt.setPalette ("Royal") + pt.setGeometry (x, y + 20, 340, 40) + pt.show () + +class Page5: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + rpLbl = QLabel ("KRootPermsIcon", self.page) + rpLbl.setGeometry (x, y, 95, 20) + rpLbl.show () + + rp = KRootPermsIcon (self.page) + rp.setGeometry (x, y + 20, 32, 32) + rp.show () + + wpLbl = QLabel ("KWritePermsIcon", self.page) + wpLbl.setGeometry (x + 125, y, 95, 20) + wpLbl.show () + + wp = KWritePermsIcon ("/usr/bin/gcc", self.page) + wp.setGeometry (x + 125, y + 20, 32, 32) + wp.show () + + y = y + 75 + + pw1Lbl = QLabel ("KPasswordEdit - echo *", self.page) + pw1Lbl.setGeometry (x, y, 150, 20) + pw1Lbl.show () + + pw1 = KPasswordEdit (self.page, "", KPasswordEdit.OneStar) + pw1.setGeometry (x, y + 20, 100, 20) + pw1.show () + + y = y + 50 + + pw2Lbl = QLabel ("KPasswordEdit - echo ***", self.page) + pw2Lbl.setGeometry (x, y, 150, 20) + pw2Lbl.show () + + pw2 = KPasswordEdit (self.page, "", KPasswordEdit.ThreeStars) + pw2.setGeometry (x, y + 20, 100, 20) + pw2.show () + + y = y + 50 + + pw3Lbl = QLabel ("KPasswordEdit - no echo", self.page) + pw3Lbl.setGeometry (x, y, 150, 20) + pw3Lbl.show () + + pw3 = KPasswordEdit (self.page, "", KPasswordEdit.NoEcho) + pw3.setGeometry (x, y + 20, 100, 20) + pw3.show () + + y = y + 50 + + urlLbl = QLabel ("KURLLabel", self.page) + urlLbl.setGeometry (x, y, 100, 20) + urlLbl.show () + + url = KURLLabel ("http://riverbankcomputing.co.uk", "PyKDE", self.page) + url.setGeometry (x, y + 20, 100, 20) + url.setUseTips (True) + url.setTipText ("http://riverbankcomputing.co.uk") + url.show () + + x = 70 + y = y + 50 + + bbLbl = QLabel ("KButtonBox", self.page) + bbLbl.setGeometry (x, y, 75, 20) + bbLbl.show () + + bbox = KButtonBox (self.page, Qt.Horizontal) + bbox.setGeometry (x, y + 20, 300, 22) + bbox.addButton ("Button 1") + bbox.addButton ("Button 2") + bbox.addButton ("Button 3") + bbox.show () + + y = y + 50 + +# dbLbl = QLabel ("KDirectionButton", self.page) +# dbLbl.setGeometry (x, y, 95, 20) +# dbLbl.show () + +# dbUp = KDirectionButton (Qt.UpArrow, self.page) +# dbDown = KDirectionButton (Qt.DownArrow, self.page) +# dbRight = KDirectionButton (Qt.RightArrow, self.page) +# dbLeft = KDirectionButton (Qt.LeftArrow, self.page) + +# dbUp.setGeometry (x, y + 20, 22, 22) +# dbDown.setGeometry (x + 30, y + 20, 22, 22) +# dbRight.setGeometry (x + 60, y + 20, 22, 22) +# dbLeft.setGeometry (x + 90, y + 20, 22, 22) + +# dbUp.show () +# dbDown.show () +# dbRight.show () +# dbLeft.show () + + x = x + 150 + +# kbLbl = QLabel ("KKeyButton", self.page) +# kbLbl.setGeometry (x, y, 95, 20) +# kbLbl.show () + +# kb = KKeyButton (self.page) +# kb.setText ("Enter") +# kb.setGeometry (x, y + 20, 50, 32) +# kb.show () + + x = 70 + y = y + 50 + +# tbLbl = QLabel ("KTabButton", self.page) +# tbLbl.setGeometry (x, y, 95, 20) +# tbLbl.show () + +# tbUp = KTabButton (Qt.UpArrow, self.page) +# tbDown = KTabButton (Qt.DownArrow, self.page) +# tbRight = KTabButton (Qt.RightArrow, self.page) +# tbLeft = KTabButton (Qt.LeftArrow, self.page) + +# tbUp.setGeometry (x, y + 20, 22, 25) +# tbDown.setGeometry (x + 30, y + 20, 22, 25) +# tbRight.setGeometry (x + 60, y + 20, 22, 25) +# tbLeft.setGeometry (x + 90, y + 20, 22, 25) + +# tbUp.show () +# tbDown.show () +# tbRight.show () +# tbLeft.show () + +class Page6: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 20 + y = 10 + + red = QColor (255, 0, 0) + green = QColor (0, 255, 0) + yellow = QColor (255, 255, 0) + blue = QColor (0, 0, 255) + + ledcolor = [red, green, yellow, blue] + ledshape = [KLed.Rectangular, KLed.Circular] + ledlook = [KLed.Flat, KLed.Raised, KLed.Sunken] + ledsize = [10, 18, 25] + self.ledlist = [] + + for look in ledlook: + for color in ledcolor: + for shape in ledshape: + for size in ledsize: + led = KLed(color, KLed.On, look, shape,self.page) + led.setGeometry (x, y, size, size) + self.ledlist.append (led) + led.show () + x = x + 50 + x = x + 50 + x = 20 + y = y + 30 + y = y + 10 + + toggle = QPushButton ("Toggle", self.page) + toggle.setGeometry (150, 400, 60, 22) + toggle.show () + + self.page.connect (toggle, SIGNAL ("clicked ()"), self.toggleClicked) + + self.page.show () + + + def toggleClicked (self): + for led in self.ledlist: + led.toggle () + +class Page7: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + tabLbl = QLabel ("KTabCtl", self.page) + tabLbl.setGeometry (x, y, 95, 20) + tabLbl.show () + + tab = KTabCtl (self.page) + tab.setGeometry (x, y + 20, 300, 100) + + page1 = QWidget (tab) + p1Lbl = QLabel ("This is page 1", page1) + p1Lbl.setGeometry (20, 20, 100, 20) + page2 = QWidget (tab) + p2Lbl = QLabel ("This is page 2", page2) + p2Lbl.setGeometry (50, 20, 100, 20) + page3 = QWidget (tab) + p3Lbl = QLabel ("This is page 3", page3) + p3Lbl.setGeometry (20, 50, 100, 20) + + tab.addTab (page1, "Tab 1") + tab.addTab (page2, "Tab 2") + tab.addTab (page3, "Tab 3") + tab.show () + + x = 10 + y = 150 + + progLbl = QLabel ("KProgress", self.page) + progLbl.setGeometry (x, y + 50, 95, 20) + progLbl.show () + + self.p1 = KProgress (self.page) + self.p2 = KProgress (15, self.page) + self.p1.setRange (0, 25) + self.p2.setRange (0, 25) + + self.p1.setGeometry (x, y + 80, 125, 20) + self.p2.setGeometry (x, y + 120, 125, 20) + + self.p2.setPercentageVisible (0) + + self.p1.show () + self.p2.show () + + self.total = 0 + + y = y + 150 + sepLbl = QLabel ("KSeparator", self.page) + sepLbl.setGeometry (x, y, 95, 20) + sepLbl.show () + + sep = KSeparator (QFrame.HLine, self.page) + sep.setGeometry (x, y + 20, 75, 10) + sep.show () + + + self.page.show () + + self.add1 (self) + + def add1 (self, junk = 0): + self.total = self.total + 1 + self.p1.advance (1) + self.p2.advance (1) + + if self.total < 26: + QTimer.singleShot (100, self.add1) + + + +class Page8: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 40 + y = 10 + + dpLbl = QLabel ("KDatePicker", self.page) + dpLbl.setGeometry (x, y, 95, 20) + dpLbl.show () + + dp = KDatePicker (self.page) + dp.setGeometry (x, y + 20, 300, 170) + dp.show () + + y = y + 210 + + dtLbl = QLabel ("KDateTable", self.page) + dtLbl.setGeometry (x, y, 95, 20) + dtLbl.show () + + dt = KDateTable (self.page) + dt.setGeometry (x, y + 20, 300, 130) + dt.show () + +class PageThisApp: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + taLbl = QLabel ("This application uses KMainWindow as its top level widget\n and KListView in the"\ + " left-hand panel", self.page) + taLbl.setGeometry (x, y, 300, 60) + taLbl.show () + +class PageNotImpl: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + niLbl = QLabel ("Nothing is currently implemented for this widget", self.page) + niLbl.setGeometry (x, y, 300, 20) + niLbl.show () + +class CSDlg (KDialog): + def __init__ (self, parent, name = "char select dlg", modal = False): + KDialog.__init__ (self, parent, name, modal) + + self.setGeometry (150, 50, 700, 320) + x = 10 + y = 10 + + csLbl = QLabel ("KCharSelect", self) + csLbl.setGeometry (x, y, 95, 20) + csLbl.show () + + cs = KCharSelect (self, "chselect", QString.null, QChar (' '), 0) + cs.setGeometry (x, y + 20, 680, 250) + cs.show () + + closeBtn = QPushButton ("Close", self) + closeBtn.setGeometry ( 610, 280, 60, 22) + closeBtn.show () + + self.connect (closeBtn, SIGNAL ("clicked ()"), self.closeClicked) + + def closeClicked (self): + self.done (1) + +def widKAnimWidget (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKAuthIcon (parent): + parent.currentPageObj = Page5 (parent) + +def widKButtonBox (parent): + parent.currentPageObj = Page5 (parent) + +def widKCharSelect (parent): + dlg = CSDlg (parent) + dlg.show () + +def widKColorButton (parent): + parent.currentPageObj = Page4 (parent) + +def widKColorCells (parent): + parent.currentPageObj = Page4 (parent) + +def widKColorCombo (parent): + parent.currentPageObj = Page2 (parent) + +def widKColorPatch (parent): + parent.currentPageObj = Page4 (parent) + +def widKComboBox (parent): + parent.currentPageObj = Page2 (parent) + +def widKCompletionBox (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKContainerLayout (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKCursor (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKDatePicker (parent): + parent.currentPageObj = Page8 (parent) + +def widKDateTable (parent): + parent.currentPageObj = Page8 (parent) + +def widKDirectionButton (parent): + parent.currentPageObj = Page5 (parent) + +def widKDualColorButton (parent): + parent.currentPageObj = Page4 (parent) + +def widKEdit (parent): + parent.currentPageObj = Page1 (parent) + +def widKEditListBox (parent): + parent.currentPageObj = Page2 (parent) + +def widKFontChooser (parent): + parent.currentPageObj = Page3 (parent) + +def widKHSSelector (parent): + parent.currentPageObj = Page4 (parent) + +def widKIconView (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKJanusWidget (parent): + parent.currentPageObj = PageNotImpl (parent) + +#def widKKeyButton (parent): +# parent.currentPageObj = Page5 (parent) + +def widKKeyChooser (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKLed (parent): + parent.currentPageObj = Page6 (parent) + +def widKLineEdit (parent): + parent.currentPageObj = Page1 (parent) + +def widKListBox (parent): + parent.currentPageObj = Page2 (parent) + +def widKListView (parent): + parent.currentPageObj = PageThisApp (parent) + +def widKNumInput (parent): + parent.currentPageObj = Page1 (parent) + +def widKPaletteTable (parent): + parent.currentPageObj = Page4 (parent) + +def widKPasswordEdit (parent): + parent.currentPageObj = Page5 (parent) + +def widKProgress (parent): + parent.currentPageObj = Page7 (parent) + +def widKRootPixmap (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKMainWindow (parent): + parent.currentPageObj = PageThisApp (parent) + +def widKRestrictedLine (parent): + parent.currentPageObj = Page1 (parent) + +def widKRuler (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKSelector (parent): + parent.currentPageObj = Page4 (parent) + +def widKSeparator (parent): + parent.currentPageObj = Page7 (parent) + +def widKSqueezedTextLabel (parent): + parent.currentPageObj = Page1 (parent) + +def widKTabButton (parent): + parent.currentPageObj = Page5 (parent) + +def widKTabCtl (parent): + parent.currentPageObj = Page7 (parent) + +def widKTextBrowser (parent): + parent.currentPageObj = PageNotImpl (parent) + +def widKURLLabel (parent): + parent.currentPageObj = Page5 (parent) + + +if __name__ == "__main__": + print + print "Please run uisampler.py" + print
\ No newline at end of file diff --git a/examples/uimodules/uixml.py b/examples/uimodules/uixml.py new file mode 100644 index 0000000..baa6c86 --- /dev/null +++ b/examples/uimodules/uixml.py @@ -0,0 +1,45 @@ +import os + +from qt import QLabel + +from kdecore import KApplication + +class PageLaunch: + def __init__ (self, parent): + self.page = parent.addPage () + + x = 10 + y = 10 + + launchLbl = QLabel ("Launching application ... please wait\n\nClose launched application to continue", self.page) + launchLbl.setGeometry (x, y, 300, 80) + launchLbl.show () + + self.page.show () + + KApplication.kApplication ().processEvents () + +def xmlKActionCollection (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python xmlmenudemo.py") + +def xmlKEditToolbar (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python xmlmenudemo.py") + +def xmlKEditToolbarWidget (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python xmlmenudemo.py") + +def xmlKXMLGUIBuilder (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python xmlmenudemo.py") + +def xmlKXMLGUIClient (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python xmlmenudemo.py") + +def xmlKXMLGUIFactory (parent): + parent.currentPageObj = PageLaunch (parent) + os.system ("python xmlmenudemo.py") + |