Skipping a gtk.Assistant Page Using set_forward_page_func()

A.K.A. Skipping Page 3!

I regularly use the excellent rednotebook for my daily notes at work. I recently decided I wanted to add a feature to the export dialogue which would allow the user to export only a selection of text.   A code reviewer suggested that, if the user has selected this new export option on one page, the next page is not relevant and should be skipped. Easier said than done.

The export dialogue makes use of gtk.Assistant. Having looked at the documentation, I found def set_forward_page_func(page_func, data) and got my hopes up. Unfortunately, I was unable to find any examples of this code in action. After much trial and error, I found that the page_func needs to accept page (the index of the current page) and needs to return the index of the next page to go to.

I found an example of gtk.Assistant from pygtk-tutorial on gitorious.org and have edited it here to include the ability to skip page 3. I hope this helps someone!

#!/usr/bin/env python

import gtk

class Assistant:
    def __init__(self):
        assistant = gtk.Assistant()

        assistant.connect("apply", self.button_pressed, "Apply")
        assistant.connect("cancel", self.button_pressed, "Cancel")

        vbox = gtk.VBox()
        vbox.set_border_width(5)
        page = assistant.append_page(vbox)
        assistant.set_page_title(vbox, "Page 1: Starting Out")
        assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_INTRO)
        label = gtk.Label("This is an example label within an Assistant. The Assistant is used to guide a user through configuration of an application.")
        label.set_line_wrap(True)
        vbox.pack_start(label, True, True, 0)
        assistant.set_page_complete(vbox, True)

        vbox = gtk.VBox()
        vbox.set_border_width(5)
        assistant.append_page(vbox)
        assistant.set_page_title(vbox, "Page 2: Moving On...")
        assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_CONTENT)
        label = gtk.Label("This is an example of a label and checkbox within a page. If this box is checked, the assistant will skip page 3.")
        label.set_line_wrap(True)
        self.checkbutton = gtk.CheckButton("Skip next page")
        vbox.pack_start(label, True, True, 0)
        vbox.pack_start(self.checkbutton, False, False, 0)
        assistant.set_page_complete(vbox, True)

        vbox = gtk.VBox()
        vbox.set_border_width(5)
        assistant.append_page(vbox)
        assistant.set_page_title(vbox, "Page 3: The skipped page")
        assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_CONTENT)
        label = gtk.Label("This is an example of a page that contains information that may be skipped depending on the status of the previous pages.")
        label.set_line_wrap(True)
        button = gtk.Button("Button Example")
        vbox.pack_start(label, True, True, 0)
        vbox.pack_start(button, False, False, 0)
        assistant.set_page_complete(vbox, True)

        vbox = gtk.VBox()
        vbox.set_border_width(5)
        assistant.append_page(vbox)
        assistant.set_page_title(vbox, "Page 4: The Finale")
        assistant.set_page_type(vbox, gtk.ASSISTANT_PAGE_CONFIRM)
        label = gtk.Label("This is the final page of the Assistant widget. It would be used to confirm the preferences we have set in the previous pages.")
        label.set_line_wrap(True)
        vbox.pack_start(label, True, True, 0)
        assistant.set_page_complete(vbox, True)

        assistant.show_all()
        # Set an alternative function to return the next page to go to
        assistant.set_forward_page_func(self.pageforward)

    def pageforward(self,page):
        """
        Function called when the forward button is pressed,
        Arguments:
            page:
                integer index of the current page
        returns:
            integer index of the next page to display
        """
        if page == 1 and self.checkbutton.get_active():
            return 3
        else:
            return page+1

    def button_pressed(self, assistant, button):
        print "%s button pressed" % button
        gtk.main_quit()

Assistant()
gtk.main()

Graduate recruitment

I was recently asked by a current student at Edinburgh University about my insight with finding a graduate job and the employment prospects someone in their final year would have. Below is my response:

To be honest, I got very lucky with my graduate job, I didn’t apply for nearly as many positions that I, in hindsight, should have done. I must stress that this is from my own personal experience and may not be the best answer for anyone else.

There are jobs out there and they must all be filled by someone. The main thing is to apply for as many jobs as you can. It does not matter how many people turn you down, it takes only one to accept you and you are sorted.

What worked for me was uploading my CV to different job sites like monster.co.uk and linkedin.com. The site that my graduate employer actually found me through was gradcracker.com. Once your CV and profile have been added, it is important to edit and update them. With some of these sites, they sort candidates by activity, so each time you update it, you go back to the top of the pile.

What also helped with both my graduate and current jobs was having my own website (not the current version, the one I had when graduating was lost when the server I was using died). I used my website as an extended CV. Where my CV had a short paragraph with only the most relevant work placements, my website had several paragraphs and covered more of my previous jobs and voluntary positions as well as a separate page detailing different projects and presentations I have been involved in (including the final reports for my research and group projects for my final years).

Once you get through to the interview stage, you want to come across as keen and interested. The most obvious way is to ask lots of questions.

I have only had a brief experience with graduate recruitment from a recruiter’s perspective where I was asked to give candidates a tour of the factory before their main interview. I was then asked by the main interviewers how they got on. They were looking for candidates that would happily have a conversation with other workers when introduced to them on the tour. Another thing they were looking for were those that were asking lots of extra questions (why does it do that? how do you get round this problem?).

Don’t get demoralised when you get a rejection. I remember getting really bothered by one company that turned me down early on. However once I found out which candidates they did take on, I was glad I hadn’t gotten the job. They were looking for people that were much more assertive and commanding, which did not suit me. I suspect that if I had gotten the job, I would not have enjoyed it. When you do get a rejection, ask what their reasons were. The worst they can do is ignore you and you might get some good feedback.

As I said at the beginning, the more places you apply to, the better your chances of finding someone who will give you an offer.

I wish you the best of luck with your search.

Sudo = Please

After a comment I made the other day, I remembered the sudo make me a sandwich xkcd comic

Proper User Policy apparently means Simon Says.

It occured to me that commanding someone by saying ‘sudo make me …’ is not very nice and it would be better to say ‘please make me …’. I wondered if my computers would appreciate the same politeness.

I have now set up my computers with an alias so that if you type ‘please’, it acts like you typed ‘sudo’.

The command to do this yourself is:

alias please='sudo'

To make these permanent you can put the alias lines to your ~/.bash_profile file. Now you can have fun and ask nicely:

 

marshall@revo:/var/local$ mkdir stuff
mkdir: cannot create directory `stuff': Permission denied
marshall@revo:/var/local$ please mkdir stuff
[sudo] password for marshall:
marshall@revo:/var/local$