add XS-VCS-Darc header
[darcs-mirror-screen-message.debian.git] / sm.py
1 #!/usr/bin/python
2 # encoding:utf8
3
4 #     vlshow.py
5 #     Copyright (C) 2006 Joachim Breitner
6 #
7 #     This program is free software; you can redistribute it and/or modify
8 #     it under the terms of the GNU General Public License as published by
9 #     the Free Software Foundation; either version 2 of the License, or
10 #     (at your option) any later version.
11 #
12 #     This program is distributed in the hope that it will be useful,
13 #     but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #     GNU General Public License for more details.
16 #
17 #     You should have received a copy of the GNU General Public License
18 #     along with this program; if not, write to the Free Software
19 #     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20
21
22 import pygtk
23 pygtk.require('2.0')
24 import gtk
25 import pango
26 import sys
27 import gobject
28
29 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
30 window.set_decorated(False)
31 window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
32 window.fullscreen()
33
34 settings = gtk.settings_get_default()
35
36 draw = gtk.DrawingArea()
37 draw.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
38 draw.set_size_request(400,300)
39
40 pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
41 color = gtk.gdk.Color()
42 cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
43
44
45 tv = gtk.TextView()
46 tb = tv.get_buffer()
47
48 def get_text():
49         return tb.get_text(tb.get_start_iter(), tb.get_end_iter())
50
51 if len(sys.argv) > 1:
52         tb.set_text(" ".join(sys.argv[1:]))
53 else:
54         tb.set_text(";-)")
55
56 quit = gtk.Button(stock=gtk.STOCK_QUIT)
57 quit.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("white"))
58 quit.connect("clicked",gtk.main_quit)
59
60 hbox = gtk.HBox()
61 hbox.pack_start(tv, expand=True, fill=True)
62 hbox.pack_start(quit,  expand=False,fill=False)
63
64 vbox = gtk.VBox()
65 vbox.pack_start(draw, expand=True, fill=True)
66 vbox.pack_start(hbox, expand=False, fill=False)
67 window.add(vbox)
68
69 font = pango.FontDescription()
70 font.set_size(60*pango.SCALE)
71 layout = draw.create_pango_layout(get_text())
72 layout.set_font_description(font)
73 layout.set_alignment(pango.ALIGN_CENTER)
74
75
76 accel = gtk.AccelGroup()
77 key, mod = gtk.accelerator_parse("<Ctrl>Q")
78 accel.connect_group(key, mod, 0, gtk.main_quit)
79 key, mod = gtk.accelerator_parse("Escape")
80 #accel.connect_group(key, mod, 0, gtk.main_quit)
81 #key, mod = gtk.accelerator_parse("<Ctrl>C")
82 accel.connect_group(key, mod, 0, (lambda x,y,z,v: tb.set_text("")))
83 window.add_accel_group(accel)
84
85 window.show_all()
86
87 need_resize=True
88 need_quick=True
89
90 def resize(w=None,rect=None):
91         global need_resize
92         draw.window.set_cursor(cursor)
93         (w1,h1) = layout.get_pixel_size()
94         if h1>0 and w1>0:
95                 (x,y,w2,h2) = draw.get_allocation()
96                 s = font.get_size()
97                 s = min ( int (s*w2/w1), int (s*h2/h1) )
98                 font.set_size(s)
99                 layout.set_font_description(font)
100                 need_resize=False
101         else:
102                 need_resize=True
103
104 def redraw(w=None,e=None):
105         global need_resize, need_quick
106         if layout.get_text(): # Fails for empty lines :-(
107                 gc = draw.get_style().fg_gc[gtk.STATE_NORMAL]
108                 (w1,h1) = layout.get_pixel_size()
109                 if h1>0 and w1>0:
110                         (x,y,w2,h2) = draw.get_allocation()
111                         draw.window.draw_layout(gc,(w2-w1)/2,(h2-h1)/2,layout)
112                         hq(True)
113
114 quality = False
115 def hq(q,force=False):
116         global quality
117         if q != quality:
118                 if q:
119                         settings.set_long_property("gtk-xft-antialias",1,"Hier halt")
120                 else:
121                         settings.set_long_property("gtk-xft-antialias",0,"Hier halt")
122         else:
123                 if force:
124                         draw.queue_draw()
125
126         quality = q
127         return False
128
129 def newtext(w):
130         global timeout_id
131         layout.set_text(get_text())
132         resize()
133         hq(False, True)
134
135 draw.connect("configure-event", resize)
136 draw.connect("expose-event", redraw)
137 tb.connect("changed", newtext)
138
139 gtk.main()