#!/usr/bin/env python

import sys
from qt import SIGNAL
from kdecore import KAboutData, KApplication, KCmdLineArgs
from kdeui import KMainWindow, KDialogBase, KPushButton


class MainWindow(KMainWindow):
    def __init__(self, *args):
        KMainWindow.__init__(self, *args)
        self.button = KPushButton('Show Dialog', self)
        self.setCentralWidget(self.button)
        self.connect(self.button, SIGNAL('clicked()'), self.showFunkyDialog)

    def showFunkyDialog(self):
        dialog = FunkyDialog(self)
        dialog.exec_loop()


##
## the problem with slotOk and slotCancel is revealed in this class
##
class FunkyDialog(KDialogBase):
    def __init__(self, *args):
        KDialogBase.__init__(self, *args)

    def slotOk(self, *args):
        if args:
            print 'slotOk was passed extra arguments %s' % (args, )
        else:
            print 'slotOk was passed single argument'
        self.accept()
       

    def slotCancel(self, *args):
        if args:
            print 'slotCancel was passed extra arguments %s' % (args, )
        else:
            print 'slotCancel was passed single argument'
        self.reject()


##
## the rest is boilerplate
##
def aboutData():
    appName = 'funkydialogslots'
    progName = 'KDialogBase Funky Slots'
    authorName = 'Troy Melhase'
    authorEmail = bugsEmailAddress = 'troy@gci.net'
    version = '0.1'
    shortDescription = ''
    licenseType = KAboutData.License_GPL_V2
    copyrightStatement = '(c) 2004, Troy Melhase' ## weird:  can't use string iterp?
    homePageAddress = ''
    aboutText = ("")

    about = KAboutData(
        appName,
        progName,
        version,
        shortDescription,
        licenseType,
        copyrightStatement,
        aboutText,
        homePageAddress,
        bugsEmailAddress,
    )
    about.addAuthor(authorName, '', authorEmail)
    return about


if __name__ == '__main__':
    aboutData = aboutData()
    KCmdLineArgs.init(sys.argv, aboutData)
    app = KApplication()
    mainWindow = MainWindow()
    mainWindow.show()
    app.exec_loop()

