Class: PdfParadise::GUI::UniversalWidgets::ConvertPdfToText

Inherits:
Base
  • Object
show all
Includes:
UniversalWidgets::BaseModule
Defined in:
lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb

Overview

PdfParadise::GUI::UniversalWidgets::ConvertPdfToText

Constant Summary collapse

TITLE =
#

TITLE

#
'Convert .pdf to text-file'
WIDTH =
#

WIDTH

#
'60% or minimum 1340px'
HEIGHT =
#

HEIGHT

#
'30% or minimum 880px'
USE_THIS_FONT =
#

USE_THIS_FONT

#
:hack_23
LARGER_FONT =
#

LARGER_FONT

#
:hack_25
SMALLER_FONT =
#

SMALLER_FONT

#
:hack_20

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#basename, #be_verbose?, #change_directory, #commandline_arguments?, #copy_file, #delete_file, #e, #ecomment, #esystem, #first_argument?, #gold, #infer_the_namespace, #input_without_leading_hyphens?, #internal_hash?, #is_an_image_file?, #is_on_roebe?, #lightsteelblue, #log_dir?, #mkdir, #mv, #n_pages?, #namespace?, #no_file_at, #opne, #opnn, #orange, #reset_the_internal_hash, #return_commandline_arguments_starting_with_hyphens, #return_files_from_the_commandline_arguments, #return_pwd, #rev, #set_be_quiet, #set_commandline_arguments, #steelblue, #try_to_ensure_that_this_directory_exists, #write_what_into

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ ConvertPdfToText

#

initialize

#


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 62

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  determine_the_GUI_to_be_used(commandline_arguments) # This must come first, even before reset().
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  on_delete_event_quit_the_application
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

PdfParadise::GUI::UniversalWidgets::ConvertPdfToText[]

#


358
359
360
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 358

def self.[](i = ARGV)
  new(i)
end

.run(i = ARGV) ⇒ Object

#

PdfParadise::GUI::UniversalWidgets::ConvertPdfToText.run

#


340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 340

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::PdfParadise::GUI::Gtk::ConvertPdfToText.new(i)
  r = ::Gtk.run
  _.set_parent_widget(r) # Must come before we enable the key-combinations.
  r << _
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.set_background :white
  r.maximize
  r.top_left_then_run
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


137
138
139
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 137

def border_size?
  2
end

#connect_the_skeletonObject

#

connect_the_skeleton (connect tag)

#


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 201

def connect_the_skeleton
  abort_on_exception

  outer_vbox = create_vbox

  hbox = create_hbox
  hbox.minimal(
    text('Convert this <b>.pdf</b> file to text:'), 4
  )
  hbox.minimal(@entry_convert_pdf_to_text,      5)
  hbox.minimal(return_the_open_pdf_file_button, 4)
  outer_vbox.minimal(hbox, 2)
  tiny_hbox = create_hbox
  tiny_hbox.minimal(@button_do_the_conversion, 10)
  outer_vbox.minimal(tiny_hbox, 2)
  outer_vbox.minimal(@scrolled_window,         5)

  window = create_window_or_runner(nil, width?, height?, title?)
  window << outer_vbox

  properly_prepare_this_window(window,
    {
      title:       title?,
      font:        font?,
      width:       width?,
      height:      height?,
      padding:     padding?,
      border_size: border_size?
    }
  )
  window.show_all
  window.top_left
  do_all_startup_related_actions
  run_main
end

#create_the_buttonsObject

#

create_the_buttons (buttons tag, button tag)

#


306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 306

def create_the_buttons
  # ======================================================================= #
  # === Create the open-file-button
  # ======================================================================= #
  @button_open_pdf_file = create_button('_Open File', self, :use_mnemonics) {
    :do_open_a_local_pdf_file
  }
  @button_open_pdf_file.pad5px
  @button_open_pdf_file.hint = 'Click on this button '\
    'in order to open a local .pdf file.'
  # ======================================================================= #
  # === button_do_the_conversion
  # ======================================================================= #
  @button_do_the_conversion = create_button('_Convert', self, :use_mnemonics) {
    :do_the_conversion
  }
  @button_do_the_conversion.clear_background
  @button_do_the_conversion.on_hover(:lightblue)
  @button_do_the_conversion.bblack1
  @button_do_the_conversion.pad5px
  @button_do_the_conversion.hint = 'Click this button '\
    'to <b>convert the .pdf file into a text-file</b>.'
end

#create_the_entryObject

#

create_the_entry

#


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 256

def create_the_entry
  # ======================================================================= #
  # === @entry_convert_pdf_to_text
  # ======================================================================= #
  @entry_convert_pdf_to_text = create_entry
  @entry_convert_pdf_to_text.width_height(600, 42)
  @entry_convert_pdf_to_text.yellow_background
  @entry_convert_pdf_to_text.set_text(
    '/Depot/PDF/foobar.pdf'
  )
  @entry_convert_pdf_to_text.enable_scroll_events
  # ======================================================================= #
  # Let this entry respond to mouse-scroll-events, e. g. the user does
  # some scrolling via the mouse-wheel.
  # ======================================================================= #
  @entry_convert_pdf_to_text.on_mouse_scroll_event {|widget, event|
    this_file = @entry_convert_pdf_to_text.text?
    base_dir = "#{File.dirname(this_file)}/"
    array_pdf_entries = Dir[base_dir+'*.pdf']
    # ===================================================================== #
    # Next, determine the position.
    # ===================================================================== #
    index = array_pdf_entries.index(this_file)
    if index
      if scroll_up?(event) # Scroll up.
        index -= 1 unless index == 0
      elsif scroll_down?(event) # Scroll down.
        index += 1 unless index >= (array_pdf_entries.size - 1)
      end
      this_file = array_pdf_entries[index]
      @entry_convert_pdf_to_text.set_text(this_file)
    end
  }
end

#create_the_scrolled_window_with_the_text_bufferObject

#

create_the_scrolled_window_with_the_text_buffer

#


295
296
297
298
299
300
301
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 295

def create_the_scrolled_window_with_the_text_buffer
  @text_buffer = create_text_buffer
  text_view    = create_text_view(@text_buffer)
  @scrolled_window = create_scrolled_window(text_view) { :always }
  @scrolled_window.width_height(600, 560)
  @scrolled_window.bblack1
end

#create_the_skeletonObject

#

create_the_skeleton (create tag, skeleton tag)

#


240
241
242
243
244
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 240

def create_the_skeleton
  create_the_entry
  create_the_buttons
  create_the_scrolled_window_with_the_text_buffer
end
#
#


195
196
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 195

def do_all_startup_related_actions
end

#do_open_a_local_pdf_fileObject

#

do_open_a_local_pdf_file

#


144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 144

def do_open_a_local_pdf_file
  # ======================================================================= #
  # Create the particular file-chooser widget that we wish to use.
  # ======================================================================= #
  create_a_new_file_chooser_dialog(self) {{
    start_dir:               return_pwd,
    filter_for:              :pdf_files,
    additional_directories:  '/Depot/PDF/'
  }}
  _ = ::Gtk.main_file?
  set_filepath(_)
  do_the_conversion
end

#do_the_conversionObject

#

do_the_conversion (conversion tag, convert tag)

This is the method that will do the actual conversion.

#


170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 170

def do_the_conversion
  _ = @entry_convert_pdf_to_text.text?
  if _ and File.exist?(_)
    result = PdfParadise::ConvertPdfToText.new(_)
    output_file = result.output_file?
    if File.exist?(output_file)
      # =================================================================== #
      # Assign it as the new text-buffer next:
      # =================================================================== #
      @text_buffer.set_text(
        File.read(output_file, encoding: 'UTF-8').to_s
      )
    end
  else
    popover(
      'Please specify a local, existing .pdf file.',
      use_this_widget: @entry_convert_pdf_to_text,
      font_to_use: :hack_20
    ).popup
  end
end

#handle_CSS_rulesObject

#

handle_CSS_rules (CSS tag)

#


108
109
110
111
112
113
114
115
116
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 108

def handle_CSS_rules
  use_gtk_paradise_project_css_file
  append_project_css_file
  more_CSS_then_apply_it '

.small_border { border: 2px solid steelblue; }

'
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


130
131
132
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 130

def padding?
  2
end

#resetObject

#

reset (reset tag)

#


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 78

def reset
  super() if respond_to?(:super)
  reset_the_shared_module # This can come early.
  reset_the_base_module
  reset_the_internal_variables
  infer_the_namespace
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, namespace?]
  # ======================================================================= #
  # === Set the title, width, height and the font in use.
  # ======================================================================= #
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  if use_gtk3?
    handle_CSS_rules
  end
  infer_the_size_automatically
end

#reset_the_shared_moduleObject

#

reset_the_shared_module

This method can be used for ruby-gtk3 and ruby-libui, among other toolkits.

#


124
125
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 124

def reset_the_shared_module
end

#return_the_open_pdf_file_buttonObject

#

return_the_open_pdf_file_button

#


249
250
251
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 249

def return_the_open_pdf_file_button
  @button_open_pdf_file
end

#runObject

#

run (run tag)

#


333
334
335
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 333

def run
  run_super
end

#set_filepath(i) ⇒ Object

#

set_filepath

#


161
162
163
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 161

def set_filepath(i)
  @entry_convert_pdf_to_text.set_text(i.to_s)
end

#smaller_font?Boolean

#

smaller_font?

#

Returns:

  • (Boolean)


101
102
103
# File 'lib/pdf_paradise/gui/universal_widgets/convert_pdf_to_text/convert_pdf_to_text.rb', line 101

def smaller_font?
  SMALLER_FONT
end