Module: PdfParadise::GUI::Gtk::SplitPdfFileModule

Includes:
Gtk::BaseModule
Included in:
SplitPdfFile
Defined in:
lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
'Split .pdf files'
WIDTH =
#

WIDTH

#
1400
HEIGHT =
#

HEIGHT

#
700
ARRAY_ADD_THESE_SHORTCUT_FOLDERS =
#

ARRAY_ADD_THESE_SHORTCUT_FOLDERS

#
[
#  "C:\\",
#  "C:\\ingrid",
#  '/ingrid'
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.runObject

#

PdfParadise::GUI::Gtk::SplitPdfFileModule.run

#


282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 282

def self.run
  require 'gtk_paradise/run'
  _ = ::PdfParadise::GUI::Gtk::SplitPdfFile.new
  r = ::Gtk.run
  r << _
  r.set_size_request(
    _.width?,
    _.height?
  )
  r.enable_quick_exit
  r.top_left_then_run
end

Instance Method Details

#add_the_split_pdf_file_buttonObject

#

add_the_split_pdf_file_button

#


100
101
102
103
104
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 100

def add_the_split_pdf_file_button
  minimal(
    @button_split_the_pdf_file, 2
  )
end

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


116
117
118
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 116

def border_size?
  2
end

#connect_skeletonObject

#

connect_skeleton

#


236
237
238
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 236

def connect_skeleton
  abort_on_exception
end

#create_buttonsObject

#

create_buttons (buttons tag)

This method can be used to create all buttons in this small application.

#


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 152

def create_buttons
  @button_file_chooser = create_button('Choose a file')
  @button_file_chooser.on_hover(:lightgreen)
  @button_file_chooser.on_clicked {
    open_file_chooser_dialog
  }
  @button_file_chooser.fancy_tooltip = 'Select this to <b>choose</b> '\
    ' a local .pdf file.'
  @button_split_the_pdf_file = create_button('_Split the pdf file')
  @button_split_the_pdf_file.clear_background
  @button_split_the_pdf_file.on_hover(:lightgreen)
  @button_split_the_pdf_file.hint =
    'Click on this button to actually <b>split the .pdf file</b> at hand.'
  @button_split_the_pdf_file.on_clicked {
    do_split_the_pdf_file
  }
end

#create_skeletonObject

#

create_skeleton

#


123
124
125
126
127
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 123

def create_skeleton
  @hbox1 = create_vbox
  create_buttons
  create_the_entries
end

#create_the_entriesObject

#

create_the_entries (entries tag)

#


132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 132

def create_the_entries
  @entry_for_the_path_to_the_pdf_file = create_entry('')
  @entry_for_the_path_to_the_pdf_file.on_click_event {
    :highlight_text
  }
  # ======================================================================= #
  # Determine where the individual .pdf files are to be kept:
  # ======================================================================= #
  _ = return_pwd
  _ = '/Depot/j/'.dup if File.directory? '/Depot/j/'
  @entry_for_the_directory_where_we_will_generate_the_individual_pdf_files_into = gtk_entry(
    _
  )
end

#do_split_the_pdf_fileObject

#

do_split_the_pdf_file (split tag)

This is the main action of this class.

#


175
176
177
178
179
180
181
182
183
184
185
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 175

def do_split_the_pdf_file
  target_file = @entry_for_the_path_to_the_pdf_file.text?
  if File.exist?(target_file)
    e 'Now splitting the .pdf file'
    PdfParadise.split_this_pdf_file(
      target_file, :default, store_in_which_directory?
    )
  else
    e 'No file was found at the location '+target_file+'.'
  end
end

#initialize(optional_file = nil, run_already = true) ⇒ Object

#

initialize

#


63
64
65
66
67
68
69
70
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 63

def initialize(
    optional_file = nil,
    run_already   = true
  )
  super(:vertical)
  reset
  run if run_already
end

#open_file_chooser_dialogObject

#

open_file_chooser_dialog

#


199
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
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 199

def open_file_chooser_dialog
  @file_chooser_dialog = create_file_chooser_dialog('Open File',
    self,
    ::Gtk::FileChooser::ACTION_OPEN, nil,
   [::Gtk::Stock::CANCEL, ::Gtk::Dialog::RESPONSE_CANCEL],
   [::Gtk::Stock::OPEN,   ::Gtk::Dialog::RESPONSE_ACCEPT]
  )
  if File.directory? '/Depot/j/'
    @file_chooser_dialog.current_folder = '/Depot/j/'
  else
    @file_chooser_dialog.current_folder = return_pwd
  end
  # @file_chooser_dialog.add_shortcut_folder(return_pwd)
  # ^^^ already exists as shortcut.
  begin
    ARRAY_ADD_THESE_SHORTCUT_FOLDERS.each {|this_directory|
      @file_chooser_dialog.add_shortcut_folder(this_directory)
    }
  rescue; end
  if File.directory? '/home/Temp/'
    @file_chooser_dialog.add_directory('/home/Temp/')
  end
  @file_chooser_dialog.show_hidden = true # Do show hidden files.
  @extra_button = create_button('_Extra button')
  @extra_button.signal_connect(:clicked) { e ' > Extra button was clicked' }
  @file_chooser_dialog.extra_widget = @extra_button
  case @file_chooser_dialog.run
  when ::Gtk::Dialog::RESPONSE_ACCEPT 
    filename = @file_chooser_dialog.filename.to_s
    @entry_for_the_path_to_the_pdf_file.set_text(filename)
  end
  @file_chooser_dialog.destroy
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


109
110
111
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 109

def padding?
  2
end

#resetObject

#

reset

#


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 75

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  set_use_this_font(:dejavu_condensed_24)
  # ======================================================================= #
  # === @title
  # ======================================================================= #
  @title  = TITLE
  # ======================================================================= #
  # === @width
  # ======================================================================= #
  set_width(WIDTH)
  # ======================================================================= #
  # === @height
  # ======================================================================= #
  set_height(HEIGHT)
  use_project_css_file
end

#runObject

#

run

#


243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 243

def run
  create_skeleton
  connect_skeleton
  gtk_text_for_the_gtk_entry_denoting_into_which_directory_we_will_generate_the_pdf_files = gtk_label(
    'Set the path to the directory where these .pdf files will be kept below:'
  )
  gtk_text = create_label(
    'Set the path to the .pdf file below this text.'
  ) {{
    tooltip: 'You need to supply the path to the .pdf file '\
             'into the input field on the right side.'
  }}
  @hbox1.minimal(gtk_text)
  @hbox1.maximal(@entry_for_the_path_to_the_pdf_file)
  # ======================================================================= #
  # And add the file-chooser button:
  # ======================================================================= #
  @hbox1.minimal(@button_file_chooser)
  maximal(@hbox1, 1)

  @vbox_denoting_where_the_individual_pdf_files_are_kept = gtk_vbox
  @vbox_denoting_where_the_individual_pdf_files_are_kept.minimal(
    gtk_text_for_the_gtk_entry_denoting_into_which_directory_we_will_generate_the_pdf_files,
    1
  )
  @vbox_denoting_where_the_individual_pdf_files_are_kept.minimal(
    @entry_for_the_directory_where_we_will_generate_the_individual_pdf_files_into,
    1
  )
  minimal(
    @vbox_denoting_where_the_individual_pdf_files_are_kept, 0
  )
  add_the_split_pdf_file_button
  show_all
end

#store_in_which_directory?Boolean

#

store_in_which_directory?

This method must return a String, hence why the method .text is used.

#

Returns:

  • (Boolean)


192
193
194
# File 'lib/pdf_paradise/gui/shared_code/split_pdf_file/split_pdf_file_module.rb', line 192

def store_in_which_directory?
  @entry_for_the_directory_where_we_will_generate_the_individual_pdf_files_into.text
end