File: clock

package info (click to toggle)
mgm 1.1.cvs.20020221-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,724 kB
  • ctags: 33
  • sloc: perl: 768; makefile: 32
file content (295 lines) | stat: -rw-r--r-- 19,505 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# -*-Perl-*-

# clock, like xclock

package MGMmodule::clock;
use vars qw($xpm $PI @days);

$PI=3.14159265358979323846;  # assume not near black hole nor in Tennessee

# called once to initialize the module.  The xpath here is a Class.
sub module_init{
    my$this=shift;
    my$toplevel=$this->{"toplevel"};
    my$xclass=$this->{"xclass"};
    $toplevel->optionAdd("$xclass.order",               '.1',20);
    $this;
}

# called to build an instance.  The xpath here is a name path.
sub module_instance{
    my$this=shift;
    my$widget=$this->{"widget"};
    my$toplevel=$this->{"toplevel"};
    my$xpath=$this->{"xpath"};

    $toplevel->optionAdd("$xpath.relief", 'sunken' ,21);
    $toplevel->optionAdd("$xpath.ipad", 20 ,21);
    $toplevel->optionAdd("$xpath.borderwidth", 1 ,21);
    $toplevel->optionAdd("$xpath.scalewidadj", 150,21);
    $toplevel->optionAdd("$xpath.scalelenadj", 60,21);
    $toplevel->optionAdd("$xpath.scalejustify", 0,20);  #centered    
    $toplevel->optionAdd("$xpath.scalerefresh", 2000,20);  

    $this->{"relief"}=$widget->optionGet("relief",'');
    my$border=$this->{"border"}=$widget->optionGet("borderwidth",'');
    $this->{"background"}=$widget->optionGet("background",'');
    $this->{"foreground"}=$widget->optionGet("foreground",'');
    $this->{"lit"}=$widget->optionGet("litbackground",'');

    # use our font and find the labelsize...
    my$testlabel=$this->{"widget"}->Label(-text=>"Wed 00:00",
					  -borderwidth=>0,
					  -padx=>1,-pady=>1);    
    my$textheight=$this->{"textheight"}=$testlabel->reqheight;
    my$textwidth=$this->{"textwidth"}=$testlabel->reqwidth;
    $testlabel->destroy;

    my$pad=$widget->optionGet("ipad","");
    my$min=35+$pad/5;
    my$minx=(($textwidth<$min?$min:$textwidth)+$border*2);
    my$miny=$textheight+$min+$border*2;

    $toplevel->optionAdd("$xpath.minx", $minx,21);      # safe
    $toplevel->optionAdd("$xpath.miny", $miny,21);      # safe

    $this;
}

sub module_run{
    my$this=shift;

    my$width=$this->{"width"};
    my$height=$this->{"height"};
    my$textwidth=$this->{"textwidth"};
    my$textheight=$this->{"textheight"};
    my$toplevel=$this->{"toplevel"};
    my$border=$this->{"border"};
    my$back=$this->{"background"};
    my$widget=$this->{"widget"}=$toplevel->Canvas(-class=>$this->{"name"},
						  Name=>$this->{"sequence"},
						  width=>$width-$border*2,
						  height=>$height-$border*2,
						  borderwidth=>$border,
						  highlightthickness=>0);
    my$pad=$widget->optionGet("ipad","");
    $height-=$textheight;
    my$square=$width;

    $square=$height if($square>$height);
    $square-=$border*2;
    $square*=(100-$pad)/100;
    $this->{"square"}=$square=int($square);
    $this->{"time"}=-1;

    my$xpm=MGM::Xpm::data($xpm);
    $xpm->scale($square,$square);
    my$pixmap=$widget->Pixmap($widget->PathName.".clock",-data=>$xpm->
			      write($this->{"background"},
				    $this->{"lit"},8));

    $widget->createImage($width/2-1,$height/2-1,-image=>$pixmap,
			 -anchor=>'center',-tags=>['clock']);

    $this->module_update;
    $widget;
}

@days=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');

sub module_update{
    my$this=shift;
    my@l=localtime;
    my$t= sprintf "%s %02d:%02d",$days[$l[6]],$l[2],$l[1];

    if($t ne $this->{"time"}){

	my$widget=$this->{"widget"};
	my$square=$this->{"square"};
	my$width=$this->{"width"};
	my$height=$this->{"height"};
	my$textwidth=$this->{"textwidth"};
	my$textheight=$this->{"textheight"};
	$widget->delete("date");

	# minute hand
	my$phi=2*$PI/60*$l[1];
	my$A=$square/2*.8;
	my$B=$A*sin($phi);
	my$C=-$A*cos($phi);
	my$base=.08;
	my$b=$A*cos($phi)*$base;
	my$c=$A*sin($phi)*$base;
	my$cx=$width/2-1;
	my$cy=($height-$textheight)/2-1;

	$widget->createPolygon($b+$cx-$B*.25,$c+$cy-$C*.25,
			       $B+$cx,$C+$cy,
			       -$b-$B*.25+$cx,-$c-$C*.25+$cy,
			       -fill=>$this->{"foreground"},
			       -outline=>$this->{"foreground"},
			       -tags=>['date']);
			    
	# hour hand
	$phi=2*$PI/12/60*($l[2]*60+$l[1]);
	$A=$square/2*.55;
	$B=$A*sin($phi);
	$C=-$A*cos($phi);
	$base=.15;
	$b=$A*cos($phi)*$base;
	$c=$A*sin($phi)*$base;

	$widget->createPolygon($b+$cx-$B*.35,$c+$cy-$C*.35,
			       $B+$cx,$C+$cy,
			       -$b-$B*.35+$cx,-$c-$C*.35+$cy,
			       -fill=>$this->{"foreground"},
			       -outline=>$this->{"foreground"},
			       -tags=>['date']);

	my$font=$widget->optionGet("font","");
	my$y=$height-($height-$textheight+$square)/2;
	$widget->createText($width/2-1,$height-$y/2-1,
			    -text=>"$t",
			    -fill=>$this->{"foreground"},-anchor=>'center',
			    -font=>$font,-tags=>['date']);

			    
	$this->{"time"}=$t;
    }
}

$xpm= <<'EOXPM';
/* XPM */
static char * clockface_xpm[] = {
"119 119 8 1",
".	g #020202",
"+	g #FBFBFB",
"@	g #2D2D2D",
"#	g #717171",
"$	g #4D4D4D",
"%	g #CFCFCF",
"&	g #8E8E8E",
"*	g #B0B0B0",
"..........................................................+++..........................................................",
"..................................................@#######+++#######@...$.@............................................",
"..........................................%++$############+++##########&%%&@...........................................",
".........................................@%++*############+++##########*++%&#@.........................................",
"......................................@###*++%############+++##########*++%#####@......................................",
"...................................@#######+++####$$@.....+++.....@$$##%++&########@...................................",
".................................@#########%+%$@..........+++..........$&*&##########@.................................",
"...............................@##########$$@.............+++..............@$###########...............................",
".............................++&#######$@.................+++.................@$######*+%#.............................",
"............................*++%#####$....................+++....................$####+++*@............................",
"..........................@#&+++*##@...............................................@#*+++###@..........................",
".........................@###*+++@..................................................@+++*####@.........................",
".......................@######+++#..................................................&++%#######@.......................",
"......................@########+++@................................................$+++$@#######@......................",
".....................@######$..%++*................................................%++*...$######@.....................",
"....................@######@...$+++$..............................................$+++@....@######@....................",
"...................@#####$......*+*@...............................................$*&.......$####&&@..................",
"................*+&#####$.......@#............................................................$##*++*..................",
"...............@%++*&##$.......................................................................$*+++%$.................",
"...............@*+++%#@.........................................................................#++%&#@................",
"...............@#%+++$...........................................................................#%&###@...............",
"..............@###%+#.............................................................................@#####@..............",
".............@####&$...............................................................................@#####@.............",
"............@#####$.................................................................................$#####@............",
"............#####$...................................................................................$#####............",
"...........@####$.....................................................................................$####@...........",
"..........@#####.......................................................................................#####@..........",
"..........#####@.......................................................................................@#####..........",
".........@####$.........................................................................................$###&&.........",
"........+*####...........................................................................................##*++#........",
"........+++*#@...........................................................................................#+++++........",
".......%++++%$.........................................................................................$%++++%&@.......",
".......#*+++++*@.....................................................................................@*+++++*###.......",
"......@###*+++++&....................................................................................#++++#@####@......",
"......#####@&+++*.....................................................................................*+*@..#####......",
".....@####@..$*+$.....................................................................................@$....@####@.....",
".....#####.....$.............................................................................................#####.....",
".....####$...................................................................................................$####.....",
"....@####.....................................................................................................####@....",
"....####$.....................................................................................................$####....",
"....####@.....................................................................................................@####....",
"...@####.......................................................................................................####@...",
"..@####$.......................................................................................................$##*%...",
".*%%*&&@.......................................................................................................$%+++$..",
".#++++%........................................................................................................@++++&..",
".*++++%.........................................................................................................%+%*$..",
"..&*%+&.........................................................................................................$####..",
"..###&@.........................................................................................................@####..",
"..####...........................................................................................................####..",
"..####...........................................................................................................####..",
".@###$...........................................................................................................$###@.",
".####$...........................................................................................................$####.",
".####@...........................................................................................................@####.",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
"++++++++++...................................................................................................++++++++++",
"++++++++++...................................................................................................++++++++++",
"++++++++++...................................................................................................++++++++++",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
".####.............................................................................................................####.",
".####@...........................................................................................................@####.",
".####$...........................................................................................................$####.",
".@###$...........................................................................................................$###@.",
"..####...........................................................................................................####..",
"..####...........................................................................................................####..",
"..####@.........................................................................................................@####..",
"..&*%+&.........................................................................................................#&&##..",
"..++++%.........................................................................................................%+%%@..",
"..++++%........................................................................................................@+++%@..",
"..%%&##@.......................................................................................................$*%+*...",
"...####$.......................................................................................................$##&&...",
"...@####.......................................................................................................####@...",
"....####@.....................................................................................................@####....",
"....####$.....................................................................................................$####....",
"....@####.....................................................................................................####@....",
".....####$...................................................................................................$####.....",
".....#####.....$.............................................................................................#####.....",
".....@####@..$%+$.....................................................................................@$....@####@.....",
"......#####@*+++*.....................................................................................*+&@..#####......",
"......@###*+++++#....................................................................................#++++#@####@......",
".......#*+++++*@.....................................................................................@*+++++*###.......",
".......%++++%$.........................................................................................$%++++%&@.......",
"........+++*#@...........................................................................................#+++++........",
"........+*####...........................................................................................##*++#........",
".........@####$.........................................................................................$###&&.........",
"..........#####@.......................................................................................@#####..........",
"..........@#####.......................................................................................#####@..........",
"...........@####$.....................................................................................$####@...........",
"............#####$...................................................................................$#####............",
"............@#####$.................................................................................$#####@............",
".............@####*#...............................................................................@#####@.............",
"..............@##&%+#.............................................................................$&####@..............",
"...............@&+++%$...........................................................................#+%###@...............",
"...............$%++%&#@.........................................................................$+++%&@................",
"................$+%&###$.......................................................................$#*++%$.................",
".................%######$.......@#............................................................$##&*%$..................",
"...................@#####$......*+*@...............................................$*#.......$#####$...................",
"....................@######@...$+++$..............................................$+++@....@######@....................",
".....................@######$..%++&................................................%++*...$######@.....................",
"......................@########+++@................................................$+++$@#######@......................",
".......................@######+++#..................................................*++%#######@.......................",
".........................@###*+++@..................................................@+++*####@.........................",
"..........................@#&+++*##@...............................................@#*+++###@..........................",
"............................*++%#####$....................+++....................$####+++*@............................",
".............................++&#######$@.................+++.................@$######*++#.............................",
"...............................@###########$@.............+++..............@$###########...............................",
".................................@########*++*$@..........+++..........@&%%##########@.................................",
"...................................@######%++*####$$@.....+++.....@$$###+++########@...................................",
"......................................@##&+++&############+++###########%++&####@......................................",
".........................................#%+%&############+++###########*++%#@.........................................",
"..........................................$&$@############+++###########&%&$...........................................",
"..................................................@#######+++#######@..................................................",
"..........................................................+++.........................................................."};
EOXPM

bless {};