1

I have created a window using quickly add dialog. But I can't figure out how to simply open the dialog from a button. I have already set up a button in my main window and set up the code for it. This is the code for the button:

def on_quicksitesbutton_clicked(self, widget):
dialog = QuicksitesDialog.QuicksitesDialog()
result = dialog.run()

I also imported the dialog with this line of code:

from brandsonicweb.QuicksitesDialog import QuicksitesDialog

The program runs fine, but when I click the button I get in the terminal:

Traceback (most recent call last):
  File "/home/brandon/brandsonicweb/brandsonicweb/BrandsonicwebWindow.py", line 71, in on_quicksitesbutton_clicked
    dialog = QuicksitesDialog.QuicksitesDialog()
AttributeError: type object 'QuicksitesDialog' has no attribute 'QuicksitesDialog'

What am I doing wrong? How can I make this work?

1 Answer 1

1

Probably this:

You import the QuicksitesDialog first:

from brandsonicweb.QuicksitesDialog import QuicksitesDialog

And then you try to call it again:

dialog = QuicksitesDialog.QuicksitesDialog()

Without looking at your code, this can be fixed in 2 ways:

from brandsonicweb.QuicksitesDialog import QuicksitesDialog
dialog = QuicksitesDialog()

Or:

from brandsonicweb import QuicksitesDialog
dialog = QuicksitesDialog.QuicksitesDialog()

It can be a bit confusing because apparently Quickly gives the module and class both the same name.

Also notice the excellent Python error which gives you a nice indication.

4
  • Does all this code go in the button?
    – Sega dude
    Jun 23, 2013 at 14:14
  • @Segadude: This is just normal Python code, you did have read at least one tutorial, right? There's no rule, but imports should be on top of the file. Calling the dialog should ofcourse be in the button handler.
    – Timo
    Jun 23, 2013 at 16:22
  • When I tried the second method, I get this error when I click the button Traceback (most recent call last): File "/home/brandon/brandsonicweb/brandsonicweb/BrandsonicwebWindow.py", line 71, in on_quicksitesbutton_clicked dialog = QuicksitesDialog.QuicksitesDialog() File "/home/brandon/brandsonicweb/brandsonicweb/QuicksitesDialog.py", line 25, in new new_object.finish_initializing(builder) AttributeError: 'NoneType' object has no attribute 'finish_initializing' Here are the relevant files: pastebin.com/du1jiCBt , pastebin.com/yJ6yXhHC
    – Sega dude
    Jun 23, 2013 at 20:55
  • I never used Quickly, but my guess is that you don't have your dialog named quicksites_dialog in your Glade file. new_object = builder.get_object('quicksites_dialog') probably returns None if it can't find a widget with that name (hence the error 'NoneType' object has no attribute 'finish_initializing'). So either rename the dialog in Glade or in that line.
    – Timo
    Jun 24, 2013 at 7:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .