compilator 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23428a336f2cfc5e51baebbb09949dd2baa5c800
4
- data.tar.gz: 5cfa57f67a36f6761dccf31b7a5e1c1b20e3be0e
3
+ metadata.gz: 9e18435dc97a5925f10d3514d70fb2fb55d9d3ca
4
+ data.tar.gz: 14a8d1ffa1d0ff3c3b4ca2a6e37418a22be2fc58
5
5
  SHA512:
6
- metadata.gz: 0fe1eaa7b760be6f13bc36f670eabae8bac2d0c270237d25e9431a446ce46ced8b136c6c54d5b577df2a894dec7d2e87dfc0add2f2de226a7f6f67414695e8be
7
- data.tar.gz: 36961c24a2e20d5dfb0ce6ab02947120747eef6c3a078b038fb70ad10c3d103c5fa5dc63ae11ad87e722e62c2020e6527a64bacdd4e509d3efbdf1e9ee266072
6
+ metadata.gz: 1d9f218bdd690d0a063d93ea5f08e660c6191ffc3a8d9016fac4b9a5529afa28dd342d74a4ad0c24b7b44460fe8ee056a9f956df5e73cfa746f632e58f062572
7
+ data.tar.gz: c802bbc8f61c9ab889b409dbd1c9924de6ebfbb4c8c45e47698e355f6e6809e2e89b26bc476618205102c7bad9e78b926b31e1c96fa5961d4e64004a7f5a84ac
@@ -1,3 +1,3 @@
1
1
  module Compilator
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/compilator.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require_relative 'compilator/version'
2
2
 
3
3
  require 'druzy/mvc'
4
- require 'gtk3'
4
+ require 'tk'
5
+ require 'tkextlib/tile'
5
6
 
6
7
  module Compilator
7
8
 
@@ -75,144 +76,167 @@ module Compilator
75
76
 
76
77
  def initialize(controller)
77
78
  super(controller)
79
+ #Tk::Tile::Style.theme_use "classic"
78
80
 
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))
81
+ @root = TkRoot.new
82
+ @root.title = 'Compilator'
83
+ @root.bind('Key') do |event|
84
+ val = event.valid_fields['keysym'].downcase
83
85
 
84
- if controller.model.score.has_key?(val)
86
+ if val == 'return'
85
87
  Thread.new do
86
- controller.notify_action(self,:key_pressed, :key => val)
88
+ @controller.notify_action(self, :key_enter_pressed, :value => @entry_variable.value)
87
89
  end
88
-
89
- elsif event.keyval == Gdk::Keyval::KEY_Return
90
+ elsif @controller.model.score.has_key?(val)
90
91
  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)
92
+ @controller.notify_action(self,:key_pressed, :key => val)
93
+ end
98
94
  end
95
+
99
96
  end
100
97
 
101
- @entry = Gtk::Entry.new
102
- @entry.editable = false
103
- @entry.xalign = 1
98
+ @window = Tk::Tile::Frame.new(@root)
99
+
100
+ @entry_variable = TkVariable.new
101
+ @entry = Tk::Tile::Entry.new(@window)
102
+ @entry.justify = 'right'
103
+ @entry.validate = 'key'
104
+ @entry.textvariable = @entry_variable
105
+ @entry.validatecommand do |valid|
106
+ if valid.action == 1
107
+ false
108
+ else
109
+ true
110
+ end
111
+ end
104
112
 
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
113
+ @button_r = Tk::Tile::Button.new(@window)
114
+ @button_r['text'] = 'R'
115
+ Tk::Tile::Style.configure('Red.TButton', {"foreground" => 'red' })
116
+ @button_r['style'] = 'Red.TButton'
117
+ @button_r.bind('ButtonPress') do
108
118
  Thread.new do
109
- controller.notify_action(self,:button_pressed, :key => 'r')
119
+ @controller.notify_action(self,:button_pressed, :key => 'r')
110
120
  end
111
121
  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
122
+
123
+ @button_o = Tk::Tile::Button.new(@window)
124
+ @button_o['text'] = 'O'
125
+ Tk::Tile::Style.configure('Orange.TButton', {"foreground" => 'orange' })
126
+ @button_o['style'] = 'Orange.TButton'
127
+ @button_o.bind('ButtonPress') do
116
128
  Thread.new do
117
- controller.notify_action(self,:button_pressed, :key => 'o')
129
+ @controller.notify_action(self,:button_pressed, :key => 'o')
118
130
  end
119
131
  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
132
+
133
+ @button_j = Tk::Tile::Button.new(@window)
134
+ @button_j['text'] = 'J'
135
+ Tk::Tile::Style.configure('Yellow.TButton', {"foreground" => 'yellow' })
136
+ @button_j['style'] = 'Yellow.TButton'
137
+ @button_j.bind('ButtonPress') do
124
138
  Thread.new do
125
- controller.notify_action(self,:button_pressed, :key => 'j')
139
+ @controller.notify_action(self,:button_pressed, :key => 'j')
126
140
  end
127
141
  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
142
+
143
+ @button_c = Tk::Tile::Button.new(@window)
144
+ @button_c['text'] = 'C'
145
+ Tk::Tile::Style.configure('Lime.TButton', {"foreground" => 'lime' })
146
+ @button_c['style'] = 'Lime.TButton'
147
+ @button_c.bind('ButtonPress') do
132
148
  Thread.new do
133
- controller.notify_action(self,:button_pressed, :key => 'c')
149
+ @controller.notify_action(self,:button_pressed, :key => 'c')
134
150
  end
135
151
  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
152
+
153
+ @button_v = Tk::Tile::Button.new(@window)
154
+ @button_v['text'] = 'V'
155
+ Tk::Tile::Style.configure('Green.TButton', {"foreground" => 'green' })
156
+ @button_v['style'] = 'Green.TButton'
157
+ @button_v.bind('ButtonPress') do
140
158
  Thread.new do
141
- controller.notify_action(self,:button_pressed, :key => 'v')
159
+ @controller.notify_action(self,:button_pressed, :key => 'v')
142
160
  end
143
161
  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
162
+
163
+ @button_e = Tk::Tile::Button.new(@window)
164
+ @button_e['text'] = 'E'
165
+ @button_e['underline'] = 0
166
+ Tk::Tile::Style.configure('Underline.TButton', {"foreground" => 'green'})
167
+ @button_e['style'] = 'Underline.TButton'
168
+ @button_e.bind('ButtonPress') do
148
169
  Thread.new do
149
- controller.notify_action(self,:button_pressed, :key => 'e')
170
+ @controller.notify_action(self,:button_pressed, :key => 'e')
150
171
  end
151
172
  end
152
-
153
- @button_equal = Gtk::Button.new(:label => '=')
154
- @button_equal.signal_connect("clicked") do
173
+
174
+ @button_raz = Tk::Tile::Button.new(@window)
175
+ @button_raz['text'] = 'RàZ'
176
+ @button_raz.bind('ButtonPress') do
155
177
  Thread.new do
156
- controller.notify_action(self,:button_equal_pressed, :value => @entry.text)
178
+ @controller.notify_action(self,:button_raz_pressed)
157
179
  end
158
180
  end
159
181
 
160
- @button_raz = Gtk::Button.new(:label => "RàZ")
161
- @button_raz.signal_connect("clicked") do
182
+ @button_equal = Tk::Tile::Button.new(@window)
183
+ @button_equal['text'] = '='
184
+ @button_equal.bind('ButtonPress') do
162
185
  Thread.new do
163
- controller.notify_action(self,:button_raz_pressed)
186
+ @controller.notify_action(self,:button_equal_pressed, :value => @entry_variable.value)
164
187
  end
165
188
  end
166
189
 
167
- @label_result = Gtk::Label.new("0")
168
- @label_result.xalign = 1
190
+ @label_result = Tk::Tile::Label.new(@window)
191
+ @label_result.justify('right')
169
192
 
170
- #container
171
- @onglet = Gtk::Notebook.new
172
-
173
- @main_vbox = Gtk::Box.new(:vertical, 0)
193
+ #ajout
194
+ TkGrid.columnconfigure( @root, 0, :weight => 1 )
195
+ TkGrid.rowconfigure( @root, 0, :weight => 1 )
174
196
 
175
- @grid_button = Gtk::Grid.new
176
- @grid_button.set_property("row_homogeneous",true)
177
- @grid_button.set_property("column-homogeneous", true)
197
+ TkGrid.columnconfigure( @window, 0, :weight => 1)
198
+ TkGrid.columnconfigure( @window, 1, :weight => 1 )
199
+ TkGrid.columnconfigure( @window, 2, :weight => 1 )
200
+ TkGrid.rowconfigure( @window, 0, :weight => 0)
201
+ TkGrid.rowconfigure( @window, 1, :weight => 1)
202
+ TkGrid.rowconfigure( @window, 2, :weight => 1)
203
+ TkGrid.rowconfigure( @window, 3, :weight => 1)
204
+ TkGrid.rowconfigure( @window, 4, :weight => 0)
205
+
206
+ @window.grid(:column => 0, :row => 0, :sticky => 'nsew')
207
+
208
+ @entry.grid(:column => 0, :row => 0, :columnspan => 3, :sticky => 'new')
209
+
210
+
211
+ @button_r.grid(:column => 0, :row => 1, :sticky => 'nsew')
212
+ @button_o.grid(:column => 1, :row => 1, :sticky => 'nsew')
213
+ @button_j.grid(:column => 2, :row => 1, :sticky => 'ewns')
214
+ @button_c.grid(:column => 0, :row => 2, :sticky => 'ewns')
215
+ @button_v.grid(:column => 1, :row => 2, :sticky => 'ewns')
216
+ @button_e.grid(:column => 2, :row => 2, :sticky => 'ewns')
217
+ @button_raz.grid(:column => 0, :row => 3, :sticky => 'ewns')
218
+ @button_equal.grid(:column => 1, :row => 3, :columnspan => 2, :sticky => 'ewns')
219
+
220
+ @label_result.grid(:column => 0, :row => 4, :columnspan => 3, :sticky => 'ew')
178
221
 
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
222
  end
197
223
 
198
224
  def display
199
- @window.show_all
200
225
  end
201
226
 
202
227
  def close
203
- @window.destroy
204
- Gtk.main_quit
205
228
  end
206
229
 
207
230
  def property_change(event)
208
231
  if event.property_name == "last_key_pressed"
209
- @entry.text = @entry.text+event.new_value
232
+ @entry_variable.set_value(@entry_variable.value+event.new_value)
210
233
 
211
234
  elsif event.property_name == 'result'
235
+
212
236
  @label_result.text = event.new_value.to_s
213
237
 
214
238
  elsif event.property_name == 'raz'
215
- @entry.text = ''
239
+ @entry_variable.set_value('')
216
240
  end
217
241
  end
218
242
 
@@ -220,11 +244,6 @@ module Compilator
220
244
 
221
245
  end
222
246
 
223
- Gtk.init
224
- Thread.new do
225
- Gtk.main
226
- end
227
-
228
247
  Compilator::Compilator.new.display_views
229
248
 
230
- Thread.list.each {|t| t.join if t!=Thread.main}
249
+ Tk.mainloop
@@ -0,0 +1,230 @@
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}
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.0
4
+ version: 1.0.1
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-04 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: druzy-mvc
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.2.0
27
- - !ruby/object:Gem::Dependency
28
- name: gtk3
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 2.2.5
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 2.2.5
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +60,7 @@ extensions: []
74
60
  extra_rdoc_files: []
75
61
  files:
76
62
  - lib/compilator.rb
63
+ - lib/compilator.rb.old
77
64
  - lib/compilator/version.rb
78
65
  homepage: https://github.com/druzy/compilator
79
66
  licenses: