#!/usr/bin/python """ textpause Accepts a number of filenames and opens a window for each, containing the text read from them. A single dash (-) may be used to indicate that stdin should be read, allowing command output to be piped to textpause and displayed. Use the -title option to specify the window's title. """ try: import pylau except ImportError: pass import os import sys import string from gtk import * _instances = 0 class TextPause(GtkWindow): def __init__(self, title, pipe): global _instances GtkWindow.__init__(self) self.connect("destroy", self.OnDestroy) self.set_title(title) self.set_border_width(2) box = GtkVBox() # Title title = GtkLabel("Output of: "+title) box.pack_start(title, FALSE) title.show() text_hbox = GtkHBox() box.pack_start(text_hbox) vadj = GtkAdjustment() text = GtkText(None, vadj) text_hbox.pack_start(text) text.set_editable(0) vscrollbar = GtkVScrollbar(vadj) text_hbox.pack_start(vscrollbar, FALSE) vscrollbar.show() text_hbox.show() text.show() button_box = GtkHBox() button = GtkButton("Close") button.connect("clicked", self.destroy) button.show() button_box.pack_start(button, TRUE, FALSE) box.pack_start(button_box, FALSE) button_box.show() self.add(box) box.show() self.show() text.insert(None, None, None, pipe.read()) _instances = _instances + 1 def OnDestroy(self, widget): global _instances _instances = _instances - 1 if not _instances: mainquit() def Main(argv): del argv[0] title = None while argv: name = argv[0] del argv[0] if name == "-title": title = argv[0] del argv[0] else: if name == "-": f = sys.stdin else: f = open(name, "r") if not title: title = name TextPause(title, f) title = None if _instances: mainloop() if __name__ == "__main__": Main(sys.argv)