smartdict-gtk 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/GPL-LICENSE.txt ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
data/README.markdown ADDED
@@ -0,0 +1,45 @@
1
+ # smartdict-gtk
2
+
3
+
4
+ ## Installation
5
+
6
+ ### Prerequisites
7
+
8
+
9
+ #### Debian/Ubuntu
10
+
11
+ On Debian/Ubuntu you need to install the next packages:
12
+
13
+ * libglib2.0-dev
14
+ * ligatk1.0-dev
15
+ * libcairo-dev
16
+ * libsqlite3-dev
17
+ * libpango1.0-dev
18
+
19
+ To do that run:
20
+
21
+ ```
22
+ apt-get install libglib2.0-dev ligatk1.0-dev libcairo-dev libsqlite3-dev libpango1.0-dev
23
+ ```
24
+
25
+ Please report if you have issues or it's not complete list of required dependencies.
26
+
27
+
28
+ ### Ruby version
29
+
30
+ Tested on MRI 1.9.3-p125
31
+
32
+
33
+ ### Install the gem
34
+
35
+ ```
36
+ gem install smartdict-gtk
37
+ ```
38
+
39
+
40
+
41
+ ## Copyright
42
+
43
+ Copyright (c) 2012 Potapov Sergey. The software is distributed under
44
+ [GNU GeneralPublic License version 2](http://www.gnu.org/licenses/gpl-2.0.txt).
45
+ See GPL-LICENSE.txt file for more details.
data/bin/smartdict-gtk ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'rubygems'
5
+
6
+ # For development
7
+ # require 'bundler'
8
+ # Bundler.setup(:default, :development)
9
+
10
+ require 'smartdict-core'
11
+ require 'smartdict-icons'
12
+ require 'smartdict-gtk'
13
+
14
+ Smartdict.env = :user
15
+
16
+ Smartdict.run
17
+ Smartdict::Gui.run
@@ -0,0 +1,26 @@
1
+ class Smartdict::Gui::AboutWindow < Gtk::AboutDialog
2
+ def initialize
3
+ super
4
+
5
+ set_info
6
+ set_license
7
+
8
+ self.run
9
+ self.destroy
10
+ end
11
+
12
+ def set_info
13
+ self.name = "Smartdict 2"
14
+ self.program_name = "Smartdict"
15
+ self.version = Smartdict::VERSION
16
+ self.copyright = "Potapov Sergey (greyblake)"
17
+ self.authors = ["Potapov Sergey"]
18
+ self.comments = "Simple dictionary"
19
+ self.website = "https://github.com/smartdict/smartdict"
20
+ end
21
+
22
+ def set_license
23
+ self.license = 'Program is distributed under GNU General'\
24
+ 'Public License version 2.'
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ class Smartdict::Gui::Controller::Config
2
+ include Smartdict::Models
3
+
4
+ def lang_names
5
+ @lang_names ||= langs.map{|code| Language[code].name }
6
+ end
7
+
8
+ def langs
9
+ @langs ||= (configatron.default.langs + [from_lang, to_lang]).uniq
10
+ end
11
+
12
+ def from_lang
13
+ @from_lang ||= configatron.default.from_lang
14
+ end
15
+
16
+ def to_lang
17
+ @to_lang ||= configatron.default.to_lang
18
+ end
19
+ end
@@ -0,0 +1,79 @@
1
+ require 'benchmark'
2
+
3
+ module Smartdict::Gui
4
+ class Controller
5
+ extend ActiveSupport::Autoload
6
+ autoload :Config
7
+
8
+ attr_reader :main_window, :word_entry, :translate_button, :menu_bar, :text_view, :status_icon,
9
+ :from_lang_combo_box, :to_lang_combo_box, :interchange_button
10
+
11
+ def initialize
12
+ @main_window = MainWindow.new(self)
13
+ @word_entry = WordEntry.new(self)
14
+ @translate_button = TranslateButton.new(self)
15
+ @menu_bar = MenuBar.new(self)
16
+ @text_view = TextView.new(self)
17
+ @status_icon = StatusIcon.new(self)
18
+ @from_lang_combo_box = LangComboBox.new(self, config.from_lang) {|lang| Smartdict::Translator.from_lang_code = lang }
19
+ @to_lang_combo_box = LangComboBox.new(self, config.to_lang) {|lang| Smartdict::Translator.to_lang_code = lang }
20
+ @interchange_button = InterchangeButton.new(self)
21
+
22
+ #open_export_dialog
23
+ #exit
24
+ end
25
+
26
+ def run
27
+ @main_window.draw_window
28
+ @main_window.show_all
29
+ Gtk.main
30
+ end
31
+
32
+ def quit
33
+ ::Gtk.main_quit
34
+ end
35
+
36
+ def translate
37
+ word = @word_entry.text.strip.downcase
38
+ translation = Smartdict::Translator.translate(word)
39
+ @text_view.show_translation(translation)
40
+ rescue Smartdict::TranslationNotFound => err
41
+ @text_view.buffer.text = err.message
42
+ end
43
+
44
+ def toggle_main_window
45
+ if @main_window.visible? and @main_window.active?
46
+ @main_window.hide_all
47
+ else
48
+ @main_window.show_all
49
+ @main_window.present
50
+ end
51
+ end
52
+
53
+ def open_about_window
54
+ AboutWindow.new
55
+ end
56
+
57
+ def open_export_dialog
58
+ ExportDialog.new(self)
59
+ end
60
+
61
+ def export_translations(format_name, file_path, options = {})
62
+ format = Smartdict::Core::FormatManager.find(format_name)
63
+ translations = Smartdict::ListBuilder.build(options)
64
+ content = format.format_list(translations)
65
+ File.open(file_path, 'w') { |file| file.write content }
66
+ end
67
+
68
+ def interchange_langs
69
+ @to_lang_combo_box.active, @from_lang_combo_box.active = @from_lang_combo_box.active, @to_lang_combo_box.active
70
+ end
71
+
72
+
73
+ private
74
+
75
+ def config
76
+ @config ||= Config.new
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,17 @@
1
+ class Smartdict::Gui::ExportDialog::FormatComboBox < ::Gtk::ComboBox
2
+ def initialize
3
+ super(true)
4
+
5
+ format_names.each {|name| append_text(name) }
6
+
7
+ set_active 0
8
+ end
9
+
10
+ def selected_format
11
+ format_names[active]
12
+ end
13
+
14
+ def format_names
15
+ Smartdict::Core::FormatManager.all.keys
16
+ end
17
+ end
@@ -0,0 +1,90 @@
1
+ class Smartdict::Gui::ExportDialog < ::Gtk::FileChooserDialog
2
+ extend ActiveSupport::Autoload
3
+
4
+ autoload :FormatComboBox
5
+
6
+
7
+ class Label < Gtk::Label
8
+ def initialize(title)
9
+ super
10
+ set_markup("<b>#{title}</b>")
11
+ end
12
+ end
13
+
14
+
15
+ DATE_RANGES = {
16
+ "Today" => lambda { Date.today },
17
+ "Week" => lambda { 1.week.ago },
18
+ "Month" => lambda { 1.month.ago }
19
+ }
20
+
21
+
22
+ def initialize(controller)
23
+ @controller = controller
24
+ super(
25
+ "Export translations",
26
+ nil,
27
+ Gtk::FileChooser::ACTION_SAVE,
28
+ nil,
29
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
30
+ [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]
31
+ )
32
+
33
+ self.vbox.pack_start(options_table, false, false)
34
+ show_all
35
+
36
+ if run == Gtk::Dialog::RESPONSE_ACCEPT
37
+ export_translations
38
+ end
39
+ destroy
40
+ end
41
+
42
+
43
+ def export_translations
44
+ format = @format_combo_box.selected_format
45
+ options = {:since => since_date}
46
+ @controller.export_translations(format, filename, options)
47
+ end
48
+
49
+ def init_date_range_buttons
50
+ @date_range_buttons = {}
51
+ button = nil
52
+ DATE_RANGES.each do |name, block|
53
+ args = button ? [button, name] : [name]
54
+ button = Gtk::RadioButton.new(*args)
55
+ @date_range_buttons[button] = block
56
+ end
57
+ end
58
+
59
+ # @return [Gtk::Table]
60
+ def options_table
61
+ table_width = DATE_RANGES.size + 2
62
+
63
+ # Create table itself
64
+ table = Gtk::Table.new(table_width, 2, false)
65
+ table.column_spacings = 5
66
+
67
+ # Format
68
+ format_label = Label.new("Format:")
69
+ @format_combo_box = FormatComboBox.new
70
+ table.attach(format_label, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0)
71
+ table.attach_defaults(@format_combo_box, 1, table_width, 0, 1)
72
+
73
+ # Date range
74
+ date_range_label = Label.new("Date range:")
75
+ init_date_range_buttons
76
+ table.attach(date_range_label, 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0)
77
+ @date_range_buttons.keys.each_with_index do |button, index|
78
+ table.attach(button, index+1, index+2, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0)
79
+ end
80
+
81
+ # A trick to make radio buttons have left alignment
82
+ table.attach_defaults(Label.new(''), table_width-1, table_width, 1, 2)
83
+ end
84
+
85
+ def since_date
86
+ @date_range_buttons.each do |button, block|
87
+ return block.call if button.active?
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,16 @@
1
+ class Smartdict::Gui::InterchangeButton < ::Gtk::Button
2
+ include Smartdict::Gui
3
+
4
+ def initialize(controller)
5
+ super('')
6
+
7
+ @controller = controller
8
+ signal_connect('clicked') { @controller.interchange_langs }
9
+
10
+ image = Gtk::Image.new(Smartdict::Icons.interchange)
11
+ set_image image
12
+ image.show
13
+
14
+ set_size_request(60, LEFT_BOX_BUTTON_HEIGHT)
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ class Smartdict::Gui::LangComboBox < ::Gtk::ComboBox
2
+ extend Forwardable
3
+ include Smartdict::Gui
4
+
5
+ def_delegator :@controller, :config
6
+
7
+ def initialize(controller, active_lang_code, &on_change_block)
8
+ super(true)
9
+ @controller = controller
10
+ @on_change_block = on_change_block
11
+
12
+ config.lang_names.each {|name| append_text(name) }
13
+ active_index = config.langs.index(active_lang_code)
14
+ set_active(active_index)
15
+
16
+ signal_connect("changed") do |comb_box|
17
+ lang_code = config.langs[active]
18
+ @on_change_block.call(lang_code)
19
+ end
20
+
21
+ set_size_request(100, LEFT_BOX_BUTTON_HEIGHT)
22
+ end
23
+
24
+ end
@@ -0,0 +1,62 @@
1
+ class Smartdict::Gui::MainWindow < ::Gtk::Window
2
+ extend Forwardable
3
+
4
+ def_delegators :@controller, :menu_bar, :word_entry, :translate_button, :text_view,
5
+ :from_lang_combo_box, :to_lang_combo_box, :interchange_button
6
+
7
+ def initialize(controller)
8
+ super("Smartdict")
9
+
10
+ @controller = controller
11
+
12
+ signal_connect("delete_event") { hide_all }
13
+ signal_connect("destroy") { @controller.quit }
14
+
15
+ set_default_size(720, 450)
16
+ set_icon(Smartdict::Icons.logo)
17
+ end
18
+
19
+
20
+ def draw_window
21
+ vertical_span = 3
22
+ left_box_border = 3
23
+
24
+ main_box = Gtk::VBox.new.
25
+ pack_start(menu_bar, false, false, 0)
26
+
27
+ main_hpaned = Gtk::HPaned.new
28
+
29
+ left_scrolled_win = Gtk::ScrolledWindow.new.
30
+ set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
31
+
32
+ left_side_box = Gtk::VBox.new.
33
+ pack_start(Gtk::VBox.new.
34
+ pack_start(Gtk::HBox.new.
35
+ pack_start(word_entry).
36
+ set_border_width(vertical_span), false, false).
37
+ pack_start(Gtk::HBox.new.
38
+ pack_start(translate_button).
39
+ set_border_width(vertical_span), false, false).
40
+ pack_start(Gtk::HBox.new.
41
+ pack_start(from_lang_combo_box).
42
+ pack_start(interchange_button).
43
+ pack_start(to_lang_combo_box).
44
+ set_border_width(vertical_span), false, false).
45
+ set_border_width(left_box_border), false, false).
46
+ pack_start(left_scrolled_win, true, true)
47
+
48
+ right_scrolled_win = Gtk::ScrolledWindow.new.
49
+ add(text_view).
50
+ set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
51
+
52
+ main_hpaned.
53
+ add_child(Gtk::Builder.new, left_side_box).
54
+ add_child(Gtk::Builder.new, right_scrolled_win)
55
+
56
+ main_box.add(main_hpaned)
57
+ #main_box.pack_start(@status_bar, false,false)
58
+
59
+ add(main_box)
60
+ end
61
+
62
+ end
@@ -0,0 +1,37 @@
1
+ module Smartdict::Gui
2
+ class MenuBar < ::Gtk::MenuBar
3
+
4
+
5
+ def initialize(controller)
6
+ @controller = controller
7
+ super()
8
+
9
+ file_menu_item = Gtk::MenuItem.new("_File")
10
+
11
+ file_exit_item = Gtk::MenuItem.new("_Exit")
12
+ file_exit_item.signal_connect("activate") {@controller.quit}
13
+ file_export_item = Gtk::MenuItem.new("_Export")
14
+ file_export_item.signal_connect("activate") { @controller.open_export_dialog }
15
+
16
+ file_menu = Gtk::Menu.new
17
+ file_menu.add(file_export_item)
18
+ file_menu.add(file_exit_item)
19
+ file_menu_item.submenu = file_menu
20
+
21
+ help_menu_item = Gtk::MenuItem.new("_Help")
22
+
23
+ help_about_item = Gtk::MenuItem.new("About")
24
+ help_about_item.signal_connect("activate"){ @controller.open_about_window }
25
+
26
+ help_menu = Gtk::Menu.new
27
+ help_menu.add(help_about_item)
28
+ help_menu_item.submenu = help_menu
29
+
30
+ append(file_menu_item)
31
+ append(help_menu_item)
32
+
33
+ end
34
+
35
+
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module Smartdict::Gui
2
+ class StatusIcon < ::Gtk::StatusIcon
3
+
4
+ def initialize(controller)
5
+ @controller = controller
6
+ super()
7
+
8
+ build_menu
9
+ self.pixbuf = Gdk::Pixbuf.new(Smartdict::Icons.logo)
10
+
11
+ signal_connect('activate'){@controller.toggle_main_window}
12
+
13
+ ##Show menu on rigth click
14
+ self.signal_connect('popup-menu'){|tray, button, time| @menu.popup(nil, nil, button, time)}
15
+ end
16
+
17
+
18
+ protected
19
+
20
+ def build_menu
21
+ info = Gtk::ImageMenuItem.new(Gtk::Stock::INFO)
22
+ info.signal_connect('activate'){@controller.open_about_window}
23
+
24
+ quit = Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
25
+ quit.signal_connect('activate'){@controller.quit}
26
+
27
+ menu = Gtk::Menu.new
28
+ menu.append(info)
29
+ menu.append(Gtk::SeparatorMenuItem.new)
30
+ menu.append(quit)
31
+ menu.show_all
32
+
33
+ @menu = menu
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,39 @@
1
+ class Smartdict::Gui::TextView::Buffer < ::Gtk::TextBuffer
2
+ INDENT = 4
3
+
4
+ def initialize
5
+ super
6
+ create_tag("word" , {"weight" => Pango::WEIGHT_BOLD , :scale => 1.3})
7
+ create_tag("transcription" , {"style" => Pango::STYLE_ITALIC, :scale => 1.3})
8
+ create_tag("word_class" , {"weight" => Pango::WEIGHT_BOLD , :scale => 1.0})
9
+ create_tag("translated_word", {:scale => 1.0})
10
+ end
11
+
12
+ def set_translation(translation)
13
+ self.text = ''
14
+
15
+ insert(end_iter, translation.word, "word")
16
+ insert(end_iter, " [#{translation.transcription}]", "transcription") if translation.transcription
17
+ insert(end_iter, "\n")
18
+
19
+ translation.translated.each do |word_class, words|
20
+ add_word_class(word_class, words)
21
+ end
22
+ end
23
+
24
+
25
+ private
26
+
27
+ def add_word_class(word_class, words)
28
+ text = (" " * INDENT) + "#{word_class}\n"
29
+ insert(end_iter, text, "word_class")
30
+ words.each do |word|
31
+ add_translated_word(word)
32
+ end
33
+ end
34
+
35
+ def add_translated_word(word)
36
+ word_text = (" " * INDENT * 2) + "#{word}\n"
37
+ insert(end_iter, word_text, "translated_word")
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ class Smartdict::Gui::TextView < ::Gtk::TextView
2
+ extend ActiveSupport::Autoload
3
+ autoload :Buffer
4
+
5
+ def initialize(controller)
6
+ super(Buffer.new)
7
+ @controller = controller
8
+ self.editable = false
9
+ end
10
+
11
+ def show_translation(translation)
12
+ buffer.set_translation(translation)
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Smartdict::Gui
2
+ class TranslateButton < ::Gtk::Button
3
+
4
+ def initialize(controller)
5
+ super("Translate")
6
+ @controller = controller
7
+ signal_connect('clicked') { @controller.translate }
8
+ set_size_request(100, LEFT_BOX_BUTTON_HEIGHT)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Smartdict::Gui
2
+ class WordEntry < ::Gtk::Entry
3
+
4
+ def initialize(controller)
5
+ super()
6
+ @controller = controller
7
+ signal_connect('activate') { @controller.translate }
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'gtk2'
2
+
3
+ module Smartdict::Gui
4
+ extend ActiveSupport::Autoload
5
+ extend self
6
+
7
+ autoload :Controller
8
+ autoload :MainWindow
9
+ autoload :WordEntry
10
+ autoload :TranslateButton
11
+ autoload :MenuBar
12
+ autoload :TextView
13
+ autoload :StatusIcon
14
+ autoload :AboutWindow
15
+ autoload :LangComboBox
16
+ autoload :InterchangeButton
17
+ autoload :ExportDialog
18
+
19
+
20
+ LEFT_BOX_BUTTON_HEIGHT = 36
21
+
22
+ def run
23
+ Smartdict::Gui::Controller.new.run
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path('../smartdict', __FILE__)
data/lib/smartdict.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Smartdict
2
+ extend ActiveSupport::Autoload
3
+
4
+ autoload :Gui
5
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smartdict-gtk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sergey Potapov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: smartdict-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: smartdict-icons
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: gtk2
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.1.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: dm-enum
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: builder
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.3.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 2.3.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.1.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.1.2
126
+ - !ruby/object:Gem::Dependency
127
+ name: jeweler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.6.4
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 1.6.4
142
+ description: GTK GUI for Smartdict dictionary
143
+ email: blake131313@gmail.com
144
+ executables:
145
+ - smartdict-gtk
146
+ extensions: []
147
+ extra_rdoc_files:
148
+ - README.markdown
149
+ files:
150
+ - ./bin/smartdict-gtk
151
+ - ./lib/smartdict-gtk.rb
152
+ - ./lib/smartdict.rb
153
+ - ./lib/smartdict/gui.rb
154
+ - ./lib/smartdict/gui/about_window.rb
155
+ - ./lib/smartdict/gui/controller.rb
156
+ - ./lib/smartdict/gui/controller/config.rb
157
+ - ./lib/smartdict/gui/export_dialog.rb
158
+ - ./lib/smartdict/gui/export_dialog/format_combo_box.rb
159
+ - ./lib/smartdict/gui/interchange_button.rb
160
+ - ./lib/smartdict/gui/lang_combo_box.rb
161
+ - ./lib/smartdict/gui/main_window.rb
162
+ - ./lib/smartdict/gui/menu_bar.rb
163
+ - ./lib/smartdict/gui/status_icon.rb
164
+ - ./lib/smartdict/gui/text_view.rb
165
+ - ./lib/smartdict/gui/text_view/buffer.rb
166
+ - ./lib/smartdict/gui/translate_button.rb
167
+ - ./lib/smartdict/gui/word_entry.rb
168
+ - GPL-LICENSE.txt
169
+ - README.markdown
170
+ - !binary |-
171
+ YmluL3NtYXJ0ZGljdC1ndGs=
172
+ homepage: http://github.com/greyblake/smartdict-gtk
173
+ licenses:
174
+ - MIT
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ requirements: []
192
+ rubyforge_project:
193
+ rubygems_version: 1.8.21
194
+ signing_key:
195
+ specification_version: 3
196
+ summary: GTK GUI for Smartdict dictionary
197
+ test_files: []