Small update add some command line argumenmts.
[Python-Scripts.git] / PyClock / bin / clock.py
blob9311fde8c70f416d3e87ce1ed6b813d715ef2254
1 #!/usr/bin/python2
3 """
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the Revised BSD License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 Revised BSD License for more details.
12 Copyright 2012 iDB Support - http://idb.berlios.de/
13 Copyright 2012 Game Maker 2k - http://gamemaker2k.org/
15 $FileInfo: clock.py - Last Update: 05/11/2012 Ver 1.0.0-10 - Author: cooldude2k $
16 """
18 import os, sys, time, locale, calendar, pygame, platform, glob;
19 from os import environ, system, mkdir;
20 from sys import version, exit;
21 from time import gmtime, strftime;
22 from glob import glob;
23 from pygame import init, quit;
24 from pygame.locals import *;
25 import shutil;
27 pythonver=version;
28 print('python version "'+pythonver+'"');
29 print('system: "%s"\nnode: "%s"\nrelease: "%s"\nversion: "%s"\nmachine: "%s"\nprocessor: "%s"' % platform.uname());
30 init();
31 print('init pygame');
32 fpsclock=pygame.time.Clock();
33 pygamever=pygame.version.ver;
34 print('pygame version '+pygamever);
35 print('sdl version %s.%s.%s' % pygame.get_sdl_version());
37 if(os.path.exists('./config.txt') == True):
38 if(os.path.isdir('./config.txtt') == True):
39 os.removedirs('./config.txt');
40 print('deleting file "./config.txt"');
41 if(os.path.exists('./config.txt') == False):
42 shutil.copyfile('./default/config.txt', './config.txt');
43 print('copying config file "./default/config.txt" to "./config.txt"');
44 if(os.path.exists('./screenshots') == False):
45 mkdir('./screenshots');
46 print('making screenshot dir "./screenshots"');
48 pyconfig=open('./config.txt', 'r');
49 print('loading config file "./config.txt"');
50 configload=pyconfig.readlines();
51 bgcpresplit=configload[2].rstrip('\n');
52 bgcsplit=bgcpresplit.split(',');
53 displaysize=configload[6].rstrip('\n');
54 displaysizesplit=displaysize.split('x');
55 pysoundfiles=configload[7].rstrip('\n');
56 pysoundconf=configload[8].rstrip('\n');
57 pysndconfsplit=pysoundconf.split(',');
59 fontload=configload[0].rstrip('\n');
60 fontloadsplit=fontload.split('|');
61 fontsizeload=configload[1].rstrip('\n');
62 fontsizesplit=fontsizeload.split('|');
63 pycolorload=configload[3].rstrip('\n');
64 pycolorsplit=pycolorload.split('|');
65 fontxyload=configload[4].rstrip('\n');
66 fontxysplit=fontxyload.split('|');
67 datetimeload=configload[5].rstrip('\n');
68 datetimesplit=datetimeload.split('|');
69 imgbgload=configload[9].rstrip('\n');
70 imgbgsplit=imgbgload.split('|');
71 imgbgxyload=configload[10].rstrip('\n');
72 imgbgxysplit=imgbgxyload.split('|');
73 pytimezones=configload[11].rstrip('\n');
74 pytimezonesplit=pytimezones.split('|');
76 numtzs=len(pytimezonesplit);
77 currenttz=0;
78 environ['SDL_VIDEODRIVER'] = 'x11';
79 pygame.display.init();
80 print('init pygame '+pygame.display.get_driver()+' display');
81 pyicon=pygame.image.load('./icon.png');
82 pygame.display.set_icon(pyicon);
84 globfiles=glob(pysoundfiles);
85 numfiles=len(globfiles);
86 countnum=0;
87 if(numfiles > 0):
88 print('number of sound files %i' % numfiles);
89 pygame.mixer.init(int(pysndconfsplit[0]),int(pysndconfsplit[1]),int(pysndconfsplit[2]),int(pysndconfsplit[3]));
90 print('init pygame sound');
92 print('supported display modes "%s"' % pygame.display.list_modes());
93 pyscreen=pygame.display.set_mode((int(displaysizesplit[0]),int(displaysizesplit[1])),FULLSCREEN);
94 print('setting display mode "'+displaysizesplit[0]+'x'+displaysizesplit[1]+'"');
95 print('setting fullscreen mode');
96 pybackground=pygame.Surface(pyscreen.get_size());
97 pybackground.fill((int(bgcsplit[0]),int(bgcsplit[1]),int(bgcsplit[2])));
98 pygame.display.set_caption('PyClock');
99 print('setting caption "PyClock"');
100 pygame.mouse.set_visible(0);
101 pygame.display.get_active();
102 # pygame.display.toggle_fullscreen();
103 pygame.font.init();
104 print('init pygame font');
106 oldtz="none";
107 fcountall = 0;
108 done = False;
109 while not done:
110 pyscreen.fill((int(bgcsplit[0]),int(bgcsplit[1]),int(bgcsplit[2])));
111 fcount0 = 0;
112 while (fcount0 < len(imgbgsplit)):
113 if (os.path.exists(imgbgsplit[int(fcount0)]) == True):
114 pybgimgall={};
115 if(fcountall == 0):
116 print('loading background image "'+imgbgsplit[int(fcount0)]+'"');
117 print('setting background image "'+imgbgsplit[int(fcount0)]+'"');
118 pybgimgall[int(fcount0)]=pygame.image.load(imgbgsplit[int(fcount0)]);
119 pybgimgxyall=imgbgxysplit[int(fcount0)].split(',');
120 pyscreen.blit(pybgimgall[int(fcount0)],(int(pybgimgxyall[0]),int(pybgimgxyall[1])));
121 fcount0 = fcount0 + 1;
122 if(pytimezonesplit[currenttz] != "System" and oldtz!=pytimezonesplit[currenttz]):
123 oldtz=pytimezonesplit[currenttz];
124 #os.environ['TZ'] = 'UTC';
125 print('setting timezone to "'+pytimezonesplit[currenttz]+'"');
126 os.putenv('TZ',pytimezonesplit[currenttz]);
127 #time.tzset();
128 if(pytimezonesplit[currenttz] == "System" and oldtz!=pytimezonesplit[currenttz]):
129 oldtz=pytimezonesplit[currenttz];
130 print('setting timezone to system time');
131 os.unsetenv('TZ');
132 #time.tzset();
133 fcount1 = 0;
134 while (fcount1 < len(fontloadsplit)):
135 fontsizeall=fontsizesplit[int(fcount1)].split(',');
136 pyfontall={};
137 pyfontall[int(fcount1)]=pygame.font.Font(fontloadsplit[int(fcount1)], int(fontsizeall[0]));
138 pyfontall[int(fcount1)].set_bold(int(fontsizeall[1]));
139 pyfontall[int(fcount1)].set_italic(int(fontsizeall[2]));
140 pyfontall[int(fcount1)].set_underline(int(fontsizeall[3]));
141 if(fcountall == 0):
142 print('loading font file "'+fontloadsplit[int(fcount1)]+'"');
143 print('setting font size '+fontsizeall[0]);
144 pycolorall=pycolorsplit[int(fcount1)].split(',');
145 fontxyall=fontxysplit[int(fcount1)].split(',');
146 pytimeall={};
147 pytimeall[int(fcount1)]=pyfontall[int(fcount1)].render(strftime(datetimesplit[int(fcount1)]), 1, (int(pycolorall[0]),int(pycolorall[1]),int(pycolorall[2])));
148 pyscreen.blit(pytimeall[int(fcount1)],(int(fontxyall[0]),int(fontxyall[1])));
149 fcount1 = fcount1 + 1;
150 if(numfiles > 0):
151 if(pygame.mixer.music.get_busy()==0):
152 pysound=pygame.mixer.music.load(globfiles[int(countnum)]);
153 print('loading music file "'+globfiles[int(countnum)]+'"');
154 pygame.mixer.music.set_volume(float(pysndconfsplit[4]));
155 print('setting sound volume %f' % float(pysndconfsplit[4]));
156 pygame.mixer.music.play(0);
157 print('playing music file "'+globfiles[int(countnum)]+'"');
158 if(countnum < numfiles):
159 countnum = countnum + 1;
160 if(countnum == numfiles):
161 countnum = 0;
162 pygame.display.update();
163 fpsclock.tick(30);
164 fcountall = fcountall + 1;
166 for event in pygame.event.get():
167 if (event.type == pygame.KEYDOWN):
168 if (event.key == pygame.K_SPACE) and (numfiles > 0):
169 pygame.mixer.music.stop();
170 print('stoping sound file "'+globfiles[int(countnum)]+'"');
171 pygame.mixer.stop();
172 print('stoping all sounds');
173 if (event.key == pygame.K_LALT) or (event.key == pygame.K_RALT):
174 saveimgnum=0;
175 imgdone=False;
176 while not imgdone:
177 if (os.path.exists('./screenshots/screenshot_%i.jpg' % saveimgnum) == False):
178 pygame.image.save(pyscreen, './screenshots/screenshot_%i.jpg' % saveimgnum);
179 print('saving screenshot at file "./screenshots/screenshot_%i.jpg"' % saveimgnum);
180 imgdone=True;
181 saveimgnum = saveimgnum + 1;
182 if (event.key == pygame.K_PRINT):
183 saveimgnum=0;
184 imgdone=False;
185 while not imgdone:
186 if (os.path.exists('./screenshots/screenshot_%i.bmp' % saveimgnum) == False):
187 pygame.image.save(pyscreen, './screenshots/screenshot_%i.bmp' % saveimgnum);
188 print('saving screenshot at file "./screenshots/screenshot_%i.bmp"' % saveimgnum);
189 imgdone=True;
190 saveimgnum = saveimgnum + 1;
191 if (event.key == pygame.K_LCTRL) or (event.key == pygame.K_RCTRL):
192 saveimgnum=0;
193 imgdone=False;
194 while not imgdone:
195 if (os.path.exists('./screenshots/screenshot_%i.png' % saveimgnum) == False):
196 pygame.image.save(pyscreen, './screenshots/screenshot_%i.png' % saveimgnum);
197 print('saving screenshot at file "./screenshots/screenshot_%i.png"' % saveimgnum);
198 imgdone=True;
199 saveimgnum = saveimgnum + 1;
200 if (event.key == pygame.K_t) or (event.key == pygame.K_w):
201 pygame.display.toggle_fullscreen();
202 print('switching screen display mode');
203 if (event.key == pygame.K_i) or (event.key == pygame.K_m):
204 pygame.display.iconify();
205 print('minimizing window to system tray');
206 if (event.key == pygame.K_LEFT):
207 if(currenttz == 0):
208 currenttz = numtzs;
209 if(currenttz > 0):
210 currenttz = currenttz - 1;
211 if (event.key == pygame.K_RIGHT):
212 if(currenttz < numtzs):
213 currenttz = currenttz + 1;
214 if(currenttz == numtzs):
215 currenttz = 0;
217 if (event.key == pygame.K_ESCAPE) or (event.key == pygame.K_q):
218 done = True;
220 if(numfiles > 0):
221 pygame.mixer.music.stop();
222 print('stoping music file "'+globfiles[int(countnum)]+'"');
223 pygame.mixer.stop();
224 print('stoping all sounds');
225 pygame.mixer.quit();
226 print('uninit pygame sound');
228 pygame.font.quit();
229 print('uninit pygame font');
230 pygame.display.quit();
231 print('uninit pygame x11 display');
232 quit();
233 print('uninit pygame');
234 print('exiting python');
235 exit();