image_paradise 0.1.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of image_paradise might be problematic. Click here for more details.

Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +38 -0
  3. data/README.md +179 -0
  4. data/USAGE.md +10 -0
  5. data/bin/black_white +10 -0
  6. data/bin/display_text_from_this_image +7 -0
  7. data/bin/image_paradise +7 -0
  8. data/bin/image_paradise_shell +7 -0
  9. data/bin/image_to_ascii +54 -0
  10. data/bin/image_to_pdf +7 -0
  11. data/bin/make_this_image_transparent +7 -0
  12. data/bin/rotate_left +7 -0
  13. data/bin/rotate_right +7 -0
  14. data/doc/README.gen +162 -0
  15. data/doc/TODO_FOR_THE_GTK_GUI.md +1 -0
  16. data/image_paradise.gemspec +50 -0
  17. data/lib/image_paradise.rb +5 -0
  18. data/lib/image_paradise/base/base.rb +91 -0
  19. data/lib/image_paradise/black_white.rb +89 -0
  20. data/lib/image_paradise/confree_generator/class.rb +614 -0
  21. data/lib/image_paradise/confree_generator/constants.rb +61 -0
  22. data/lib/image_paradise/confree_generator/gui/gtk_confree_generator.rb +752 -0
  23. data/lib/image_paradise/confree_generator/gui/insert_button.rb +78 -0
  24. data/lib/image_paradise/confree_generator/reset.rb +61 -0
  25. data/lib/image_paradise/confree_generator/shared/shared.rb +100 -0
  26. data/lib/image_paradise/constants.rb +43 -0
  27. data/lib/image_paradise/constants/image_file_types.rb +21 -0
  28. data/lib/image_paradise/create_animated_gif.rb +47 -0
  29. data/lib/image_paradise/crop/crop.rb +302 -0
  30. data/lib/image_paradise/gm_support.rb +34 -0
  31. data/lib/image_paradise/graphs.rb +36 -0
  32. data/lib/image_paradise/graphs/accumulator_bar.rb +29 -0
  33. data/lib/image_paradise/graphs/area.rb +64 -0
  34. data/lib/image_paradise/graphs/bar.rb +117 -0
  35. data/lib/image_paradise/graphs/bar_conversion.rb +53 -0
  36. data/lib/image_paradise/graphs/base.rb +1392 -0
  37. data/lib/image_paradise/graphs/bezier.rb +45 -0
  38. data/lib/image_paradise/graphs/bullet.rb +115 -0
  39. data/lib/image_paradise/graphs/deprecated.rb +42 -0
  40. data/lib/image_paradise/graphs/dot.rb +129 -0
  41. data/lib/image_paradise/graphs/line.rb +328 -0
  42. data/lib/image_paradise/graphs/mini/bar.rb +42 -0
  43. data/lib/image_paradise/graphs/mini/legend.rb +109 -0
  44. data/lib/image_paradise/graphs/mini/pie.rb +42 -0
  45. data/lib/image_paradise/graphs/mini/side_bar.rb +41 -0
  46. data/lib/image_paradise/graphs/net.rb +133 -0
  47. data/lib/image_paradise/graphs/photo_bar.rb +106 -0
  48. data/lib/image_paradise/graphs/pie.rb +139 -0
  49. data/lib/image_paradise/graphs/scatter.rb +264 -0
  50. data/lib/image_paradise/graphs/scene.rb +216 -0
  51. data/lib/image_paradise/graphs/side_bar.rb +144 -0
  52. data/lib/image_paradise/graphs/side_stacked_bar.rb +116 -0
  53. data/lib/image_paradise/graphs/spider.rb +163 -0
  54. data/lib/image_paradise/graphs/stacked_area.rb +73 -0
  55. data/lib/image_paradise/graphs/stacked_bar.rb +68 -0
  56. data/lib/image_paradise/graphs/stacked_mixin.rb +30 -0
  57. data/lib/image_paradise/graphs/themes.rb +117 -0
  58. data/lib/image_paradise/graphviz/README.md +2 -0
  59. data/lib/image_paradise/graphviz/generate_graphviz_image.rb +274 -0
  60. data/lib/image_paradise/gui/gtk/control_panel.rb +126 -0
  61. data/lib/image_paradise/identify.rb +145 -0
  62. data/lib/image_paradise/image_border.rb +231 -0
  63. data/lib/image_paradise/image_manipulations.rb +320 -0
  64. data/lib/image_paradise/image_paradise.rb +150 -0
  65. data/lib/image_paradise/image_to_ascii/image_to_ascii.rb +187 -0
  66. data/lib/image_paradise/image_to_pdf/image_to_pdf.rb +99 -0
  67. data/lib/image_paradise/label/README.md +2 -0
  68. data/lib/image_paradise/label/simple_label.rb +206 -0
  69. data/lib/image_paradise/optimizer.rb +483 -0
  70. data/lib/image_paradise/project/project.rb +29 -0
  71. data/lib/image_paradise/random_text_to_image.rb +363 -0
  72. data/lib/image_paradise/requires/common_base_requires.rb +17 -0
  73. data/lib/image_paradise/requires/require_colours.rb +9 -0
  74. data/lib/image_paradise/requires/require_gtk_components.rb +8 -0
  75. data/lib/image_paradise/requires/require_image_to_ascii.rb +7 -0
  76. data/lib/image_paradise/requires/require_the_image_paradise_project.rb +24 -0
  77. data/lib/image_paradise/requires/require_toplevel_methods.rb +21 -0
  78. data/lib/image_paradise/rotate/README.md +2 -0
  79. data/lib/image_paradise/rotate/rotate.rb +98 -0
  80. data/lib/image_paradise/shell/interactive.rb +156 -0
  81. data/lib/image_paradise/svg/README.md +5 -0
  82. data/lib/image_paradise/svg/circle.rb +106 -0
  83. data/lib/image_paradise/svg/feature.rb +48 -0
  84. data/lib/image_paradise/svg/rectangle.rb +154 -0
  85. data/lib/image_paradise/svg/svg.rb +102 -0
  86. data/lib/image_paradise/to_gif.rb +91 -0
  87. data/lib/image_paradise/to_jpg.rb +90 -0
  88. data/lib/image_paradise/toplevel_methods/add_black_border_to_this_image.rb +56 -0
  89. data/lib/image_paradise/toplevel_methods/crop.rb +28 -0
  90. data/lib/image_paradise/toplevel_methods/e.rb +16 -0
  91. data/lib/image_paradise/toplevel_methods/esystem.rb +19 -0
  92. data/lib/image_paradise/toplevel_methods/extract_text_from_this_image.rb +56 -0
  93. data/lib/image_paradise/toplevel_methods/file_related_code.rb +25 -0
  94. data/lib/image_paradise/toplevel_methods/flip_image_left_right.rb +32 -0
  95. data/lib/image_paradise/toplevel_methods/greyscale_this_image.rb +59 -0
  96. data/lib/image_paradise/toplevel_methods/help.rb +30 -0
  97. data/lib/image_paradise/toplevel_methods/make_this_image_transparent.rb +30 -0
  98. data/lib/image_paradise/toplevel_methods/menu.rb +92 -0
  99. data/lib/image_paradise/toplevel_methods/merge_these_images.rb +49 -0
  100. data/lib/image_paradise/toplevel_methods/mirror_image.rb +28 -0
  101. data/lib/image_paradise/toplevel_methods/misc.rb +31 -0
  102. data/lib/image_paradise/toplevel_methods/png_to_svg.rb +34 -0
  103. data/lib/image_paradise/toplevel_methods/roebe.rb +17 -0
  104. data/lib/image_paradise/toplevel_methods/to_png.rb +105 -0
  105. data/lib/image_paradise/toplevel_methods/wallpaper.rb +37 -0
  106. data/lib/image_paradise/toplevel_methods/write_this_text.rb +76 -0
  107. data/lib/image_paradise/version/version.rb +19 -0
  108. data/test/16x16_red_square_image_for_testing.png +0 -0
  109. data/test/testing_confree_generator.rb +8 -0
  110. data/test/testing_crop.rb +19 -0
  111. data/test/testing_image_magick_commands.rb +39 -0
  112. data/test/testing_image_paradise.rb +49 -0
  113. data/test/testing_the_svg_component.html +261 -0
  114. data/test/testing_the_svg_component.rb +106 -0
  115. metadata +217 -0
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'image_paradise/confree_generator/constants.rb'
6
+ # =========================================================================== #
7
+ require 'image_paradise/base/base.rb'
8
+
9
+ module ImageParadise
10
+
11
+ class ConfreeGenerator < ::ImageParadise::Base # === ImageParadise::ConfreeGenerator
12
+
13
+ # ========================================================================= #
14
+ # === NAMESPACE
15
+ # ========================================================================= #
16
+ NAMESPACE = inspect
17
+
18
+ # ========================================================================= #
19
+ # === ALPHABET
20
+ # ========================================================================= #
21
+ ALPHABET = ('a'..'z').to_a
22
+
23
+ # ========================================================================= #
24
+ # === TRY_TO_OPEN_THE_GENERATED_IMAGE_IN_THE_BROWSER
25
+ # ========================================================================= #
26
+ TRY_TO_OPEN_THE_GENERATED_IMAGE_IN_THE_BROWSER = true
27
+
28
+ # ========================================================================= #
29
+ # === NAME_OF_OUTPUT_FILE
30
+ # ========================================================================= #
31
+ NAME_OF_OUTPUT_FILE = 'output.png'
32
+
33
+ # ========================================================================= #
34
+ # === CREATE_HTML_GALLERY
35
+ # ========================================================================= #
36
+ CREATE_HTML_GALLERY = false
37
+
38
+ # ========================================================================= #
39
+ # === GENERATE_THE_IMAGE
40
+ #
41
+ # If this constant is false, then we will NOT generate any images.
42
+ #
43
+ # But we will auto-generate the html parts still.
44
+ # ========================================================================= #
45
+ GENERATE_THE_IMAGE = true
46
+
47
+ # ========================================================================= #
48
+ # === OPTIMIZE_PNG_FILES
49
+ #
50
+ # If this constant is set to true, then we will try to run
51
+ # "pngquant" on the generated .png file.
52
+ # ========================================================================= #
53
+ OPTIMIZE_PNG_FILES = true
54
+
55
+ # ========================================================================= #
56
+ # === HARDCODED_PATH_TO_THE_CFDG_IMAGES_DIRECTORY
57
+ # ========================================================================= #
58
+ HARDCODED_PATH_TO_THE_CFDG_IMAGES_DIRECTORY =
59
+ '/home/x/DATA/images/cfdg/'
60
+
61
+ end; end
@@ -0,0 +1,752 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === GtkConfreeGenerator
6
+ #
7
+ # This is my gtk2 Wrapper for Confree-Generator (cfdg).
8
+ # =========================================================================== #
9
+ # rconfree
10
+ # bl $RSRC/confree_generator/lib/confree_generator/gui/gtk_confree_generator.rb
11
+ # =========================================================================== #
12
+ require 'image_paradise/requires/require_colours.rb'
13
+ begin
14
+ require 'gtk_module'
15
+ rescue LoadError; end
16
+ begin
17
+ require 'open_in_browser'
18
+ rescue LoadError; end
19
+ require 'image_paradise/confree_generator/shared/shared.rb'
20
+ require 'image_paradise/confree_generator/gui/insert_button.rb'
21
+ require 'image_paradise/confree_generator/class.rb'
22
+ begin
23
+ require 'x/tools/imageshack.rb' # bl $RUBY_TOOLS/imageshack.rb
24
+ rescue LoadError; end
25
+ begin
26
+ require 'gtksourceview2'
27
+ rescue Exception => error
28
+ p error
29
+ end
30
+
31
+ module ImageParadise
32
+
33
+ class ConfreeGenerator < ::ImageParadise::Base
34
+
35
+ class GtkConfreeGenerator < ::Gtk::VBox # === ImageParadise::ConfreeGenerator::GtkConfreeGenerator.new
36
+
37
+ include Colours
38
+ include ::ImageParadise::ConfreeGenerator::Shared
39
+ include ::Gtk
40
+ include ::Gtk::Colours
41
+ include Esystem
42
+
43
+ attr_accessor :source_buffer
44
+
45
+ # ========================================================================= #
46
+ # === MAIN_WINDOW_WIDTH
47
+ # ========================================================================= #
48
+ MAIN_WINDOW_WIDTH = 950
49
+
50
+ # ========================================================================= #
51
+ # === MAIN_WINDOW_HEIGHT
52
+ # ========================================================================= #
53
+ MAIN_WINDOW_HEIGHT = 900
54
+
55
+ # ========================================================================= #
56
+ # === TOOLTIP_EDITOR
57
+ # ========================================================================= #
58
+ TOOLTIP_EDITOR = 'Open the file in '+YOUR_FAVOURITE_EDITOR+'.'
59
+ # === TOOLTIP_IMAGESHACK
60
+ TOOLTIP_IMAGESHACK = 'Upload the image to Imageshack.'
61
+ DEFAULT_TEXT_FOR_ENTRY_FILE_NAME = MY_CONFREE_DIR+'output.png'
62
+ IMG = ENV['IMG'].to_s
63
+
64
+ # ========================================================================= #
65
+ # === POSSIBLE_RESOLUTIONS
66
+ # ========================================================================= #
67
+ POSSIBLE_RESOLUTIONS = [
68
+ "#{DEFAULT_WIDTH}x#{DEFAULT_HEIGHT}",
69
+ '600x300', '600x400', '640x480',
70
+ '640x640', '800x300', '800x800',
71
+ '900x400', '1000x1000', '1024x800',
72
+ '1200x860', '1280x1024', '1600x1600',
73
+ '2400x2400'
74
+ ]
75
+
76
+ # ========================================================================= #
77
+ # === initialize
78
+ # ========================================================================= #
79
+ def initialize(
80
+ i = nil,
81
+ run_already = true
82
+ )
83
+ super()
84
+ reset
85
+ set_file_location(i)
86
+ run if run_already
87
+ end
88
+
89
+ # ========================================================================= #
90
+ # === reset (reset tag)
91
+ # ========================================================================= #
92
+ def reset
93
+ @confree_generator = ConfreeGenerator.new(:batch, false)
94
+ @last_selected_file = '' # this will contain the last selected file.
95
+ @source_buffer = nil
96
+ end
97
+
98
+ # ========================================================================= #
99
+ # === set_file_location
100
+ #
101
+ # We will load this cfdg file.
102
+ # ========================================================================= #
103
+ def set_file_location(i = nil)
104
+ # Now, set a default, either if you passed no arg, or 'default':
105
+ if i.nil? or i == 'default' # default is also allowed
106
+ i = get_random_cfdg
107
+ end
108
+ i = i.to_s.dup
109
+ @file_location = i
110
+ opn; e 'The cfdg file was found at: '+sfile(i)+'.'
111
+ @cfdg_file_content = File.readlines(i) # Bundled.
112
+ end; alias set_input set_file_location # === set_input
113
+
114
+ # ========================================================================= #
115
+ # === open_random_file
116
+ #
117
+ # Open a random cfdg file here. This method will then invoke the
118
+ # method open_this_file().
119
+ # ========================================================================= #
120
+ def open_random_file
121
+ random_file = get_random_cfdg_file
122
+ e 'Loading this `'+sfile(random_file)+'` random file now.'
123
+ open_this_file(random_file)
124
+ end
125
+
126
+ # ========================================================================= #
127
+ # === open_this_file (open tag)
128
+ #
129
+ # Use this method if you want to open a .cfdg file. It will set all
130
+ # necessary stuff.
131
+ # ========================================================================= #
132
+ def open_this_file(i)
133
+ @last_selected_file = i
134
+ string = File.read(@last_selected_file)
135
+ _ = File.basename(@file_location)
136
+ set_source_buffer(string) # we set source buffer
137
+ @entry_filename.set_text(@last_selected_file)
138
+ @file_location = @last_selected_file
139
+ @label_file_name_top.set_text(_)
140
+ @label_top.set_text(_)
141
+ @entry_cfdg_file.set_text(@file_location)
142
+ update_image # as of 16.01.2008 this is also coupled with updating the image.
143
+ end
144
+
145
+ # ========================================================================= #
146
+ # === startup_application
147
+ #
148
+ # Runs all stuff
149
+ # ========================================================================= #
150
+ def startup_application
151
+ create_callbacks
152
+ create_confree_textedit
153
+ create_buttons
154
+ create_gtk_menubar
155
+ create_vboxes
156
+ set_main_image
157
+ create_gtk_entries_and_checkbox_and_combobox
158
+ create_table
159
+ open_this_file(@file_location)
160
+ connect_skeleton
161
+ run_main
162
+ end; alias run startup_application # === run
163
+
164
+ # ========================================================================= #
165
+ # === open_firefox_tab
166
+ #
167
+ # Simply opens a firefox tab.
168
+ # ========================================================================= #
169
+ def open_firefox_tab(
170
+ i = DEFAULT_TEXT_FOR_ENTRY_FILE_NAME
171
+ )
172
+ e "Opening picture #{sfile(i)}"
173
+ open_in_browser(i)
174
+ end
175
+
176
+ # ========================================================================= #
177
+ # === ui_manager?
178
+ # ========================================================================= #
179
+ def ui_manager?
180
+ @ui_manager
181
+ end; alias ui_manager ui_manager? # === ui_manager
182
+
183
+ # ========================================================================= #
184
+ # === update_image
185
+ #
186
+ # The image will be created via this method invocation.
187
+ # ========================================================================= #
188
+ def update_image
189
+ if program_exists? 'cfdg'
190
+ e "Updating @main_image now: #{sfancy(@main_image)}."
191
+ e "Saving file: #{@confree_generator.save_file}"
192
+ save_file(@source_buffer.text, @confree_generator.save_file)
193
+ @confree_generator.run_sys_cmd(@entry_width.text, @entry_height.text)
194
+ @main_image.clear
195
+ @main_image.set(DEFAULT_TEXT_FOR_ENTRY_FILE_NAME)
196
+ else
197
+ ewarn 'Sorry, the program `cfdg` could not be found. Did you install it?'
198
+ end
199
+ end
200
+
201
+ # ========================================================================= #
202
+ # === set_main_image
203
+ #
204
+ # zeigt unser image an, unser @main_image. Das ist rechter Hand zu finden.
205
+ # ========================================================================= #
206
+ def set_main_image
207
+ @main_image = Gtk::Image.new(
208
+ DEFAULT_TEXT_FOR_ENTRY_FILE_NAME
209
+ )
210
+ @image_event_box = Gtk::EventBox.new
211
+ @scrolled_window = Gtk::ScrolledWindow.new
212
+ @scrolled_window.add_with_viewport(@main_image)
213
+ @scrolled_window.set_size_request(280,280)
214
+ @image_event_box.add(@scrolled_window)
215
+ @image_event_box.signal_connect(:button_press_event) { |widget, event|
216
+ case event.button
217
+ when 1
218
+ @callback_open_file.call
219
+ when 2
220
+ open_random_file # just assign a random file on middle-click
221
+ else
222
+ @callback_open_file.call
223
+ end
224
+ }
225
+ end
226
+
227
+ # ========================================================================= #
228
+ # === create_gtk_entries_and_checkbox_and_combobox
229
+ #
230
+ # Hier legt man width und height des images fest
231
+ # entries. Zudem wird der Gtk::CheckButton definiert.
232
+ # ========================================================================= #
233
+ def create_gtk_entries_and_checkbox_and_combobox
234
+ # Der check button
235
+ @button_check_coupled = Gtk::CheckButton.new('Coupled')
236
+ @button_check_coupled.set_active(false)
237
+ @combo_box_entry = Gtk::ComboBoxEntry.new(true)
238
+ ARRAY_POSSIBLE_RESOLUTIONS.each { |val| @combo_box_entry.append_text(val) }
239
+ @combo_box_entry.active = 0
240
+ # Popup on button release
241
+ @combo_box_entry.signal_connect(:event) { |widget, event|
242
+ case event.event_type # event.event_type.name
243
+ when Gdk::Event::BUTTON_RELEASE
244
+ Thread.new { @combo_box_entry.popup }
245
+ end
246
+ }
247
+ # If combo box was changed, do sth
248
+ @combo_box_entry.signal_connect(:changed) {
249
+ if @combo_box_entry.active_iter
250
+ combined = @combo_box_entry.active_iter[0]
251
+ wid,hei = combined.split('x')
252
+ @entry_width.text = wid
253
+ @entry_height.text = hei
254
+ # also, force a decoupling again
255
+ @button_check_coupled.active = false
256
+ end
257
+ }
258
+ # Is on the top
259
+ @entry_width = Gtk::Entry.new
260
+ @entry_width.set_max_length( 7 )
261
+ @entry_width.signal_connect(:activate) { |w| enter_callback( w ) }
262
+ @entry_width.set_text( DEFAULT_WIDTH ) # DEFAULT_WIDTH is in togtk;bl CFDG/confree_shared_data.rb
263
+ @entry_width.signal_connect(:changed) { |w, event|
264
+ @entry_height.text = @entry_width.text if @button_check_coupled.active?
265
+ }
266
+ # The middle entry.
267
+ @entry_height = Gtk::Entry.new
268
+ @entry_height.set_max_length( 7 )
269
+ @entry_height.signal_connect(:activate) { |w| enter_callback( w ) }
270
+ @entry_height.set_text( DEFAULT_HEIGHT )
271
+ @entry_height.signal_connect(:changed) { |w,event|
272
+ if @button_check_coupled.active?
273
+ @entry_width.text = @entry_height.text
274
+ end
275
+ }
276
+ # entry file name contains the name of our programs
277
+ @entry_filename = Gtk::Entry.new
278
+ @entry_filename.set_max_length( 20 )
279
+ @entry_filename.signal_connect(:activate) { |w| enter_callback( w ) }
280
+ @entry_filename.set_text( @last_selected_file )
281
+ # This entry contains the output.png file name.
282
+ @entry_file_name = Gtk::Entry.new
283
+
284
+ @entry_file_name.set_text(DEFAULT_TEXT_FOR_ENTRY_FILE_NAME)
285
+ @entry_file_name.signal_connect(:button_press_event) do |widget, event|
286
+ @entry_file_name.set_focus( true )
287
+ @entry_file_name.select_region(0, -1)
288
+ end
289
+
290
+ @entry_cfdg_file = Gtk::Entry.new
291
+ @entry_cfdg_file.set_text('')
292
+ @vbox_entries_and_checkbox = Gtk::VBox.new
293
+ vbox = Gtk::VBox.new
294
+ vbox.pack_start(@entry_width,true,true,0)
295
+ vbox.pack_start(@entry_height,true,true,0)
296
+
297
+ image = Gtk::Image.new
298
+ image.set(:'gtk-preferences', Gtk::IconSize::MENU)
299
+
300
+ @event_box_for_small_icon = Gtk::EventBox.new.add(image)
301
+ @event_box_for_small_icon.signal_connect(:event) { |widget, event|
302
+ case event.event_type
303
+ when Gdk::Event::BUTTON_PRESS
304
+ @button_check_coupled.set_active(true)
305
+ end
306
+ }
307
+
308
+ hbox_with_checkbox_and_combo_box = Gtk::HBox.new
309
+ hbox_with_checkbox_and_combo_box.pack_start(vbox,true,true,0)
310
+ hbox_with_checkbox_and_combo_box.pack_start(@combo_box_entry,false,true,0)
311
+ hbox_with_checkbox_and_combo_box.pack_start(
312
+ create_paned_hbox( @button_check_coupled, @event_box_for_small_icon),true,true,0
313
+ )
314
+ @vbox_entries_and_checkbox.pack_start(hbox_with_checkbox_and_combo_box)
315
+ @vbox_entries_and_checkbox.pack_start(@entry_filename,true,true)
316
+ end
317
+
318
+ # ========================================================================= #
319
+ # === create_buttons (button tag butt tag but tag)
320
+ #
321
+ # will make our buttons. All buttons. If the update button
322
+ # is pressed, it will store a temporary file.
323
+ # ========================================================================= #
324
+ def create_buttons
325
+ @button_clear = Gtk::Button.new('_Clear')
326
+ @button_clear.signal_connect(:clicked) { clear_buffer }
327
+ @button_clear.set_image(Gtk::Image.new(Gtk::Stock::OK,
328
+ Gtk::IconSize::SMALL_TOOLBAR))
329
+
330
+ # exit tag, quit tag
331
+ @button_quit = Gtk::Button.new(Gtk::Stock::QUIT)
332
+ @button_quit.signal_connect(:clicked) { @callback_quit_application.call }
333
+
334
+ @button_debug = Gtk::Button.new('_Debug')
335
+ @button_debug.set_image Gtk::Image.new(Gtk::Stock::INFO,
336
+ Gtk::IconSize::SMALL_TOOLBAR)
337
+ @button_debug.signal_connect(:clicked) { e @source_buffer.text }
338
+
339
+ @button_open_random_file = Gtk::Button.new('_OpenRandomFile')
340
+ @button_open_random_file.set_image Gtk::Image.new(Gtk::Stock::INFO,
341
+ Gtk::IconSize::SMALL_TOOLBAR)
342
+ @button_open_random_file.signal_connect(:clicked) { open_random_file }
343
+
344
+ @button_update = Gtk::Button.new('_Update (Create Image)')
345
+ @button_update.relief = Gtk::RELIEF_HALF
346
+ @button_update.set_image(Gtk::Image.new(Gtk::Stock::REFRESH,
347
+ Gtk::IconSize::SMALL_TOOLBAR))
348
+ @button_update.signal_connect(:clicked) { update_image }
349
+ [
350
+ @button_clear,
351
+ @button_quit,
352
+ @button_debug,
353
+ @button_open_random_file,
354
+ @button_update
355
+ ].each { |button| button_modify_bg(button) }
356
+ end
357
+
358
+ # ========================================================================= #
359
+ # === create_batch_gallery
360
+ # ========================================================================= #
361
+ def create_batch_gallery
362
+ @confree_generator.run
363
+ end
364
+
365
+ # ========================================================================= #
366
+ # === width
367
+ # ========================================================================= #
368
+ def width
369
+ MAIN_WINDOW_WIDTH
370
+ end
371
+
372
+ # ========================================================================= #
373
+ # === height
374
+ # ========================================================================= #
375
+ def height
376
+ MAIN_WINDOW_HEIGHT
377
+ end
378
+
379
+ # ========================================================================= #
380
+ # === run_main
381
+ #
382
+ # also shows main window
383
+ # ========================================================================= #
384
+ def run_main
385
+ self.show_all
386
+ end
387
+
388
+ # ========================================================================= #
389
+ # === program_exists?
390
+ #
391
+ # Find out whether a program exists or not.
392
+ # ========================================================================= #
393
+ def program_exists?(this_program)
394
+ does_program_exist = false # default is false
395
+ array_available_paths = [ ENV['SYSBIN'].to_s, '/usr/bin/']
396
+ array_available_paths.each { |path|
397
+ _ = path+'/'+this_program
398
+ does_program_exist = true if File.exist? _
399
+ }
400
+ return does_program_exist
401
+ end
402
+
403
+ # ========================================================================= #
404
+ # === create_confree_textedit
405
+ #
406
+ # Entry so that the context free design can be added here.
407
+ # ========================================================================= #
408
+ def create_confree_textedit
409
+ @source_buffer = Gtk::SourceBuffer.new
410
+ @text_field = Gtk::SourceView.new(@source_buffer)
411
+ @text_field.show_line_numbers = true
412
+ # @text_field.show_line_markers = true
413
+ # @text_field.smart_home_end = true
414
+ # @text_field.tabs_width = 2
415
+ @scw = Gtk::ScrolledWindow.new
416
+ @scw.add_with_viewport(@text_field)
417
+ end
418
+
419
+ # ========================================================================= #
420
+ # === upload_image_to_imageshack
421
+ #
422
+ # Upload image to imageshack
423
+ # ========================================================================= #
424
+ def upload_image_to_imageshack
425
+ RImageshack.new(@file_location)
426
+ end
427
+
428
+ # ========================================================================= #
429
+ # === create_table (table tag, tab tag. main table.)
430
+ #
431
+ # Creates the tables.
432
+ # ========================================================================= #
433
+ def create_table
434
+ @top_table = Gtk::Table.new(1, 2, true)
435
+ @top_table.row_spacings = 1
436
+ @top_table.attach_defaults( @scw, 0,1, 0, 1)
437
+
438
+ @label_file_name_top = Gtk::Label.new
439
+ @label_file_name_top.set_text(File.basename(@file_location))
440
+
441
+ @label_top = Gtk::Label.new
442
+ @label_top.set_justify(Gtk::JUSTIFY_LEFT)
443
+ @label_top.set_text(File.basename(@file_location))
444
+
445
+ vbox_top = VBox.new
446
+ vbox_top.pack_start(@vbox_for_actions,true,true)
447
+ vbox_top.pack_start(@label_file_name_top,false,true)
448
+ hbox = create_paned_hbox(vbox_top, @image_event_box)
449
+ @top_table.attach_defaults(hbox, 1,2,0,1)
450
+
451
+ @main_table = Gtk::Table.new(4, 2, true)
452
+ @main_table.row_spacings = 0
453
+ @main_table.attach_defaults( @button_clear, 0,1, 0, 1)
454
+
455
+ hbox = HBox.new
456
+ hbox.add @button_debug
457
+ hbox.add @button_open_random_file
458
+ @main_table.attach_defaults( hbox, 0,1, 1, 2)
459
+ @main_table.attach_defaults( @button_quit, 0,1, 2, 3)
460
+ @main_table.attach_defaults( @button_update, 1,2, 0, 1)
461
+ @main_table.attach_defaults( @vbox_entries_and_checkbox,1,2, 1,2)
462
+
463
+ @event_box_for_firefox = Gtk::EventBox.new
464
+ firefox_image = Gtk::Image.new(IMG+'/FF/FIREFOX_FAVICON.png')
465
+ @event_box_for_firefox.add(firefox_image)
466
+ @event_box_for_firefox.signal_connect(:button_press_event) { open_firefox_tab }
467
+ hover_message = 'Opens a firefox tab.'
468
+ Gtk::Tooltips.new.set_tip(firefox_image, hover_message, nil)
469
+
470
+ label = modify_bold_label('ImagePath ' ,'darkblue',:left)
471
+ event_box_image_path = Gtk::EventBox.new.add(label)
472
+ event_box_image_path.signal_connect(:button_press_event) {
473
+ @entry_file_name.select_region(0, -1)
474
+ @entry_file_name.set_focus(true)
475
+ e 'Restoring to default '+DEFAULT_TEXT_FOR_ENTRY_FILE_NAME
476
+ @entry_file_name.set_text(DEFAULT_TEXT_FOR_ENTRY_FILE_NAME) # restore to default again.
477
+ }
478
+
479
+ hbox_tiny = create_paned_hbox(
480
+ event_box_image_path,
481
+ @event_box_for_firefox
482
+ )
483
+
484
+ image_bluefish = Gtk::Image.new
485
+ image_bluefish.set( Gdk::Pixbuf.new(
486
+ IMG+'/PC/EDITORS/BLUEFISH/BLUEFISH.png', 25,25 )
487
+ )
488
+ event_box = Gtk::EventBox.new
489
+ event_box.add(image_bluefish)
490
+
491
+ Gtk::Tooltips.new.set_tip(event_box, TOOLTIP_EDITOR, nil)
492
+ event_box.signal_connect(:event) { |widget, event|
493
+ case event.event_type # event.event_type.name
494
+ when Gdk::Event::BUTTON_PRESS
495
+ open_file_in_editor
496
+ end
497
+ }
498
+ _ = IMG+'/PC/IMAGESHACK/IMAGESHACK_FAVICON.png' # cd $IMG/PC/IMAGESHACK/IMAGESHACK_FAVICON.png
499
+ if File.exist? _
500
+ image_rshack = Gtk::Image.new
501
+ pixbuf = Gdk::Pixbuf.new(_, 25, 25)
502
+ image_rshack.set(pixbuf)
503
+ event_box_with_imageshack = Gtk::EventBox.new
504
+ event_box_with_imageshack.add(image_rshack)
505
+ Gtk::Tooltips.new.set_tip(event_box_with_imageshack, TOOLTIP_IMAGESHACK, nil)
506
+ event_box_with_imageshack.signal_connect(:event) { |widget, event|
507
+ case event.event_type
508
+ when Gdk::Event::BUTTON_PRESS then upload_image_to_imageshack
509
+ end
510
+ }
511
+ vbox = create_paned_vbox(
512
+ hbox_tiny, @entry_file_name,
513
+ create_paned_hbox(@entry_cfdg_file, event_box, event_box_with_imageshack)
514
+ )
515
+ # Hier der label zum Pfad
516
+ @main_table.attach_defaults(vbox,1,2,2,3)
517
+ end
518
+ end
519
+
520
+ # ========================================================================= #
521
+ # === create_gtk_menubar (menu tag)
522
+ #
523
+ # Makes the menu bar.
524
+ # ========================================================================= #
525
+ def create_gtk_menubar
526
+
527
+ @menu_ui_design = %Q[
528
+ <ui>
529
+ <menubar name='MenuBar'>
530
+ <menu action='FileMenu'>
531
+ <separator/>
532
+ <menuitem action='Open'/>
533
+ <menuitem action='OpenRandomFile'/>
534
+ <menuitem action='Save'/>
535
+ <menuitem action='New'/>
536
+ <separator/>
537
+ <menuitem action='Quit'/>
538
+ <separator/>
539
+ </menu>
540
+ <menu action='FileMenu2'>
541
+ <separator/>
542
+ <menuitem action='Scramble'/>
543
+ <separator/>
544
+ </menu>
545
+ <menu action='FileMenu3'>
546
+ <separator/>
547
+ <menuitem action='BatchMode'/>
548
+ <separator/>
549
+ </menu>
550
+ </menubar>
551
+ </ui>
552
+ ]
553
+
554
+ @menu_actions = [
555
+ [ 'FileMenu', nil, '_File'],
556
+ # der 4. parameter is leider nil, ansonsten nämlich kann
557
+ # man nit mehr ordentlich schreiben
558
+ [ 'Open', Gtk::Stock::OPEN, '_Open File', nil, 'Open', @callback_open_file ],
559
+ [ 'OpenRandomFile', Gtk::Stock::OPEN, 'Open _Random File', '<Control>r', 'OpenRandomFile', @callback_open_random_file ],
560
+ [ 'Save', Gtk::Stock::SAVE, '_Save', nil, 'Save', @callback_save_file ],
561
+ [ 'Quit', Gtk::Stock::QUIT, '_Quit', nil, 'Quit', @callback_quit_application ],
562
+ [ 'New', Gtk::Stock::NEW, '_New', nil, 'Create a new file', @callback_create_new_file ]
563
+ ]
564
+
565
+ @action_group = Gtk::ActionGroup.new('Actions')
566
+ @action_group.add_actions( @menu_actions )
567
+
568
+ @menu_actions2 = [
569
+ [ 'FileMenu2', nil, '_Scramble' ],
570
+ # der 4. parameter is leider nil, ansonsten nämlich kann
571
+ # man nit mehr ordentlich schreiben
572
+ [ 'Scramble', Gtk::Stock::NO,
573
+ '_Scramble Large', nil, 'Scramble', @callback_scramble_image ]
574
+ ]
575
+ @action_group.add_actions(@menu_actions2)
576
+ @menu_actions3 = [
577
+ [ 'FileMenu3', nil, '_OtherActions' ],
578
+ [ 'BatchMode', Gtk::Stock::REFRESH,'_BatchMode', nil, 'BatchMode allows you to create a gallery
579
+ without questions answered etc...', @callback_create_batch_gallery ]
580
+ ]
581
+ @action_group.add_actions(@menu_actions3)
582
+
583
+ @ui_manager = Gtk::UIManager.new
584
+ @ui_manager.insert_action_group(@action_group, 0)
585
+ @ui_manager.add_ui(@menu_ui_design)
586
+ @ui_manager.add_tearoffs = true
587
+ end
588
+
589
+ # ========================================================================= #
590
+ # === open_file_in_editor
591
+ # This method opens the cfdg file in your designated editor.
592
+ # ========================================================================= #
593
+ def open_file_in_editor
594
+ _ = YOUR_FAVOURITE_EDITOR+ ' '+@file_location
595
+ esystem _
596
+ end
597
+
598
+ # ========================================================================= #
599
+ # === create_callbacks
600
+ #
601
+ # Creates the callback objects.
602
+ # ========================================================================= #
603
+ def create_callbacks
604
+ @callback_create_new_file = Proc.new { |actiongroup, action|
605
+ e "`#{action.name}' new file created. "
606
+ }
607
+ @callback_quit_application = Proc.new { Gtk.main_quit }
608
+ @callback_scramble_image = Proc.new { scramble_image }
609
+ @callback_create_batch_gallery = Proc.new { create_batch_gallery }
610
+ @callback_open_random_file = Proc.new { open_random_file }
611
+ @callback_save_file = Proc.new { save_file }
612
+ # ======================================================================= #
613
+ # Here we decide what will happen when we open a new file. (File Dialog)
614
+ # ======================================================================= #
615
+ @callback_open_file = Proc.new { |actiongroup, action|
616
+ @file_chooser_dialog = Gtk::FileChooserDialog.new('Open File',
617
+ nil, Gtk::FileChooser::ACTION_OPEN, nil,
618
+ [ Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
619
+ [ Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT] )
620
+ # @file_chooser_dialog.show_hidden=true
621
+ @file_chooser_dialog.add_shortcut_folder( ENV['CFDG'] )
622
+ @file_chooser_dialog.add_shortcut_folder( IMG )
623
+ @file_filter = Gtk::FileFilter.new
624
+ @file_filter.name = 'CFDG Filter'
625
+ @file_filter.add_pattern '*.cfdg'
626
+ @file_chooser_dialog.add_filter(@file_filter)
627
+ @file_chooser_dialog.current_folder = CFDG_DIRECTORY
628
+ if @file_chooser_dialog.run == Gtk::Dialog::RESPONSE_ACCEPT
629
+ _ = @file_chooser_dialog.filename
630
+ e " filename = #{_}"
631
+ open_this_file(_)
632
+ end
633
+ @file_chooser_dialog.destroy
634
+ }
635
+ end
636
+
637
+ # ========================================================================= #
638
+ # === scramble_image
639
+ #
640
+ # Scrambles your image
641
+ # ========================================================================= #
642
+ def scramble_image
643
+ _ = @source_buffer.text.dup
644
+ _.gsub!(/260/,'268')
645
+ _.gsub!(/100/,'105')
646
+ _.gsub!(/110/,'115')
647
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
648
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
649
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
650
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
651
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
652
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
653
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
654
+ _.gsub!(/#{rand(300)}/,"#{rand(300)}")
655
+ _.gsub!(/90/,(95+rand(60)).to_s)
656
+ _.gsub!(/80/,(85+rand(50)).to_s)
657
+ _.gsub!(/70/,(70+rand(40)).to_s)
658
+ set_source_buffer(_)
659
+ end
660
+
661
+ # ========================================================================= #
662
+ # === create_vboxes
663
+ #
664
+ # This method creates the vbox and the box for our action buttons (filled
665
+ # with InsertButtons.)
666
+ #
667
+ # The InsertButton class can be found in the file insert_button.rb
668
+ # ========================================================================= #
669
+ def create_vboxes
670
+ @v_box = Gtk::VBox.new
671
+ @v_box.show
672
+ @vbox_for_actions = Gtk::VBox.new
673
+ @vbox_for_actions.pack_start InsertButton.new(:comment, self),false,false,0
674
+ @vbox_for_actions.pack_start InsertButton.new(:background, self),false,false,0
675
+ @vbox_for_actions.pack_start InsertButton.new(:square, self),false,false,0
676
+ @vbox_for_actions.pack_start InsertButton.new(:triangle, self),false,false,0
677
+ @vbox_for_actions.pack_start InsertButton.new(:line, self),false,true,0
678
+ @vbox_for_actions.pack_start InsertButton.new(:rect, self),false,true,0
679
+ @vbox_for_actions.pack_start InsertButton.new(:circle, self),false,true,0
680
+ @vbox_for_actions.pack_start InsertButton.new(:hue, self),false,true,0
681
+ @vbox_for_actions.pack_start InsertButton.new(:sat, self),false,true,0
682
+ @vbox_for_actions.pack_start InsertButton.new(:b, self),false,true,0
683
+ @vbox_for_actions.pack_start InsertButton.new(:n, self),false,true,0
684
+ @vbox_for_actions.show
685
+ end
686
+
687
+ # ========================================================================= #
688
+ # === set_source_buffer
689
+ #
690
+ # This simply sets the source buffer.
691
+ # ========================================================================= #
692
+ def set_source_buffer(i = '')
693
+ @source_buffer.text = i
694
+ end
695
+
696
+ # ========================================================================= #
697
+ # === button_modify_bg
698
+ #
699
+ # Modifies a button, i.e. background stuff, mouseover event.
700
+ # ========================================================================= #
701
+ def button_modify_bg(i)
702
+ i.modify_bg( Gtk::StateType::NORMAL, CADETBLUE )
703
+ i.modify_bg( Gtk::StateType::ACTIVE, BROWN )
704
+ i.modify_bg( Gtk::StateType::PRELIGHT, BISQUE )
705
+ end
706
+
707
+ # ========================================================================= #
708
+ # === clear_buffer
709
+ #
710
+ # This method clears the buffer.
711
+ # ========================================================================= #
712
+ def clear_buffer
713
+ @source_buffer.text = ''
714
+ end
715
+
716
+ # ========================================================================= #
717
+ # === connect_skeleton
718
+ #
719
+ # glues the parts together. glue tag.
720
+ # ========================================================================= #
721
+ def connect_skeleton
722
+ @v_box.pack_start( @ui_manager['/MenuBar'], false, false ) # das Menü
723
+ @v_box.pack_start( @label_top, false, false, 0 )
724
+ @v_box.pack_start( @top_table,false )
725
+ @v_box.pack_start( Gtk::HSeparator.new, false, false, 0)
726
+ @v_box.pack_start( @main_table,false ) # mit den buttons, unten.
727
+ add(@v_box)
728
+ end
729
+
730
+ end; end; end
731
+
732
+ if __FILE__ == $PROGRAM_NAME
733
+ confree_generator = ImageParadise::ConfreeGenerator::GtkConfreeGenerator.new(
734
+ ARGV.first
735
+ )
736
+ r = Gtk.run(
737
+ confree_generator.width,
738
+ confree_generator.height,
739
+ '/Users/x/DATA/IMG/ART/NEURONAL_HAND.png',
740
+ 'Confree Design',4
741
+ )
742
+ # r.add_accel_group( gtk_confree_generator.ui_manager.accel_group )
743
+ # ^^^ the above does not work.
744
+ r << confree_generator
745
+ r.top_left
746
+ r.run
747
+ end # gtkconfree
748
+ # =========================================================================== #
749
+ # The first is batch mode, the second is GUI mode.
750
+ # rconfree b
751
+ # rconfree
752
+ # =========================================================================== #