summaryrefslogtreecommitdiffstats
path: root/examples/uisampler.py
blob: af61e933b79c40b6a28b70b9fea45f977b68c574 (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 QSplitter, QWidgetStack, QWidget, QListViewItem, SIGNAL, QCString , QScrollView, QRect, Qt

from tdecore import KApplication, KCmdLineArgs, KAboutData
from tdeui import KMainWindow, KListView

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"],\
                "KFontDialog": [],\
                "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": [],\
                 "KFontChooser": [],\
                 "KHSSelector": [],\
                 "KIconView": [],\
                 "KJanusWidget": ["KJanusWidget::IconListBox"],\
                 "KKeyChooser": [],\
                 "KLed": [],\
                 "KLineEdit": [],\
                 "KListBox": [],\
                 "KListView": [],\
                 "KNumInput": ["KDoubleNumInput", "KIntNumInput"],\
                 "KPaletteTable": [],\
                 "KPasswordEdit": [],\
                 "KProgress": [],\
                 "KRootPixmap": [],\
                 "KMainWindow": [],\
                 "KRestrictedLine": [],\
                 "KRuler": [],\
                 "KSelector": ["KGradientSelector", "KValueSelector", "KHSSelector", "KXYSelector"],\
                 "KSeparator": [],\
                 "KSqueezedTextLabel": [],\
                 "KTabCtl": [],\
                 "KTextBrowser": [],\
                 "KURLLabel": []},\
            "XML":
                {"KActionCollection": [],\
                 "KEditToolbar": [],\
                 "KEditToolbarWidget": [],\
                 "KXMLGUIBuilder": [],\
                 "KXMLGUIClient": ["KXMLGUIClient::DocStruct"],\
                 "KXMLGUIFactory": []},\
            "Menus/Toolbars":
                {"KAccelMenu": [],\
                 "KAction": ["KFontAction", "KFontSizeAction", "KListAction", "KRecentFilesAction", "KRadioAction",\
                             "KSelectAction", "KToggleAction"],\
                 "KActionMenu": [],\
                 "KActionSeparator": [],\
                 "KContextMenuManager": [],\
                 "KDCOPActionProxy": [],\
                 "KHelpMenu": [],\
                 "KMenuBar": [],\
                 "KPanelApplet": [],\
                 "KPanelExtension": [],\
                 "KPanelMenu": [],\
                 "KPopupFrame": [],\
                 "KPopupMenu": [],\
                 "KPopupTitle": [],\
                 "KStatusBar": [],\
                 "KStatusBarLabel": [],\
                 "KStdAction": [],\
                 "KToolBar": ["KToolBarButton", "KToolBarButtonList", "KToolBarPopupAction",\
                              "KToolBarRadioGroup", "KToolBarSeparator"],\
                 "KWindowListMenu": []},\
            "Other":
                {"KAlphaPainter": [],\
                 "KCModule": [],\
                 "KColor": [],\
                 "KColorDrag": [],\
                 "KCommand": ["KMacroCommand"],\
                 "KCommandHistory": [],\
                 "KDateValidator": [],\
                 "KDockWindow": ["KDockButton_Private - KPanelMenu", "KDockButton_Private",\
                                 "KDockSplitter", "KDockTabCtl_PrivateStruct", "KDockWidgetAbstractHeader",\
                                 "KDockWidgetAbstractHeaderDrag", "KDockWidgetHeader",\
                                 "KDockWidgetHeaderDrag", "KDockWidgetPrivate"],\
                 "KFloatValidator": [],\
                 "KIntValidator": [],\
                 "KPixmapIO": [],\
                 "KSharedPixmap": [],\
                 "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  = QRect (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 (KMainWindow):
    def __init__ (self, *args):
        apply (KMainWindow.__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  = QSplitter (self, "main view")
        self.tree      = KListView (self.mainView, "tree")
        self.page      = QWidgetStack (self.mainView, "page")
        self.blankPage = QWidget (self.page, "blank")
        self.blankPage.setGeometry (0, 0, 375, 390)
        self.blankPage.setBackgroundMode (QWidget.PaletteBase)

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

        blankPM = QPixmap ("pytestimage.png")
        pmLbl   = QLabel ("", self.blankPage)
        pmLbl.setPixmap (blankPM)
        pmLbl.setGeometry (40, 160, 300, 200)
        pmLbl.setBackgroundMode (QWidget.PaletteBase)

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

        self.setCentralWidget (self.mainView)

        self.initListView ()
        self.connect (self.tree, SIGNAL ("clicked (QListViewItem *)"), 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 (QScrollView.AlwaysOn)
        topLevel = listItems.keys ()
        for item_1 in topLevel:
            parent = QListViewItem (self.tree, item_1)
            secondLevel = listItems [item_1].keys ()
            for item_2 in secondLevel:
                child = QListViewItem (parent, item_2)
                for item_3 in listItems [item_1][item_2]:
                    QListViewItem (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 = QWidget (self.page)
        newPage.setGeometry (0, 0, 375, 390)
#        newPage.setBackgroundMode (QWidget.PaletteBase)
        self.page.addWidget (newPage, 2)
        self.page.raiseWidget (2)

        return newPage


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

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