compilator 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 23428a336f2cfc5e51baebbb09949dd2baa5c800
4
+ data.tar.gz: 5cfa57f67a36f6761dccf31b7a5e1c1b20e3be0e
5
+ SHA512:
6
+ metadata.gz: 0fe1eaa7b760be6f13bc36f670eabae8bac2d0c270237d25e9431a446ce46ced8b136c6c54d5b577df2a894dec7d2e87dfc0add2f2de226a7f6f67414695e8be
7
+ data.tar.gz: 36961c24a2e20d5dfb0ce6ab02947120747eef6c3a078b038fb70ad10c3d103c5fa5dc63ae11ad87e722e62c2020e6527a64bacdd4e509d3efbdf1e9ee266072
@@ -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}
@@ -0,0 +1,3 @@
1
+ module Compilator
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compilator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Le Greneur
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: druzy-mvc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: unknown
70
+ email:
71
+ - jonathan.legreneur@free.fr
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/compilator.rb
77
+ - lib/compilator/version.rb
78
+ homepage: https://github.com/druzy/compilator
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: unknown
102
+ test_files: []