Class: PdfParadise::GUI::UniversalWidgets::ToPDF

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

Overview

PdfParadise::GUI::UniversalWidgets::ToPDF

Constant Summary collapse

TITLE =
#

TITLE

#
'Convert to .pdf'
FONT_SIZE =
#

FONT_SIZE

#
18
USE_THIS_FONT =
#

USE_THIS_FONT

#
:hack_28
WIDTH =
#

WIDTH

#
'95% or minimum 1820px'
HEIGHT =
#

HEIGHT

#
'35% or minimum 840px'
LARGER_FONT =
#

LARGER_FONT

#
:hack_24
SMALLER_FONT =
#

SMALLER_FONT

#
:hack_28

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) ⇒ ToPDF

#

initialize

#


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 71

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
  )
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

PdfParadise::GUI::UniversalWidgets::ToPDF[]

#


343
344
345
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 343

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

.run(i = ARGV) ⇒ Object

#

PdfParadise::GUI::Gtk::ToPDF.run

#


327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 327

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::PdfParadise::GUI::Gtk::ToPDF.new(i)
  r = ::Gtk.run
  r << _
  r.automatic_size
  r.automatic_title
  r.easy_exit
  r.top_left_then_run
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


275
276
277
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 275

def border_size?
  8
end

#connect_the_skeletonObject

#

connect_the_skeleton (connect tag)

#


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 126

def connect_the_skeleton
  abort_on_exception

  chdir('/Depot/j/') if File.directory? '/Depot/j/'

  outer_vbox = create_vbox
  
  text1 = label('Input the filename that you wish to convert here:')
  text1.make_selectable
  text1.deselect
  outer_vbox.minimal(
    text1, 1
  )
  outer_vbox.minimal(@entry_filename, 1)
  outer_vbox.minimal(@button_choose_file, 1)
  small_hbox = create_hbox
  small_hbox.minimal(@button_do_convert)
  small_hbox.hcenter
  outer_vbox.minimal(small_hbox,  1)
  hbox = create_hbox
  hbox.maximal(@statusbar, 1)
  hbox.minimal(@button_open_the_converted_file, 1)
  outer_vbox.minimal(hbox)
  @text_buffer = create_text_buffer
  @text_view = create_text_view(@text_buffer)
  @scrolled_window = create_scrolled_window(@text_view) { :top_to_bottom }
  @scrolled_window.bblack1
  @scrolled_window.css_class('pad4px')
  @scrolled_window.width_height(500, 400)
  outer_vbox.minimal(@scrolled_window)

  window = create_window_or_runner(
    widget: outer_vbox,
    width:  width?,
    height: height?,
    title:  title?,
    font:   font?
  )

  window.set_padding(padding?)
  window.set_border_size(border_size?)
  window.show_all
  do_style_all_buttons_in_a_uniform_manner
  do_jump_into_the_scrolled_window
  run_main
end

#create_the_buttonsObject

#

create_the_buttons (buttons tag, button tag)

#


200
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
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 200

def create_the_buttons
  # ======================================================================= #
  # === @button_do_convert
  # ======================================================================= #
  @button_do_convert = button('_Convert it to .pdf format') {
    :do_convert_the_given_file
  }
  #@button_do_convert.disallow_resizing
  @button_do_convert.css_class('clear_background')
  @button_do_convert.on_hover(:steelblue)
  @button_do_convert.css_class('BG_lightblue')
  @button_do_convert.pad5px
  @button_do_convert.hint = 'This will use libreoffice '\
    'to convert the file at hand into a <b>.pdf file</b>.'
  # ======================================================================= #
  # === @button_choose_file                                      (open tag)
  #
  # This is the "Open File" button.
  # ======================================================================= #
  @button_choose_file = create_file_chooser_button
  @button_choose_file.on_clicked {
    create_a_new_file_chooser_dialog
    main_entry?.set_text(main_file?.to_s)
  }
  # ======================================================================= #
  # === @button_open_the_converted_file
  # ======================================================================= #
  @button_open_the_converted_file = create_button('_Open the converted file')
  @button_open_the_converted_file.hint = 'Click to open the '\
    'converted file via main .pdf reader.'
  @button_open_the_converted_file.on_clicked {
    do_open_the_converted_file_via_a_pdf_reader
  }
end

#create_the_entry_filenameObject

#

create_the_entry_filename

#


245
246
247
248
249
250
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 245

def create_the_entry_filename
  @entry_filename = create_entry
  @entry_filename.clear_background
  @entry_filename.bblack1
  @entry_filename.yellow_background
end

#create_the_skeletonObject

#

create_skeleton (create tag, skeleton tag)

#


117
118
119
120
121
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 117

def create_the_skeleton
  create_the_buttons
  create_the_statusbar
  create_the_entry_filename
end

#create_the_statusbarObject

#

create_the_statusbar

#


109
110
111
112
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 109

def create_the_statusbar
  @statusbar = gtk_statusbar_with_handle
  @status_bar_context_id = @statusbar.get_context_id('to_pdf')
end

#do_convert_the_given_fileObject

#

do_convert_the_given_file

This is the method that will convert the target file into the .pdf file, usually by using “soffice”.

#


299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 299

def do_convert_the_given_file
  _ = stored_where?
  @statusbar.display(
    'Stored the file at: '+_, :default, @status_bar_context_id
  ) if File.exist? _
  # ======================================================================= #
  # Read in the .pdf file if it exists and if the PDF::Reader namespace
  # exists.
  # ======================================================================= #
  if File.exist?(_) and
     Object.const_defined?(:PDF) and PDF.const_defined?(:Reader)
    reader = PDF::Reader.new(_)
    page   = reader.page(1)
    use_this_text = page.text.to_s
    @scrolled_window.set_text(use_this_text.to_s)
  end
end

#do_jump_into_the_scrolled_windowObject

#

do_jump_into_the_scrolled_window

#


176
177
178
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 176

def do_jump_into_the_scrolled_window
  @scrolled_window.do_focus
end

#do_open_the_converted_file_via_a_pdf_reader(stored_here = stored_where? ) ⇒ Object

#

do_open_the_converted_file_via_a_pdf_reader

#


255
256
257
258
259
260
261
262
263
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 255

def do_open_the_converted_file_via_a_pdf_reader(
    stored_here = stored_where?
  )
  if File.exist? stored_here
    esystem "evince #{stored_here}"
  else
    e 'No file exists at '+sfile(stored_here)+'.'
  end
end

#do_style_all_buttons_in_a_uniform_mannerObject

#

do_style_all_buttons_in_a_uniform_manner

#


183
184
185
186
187
188
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 183

def do_style_all_buttons_in_a_uniform_manner
  return_all_buttons.each {|entry|
    entry.bblack2
    entry.pad5px
  }
end

#entry_filename?Boolean Also known as: main_entry?

#

entry_filename?

#

Returns:

  • (Boolean)


238
239
240
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 238

def entry_filename?
  @entry_filename
end

#favicon?Boolean

#

favicon?

#

Returns:

  • (Boolean)


193
194
195
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 193

def favicon?
  :tabble
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


268
269
270
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 268

def padding?
  4
end

#resetObject

#

reset (reset tag)

#


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 86

def reset
  super() if respond_to?(:super)
  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?
    append_project_css_file 
    use_gtk_paradise_project_css_file
  end  
  infer_the_size_automatically
end

#runObject

#

run (run tag)

#


320
321
322
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 320

def run
  run_super
end

#stored_where?(i = @entry_filename.text?) ⇒ Boolean

#

stored_where?

#

Returns:

  • (Boolean)


282
283
284
285
286
287
288
289
290
291
# File 'lib/pdf_paradise/gui/universal_widgets/to_pdf/to_pdf.rb', line 282

def stored_where?(
    i = @entry_filename.text?
  )
  _ = PdfParadise.to_pdf(i)
  _ = _.dup
  _ = _.join(' ').strip if _.is_a? Array
  _.delete_suffix!(File.extname(i))
  _ << '.pdf' unless _.end_with? '.pdf' 
  return _.to_s
end