summaryrefslogtreecommitdiffstats
path: root/examples/uisampler.py
blob: 98437ee500d541f780e6c0620ab4c7a1855e7717 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import sys
sys.path.append ("./uimodules")

from qt import TQSplitter, TQWidgetStack, TQWidget, TQListViewItem, SIGNAL, TQCString , TQScrollView, TQRect, TQt

from tdecore import TDEApplication, TDECmdLineArgs, TDEAboutData
from tdeui import TDEMainWindow, TDEListView

from uidialogs import *
from uiwidgets import *
from uimenus import *
from uixml import *
from uimisc import *

False = 0
True  = not False

listItems = {"Dialogs":
                {"KAboutDialog": ["KAboutApplication", "KAboutContainer", "KImageTrackLabel",\
                                  "KAboutContainerBase", "KAboutContributor", "KAboutWidget"],\
                "KAboutKDE": [],\
                "KBugReport": [],\
                "KColorDialog": [],\
                "KDialog": [],\
                "KDialogBase": ["KDialogBaseButton", "KDialogBase::SButton", "KDialogBaseTile"],\
                "TDEFontDialog": [],\
                "KKeyDialog": [],\
                "KLineEditDlg": [],\
                "KMessageBox": [],\
                "KPasswordDialog": [],\
                "KWizard": []},\
            "Widgets":
                {"KAnimWidget": [],\
                 "KAuthIcon": ["KRootPermsIcon", "KWritePermsIcon"],\
                 "KButtonBox": [],\
                 "KCharSelect": ["KCharSelectTable"],\
                 "KColorButton": [],\
                 "KColorCells": [],\
                 "KColorCombo": [],\
                 "KColorPatch": [],\
                 "KComboBox": [],\
                 "KCompletionBox": [],\
                 "KContainerLayout": ["KContainerLayout::KContainerLayoutItem"],\
                 "KCursor": [],\
                 "KDatePicker": ["KDateInternalMonthPicker", "KDateInternalYearSelector"],\
                 "KDateTable": [],\
                 "KDualColorButton": [],\
                 "KEdit": ["KEdFind", "KEdGotoLine", "KEdReplace"],\
                 "KEditListBox": [],\
                 "TDEFontChooser": [],\
                 "KHSSelector": [],\
                 "TDEIconView": [],\
                 "KJanusWidget": ["KJanusWidget::IconListBox"],\
                 "KKeyChooser": [],\
                 "KLed": [],\
                 "KLineEdit": [],\
                 "TDEListBox": [],\
                 "TDEListView": [],\
                 "KNumInput": ["KDoubleNumInput", "KIntNumInput"],\
                 "KPaletteTable": [],\
                 "KPasswordEdit": [],\
                 "KProgress": [],\
                 "KRootPixmap": [],\
                 "TDEMainWindow": [],\
                 "KRestrictedLine": [],\
                 "KRuler": [],\
                 "TDESelector": ["KGradientSelector", "KValueSelector", "KHSSelector", "KXYSelector"],\
                 "KSeparator": [],\
                 "KSqueezedTextLabel": [],\
                 "KTabCtl": [],\
                 "KTextBrowser": [],\
                 "KURLLabel": []},\
            "XML":
                {"TDEActionCollection": [],\
                 "KEditToolbar": [],\
                 "KEditToolbarWidget": [],\
                 "KXMLGUIBuilder": [],\
                 "KXMLGUIClient": ["KXMLGUIClient::DocStruct"],\
                 "KXMLGUIFactory": []},\
            "Menus/Toolbars":
                {"TDEAccelMenu": [],\
                 "TDEAction": ["TDEFontAction", "TDEFontSizeAction", "TDEListAction", "TDERecentFilesAction", "TDERadioAction",\
                             "TDESelectAction", "TDEToggleAction"],\
                 "TDEActionMenu": [],\
                 "TDEActionSeparator": [],\
                 "KContextMenuManager": [],\
                 "KDCOPActionProxy": [],\
                 "KHelpMenu": [],\
                 "KMenuBar": [],\
                 "KPanelApplet": [],\
                 "KPanelExtension": [],\
                 "KPanelMenu": [],\
                 "TDEPopupFrame": [],\
                 "TDEPopupMenu": [],\
                 "TDEPopupTitle": [],\
                 "KStatusBar": [],\
                 "KStatusBarLabel": [],\
                 "KStdAction": [],\
                 "TDEToolBar": ["TDEToolBarButton", "TDEToolBarButtonList", "TDEToolBarPopupAction",\
                              "TDEToolBarRadioGroup", "TDEToolBarSeparator"],\
                 "KWindowListMenu": []},\
            "Other":
                {"KAlphaPainter": [],\
                 "TDECModule": [],\
                 "KColor": [],\
                 "KColorDrag": [],\
                 "KCommand": ["KMacroCommand"],\
                 "KCommandHistory": [],\
                 "KDateValidator": [],\
                 "KDockWindow": ["KDockButton_Private - KPanelMenu", "KDockButton_Private",\
                                 "KDockSplitter", "KDockTabCtl_PrivateStruct", "KDockWidgetAbstractHeader",\
                                 "KDockWidgetAbstractHeaderDrag", "KDockWidgetHeader",\
                                 "KDockWidgetHeaderDrag", "KDockWidgetPrivate"],\
                 "KFloatValidator": [],\
                 "KIntValidator": [],\
                 "KPixmapIO": [],\
                 "TDESharedPixmap": [],\
                 "KSystemTray": [],\
                 "KThemeBase": ["KThemeCache", "KThemePixmap", "KThemeStyle"],\
                 "QXEmbed": []}}

prefix = {"Dialogs": "dlg", "Widgets": "wid", "XML": "xml", "Menus/Toolbars": "menu", "Other": "misc"}

# The following leave about 375 x 390 for the rt hand panel
mainGeom  = TQRect (0, 0, 640, 500)
treeWidth = 220

blankMsg = """ UISampler - provides examples of PyKDE widgets

Select a dialog/widget/menu/etc example from the tree at left
"""


class MainWin (TDEMainWindow):
    def __init__ (self, *args):
        apply (TDEMainWindow.__init__, (self,) + args)

        self.setCaption ("Samples of PyKDE widget usage")
        self.setGeometry (mainGeom)

        # create the main view - list view on the left and an
        # area to display frames on the right
        self.mainView  = TQSplitter (self, "main view")
        self.tree      = TDEListView (self.mainView, "tree")
        self.page      = TQWidgetStack (self.mainView, "page")
        self.blankPage = TQWidget (self.page, "blank")
        self.blankPage.setGeometry (0, 0, 375, 390)
        self.blankPage.setBackgroundMode (TQWidget.PaletteBase)

        blankLbl = TQLabel (blankMsg, self.blankPage)
        blankLbl.setGeometry (40, 10, 380, 150)
        blankLbl.setBackgroundMode (TQWidget.PaletteBase)

        blankPM = TQPixmap ("pytestimage.png")
        pmLbl   = TQLabel ("", self.blankPage)
        pmLbl.setPixmap (blankPM)
        pmLbl.setGeometry (40, 160, 300, 200)
        pmLbl.setBackgroundMode (TQWidget.PaletteBase)

        self.page.addWidget (self.blankPage, 1)
        self.page.raiseWidget (1)

        self.setCentralWidget (self.mainView)

        self.initListView ()
        self.connect (self.tree, SIGNAL ("clicked (TQListViewItem *)"), self.lvClicked)

        self.edit = None
        self.currentPageObj = None

    def initListView (self):
        self.tree.addColumn ("Category", treeWidth - 21)
#        self.tree.setMaximumWidth (treeWidth)
        self.mainView.setSizes ([treeWidth, 375])
        self.tree.setRootIsDecorated (True)
        self.tree.setVScrollBarMode (TQScrollView.AlwaysOn)
        topLevel = listItems.keys ()
        for item_1 in topLevel:
            parent = TQListViewItem (self.tree, item_1)
            secondLevel = listItems [item_1].keys ()
            for item_2 in secondLevel:
                child = TQListViewItem (parent, item_2)
                for item_3 in listItems [item_1][item_2]:
                    TQListViewItem (child, item_3)

    def lvClicked (self, lvItem):
        if not lvItem:
            return

        if lvItem.text (0).latin1 () in listItems.keys ():
            return

        p = lvItem.parent ()
        if p.text (0).latin1 () in listItems.keys ():
            pfx = prefix [p.text (0).latin1 ()]
            funcCall = pfx + lvItem.text (0).latin1 () + "(self)"
        else:
            pfx = prefix [p.parent ().text (0).latin1 ()]
            funcCall = pfx + lvItem.parent ().text (0).latin1 () + "(self)"

        eval (funcCall)

    def addPage (self):
        self.edit = None
        self.currentPageObj = None
        current = self.page.widget (2)
        if current:
            self.page.removeWidget (current)
            del current

        newPage = TQWidget (self.page)
        newPage.setGeometry (0, 0, 375, 390)
#        newPage.setBackgroundMode (TQWidget.PaletteBase)
        self.page.addWidget (newPage, 2)
        self.page.raiseWidget (2)

        return newPage


#-------------------- main ------------------------------------------------

appName = "UISampler"
app = TDEApplication (sys.argv, appName)
mainWindow = MainWin (None, "main window")
mainWindow.show()
app.exec_loop()