Example #1
0
def main():
    parser = OptionParser(usage="usage: %prog command")
    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.print_help()
        sys.exit(1)

    win = gtk.Window()
    textview = gtk.TextView()
    textview.modify_font(pango.FontDescription("Monospace"))
    textview.show()
    sw = gtk.ScrolledWindow()
    sw.add(textview)
    sw.show()
    win.add(sw)
    win.set_default_size(gtk.gdk.screen_width() * 2 / 3,
                         gtk.gdk.screen_height() * 2 / 3)
    win.show()

    ## launch process
    proc = subprocess.Popen(args[0],
                            shell=True,
                            stdout=subprocess.PIPE,
                            bufsize=1,
                            close_fds=True)
    win.set_title("%s (running)" % args[0])
    # print proc.stdout, type(proc.stdout), dir(proc.stdout)
    chan = gobject.IOChannel(filedes=proc.stdout.fileno())
    chan.set_flags(gobject.IO_FLAG_NONBLOCK)
    sink = tasklet.run(
        process_stdout_sink(chan, textview.get_buffer(), textview))

    ## child watch
    yield (tasklet.WaitForProcess(proc.pid),
           tasklet.WaitForSignal(win, "destroy"))

    if isinstance(tasklet.get_event(), tasklet.WaitForSignal):
        killproc(proc.pid)
        gtk.main_quit()
    else:
        ## stop reader
        yield tasklet.Message("quit", dest=sink)
        win.set_title("%s (completed)" % args[0])
        yield tasklet.WaitForSignal(win, "destroy")
        tasklet.get_event()
        gtk.main_quit()
Example #2
0
def main():
    dialog = Gtk.MessageDialog(parent=None,
                               flags=0,
                               type=Gtk.MessageType.QUESTION,
                               buttons=Gtk.ButtonsType.YES_NO,
                               message_format="Please answer Yes or No")
    dialog.format_secondary_markup("Time left: <b>??</b> seconds")
    dialog.show()

    counter = Counter(dialog)

    yield (tasklet.WaitForTasklet(counter),
           tasklet.WaitForSignal(dialog, "response"),
           tasklet.WaitForSignal(dialog, "close"))

    event = tasklet.get_event()
    if isinstance(event, tasklet.WaitForSignal):
        print("signal '%s', stopping counter" % event.signal)
        yield tasklet.Message("quit", dest=counter)  # stop the counter

        if event.signal == 'close':
            Gtk.main_quit()
            return

        response = event.signal_args[0]
        msgbox = Gtk.MessageDialog(parent=dialog,
                                   flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                   type=Gtk.MessageType.INFO,
                                   buttons=Gtk.ButtonsType.OK,
                                   message_format=("Thank you "
                                                   "for your kind answer!"))
        print("response was", response)
        if response == Gtk.ResponseType.YES:
            msgbox.format_secondary_markup(
                "Your response was <i><b>Yes</b></i>")
        elif response == Gtk.ResponseType.NO:
            msgbox.format_secondary_markup(
                "Your response was <i><b>No</b></i>")
        else:
            ## must have been a delete event
            print("response was delete event")
            Gtk.main_quit()
            return
        msgbox.show()

        print("showing dialog")
        yield (tasklet.WaitForSignal(msgbox, "response"),
               tasklet.WaitForSignal(msgbox, "close"))
        print("event", tasklet.get_event())

    else:
        ## timeout must have exausted..
        assert isinstance(event, tasklet.WaitForTasklet)
        msgbox = Gtk.MessageDialog(parent=dialog,
                                   flags=Gtk.DialogFlags.DESTROY_WITH_PARENT,
                                   type=Gtk.MessageType.WARNING,
                                   buttons=Gtk.ButtonsType.OK,
                                   message_format="You're too slow!!")
        msgbox.show()

        yield (tasklet.WaitForSignal(msgbox, "response"),
               tasklet.WaitForSignal(msgbox, "close"))

    Gtk.main_quit()
Example #3
0
 def some_task():
     yield tasklet.WaitForSignal(C, 'my-signal')
     tasklet.get_event()
     raise StopIteration("return-val")
Example #4
0
 def testGoodArguments(self):
     tasklet.WaitForSignal(gobject.GObject(), 'notify')