如何禁用GTK中的关闭按钮?

时间:2014-01-17 05:41:52

标签: python gtk client pygtk openerp

我在OpenERP 6.0.3的GTK客户端中创建了一次性密码机制。登录后,GTK客户端会显示一个窗口,输入一次性密码,如下所示。

One Time Password Window

现在我要禁用窗口左上角的关闭按钮。我怎样才能做到这一点?我正在使用python和创建窗口的代码是:

修改

class sms_auth(gtk.Dialog):

    def run_thread(self):
        code=self.textbox_code.get_text()
        self.result = rpc.session.rpc_exec_auth('/object', 'execute', 'res.users', 'check_code', code)
        return self.result

    def run(self):
        self.show_all()
        res = super(sms_auth, self).run()
        result = None
        if res == gtk.RESPONSE_ACCEPT:
            result = self.run_thread()

        self.destroy()
        return result

    def hide(*args):
        window.hide()
        return gtk.TRUE

    def __init__(self, parent, response):
        # To use cancel butto add gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
        gtk.Dialog.__init__(
            self, 'Sms Authentication', parent,
            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
        )
        label = gtk.Label("Please enter sms code :")
        self.parent_widget = parent
        self.response = False
        self.db_login_response = response
        self.connect('delete_event', hide)

        self.textbox_code = gtk.Entry()
        label.set_alignment(0,0)

        table = gtk.Table(1, 7)
        table.set_homogeneous(False)
        table.set_col_spacings(40)
        table.attach(label, 0, 6, 0, 1, ypadding=4)
        table.attach(self.textbox_code, 5, 6, 0, 1, ypadding=4)

        self.vbox.pack_start(table,False, False, 0)

1 个答案:

答案 0 :(得分:2)

试试这个

def hide(self, *args):
    window.hide()
    return gtk.TRUE


self.window.connect('delete_event', self.hide)

注意:请参阅here

import pygtk
pygtk.require('2.0')
import gtk


class DialogExample(gtk.Dialog):

    def __init__(self, parent=None):
        gtk.Dialog.__init__(self, "My Dialog", parent,
            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
            (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
        )
        self.set_default_size(150, 100)
        label = gtk.Label("This is a dialog to display additional information")
        box = self.get_content_area()
        box.add(label)
        self.show_all()
        self.connect('delete-event', self.delete_event)

    def delete_event(self, widget, event=None):
        print "Here"
        return True


def main():
    # rest in gtk_main and wait for the fun to begin!
    gtk.main()
    return 0


if __name__ == "__main__":
    DialogExample()
    main()