File: cappuccino

package info (click to toggle)
cappuccino 0.5.1-2.2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 132 kB
  • ctags: 25
  • sloc: python: 97; makefile: 42
file content (140 lines) | stat: -rwxr-xr-x 3,789 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
# -*- python -*-
#
# Copyright (C) 2000-2006 Christopher R. Gabriel <cgabriel@cgabriel.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.

import sys, gtk, os, gobject, os.path, glob, random

# FIXME: change with something based on the setup script
try:
	os.stat("cappuccino.grm")
	PLUGIN_DIR = "./"
except OSError:
	PLUGIN_DIR = "/usr/share/cappuccino/"
		
# to be discussed
pipe_command = 'polygen %s' % os.path.join(PLUGIN_DIR, 'cappuccino.grm')

class CappuccinoSplash(gtk.Window):
	def __init__(self):
		gtk.Window.__init__(self)
		image = gtk.Image()
		pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(PLUGIN_DIR,'cappuccino.jpg'))
		image.set_from_pixbuf(pixbuf)
		self.add(image)
		
		
class Cappuccino(gtk.Window):
	def __init__(self,title,speed=400):
		gtk.Window.__init__(self)
		# our data
		self.cur_position = 0.0
		self.speed = speed
		self.waiting_message = "Work in progress"
		self.current_message = self.new_phrase()

		# set window stuff
		self.fullscreen()
		self.set_title = title

		#window's widgets
		self.w_vbox = gtk.VBox()

		
		self.w_label = gtk.Label()
		self.w_vbox.pack_start(self.w_label,True,True,40)

		self.w_scroll = gtk.ScrolledWindow()
		self.w_scroll.set_shadow_type(gtk.SHADOW_ETCHED_IN)
		self.w_scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
		self.w_vbox.pack_start(self.w_scroll, True, True,100)
		
		self.w_text = gtk.TextView()
		self.w_text.set_editable(False)
		self.w_scroll.add(self.w_text)
		
		self.w_align = gtk.Alignment(0.5,0.5,0.5,0.0)
		self.w_vbox.pack_start(self.w_align, True, True)

		self.progressbar = gtk.ProgressBar()
		# the bar is reset upon startup
		self.progressbar.set_fraction(0.0)
		self.w_align.add(self.progressbar)
		#self.w_vbox.pack_start(self.progressbar,True,True)

		self.get_log_data()
		self.add(self.w_vbox)
		# timeout that starts it all
		self.timeouter = gobject.timeout_add(self.speed, self.update)
		self.log_timeouter = gobject.timeout_add(1000, self.update_log)
		
		# event handling. Add some key press events handlers!!
		self.connect("delete_event", self.delete_handler)
		self.connect("destroy_event", self.delete_handler)


	def delete_handler(self,obj,param):
		# remove the timeout upon delete or  destroy event!
		gobject.source_remove(self.timeouter)

	def get_log_data(self):
		p = os.popen("polygen -X 50 %s" % os.path.join(PLUGIN_DIR,"compileline.grm"))
		self.log = p.readlines()
		p.close()
		
	def update_log(self):
				   
		# do the log!
		if len(self.log) < 1:
			self.get_log_data()
		buf = self.w_text.get_buffer()
		buf.insert_at_cursor(self.log.pop())
		self.w_text.set_buffer(buf)
		ha = self.w_scroll.get_vadjustment()
		ha.set_value(ha.upper)
		self.w_scroll.set_vadjustment(ha)
		return True
	
	def update(self):
		
		self.cur_position += random.random() / 5.0

		
		if self.cur_position > 1.2:
			self.cur_position = 0.0
			self.current_message = self.new_phrase()

		self.w_label.set_markup('<span foreground="black" size="x-large"><b>%s</b></span>' % (self.current_message))

		pos = (self.cur_position > 1 and 1 or self.cur_position)
		self.progressbar.set_fraction(pos)
		self.progressbar.set_text(str(int(100*pos))+" %")
		return True

	def new_phrase(self):
		p = os.popen(pipe_command,"r")
		phrase = p.read().strip()
		p.close()
		return phrase

def startup(par):
	par.destroy()
	app = Cappuccino(sys.argv[0])
	app.connect("delete_event", gtk.main_quit)
	app.connect("destroy_event", gtk.main_quit)
	app.show_all()
	
		
if __name__ == "__main__":
	splash = CappuccinoSplash()
	splash.show_all()
	t = gobject.timeout_add(3000, startup, splash)
	gtk.main()