Interrogation with Apport hooks – Qt Included

June 9th, 2009  |  Published in Coding, Development, FYI, KDE, Kubuntu, Python, Qt  |  12 Comments

Earlier today my buddy Martin Pitt blogged about how he needed a Qt developer to work on implementing the ui_question_choice() dialog. I looked through the code a bit this morning, and needed a little help right off the bat getting the GTK version running. One little thing I missed a bug report and Martin helped get it up and running. So as the day went on, storms came through, and for some reason I get in this storm hunter mode and nothing else gets done. Well, about an hour ago all the storms have cleared up and back to work I went. I spent about an hour, most of which was silly Qt Designer and layouts, which Kubuntu guys, I suck at, never listen to me brag about my Qt Designer classes again! The other thing that had me for a second was trying to iterate over a layout to get button statuses. After all was said and done, this is the little beauty that popped up when testing:

apport-qt4

Not to shabby. I will spend some time looking through all of the apport-qt ui stuff and see if I can make it as simple as the GTK side. The checkboxes in that image are generated dynamically by the hook. So once they are added to the layout, trying to figure out their status when they weren’t provided a name was tricky. Thankfully the PyQt 4 API Documentation is great!

So here it is, there is the main dialog and then there is the groupbox with a vertical box inside of it. The vertical box makes it simple to add and remove stuff so that’s why I went that route, KISS. So after the box is populate, you select the stuff you need then press OK to submit it. Well the trick was finding out what is checked. So the main dialog is named dialog and the vertical box that holds the check boxes is called vbox_choices. So here is how I got those values:

result = []
for c in range(0, dialog.vbox_choices.count()):
    if dialog.vbox_choices.itemAt(c).widget().isChecked():
        result.append(c)

So, the main reason for doing this, is so I can find it a bit easier next time, and the fact that I couldn’t find this little bit documented anywhere else. If there is a better way to do this, let me know.

EDIT: Removed the index variable as it was old code left hanging around when I did the copy and paste. Thanks Milian for catching that.

Responses

  1. Milian WolffNo Gravatar says:

    June 9th, 2009 at 01:11:46 (#)

    Quick question: isn’t the index variable superflous? It should have the same value as c.

  2. Martin PittNo Gravatar says:

    June 9th, 2009 at 01:24:21 (#)

    Many thanks! I’ll look at your branch today and merge it.

  3. nixternalNo Gravatar says:

    June 9th, 2009 at 02:13:08 (#)

    @Milian – yes it would, I didn’t remove it when I did a copy paste and it was hanging around from old code.

  4. J. JanzNo Gravatar says:

    June 9th, 2009 at 09:47:20 (#)

    Dude,

    That’s just me being silly ( =D ) but those four lines could be: result = [c for c in range(0, dialog.vbox_choices.count()) if dialog.vbox_choices.itemAt(c).widget().isChecked()].

    BTW, I always wanted to thank you for your work with kubuntu and nowlooked like an opportunity: Thank you a lot for that!

  5. ANo Gravatar says:

    June 9th, 2009 at 10:36:49 (#)

    I would have kept the checkboxes in a separate array, this way it’s easy to loop through them when need be.

  6. YuriyNo Gravatar says:

    June 9th, 2009 at 10:48:09 (#)

    Wouldn’t a QButtonGroup take care of that?

    I don’t think the PyQt documentation is so great actually. Most of it is just copied right from the C++ documentation, which can be annoying sometimes. The Qt documentation is great though.

  7. Michael "Grammar Police" HowellNo Gravatar says:

    June 9th, 2009 at 10:55:35 (#)

    In the dialog: “I can has a bug report?” should be “I can have a bug report?”

  8. SeaJeyNo Gravatar says:

    June 9th, 2009 at 11:33:05 (#)

    >In the dialog: “I can has a bug report?” should be “I can have a bug report?”

    http://en.wikipedia.org/wiki/Lolcat

  9. nixternalNo Gravatar says:

    June 9th, 2009 at 12:56:39 (#)

    @J. Janz – you are 100% correct – I tend to forget about utilizing loops like that. Thank you for the kind words! I try to help as much as possible here in the Kubuntu world as well as the KDE world, time permitting of course.

    @A – that isn’t a bad idea honestly.

    @Yuriy – It was just easier to implement the way I did because Designer doesn’t have a QButtonGroup widget, and writing the code for that would have been more work, KISS :)

    @Michael – haha, ya the python file we used for testing has that, lolcatified :)

  10. J. JanzNo Gravatar says:

    June 9th, 2009 at 13:19:31 (#)

    Yeah, I know better now how hard it is to do this kind of work on spare time (I’m trying to contribute to KDE but spare time looks like not enougth!) and that’s an extra reason for me to thank you.

    And, for that line of code, who doesn’t love list comprehensions[1]? ;)

    See you around and keep up the good work!

    [1] http://docs.python.org/3.0/tutorial/datastructures.html#list-comprehensions

  11. nixternalNo Gravatar says:

    June 10th, 2009 at 03:36:22 (#)

    Now I am going to rewrite all of this in PyKDE4 and will change the dialogs so they at least all match up now and are logically correct. I will continue to document these changes here, so please follow if interested. Of course if you have a feed to Planet Ubuntu, well then you will get stuck with the future posts :)

  12. nixternalNo Gravatar says:

    June 10th, 2009 at 03:37:25 (#)

    Heh, I am not using Safari on Mac OS X. I wanted to see if I could build a webkit browser in less than 20 lines of code :)

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">