From a650af79e3e67c4e470e425505d61e59b519a18b Mon Sep 17 00:00:00 2001 From: Chris Ball Date: Mon, 10 Sep 2007 19:35:58 +0000 Subject: Add a "Stop!" button. --- (limited to 'activity.py') diff --git a/activity.py b/activity.py index 8505ab7..3d0fb16 100644 --- a/activity.py +++ b/activity.py @@ -27,6 +27,7 @@ import vte import sys import os import gobject +from signal import SIGTERM from dbus import Interface from dbus.service import method, signal @@ -123,11 +124,22 @@ class PippyActivity(Activity): codesw.add(self.text_view) vbox.pack_start(codesw) + # An hbox for the buttons + buttonhbox = gtk.HBox() + # The "go" button gobutton = gtk.Button(label="Run!") gobutton.connect('clicked', self.gobutton_cb) - gobutton.set_size_request(1000, 2) - vbox.pack_start(gobutton) + gobutton.set_size_request(800, 2) + buttonhbox.pack_start(gobutton) + + # The "stop" button + stopbutton = gtk.Button(label="Stop!") + stopbutton.connect('clicked', self.stopbutton_cb) + stopbutton.set_size_request(200, 2) + buttonhbox.pack_end(stopbutton) + + vbox.pack_start(buttonhbox) # An hbox to hold the vte window and its scrollbar. outbox = gtk.HBox() @@ -204,7 +216,10 @@ class PippyActivity(Activity): file.write(line) file.close() - pid = self._vte.fork_command("/bin/sh", ["/bin/sh", "-c", "python /tmp/pippy.py; sleep 1"]) + self._pid = self._vte.fork_command("/bin/sh", ["/bin/sh", "-c", "python /tmp/pippy.py; sleep 1"]) + + def stopbutton_cb(self, button): + os.kill(self._pid, SIGTERM) def write_file(self, file_path): self.metadata['mime_type'] = 'text/x-python' -- cgit v0.9.1