Remove unused variable
[vte.git] / python / vte-demo.py
1 #!/usr/bin/python
2 import sys
3 import string
4 import getopt
5 import gtk
6 import vte
7
8 def selected_cb(terminal, column, row, cb_data):
9         if (row == 15):
10                 if (column < 40):
11                         return 1
12         return 0
13
14 def restore_cb(terminal):
15         (text, attrs) = terminal.get_text(selected_cb, 1)
16         print "A portion of the text at restore-time is:"
17         print text
18
19 def child_exited_cb(terminal):
20         gtk.main_quit()
21
22 if __name__ == '__main__':
23         child_pid = -1;
24         # Defaults.
25         audible = 0
26         background = None
27         blink = 0
28         command = None
29         emulation = "xterm"
30         font = "fixed 12"
31         scrollback = 100
32         transparent = 0
33         visible = 0
34         # Let the user override them.
35         (shorts, longs) = getopt.getopt(sys.argv[1:], "B:Tabc:f:n:t:v", ["background", "transparent", "audible", "blink", "command=", "font=", "scrollback=", "terminal=", "visible"])
36         for argpair in (shorts + longs):
37                 if ((argpair[0] == '-B') or (argpair[0] == '--background')):
38                         print "Setting background image to `" + argpair[1] + "'."
39                         background = argpair[1]
40                 if ((argpair[0] == '-T') or (argpair[0] == '--transparent')):
41                         print "Setting transparency."
42                         transparent = not transparent
43                 if ((argpair[0] == '-a') or (argpair[0] == '--audible')):
44                         print "Setting audible bell."
45                         audible = not audible
46                 if ((argpair[0] == '-b') or (argpair[0] == '--blink')):
47                         print "Setting blinking cursor."
48                         blink = not blink
49                 if ((argpair[0] == '-c') or (argpair[0] == '--command')):
50                         print "Running command `" + argpair[1] + "'."
51                         command = argpair[1]
52                 if ((argpair[0] == '-f') or (argpair[0] == '--font')):
53                         print "Setting font to `" + argpair[1] + "'."
54                         font = argpair[1]
55                 if ((argpair[0] == '-n') or (argpair[0] == '--scrollback')):
56                         scrollback = string.atoi(argpair[1])
57                         if (scrollback == 0):
58                                 scrollback = 100
59                         else:
60                                 print "Setting scrollback size to `" + str(scrollback) + "'."
61                 if ((argpair[0] == '-t') or (argpair[0] == '--terminal')):
62                         print "Setting terminal type to `" + argpair[1] + "'."
63                         emulation = argpair[1]
64                 if ((argpair[0] == '-v') or (argpair[0] == '--visible')):
65                         print "Setting visible bell."
66                         visible = not visible
67         window = gtk.Window()
68         terminal = vte.Terminal()
69         if (background):
70                 terminal.set_background_image(background)
71         if (transparent):
72                 terminal.set_background_transparent(gtk.TRUE)
73         terminal.set_cursor_blinks(blink)
74         terminal.set_emulation(emulation)
75         terminal.set_font_from_string(font)
76         terminal.set_scrollback_lines(scrollback)
77         terminal.set_audible_bell(audible)
78         terminal.set_visible_bell(visible)
79         terminal.connect("child-exited", child_exited_cb)
80         terminal.connect("restore-window", restore_cb)
81         if (command):
82                 # Start up the specified command.
83                 child_pid = terminal.fork_command(command)
84         else:
85                 # Start up the default command, the user's shell.
86                 child_pid = terminal.fork_command()
87         terminal.show()
88
89         scrollbar = gtk.VScrollbar()
90         scrollbar.set_adjustment(terminal.get_adjustment())
91
92         box = gtk.HBox()
93         box.pack_start(terminal)
94         box.pack_start(scrollbar)
95
96         window.add(box)
97         window.show_all()
98         gtk.main()