compilator 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14278249ee5b9a507d40073db9b7a92b392b38fd
4
- data.tar.gz: 676b006a453d8cb101da7ab58c596823cc28b321
3
+ metadata.gz: c1eee5eae5f10d32df205126d3370343e7b6bb45
4
+ data.tar.gz: 6b1e6e076a90fcab32ba1b6c43fa69014a4f944f
5
5
  SHA512:
6
- metadata.gz: fa1cb7b4ab01c0bac652df2e059e108d65cdfcb692b205177c3145064876b1ddb3b071ec9f15a90d56dc5045ccb0ef87255bfee5b538df574ba77cd3094426ec
7
- data.tar.gz: 578770a4cd912fabed36009c70d38d878767801dce89841c4cdef7dc744727a240061996eba4a51d3a7dd108c9fcdada125ee41f9fb524525db9e9e3ff5e1f69
6
+ metadata.gz: 876863003618cc44fbb63f3e0e6a9523ce43cb53f954547a07aea0a04158bb1d344f508287ab49d97fbc63b586202f9ddbb29ab62293641f7440cc6a606b8c64
7
+ data.tar.gz: 32a8a8b8acc46acc0d50371e9b85b90144c16bb0dbc16305141ac150f378dbf1cfd1a95bb321155666646f74bc7d082b81875db4dfca5408f0cda22befa5c253
@@ -19,28 +19,44 @@ module Compilator
19
19
  end
20
20
 
21
21
  def notify_action(view,action,kwargs={})
22
-
23
- if action == :key_pressed || action == :button_pressed
24
- @model.last_key_pressed = kwargs[:key]
25
-
26
- elsif action == :key_enter_pressed
27
- notify_action(view,:button_equal_pressed,kwargs)
22
+ if kwargs[:location] == @model.calculatrice
23
+
24
+ if action == :key_pressed || action == :button_pressed
25
+ @model.last_key_pressed = kwargs[:key]
28
26
 
29
- elsif action == :key_delete_pressed
30
- @model.delete = true
31
-
32
- elsif action == :button_equal_pressed
33
- numerateur = 0
34
- kwargs[:value].each_char do |c|
35
- numerateur = numerateur+model.score[c]
27
+ elsif action == :key_enter_pressed
28
+ notify_action(view,:button_equal_pressed,kwargs)
29
+
30
+ elsif action == :key_delete_pressed
31
+ @model.delete = true
32
+
33
+ elsif action == :button_equal_pressed
34
+ numerateur = 0
35
+ kwargs[:value].each_char do |c|
36
+ numerateur = numerateur+model.score[c]
37
+ end
38
+ denominateur = kwargs[:value].size*5
39
+ @model.result = numerateur.to_s+"/"+denominateur.to_s+" => "+(numerateur*20.to_f/denominateur).round(2).to_s+"/20"
40
+
41
+ elsif action == :button_raz_pressed
42
+ @model.raz = true
36
43
  end
37
- denominateur = kwargs[:value].size*5
38
- @model.result = numerateur.to_s+"/"+denominateur.to_s+" => "+(numerateur*20.to_f/denominateur).round(2).to_s+"/20"
39
44
 
40
- elsif action == :button_raz_pressed
41
- @model.raz = true
45
+ elsif kwargs[:location] == @model.total
46
+ if action == :button_calcul_pressed
47
+ num = kwargs['a'].to_i+kwargs['c'].to_i+kwargs['e'].to_i+kwargs['g'].to_i+kwargs['i'].to_i
48
+ denom = kwargs['b'].to_i+kwargs['d'].to_i+kwargs['f'].to_i+kwargs['h'].to_i+kwargs['j'].to_i
49
+ @model.result_total = num.to_s+"/"+denom.to_s
50
+ @model.result_arrondi = (num*20.to_f/denom).round(2).to_s+'/20'
42
51
 
43
- elsif action == :close_window
52
+ elsif action == :key_enter_pressed
53
+ notify_action(view,:button_calcul_pressed,kwargs)
54
+
55
+ elsif action == :button_raz_pressed
56
+ @model.raz_total = true
57
+ end
58
+ end
59
+ if action == :close_window
44
60
  view.close
45
61
  end
46
62
  end
@@ -48,7 +64,7 @@ module Compilator
48
64
 
49
65
  class CompilatorModel < Druzy::MVC::Model
50
66
 
51
- attr_accessor :score, :last_key_pressed, :result, :delete
67
+ attr_accessor :score, :last_key_pressed, :result, :delete, :calculatrice, :total
52
68
 
53
69
 
54
70
  def initialize
@@ -58,6 +74,9 @@ module Compilator
58
74
  @result = nil
59
75
  @raz = false
60
76
  @delete = false
77
+ @result_total = nil
78
+ @result_arrondi = nil
79
+ @raz_total
61
80
  end
62
81
 
63
82
  def last_key_pressed=(last_key_pressed)
@@ -79,6 +98,21 @@ module Compilator
79
98
  old, @delete = @delete, delete
80
99
  fire_property_change(Druzy::MVC::PropertyChangeEvent.new(self,'delete',old,@delete))
81
100
  end
101
+
102
+ def result_total=(result_total)
103
+ old, @result_total = @result_total, result_total
104
+ fire_property_change(Druzy::MVC::PropertyChangeEvent.new(self,'result_total',old,@result_total))
105
+ end
106
+
107
+ def result_arrondi=(result_arrondi)
108
+ old, @result_arrondi = @result_arrondi, result_arrondi
109
+ fire_property_change(Druzy::MVC::PropertyChangeEvent.new(self,'result_arrondi',old,@result_arrondi))
110
+ end
111
+
112
+ def raz_total=(raz_total)
113
+ old, @raz_total = @raz_total, raz_total
114
+ fire_property_change(Druzy::MVC::PropertyChangeEvent.new(self,'raz_total',old,@raz_total))
115
+ end
82
116
  end
83
117
 
84
118
  class CompilatorView < Druzy::MVC::View
@@ -92,33 +126,38 @@ module Compilator
92
126
  val = event.valid_fields['keysym'].downcase
93
127
  if val == 'return'
94
128
  Thread.new do
95
- @controller.notify_action(self, :key_enter_pressed, :value => @entry_variable.value)
129
+ @controller.notify_action(self, :key_enter_pressed, {:value => @entry_variable.value, :location => @notebook.selected}.merge(Hash[('a'..'j').collect{|el| [el,instance_variable_get("@entry_variable_"+el)]}]))
96
130
  end
97
131
 
98
132
  elsif val == 'escape'
99
133
  Thread.new do
100
- @controller.notify_action(self, :button_raz_pressed)
134
+ @controller.notify_action(self, :button_raz_pressed, :location => @notebook.selected)
101
135
  end
102
136
 
103
137
  elsif val == 'delete'
104
138
  Thread.new do
105
- @controller.notify_action(self, :key_delete_pressed)
139
+ @controller.notify_action(self, :key_delete_pressed, :location => @notebook.selected)
106
140
  end
107
141
 
108
142
  elsif @controller.model.score.has_key?(val)
109
143
  Thread.new do
110
- @controller.notify_action(self,:key_pressed, :key => val)
144
+ @controller.notify_action(self,:key_pressed, :key => val, :location => @notebook.selected)
111
145
  end
112
146
  end
113
147
 
114
148
  end
149
+
150
+ @notebook = Tk::Tile::Notebook.new(@root) do
151
+ place('x' => 0, 'y' => 0)
152
+ end
115
153
 
116
- @window = Tk::Tile::Frame.new(@root)
154
+ @window_calc = Tk::Tile::Frame.new(@notebook)
155
+ @controller.model.calculatrice = @window_calc
117
156
 
118
157
  @font_button = TkFont.new("size" => 24)
119
158
 
120
159
  @entry_variable = TkVariable.new
121
- @entry = Tk::Tile::Entry.new(@window)
160
+ @entry = Tk::Tile::Entry.new(@window_calc)
122
161
  @entry.justify = 'right'
123
162
  @entry.validate = 'key'
124
163
  @entry.textvariable = @entry_variable
@@ -126,74 +165,39 @@ module Compilator
126
165
  false
127
166
  end
128
167
 
129
- @button_r = Tk::Tile::Button.new(@window)
130
- @button_r['text'] = 'R'
131
- Tk::Tile::Style.configure('Red.TButton', {"foreground" => 'red', 'font' => @font_button})
132
- @button_r['style'] = 'Red.TButton'
133
- @button_r['width'] = 1
134
- @button_r.bind('ButtonPress') do
135
- Thread.new do
136
- @controller.notify_action(self,:button_pressed, :key => 'r')
168
+ @controller.model.score.keys.each do |key|
169
+ var_name = "@button_"+key
170
+ instance_variable_set(var_name.to_sym,Tk::Tile::Button.new(@window_calc))
171
+ button = instance_variable_get(var_name.to_sym)
172
+ button['text'] = key.upcase
173
+ button['width'] = 1
174
+ button.bind('ButtonPress') do
175
+ Thread.new do
176
+ @controller.notify_action(self,:button_pressed, :key => key, :location => @notebook.selected)
177
+ end
137
178
  end
138
179
  end
139
180
 
140
- @button_o = Tk::Tile::Button.new(@window)
141
- @button_o['text'] = 'O'
181
+ Tk::Tile::Style.configure('Red.TButton', {"foreground" => 'red', 'font' => @font_button})
182
+ @button_r['style'] = 'Red.TButton'
183
+
142
184
  Tk::Tile::Style.configure('Orange.TButton', {"foreground" => 'orange', 'font' => @font_button})
143
185
  @button_o['style'] = 'Orange.TButton'
144
- @button_o['width'] = 1
145
- @button_o.bind('ButtonPress') do
146
- Thread.new do
147
- @controller.notify_action(self,:button_pressed, :key => 'o')
148
- end
149
- end
150
186
 
151
- @button_j = Tk::Tile::Button.new(@window)
152
- @button_j['text'] = 'J'
153
- @button_j['width'] = 1
154
187
  Tk::Tile::Style.configure('Yellow.TButton', {"foreground" => 'yellow', 'font' => @font_button})
155
188
  @button_j['style'] = 'Yellow.TButton'
156
- @button_j.bind('ButtonPress') do
157
- Thread.new do
158
- @controller.notify_action(self,:button_pressed, :key => 'j')
159
- end
160
- end
161
189
 
162
- @button_c = Tk::Tile::Button.new(@window)
163
- @button_c['text'] = 'C'
164
- @button_c['width'] = 1
165
190
  Tk::Tile::Style.configure('Lime.TButton', {"foreground" => 'lime green', 'font' => @font_button})
166
191
  @button_c['style'] = 'Lime.TButton'
167
- @button_c.bind('ButtonPress') do
168
- Thread.new do
169
- @controller.notify_action(self,:button_pressed, :key => 'c')
170
- end
171
- end
172
192
 
173
- @button_v = Tk::Tile::Button.new(@window)
174
- @button_v['text'] = 'V'
175
- @button_v['width'] = 1
176
193
  Tk::Tile::Style.configure('Green.TButton', {"foreground" => 'green', 'font' => @font_button})
177
194
  @button_v['style'] = 'Green.TButton'
178
- @button_v.bind('ButtonPress') do
179
- Thread.new do
180
- @controller.notify_action(self,:button_pressed, :key => 'v')
181
- end
182
- end
183
195
 
184
- @button_e = Tk::Tile::Button.new(@window)
185
- @button_e['text'] = 'E'
186
196
  @button_e['underline'] = 0
187
- @button_e['width'] = 1
188
197
  Tk::Tile::Style.configure('Underline.TButton', {"foreground" => 'green', 'font' => @font_button})
189
198
  @button_e['style'] = 'Underline.TButton'
190
- @button_e.bind('ButtonPress') do
191
- Thread.new do
192
- @controller.notify_action(self,:button_pressed, :key => 'e')
193
- end
194
- end
195
199
 
196
- @button_raz = Tk::Tile::Button.new(@window)
200
+ @button_raz = Tk::Tile::Button.new(@window_calc)
197
201
  @button_raz['text'] = 'RàZ'
198
202
  @button_raz['width'] = 1
199
203
  Tk::Tile::Style.configure('Medium.TButton', {'font' => TkFont.new('size' => 12)})
@@ -204,7 +208,7 @@ module Compilator
204
208
  end
205
209
  end
206
210
 
207
- @button_equal = Tk::Tile::Button.new(@window)
211
+ @button_equal = Tk::Tile::Button.new(@window_calc)
208
212
  @button_equal['text'] = '='
209
213
  Tk::Tile::Style.configure('Big.TButton', {'font' => TkFont.new('size' => 24)})
210
214
  @button_equal['style'] = 'Big.TButton'
@@ -215,29 +219,125 @@ module Compilator
215
219
  end
216
220
  end
217
221
 
218
- @label_result = Tk::Tile::Label.new(@window)
222
+ @label_result = Tk::Tile::Label.new(@window_calc)
219
223
  @label_result.justify = 'right'
220
- Tk::Tile::Style.configure('Big.TLabel',{'font' => TkFont.new('size' => 12)})
224
+ Tk::Tile::Style.configure('Big.TLabel',{'font' => TkFont.new('size' => 14)})
221
225
  @label_result['style'] = 'Big.TLabel'
226
+
227
+ #onglet total
228
+
229
+ @window_total = Tk::Tile::Frame.new(@notebook)
230
+ @controller.model.total = @window_total
231
+
232
+ @paned_fraction = Tk::Tile::Paned.new(@window_total)
233
+
234
+ {'co' => ['a','b'], 'ce' => ['c','d'], 'ee' => ['e','f'], 'eoc' => ['g','h'], 'eoi'=> ['i','j']}.each do |key,value|
235
+ label_name = "@label_frame_"+key
236
+ instance_variable_set(label_name.to_sym,Tk::Tile::Labelframe.new(@paned_fraction))
237
+ label_frame = instance_variable_get(label_name.to_sym)
238
+ label_frame['text'] = key.upcase
239
+
240
+ value.each do |val|
241
+ entry_name = "@entry_"+val
242
+ entry_variable_name = "@entry_variable_"+val
243
+ instance_variable_set(entry_name.to_sym,Tk::Tile::Entry.new(label_frame))
244
+ instance_variable_set(entry_variable_name.to_sym,TkVariable.new)
245
+ entry = instance_variable_get(entry_name.to_sym)
246
+ entry_variable = instance_variable_get(entry_variable_name.to_sym)
247
+
248
+ entry.width = 3
249
+ entry.textvariable = entry_variable
250
+ entry.validate = 'key'
251
+ entry.validatecommand do |valid|
252
+ if (0..9).map{|el| el.to_s}.include?(valid.string)
253
+ true
254
+ else
255
+ false
256
+ end
257
+ end
258
+ end
259
+
260
+ end
261
+
262
+ @paned_result = Tk::Tile::Paned.new(@window_total)
263
+
264
+ @label_frame_brut = Tk::Tile::Labelframe.new(@paned_result)
265
+ @label_frame_brut['text'] = 'Résultat brut'
222
266
 
267
+ @label_result_brut = Tk::Tile::Label.new(@label_frame_brut)
268
+ @label_result_brut['text'] = '0'
269
+ @label_result_brut.justify = 'right'
270
+
271
+ @label_frame_arrondi = Tk::Tile::Labelframe.new(@paned_result)
272
+ @label_frame_arrondi['text'] = "Résultat arrondi au centième"
273
+
274
+ @label_result_arrondi = Tk::Tile::Label.new(@label_frame_arrondi)
275
+ @label_result_arrondi['text'] = '0'
276
+ @label_result_arrondi.justify = 'right'
277
+
278
+ @paned_button = Tk::Tile::Paned.new(@window_total)
223
279
 
280
+ for n in (0..9)
281
+ var_name = "@button_"+n.to_s
282
+ instance_variable_set(var_name.to_sym,Tk::Tile::Button.new(@paned_button))
283
+ button = instance_variable_get(var_name.to_sym)
284
+ button['text'] = n.to_s
285
+ button['style'] = 'Big.TButton'
286
+ button['width'] = 1
287
+ end
288
+
289
+ @button_raz_total = Tk::Tile::Button.new(@paned_button)
290
+ @button_raz_total['text'] = 'RàZ'
291
+ @button_raz_total.bind('ButtonPress') do
292
+ puts "rrrr"
293
+ Thread.new do
294
+ @controller.notify_action(self,:button_raz_pressed, :location => @notebook.selected)
295
+ end
296
+ end
297
+
298
+ @button_del = Tk::Tile::Button.new(@paned_button)
299
+ @button_del['text'] = 'Del/Suppr'
300
+
301
+ @button_calcul = Tk::Tile::Button.new(@paned_button)
302
+ @button_calcul['text'] = 'Calculer'
303
+ @button_calcul.bind('ButtonPress') do
304
+ Thread.new do
305
+ @controller.notify_action(self,:button_calcul_pressed, {:location => @notebook.selected}.merge(Hash[('a'..'j').collect{|el| [el,instance_variable_get("@entry_variable_"+el)]}]))
306
+ end
307
+ end
224
308
  #ajout
309
+
225
310
  TkGrid.columnconfigure( @root, 0, :weight => 1 )
226
311
  TkGrid.rowconfigure( @root, 0, :weight => 1 )
227
312
 
228
- TkGrid.columnconfigure( @window, 0, :weight => 1)
229
- TkGrid.columnconfigure( @window, 1, :weight => 1 )
230
- TkGrid.columnconfigure( @window, 2, :weight => 1 )
231
- TkGrid.rowconfigure( @window, 0, :weight => 0)
232
- TkGrid.rowconfigure( @window, 1, :weight => 1)
233
- TkGrid.rowconfigure( @window, 2, :weight => 1)
234
- TkGrid.rowconfigure( @window, 3, :weight => 1)
235
- TkGrid.rowconfigure( @window, 4, :weight => 0)
313
+ TkGrid.columnconfigure( @window_calc, 0, :weight => 1)
314
+ TkGrid.columnconfigure( @window_calc, 1, :weight => 1 )
315
+ TkGrid.columnconfigure( @window_calc, 2, :weight => 1 )
316
+ TkGrid.rowconfigure( @window_calc, 0, :weight => 0)
317
+ TkGrid.rowconfigure( @window_calc, 1, :weight => 1)
318
+ TkGrid.rowconfigure( @window_calc, 2, :weight => 1)
319
+ TkGrid.rowconfigure( @window_calc, 3, :weight => 1)
320
+ TkGrid.rowconfigure( @window_calc, 4, :weight => 0)
236
321
 
237
- @window.grid(:column => 0, :row => 0, :sticky => 'nsew')
322
+ TkGrid.columnconfigure(@window_total,0, :weight => 1)
323
+ TkGrid.rowconfigure(@window_total, 0, :weight => 0)
324
+ TkGrid.rowconfigure(@window_total, 1, :weight => 0)
325
+ TkGrid.rowconfigure(@window_total, 2, :weight => 1)
238
326
 
239
- @entry.grid(:column => 0, :row => 0, :columnspan => 3, :sticky => 'new')
327
+ TkGrid.columnconfigure(@paned_fraction, 0, :weight =>1)
328
+ TkGrid.columnconfigure(@paned_fraction, 1, :weight =>1)
329
+ TkGrid.columnconfigure(@paned_fraction, 2, :weight =>1)
330
+ TkGrid.columnconfigure(@paned_fraction, 3, :weight =>1)
331
+ TkGrid.columnconfigure(@paned_fraction, 4, :weight =>1)
332
+
333
+ TkGrid.columnconfigure(@paned_result, 0, :weight =>1)
334
+ TkGrid.columnconfigure(@paned_result, 1, :weight =>1)
335
+
336
+ @notebook.add(@window_calc, :text => 'Calculatrice')
337
+ @notebook.add(@window_total, :text => 'Total')
338
+ @notebook.grid(:column => 0, :row => 0, :sticky => 'nsew')
240
339
 
340
+ @entry.grid(:column => 0, :row => 0, :columnspan => 3, :sticky => 'new')
241
341
 
242
342
  @button_r.grid(:column => 0, :row => 1, :sticky => 'nsew')
243
343
  @button_o.grid(:column => 1, :row => 1, :sticky => 'nsew')
@@ -248,8 +348,49 @@ module Compilator
248
348
  @button_raz.grid(:column => 0, :row => 3, :sticky => 'ewns')
249
349
  @button_equal.grid(:column => 1, :row => 3, :columnspan => 2, :sticky => 'ewns')
250
350
 
351
+
251
352
  @label_result.grid(:column => 0, :row => 4, :columnspan => 3, :sticky => 'ews')
252
353
 
354
+ @paned_fraction.grid(:column => 0, :row => 0, :sticky => 'ew')
355
+
356
+ @label_frame_co.grid(:column => 0, :row => 0)
357
+ @entry_a.grid(:column => 0, :row => 0)
358
+ @entry_b.grid(:column => 0, :row => 1)
359
+
360
+ @label_frame_ce.grid(:column => 1, :row => 0)
361
+ @entry_c.grid(:column => 0, :row => 0)
362
+ @entry_d.grid(:column => 0, :row => 1)
363
+
364
+ @label_frame_ee.grid(:column => 2, :row => 0)
365
+ @entry_e.grid(:column => 0, :row => 0)
366
+ @entry_f.grid(:column => 0, :row => 1)
367
+
368
+ @label_frame_eoc.grid(:column => 3, :row => 0)
369
+ @entry_g.grid(:column => 0, :row => 0)
370
+ @entry_h.grid(:column => 0, :row => 1)
371
+
372
+ @label_frame_eoi.grid(:column => 4, :row => 0)
373
+ @entry_i.grid(:column => 0, :row => 0)
374
+ @entry_j.grid(:column => 0, :row => 1)
375
+
376
+ @paned_result.grid(:column => 0, :row => 1, :sticky => 'ew')
377
+ @label_frame_brut.grid(:column => 0, :row => 0, :sticky => 'ew')
378
+ @label_result_brut.grid(:column => 0, :row => 0, :sticky => 'ew')
379
+
380
+ @label_frame_arrondi.grid(:column => 1, :row => 0, :sticky => 'ew')
381
+ @label_result_arrondi.grid(:column => 0, :row => 0, :sticky => 'ew')
382
+
383
+ @paned_button.grid(:column => 0, :row => 2)
384
+ @button_raz_total.grid(:column => 0, :row => 0)
385
+ @button_del.grid(:column => 0, :row => 1)
386
+ @button_calcul.grid(:column => 0, :row => 2, :columnspan => 6, :sticky => 'ew' )
387
+ for n in (0..4) do
388
+ button1 = instance_variable_get("@button_"+n.to_s)
389
+ button2 = instance_variable_get("@button_"+(n+5).to_s)
390
+ button1.grid(:column => n+1, :row => 0)
391
+ button2.grid(:column => n+1, :row => 1)
392
+ end
393
+
253
394
  end
254
395
 
255
396
  def display
@@ -278,6 +419,25 @@ module Compilator
278
419
  Thread.new do
279
420
  @entry_variable.set_value(@entry_variable.value[0..-2])
280
421
  end
422
+
423
+ elsif event.property_name == 'result_total'
424
+ Thread.new do
425
+ @label_result_brut.text = event.new_value.to_s
426
+ end
427
+
428
+ elsif event.property_name == 'result_arrondi'
429
+ Thread.new do
430
+ @label_result_arrondi.text = event.new_value.to_s
431
+ end
432
+
433
+ elsif event.property_name == 'raz_total'
434
+ puts "coucou"
435
+ Thread.new do
436
+ ('a'..'j').each do |el|
437
+
438
+ instance_variable_get("@entry_variable_"+el).set_value('')
439
+ end
440
+ end
281
441
  end
282
442
  end
283
443
 
@@ -1,3 +1,3 @@
1
1
  module Compilator
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compilator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Le Greneur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-19 00:00:00.000000000 Z
11
+ date: 2016-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: druzy-mvc
@@ -60,7 +60,6 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - lib/compilator.rb
63
- - lib/compilator.rb.old
64
63
  - lib/compilator/version.rb
65
64
  homepage: https://github.com/druzy/compilator
66
65
  licenses:
@@ -1,230 +0,0 @@
1
- require_relative 'compilator/version'
2
-
3
- require 'druzy/mvc'
4
- require 'gtk3'
5
-
6
- module Compilator
7
-
8
- class Compilator < Druzy::MVC::Controller
9
-
10
- def initialize(model = nil)
11
- if model == nil
12
- initialize(CompilatorModel.new)
13
- else
14
- super(model)
15
- add_view(CompilatorView.new(self))
16
- end
17
-
18
- end
19
-
20
- def notify_action(view,action,kwargs={})
21
-
22
- if action == :key_pressed || action == :button_pressed
23
- model.last_key_pressed = kwargs[:key]
24
-
25
- elsif action == :key_enter_pressed
26
- notify_action(view,:button_equal_pressed,kwargs)
27
-
28
- elsif action == :button_equal_pressed
29
- numerateur = 0
30
- kwargs[:value].each_char do |c|
31
- numerateur = numerateur+model.score[c]
32
- end
33
- denominateur = kwargs[:value].size*5
34
- model.result = numerateur.to_s+"/"+denominateur.to_s+" => "+(numerateur*20.to_f/denominateur).round(2).to_s+"/20"
35
-
36
- elsif action == :button_raz_pressed
37
- model.raz = true
38
-
39
- elsif action == :close_window
40
- view.close
41
- end
42
- end
43
- end
44
-
45
- class CompilatorModel < Druzy::MVC::Model
46
-
47
- attr_accessor :score, :last_key_pressed, :result
48
-
49
-
50
- def initialize
51
- super()
52
- @score = {'r' => 0, 'o' => 1, 'j' => 2, 'c' => 3, 'v' => 4, 'e' => 5}
53
- @last_key_pressed = nil
54
- @result = nil
55
- @raz = false
56
- end
57
-
58
- def last_key_pressed=(last_key_pressed)
59
- old, @last_key_pressed = @last_key_pressed, last_key_pressed
60
- fire_property_change(Druzy::MVC::PropertyChangeEvent.new(self,"last_key_pressed",old,@last_key_pressed))
61
- end
62
-
63
- def result=(result)
64
- old, @result = @result, result
65
- fire_property_change(Druzy::MVC::PropertyChangeEvent.new(self,"result",old,@result))
66
- end
67
-
68
- def raz=(raz)
69
- old, @raz = @raz, raz
70
- fire_property_change(Druzy::MVC::PropertyChangeEvent.new(self,"raz",old,@raz))
71
- end
72
- end
73
-
74
- class CompilatorView < Druzy::MVC::View
75
-
76
- def initialize(controller)
77
- super(controller)
78
-
79
- @window = Gtk::Window.new
80
- @window.title = 'COMPILATOR'
81
- @window.signal_connect('key_press_event') do |widget, event|
82
- val = Gdk::Keyval.name(Gdk::Keyval.to_lower(event.keyval))
83
-
84
- if controller.model.score.has_key?(val)
85
- Thread.new do
86
- controller.notify_action(self,:key_pressed, :key => val)
87
- end
88
-
89
- elsif event.keyval == Gdk::Keyval::KEY_Return
90
- Thread.new do
91
- controller.notify_action(self, :key_enter_pressed, :value => @entry.text)
92
- end
93
- end
94
- end
95
- @window.signal_connect('delete-event') do
96
- Thread.new do
97
- controller.notify_action(self,:close_window)
98
- end
99
- end
100
-
101
- @entry = Gtk::Entry.new
102
- @entry.editable = false
103
- @entry.xalign = 1
104
-
105
- @button_r = Gtk::Button.new
106
- @button_r.add(Gtk::Label.new.set_markup('<span size="xx-large" foreground="red">R</span>'))
107
- @button_r.signal_connect("clicked") do
108
- Thread.new do
109
- controller.notify_action(self,:button_pressed, :key => 'r')
110
- end
111
- end
112
-
113
- @button_o = Gtk::Button.new
114
- @button_o.add(Gtk::Label.new.set_markup('<span size="xx-large" foreground="orange">O</span>'))
115
- @button_o.signal_connect("clicked") do
116
- Thread.new do
117
- controller.notify_action(self,:button_pressed, :key => 'o')
118
- end
119
- end
120
-
121
- @button_j = Gtk::Button.new
122
- @button_j.add(Gtk::Label.new.set_markup('<span size="xx-large" foreground="yellow">J</span>'))
123
- @button_j.signal_connect("clicked") do
124
- Thread.new do
125
- controller.notify_action(self,:button_pressed, :key => 'j')
126
- end
127
- end
128
-
129
- @button_c = Gtk::Button.new
130
- @button_c.add(Gtk::Label.new.set_markup('<span size="xx-large" foreground="lime">C</span>'))
131
- @button_c.signal_connect("clicked") do
132
- Thread.new do
133
- controller.notify_action(self,:button_pressed, :key => 'c')
134
- end
135
- end
136
-
137
- @button_v = Gtk::Button.new
138
- @button_v.add(Gtk::Label.new.set_markup('<span size="xx-large" foreground="green">V</span>'))
139
- @button_v.signal_connect("clicked") do
140
- Thread.new do
141
- controller.notify_action(self,:button_pressed, :key => 'v')
142
- end
143
- end
144
-
145
- @button_e = Gtk::Button.new
146
- @button_e.add(Gtk::Label.new.set_markup('<span underline="single" size="xx-large" foreground="green">E</span>'))
147
- @button_e.signal_connect("clicked") do
148
- Thread.new do
149
- controller.notify_action(self,:button_pressed, :key => 'e')
150
- end
151
- end
152
-
153
- @button_equal = Gtk::Button.new(:label => '=')
154
- @button_equal.signal_connect("clicked") do
155
- Thread.new do
156
- controller.notify_action(self,:button_equal_pressed, :value => @entry.text)
157
- end
158
- end
159
-
160
- @button_raz = Gtk::Button.new(:label => "RàZ")
161
- @button_raz.signal_connect("clicked") do
162
- Thread.new do
163
- controller.notify_action(self,:button_raz_pressed)
164
- end
165
- end
166
-
167
- @label_result = Gtk::Label.new("0")
168
- @label_result.xalign = 1
169
-
170
- #container
171
- @onglet = Gtk::Notebook.new
172
-
173
- @main_vbox = Gtk::Box.new(:vertical, 0)
174
-
175
- @grid_button = Gtk::Grid.new
176
- @grid_button.set_property("row_homogeneous",true)
177
- @grid_button.set_property("column-homogeneous", true)
178
-
179
- #ajout
180
- @onglet.append_page(@main_vbox, Gtk::Label.new("Calculatrice"))
181
-
182
- @window.add(@onglet)
183
-
184
- @main_vbox.pack_start(@entry, :expand => false)
185
- @main_vbox.pack_start(@grid_button,:expand => true, :fill => true, :padding => 10)
186
- @main_vbox.pack_start(@label_result, :expand => false, :padding => 10)
187
-
188
- @grid_button.attach(@button_r,0,0,1,1,)
189
- @grid_button.attach(@button_o,1,0,1,1)
190
- @grid_button.attach(@button_j,2,0,1,1)
191
- @grid_button.attach(@button_c,0,1,1,1)
192
- @grid_button.attach(@button_v,1,1,1,1)
193
- @grid_button.attach(@button_e,2,1,1,1)
194
- @grid_button.attach(@button_raz,0,2,1,1)
195
- @grid_button.attach(@button_equal,1,2,2,1)
196
- end
197
-
198
- def display
199
- @window.show_all
200
- end
201
-
202
- def close
203
- @window.destroy
204
- Gtk.main_quit
205
- end
206
-
207
- def property_change(event)
208
- if event.property_name == "last_key_pressed"
209
- @entry.text = @entry.text+event.new_value
210
-
211
- elsif event.property_name == 'result'
212
- @label_result.text = event.new_value.to_s
213
-
214
- elsif event.property_name == 'raz'
215
- @entry.text = ''
216
- end
217
- end
218
-
219
- end
220
-
221
- end
222
-
223
- Gtk.init
224
- Thread.new do
225
- Gtk.main
226
- end
227
-
228
- Compilator::Compilator.new.display_views
229
-
230
- Thread.list.each {|t| t.join if t!=Thread.main}