0 0 1
default
Jean-Francois Pieronne - 5 years ago 2014-10-20 18:38:45
jf.pieronne@laposte.net
Initial version of test2.py
1 file changed with 399 insertions and 0 deletions:
↑ Collapse Diff ↑
 
new file 100755
1
 
import time
2
 
import sys,sets,os
3
 
from string import atoi
4
 
import formencode
5
 
import re
6
 
from formencode import validators
7
 
from vms.rtl.smg import *
8
 
from vms.smgdef import *
9
 

	
10
 
#-------------------------------------------------------------------------#
11
 
#                           class Control                                 #  
12
 
#-------------------------------------------------------------------------#
13
 
"""Control class"""
14
 

	
15
 

	
16
 
class Control (formencode.FancyValidator):
17
 
    """ class registration"""
18
 

	
19
 

	
20
 
    #-----------------------------------#
21
 
    #          get_integer              #
22
 
    #-----------------------------------#
23
 

	
24
 
    def get_integer(self, prompt):
25
 

	
26
 
        validator = validators.Int()
27
 
        while 1:
28
 
            try:
29
 
                value = raw_input(prompt)
30
 
                return validator.to_python(value)
31
 
            except formencode.Invalid, e:
32
 
                print e
33
 

	
34
 

	
35
 
    #-----------------------------------#
36
 
    #           get_email               #
37
 
    #-----------------------------------#
38
 

	
39
 

	
40
 
    def get_email(self, prompt):
41
 

	
42
 
        validator = validators.Email()
43
 

	
44
 
        while 1:
45
 
            try:
46
 
                value = raw_input(prompt)
47
 
                return validator.to_python(value)
48
 
            except formencode.Invalid, e:
49
 
                print e
50
 

	
51
 

	
52
 

	
53
 
    #-----------------------------------#
54
 
    #            get_string             #
55
 
    #-----------------------------------#
56
 

	
57
 

	
58
 

	
59
 
    def get_string(self, prompt):
60
 

	
61
 
        validator = validators.String()
62
 

	
63
 
        while 1:
64
 
            try:
65
 
                value = raw_input(prompt)
66
 
                return validator.to_python(value)
67
 
            except formencode.Invalid, e:
68
 
                print e
69
 

	
70
 

	
71
 

	
72
 

	
73
 
#------------------------------------------------------------------------------#
74
 
#                              Program test                                    #
75
 
#------------------------------------------------------------------------------#
76
 

	
77
 
p = Pasteboard()
78
 
k = Keyboard()
79
 
c = Control()
80
 

	
81
 
s = (0,0)
82
 
while s[0] != 16:
83
 

	
84
 
    #----------------------#
85
 
    #       titre          #   
86
 
    #----------------------#
87
 
    dtitre = p.new_display(3, 75)
88
 
    dtitre.paste_virtual_display(2,2)
89
 
    dtitre.put_chars(" Application",2,30)
90
 
    
91
 
    #----------------------#
92
 
    #   menu dynamique     #
93
 
    #----------------------#
94
 
    table = [ '-------------------- ',
95
 
              'Open file', 'copy virtual display', 'Move Virtual display',
96
 
              'draw line','insert chars', 'change pbd charac',
97
 
              'move text','put status line', 'change virtual display',
98
 
              'put help text','insert/delete line', 'execute commande',
99
 
              'read keystroke','Control','-------------------- ',
100
 
              'Quitter']
101
 

	
102
 
    dmenu = p.new_display(39, 22)
103
 
    dmenu.paste_virtual_display(8,2)
104
 
    dmenu.create_menu(table)
105
 
    s = dmenu.select_from_menu(k)
106
 
    dmenu.delete_menu()
107
 
    dmenu.create_menu(table)
108
 

	
109
 
    #----------------------#
110
 
    #     open_fille       #
111
 
    #----------------------#
112
 
    if s[0] == 1:
113
 
        d2 = p.new_display(39, 50)
114
 
        d2.paste_virtual_display(8,27)
115
 
        d2.label_border(table[1],None,None,SMG_M_BOLD)
116
 
        d2.set_cursor_abs(3,2)
117
 
        resultat = k.read_string(prompt_string="Saisir un fichier>",
118
 
                                 display=d2)[0]
119
 
        d2.put_chars("Vous avez saisie :",7,2)
120
 
        d2.put_chars(resultat, 7, 20)
121
 

	
122
 
        file = open(resultat,'r')
123
 
        lines  = file.readlines()
124
 
        line=2
125
 
        for i in lines:
126
 
            if line > d2.get_display_attr()[0]: break
127
 
            d2.put_chars(i, line, 1)
128
 
            line = line + 1
129
 

	
130
 
        d2.set_cursor_abs(line-1,1)
131
 
        time.sleep(4)
132
 
#        resultat = k.read_string(display=d2)
133
 
        file.close()
134
 
        del d2
135
 

	
136
 
    #----------------------#
137
 
    # copy_virtual_display #
138
 
    #----------------------#
139
 
    elif s[0] == 2:
140
 
        d = p.new_display(18, 23)
141
 
        d.paste_virtual_display(8,27)
142
 
        d.put_chars(" virtual_display ",7,2)
143
 
        d.label_border(table[2],None,None,SMG_M_BOLD)
144
 
        d1 = d.copy_virtual_display()
145
 
        d2 = d.copy_virtual_display()
146
 
        d3 = d.copy_virtual_display()
147
 
        time.sleep(2)
148
 
        d1.paste_virtual_display( 8, 54)
149
 
        time.sleep(2)
150
 
        d2.paste_virtual_display( 29, 27)
151
 
        time.sleep(2)
152
 
        d3.paste_virtual_display( 29, 54)
153
 
        time.sleep(2)
154
 
        del d
155
 
        time.sleep(2)
156
 
        del d1
157
 
        time.sleep(2)
158
 
        del d2
159
 
        time.sleep(2)
160
 
        del d3
161
 
    #------------------------------#
162
 
    #    Move Virtual display      #
163
 
    #------------------------------#
164
 
    elif s[0] == 3:
165
 
        d = p.new_display(18, 23)
166
 
        d.paste_virtual_display(8,27)
167
 
        d.put_chars(" tour de manege !! ",5,5)
168
 
        d.label_border(table[3],rendition_set=SMG_M_BOLD)
169
 
        time.sleep(1)
170
 

	
171
 
        for i in range(27):
172
 
            d.move_virtual_display(8,27+i,p)
173
 
            time.sleep(0.1)
174
 
        for i in range(21):
175
 
            d.move_virtual_display(8+i,54,p)
176
 
            time.sleep(0.1)
177
 
        for i in range(27):
178
 
            d.move_virtual_display(30,54-i, p)
179
 
            time.sleep(0.1)
180
 
        for i in range(21):
181
 
            d.move_virtual_display(30-i,27, p)
182
 
            time.sleep(0.1)
183
 

	
184
 
        time.sleep(1)
185
 
        del d
186
 

	
187
 

	
188
 
    #------------------------------#
189
 
    #         draw line            #
190
 
    #------------------------------#
191
 
    elif s[0] == 4:
192
 

	
193
 
        d = p.new_display(39, 50)
194
 
        d.paste_virtual_display(8,27)
195
 
        d.put_chars(" Courbe!! ",6,18)
196
 
        d.label_border(table[4],None,None,SMG_M_BOLD)
197
 

	
198
 
        d.draw_line (20, 6, 20, 44)
199
 
        d.draw_line (13, 25, 27, 25)
200
 

	
201
 
        for i in range(6):
202
 
            d.draw_line (20-i, 6+i, 20-i, 6+i)
203
 
        for i in range(12):
204
 
            d.draw_line (15+i, 13+i, 15+i, 13+i)
205
 
        for i in range(12):
206
 
            d.draw_line (26-i, 26+i, 26-i, 26+i)
207
 
        for i in range(6):
208
 
            d.draw_line (15+i, 39+i, 15+i, 39+i)
209
 

	
210
 
        time.sleep(5)
211
 
        del d
212
 

	
213
 
    #------------------------------#
214
 
    #        insert chars          #
215
 
    #------------------------------#
216
 
    elif s[0] == 5:
217
 
        d = p.new_display (20, 50)
218
 
        d.paste_virtual_display (8, 27)
219
 
        d.label_border (table[5],None,None,SMG_M_BOLD)
220
 
        d.put_chars(" Des voitures, des freins uses, une route",3,1)
221
 
        time.sleep (1)
222
 
        cur_disp = p.find_cursor_display(6, 6)
223
 
        cur_disp = None
224
 
        time.sleep (1)
225
 
        d.erase_chars (8, 3, 6)
226
 
        time.sleep (1)
227
 
        d.insert_chars("  ", 3 ,6)
228
 
        d.put_chars("etincelles",3,6)
229
 
        time.sleep (3)
230
 
        d.insert_chars("petites ", 3 ,6)
231
 
        time.sleep(3)
232
 
        del d
233
 

	
234
 
    #------------------------------#
235
 
    # change_pbd_characteristics   #
236
 
    #------------------------------#
237
 
    elif s[0] == 6:
238
 
        st = p.change_pbd_characteristics()
239
 
        if st[2] == 1:
240
 
            p.change_pbd_characteristics (None, None, SMG_C_COLOR_BLACK)
241
 
        else:
242
 
            p.change_pbd_characteristics (None, None, SMG_C_COLOR_WHITE)
243
 

	
244
 
    #------------------------------#
245
 
    #          move_text           #
246
 
    #------------------------------#
247
 
    elif s[0] == 7:
248
 
        d = p.new_display (18, 50)
249
 
        d.paste_virtual_display (8, 27)
250
 
        d.label_border (" display 1 ",None,None,SMG_M_BOLD)
251
 
        d1 = p.new_display (18, 50)
252
 
        d1.paste_virtual_display (29, 27)
253
 
        d1.label_border (" display 2 ",None,None,SMG_M_BOLD)
254
 
        d.put_chars(" Des etincelles, des freins uses, une route",1,1)
255
 
        time.sleep (1)
256
 
        d.move_text (1, 1, 5, 15, d1)
257
 
        d.put_chars(" Des etincelles",1,1)
258
 
        time.sleep (3)
259
 
        del d, d1
260
 
    #------------------------------#
261
 
    #      put_status_line         #
262
 
    #------------------------------#
263
 
    elif s[0] == 8:
264
 
        d = p.new_display(10, 50)
265
 
        d.paste_virtual_display(8, 27)
266
 
        d.label_border(" put_status_line ", None, None, SMG_M_BOLD)
267
 
        d.set_cursor_abs(3,2)
268
 
        resultat = k.read_string("Saisir>", display=d)[0]
269
 
        p.put_status_line(resultat)
270
 
        del d
271
 
    #------------------------------#
272
 
    #   change_virtual_display     #
273
 
    #------------------------------#
274
 
    elif s[0] == 9:
275
 
        d = p.new_display (10, 25)
276
 
        d.paste_virtual_display (8, 27)
277
 
        d.put_chars(" bouhhh !!!! ",5,5)
278
 
        time.sleep (1)
279
 
        d.paste_virtual_display (30, 30)
280
 
        d.change_virtual_display (30, 30)
281
 
        time.sleep (1)
282
 
        d.paste_virtual_display (10, 40)
283
 
        d.change_virtual_display (10, 40)
284
 
        time.sleep (1)
285
 
        d.paste_virtual_display (25, 29)
286
 
        d.change_virtual_display (25, 29)
287
 
        time.sleep (3)
288
 
        del d
289
 
    #------------------------------#
290
 
    #        put_help_text         #
291
 
    #------------------------------#
292
 
    elif s[0] == 10:
293
 
        d = p.new_display (40, 50)
294
 
        d.paste_virtual_display (8, 27)
295
 
        d.put_help_text(k,None,None,SMG_M_BOLD)
296
 
        del d
297
 
    #------------------------------#
298
 
    #    insert/delete line        #
299
 
    #------------------------------#
300
 
    elif s[0] == 11:
301
 
        d = p.new_display(40, 50)
302
 
        d.paste_virtual_display(8, 27)
303
 
        d.label_border (" insert/delete line ", None, None, SMG_M_BOLD)
304
 
        d.put_chars(" 1 phrase  comme une autre ",6,1)
305
 
        d.put_chars(" 2 phrases comme une autre ",7,1)
306
 
        d.put_chars(" 4 phrases comme une autre ",8,1)
307
 
        d.put_chars(" 6 phrases comme une autre ",9,1)
308
 
        d.put_chars(" 7 phrases comme une autre ",10,1)
309
 
        time.sleep (2)
310
 
        d.insert_line (7," 3 phrases comme une autre ")
311
 
        time.sleep (2)
312
 
        d.insert_line (8," 5 phrases comme une autre ")
313
 
        time.sleep (3)
314
 
        p.repaint_line(2,4)
315
 
        time.sleep (3)
316
 
        inser = 1
317
 
        while (inser == 1):
318
 
            d.set_cursor_abs(20,1)
319
 
            resultat_inser = k.read_string(
320
 
                "Insert a new line (y/n)? ", display=d)[0]
321
 
            d.delete_line(20)
322
 
            if resultat_inser in ('y', 'Y'):
323
 
                d.set_cursor_abs(20, 1)
324
 
                resultat_inser = k.read_string("line number: ", display=d)[0]
325
 
                d.delete_line(20)
326
 
                resultati_inser = atoi(resultat_inser)
327
 
                d.set_cursor_abs(20, 1)
328
 
                inser_chaine = k.read_string("text>", display=d)[0]
329
 
                d.insert_line(resultati_inser, inser_chaine)
330
 
                d.delete_line(20)
331
 
            else :
332
 
                inser =0
333
 
        supp = 1
334
 
        while supp == 1:
335
 
            d.set_cursor_abs(20,1)
336
 
            resultat = k.read_string(
337
 
                "Delete a line (y/n)? ", display=d)[0]
338
 
            d.delete_line(20)
339
 
            if resultat in ('y', 'Y'):
340
 
                d.set_cursor_abs(20, 1)
341
 
                resultat = k.read_string("line number: ", display=d)[0]
342
 
                d.delete_line(20)
343
 
                resultati = atoi(resultat)
344
 
                d.delete_line(resultati)
345
 
            else :
346
 
                supp =0
347
 
        time.sleep(1)
348
 
        del d
349
 
    #------------------------------#
350
 
    #       execute command        #
351
 
    #------------------------------#
352
 
    elif s[0] == 12:
353
 
        d = p.new_display (40, 50)
354
 
        d.paste_virtual_display (8, 27)
355
 
        d.label_border (" execute_command ", None, None, SMG_M_BOLD)
356
 
        d.create_subprocess()
357
 
        command = "ok"
358
 
        d.put_chars(" Enter quit to exit", 1, 1)
359
 
        d.set_cursor_abs(2,1)
360
 
        while command != "quit":
361
 
            command = k.read_string("$", display=d)[0]
362
 
            d.execute_command(command, SMG_M_DATA_FOLLOWS)
363
 
        #time.sleep(5)
364
 
        d.delete_subprocess()
365
 
        del d
366
 
    #------------------------------#
367
 
    #        read_keystroke        #
368
 
    #------------------------------#
369
 
    elif s[0] == 13:
370
 
        d = p.new_display (40, 50)
371
 
        d.paste_virtual_display (8, 27)
372
 
        d.label_border (" read_keystroke ", rendition_set=SMG_M_BOLD)
373
 
        d.set_cursor_abs(2,2)
374
 
        key = k.read_keystroke("read_keystroke", display=d,
375
 
                             rendition_set=SMG_M_BOLD)
376
 
        print key
377
 
        time.sleep(3)
378
 
        del d
379
 
    #------------------------------#
380
 
    #           control            #
381
 
    #------------------------------#
382
 
    elif s[0] == 14:
383
 
        d = p.new_display (40, 50)
384
 
        d.paste_virtual_display (8, 27)
385
 
        c.get_integer('Entrer un nombre: ')
386
 
        time.sleep (2)
387
 
        c.get_string('Entrer une chaine: ')
388
 
        time.sleep (2)
389
 
        c.get_email('Entrer un email: ')
390
 
        time.sleep (2)
391
 
	del d
392
 
#------------------------------#
393
 
# delete Pasteboard + Keyboard #
394
 
#------------------------------#
395
 
if s[0] == 16:
396
 
    del dtitre
397
 
    del dmenu
398
 
    del k
399
 
    del p
0 comments (0 inline, 0 general)