-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.tk
More file actions
executable file
·164 lines (116 loc) · 4.12 KB
/
app.tk
File metadata and controls
executable file
·164 lines (116 loc) · 4.12 KB
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
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" "$@"
#### INITIALISATION DES VARIABLES GLOBALES ###########################
set var_ident "local"
set var_message_recu "-"
set var_message_envoye "-"
set var_mode_auto false
set var_fonte_bouton -misc-*-*-r-*-*-14-*-*-*-*-*-*-*
#### DECODAGE DES ARGUMENTS ##########################################
set var_chaine_args [join $argv]
set var_liste_args [split $var_chaine_args " "]
set i 0
set var_option [lindex $var_liste_args $i]
while { $var_option != "" } {
set var_option_value [split $var_option '=' ]
if { [lindex $var_option_value 0] == "--ident" } {
set var_ident [lindex $var_option_value 1]
}
# Ajouter ici d'autres options
incr i
set var_option [lindex $var_liste_args $i]
}
#### DEFINITION DES ZONES DE L'INTERFACE #############################
wm title . $var_ident
#### zone pour l'emission
labelframe .out -pady 2 -padx 2 -text "Message ˆ envoyer"
entry .out.msg -width 24 -textvariable var_message_envoye
pack .out.msg -side left -fill y -pady 2
#### zone pour la reception
labelframe .in -pady 2 -padx 2 -text "Message reu"
label .in.msg -textvariable var_message_recu -width 32
pack .in.msg -side left -fill y -pady 2
#### zone des boutons
frame .bt
button .bt.quit -text "Quitter" \
-activebackground red \
-foreground red \
-font $var_fonte_bouton \
-width 10 \
-command { exit }
button .bt.snd -text "Envoyer" \
-activebackground SeaGreen4 \
-foreground SeaGreen4 \
-font $var_fonte_bouton \
-width 10 \
-command { proc_emission_message }
button .bt.auto -text "Mode auto" \
-activebackground SeaGreen4 \
-foreground SeaGreen4 \
-font $var_fonte_bouton \
-width 8 \
-command proc_aut_btdebut
pack .bt.quit .bt.snd .bt.auto -side right
### zone du timer
labelframe .aut -pady 2 -padx 2 -text "Emission pŽriodique \[Žtat : dŽsactivŽ\]"
label .aut.lfrq -text "frŽquence (ms) :"
spinbox .aut.sfrq -values "500 800 1000 2000 3000 5000 10000" -width 6 \
-textvariable var_aut_frq
pack .aut.lfrq .aut.sfrq -side left -padx 2
#### affichage des zones horizontales
pack .bt .in .out .aut -fill both -expand yes -side top -pady 5
#### LECTURES ASYNCHRONES ############################################
# lectures asynchrones non bloquantes et appel de la procedure
# proc_reception_message en cas de reception
fileevent stdin readable proc_reception_message
fconfigure stdin -blocking off
#### PROCEDURES ######################################################
# procedure appelee en cas de reception sur l'entree standard
proc proc_reception_message { } {
# recuperation d'une variable de portee globale
global var_message_recu
# Fin d'interruption sur reception
fileevent stdin readable ""
# Lecture de l'entree standard
set var_message_recu [gets stdin]
# Traitement --
# ici : mise a jour de l'affichage
#.in.msg configure -text $var_message_recu -width 32 update
# Reprise des interruptions sur reception
fileevent stdin readable proc_reception_message
}
# procedure appelee en cas de click sur le bouton envoyer
proc proc_emission_message { } {
# recuperation d'une variable de portee globale
global var_message_envoye
# ecriture sur la sortie standard
puts stdout $var_message_envoye
}
# procedure appelee en cas de click sur le bouton auto
proc proc_aut_btdebut { } {
global var_mode_auto .aut
if { $var_mode_auto } {
# passage de "emission en cours" a "aucune emission"
# arret des emissions programmees
after cancel proc_aut_emission
# remise a l'etat initial des affichages
.aut configure -text "Mode automatique \[Žtat : dŽsactivŽ]"
.bt.auto configure -text "Mode auto"
set var_mode_auto false
} else {
# passage de "aucune emission" a "emission en cours"
# mise a jour des affichages
.aut configure -text "Mode automatique \[Žtat : activŽ\]"
.bt.auto configure -text "Fin auto"
set var_mode_auto true
proc_aut_emission
}
}
# Procedure realisant les emissions automatiques
proc proc_aut_emission { } {
global var_aut_frq
proc_emission_message
# programmation de la prochaine emission
after $var_aut_frq proc_aut_emission
}