Class: PdfParadise::GUI::LibUI::RemoveTheFirstPageOfThisPdfFile

Inherits:
Object
  • Object
show all
Includes:
LibuiParadise::Extensions, RemoveTheFirstPageOfThisPdfFileModule
Defined in:
lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb

Overview

PdfParadise::GUI::LibUI::RemoveTheFirstPageOfThisPdfFile

Constant Summary collapse

FILE_LAST_MODIFIED_PDF_FILE =
#

FILE_LAST_MODIFIED_PDF_FILE

This is hardcoded for now. At a later time we may have to query for the primary log-directory in use.

#
'/tmp/pdf_paradise/last_modified_pdf_file.yml'
DEFAULT_PDF_FILE_TO_WORK_ON_WINDOWS =
#

DEFAULT_PDF_FILE_TO_WORK_ON_WINDOWS

This is also hardcoded.

#
'/home/x/books/Basiswissen_Humangenetik_3rd_edition_by_Christian_Schaaf_2018/'\
'Basiswissen_Humangenetik_3rd_edition_by_Christian_Schaaf_2018.pdf'
WIDTH =
#

WIDTH

#
1280
HEIGHT =
#

HEIGHT

#
380

Constants included from RemoveTheFirstPageOfThisPdfFileModule

RemoveTheFirstPageOfThisPdfFileModule::TITLE

Instance Method Summary collapse

Constructor Details

#initialize(optional_commandline_arguments = [], run_already = true) ⇒ RemoveTheFirstPageOfThisPdfFile

#

initialize

#


62
63
64
65
66
67
68
69
70
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 62

def initialize(
    optional_commandline_arguments = [],
    run_already                    = true
  )
  reset
  @commandline_arguments = [optional_commandline_arguments].flatten.compact
  sanitize_the_commandline_arguments
  run if run_already
end

Instance Method Details

#create_a_clean_stateObject

#

create_a_clean_state

#


176
177
178
179
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 176

def create_a_clean_state
  PdfParadise.ensure_that_the_log_directory_exists
  PdfParadise.cd_to_the_log_directory
end

#create_skeletonObject

#

create_skeleton (create tag, skeleton tag)

#


93
94
95
96
97
98
99
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 93

def create_skeleton
  # ======================================================================= #
  # === @window
  # ======================================================================= #
  @window = ui_padded_main_window(title?, width?, height?, 0)
  create_the_main_entry
end

#create_the_main_entryObject

#

create_the_main_entry

#


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 104

def create_the_main_entry
  @entry1 = ui_entry
  _ = PdfParadise.use_which_file?
  unless @commandline_arguments.empty?
    _ = @commandline_arguments.first
  end
  _ = File.absolute_path(_) if _
  if _ # In this case we first assume that the file exists.
    @entry1.set_text(_)
  elsif File.exist? FILE_LAST_MODIFIED_PDF_FILE
    @entry1.set_text(YAML.load_file(FILE_LAST_MODIFIED_PDF_FILE))
  elsif PdfParadise.is_on_windows?
    @entry1.set_text(DEFAULT_PDF_FILE_TO_WORK_ON_WINDOWS)
  end
end

#do_remove_the_first_page_of_this_pdf_file(i = main_entry? ) ⇒ Object

#

do_remove_the_first_page_of_this_pdf_file (remove tag)

This is the method that will do the remove-the-first-page action.

It will delegate towards the method called PdfParadise.delete_the_first_page_of_this_pdf_file.

#


146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 146

def do_remove_the_first_page_of_this_pdf_file(
    i = main_entry?
  )
  if i and i.respond_to?(:text?)
    i = i.text?
  end
  i = i.to_s
  if File.exist?(i) and i.end_with?('.pdf')
    e "#{rev}Working on the file `#{i}#{rev}` next:"
    _result = PdfParadise.delete_the_first_page_of_this_pdf_file(i)
  else
    e 'No file was found at `'+i+'`.'
  end
end

#main_entry?Boolean

#

main_entry?

#

Returns:

  • (Boolean)


123
124
125
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 123

def main_entry?
  @entry1
end

#resetObject

#

reset (reset tag)

#


86
87
88
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 86

def reset
  title_width_height(TITLE, WIDTH, HEIGHT)
end

#return_button_open_fileObject

#

return_button_open_file

#


164
165
166
167
168
169
170
171
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 164

def return_button_open_file
  button_open_file = button('Open file')
  button_open_file.on_clicked {
    filename = ui_open_file(window).to_s # This is the part that will open a local file.
    main_entry?.set_text(filename)
  }
  return button_open_file
end

#return_open_the_pdf_file_buttonObject

#

return_open_the_pdf_file_button

#


130
131
132
133
134
135
136
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 130

def return_open_the_pdf_file_button
  button = ui_button('Open the .pdf file via okular')
  button.on_clicked {
    esystem "okular #{main_entry?.text?.to_s}"
  }
  return button
end

#runObject

#

run

#


184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 184

def run
  # Create a clean state here.
  create_a_clean_state
  create_skeleton_then_connect_skeleton
  outer_vbox = padded_vbox
  # ======================================================================= #
  # First add the two buttons on top:
  # ======================================================================= #
  button_do_remove_the_first_page_of_this_pdf_file = ui_button(
    'Do remove the first page of this .pdf file'
  )
  button_do_remove_the_first_page_of_this_pdf_file.on_clicked {
    do_remove_the_first_page_of_this_pdf_file
  }
  outer_vbox.add_hsep

  grid = ui_padded_grid
  #                         widget,                       left, top, xspan, yspan, hexpand, halign, vexpand, valign
  grid.ui_grid_append(text('Work on this .pdf file → '),  0,     0,    1,     1,     0,      0.5,     0,        0)
  grid.ui_grid_append(main_entry?,                        1,     0,    1,     1,     1,      0.5,     0,        0)
  grid.ui_grid_append(return_button_open_file,            2,     0,    1,     1,     0,      0.5,     0,        0)

  # ======================================================================= #
  # Add the button that allows the user to remove the first page of
  # the .pdf file next:
  # ======================================================================= #
  grid.hash_grid(
    button_do_remove_the_first_page_of_this_pdf_file,
    left:    0,
    top:     1,
    xspan:   1,
    yspan:   1,
    hexpand: 0,
    halign:  0.5,
    vexpand: 0,
    valign:  0
  )
  # ======================================================================= #
  # === Add a text that shows the current working directory in use:
  # ======================================================================= #
  grid.hash_grid(
    text('Current working directory: '+return_pwd),
    left:    1,
    top:     1,
    xspan:   2,
    yspan:   1,
    hexpand: 0,
    halign:  0.5,
    vexpand: 0,
    valign:  0
  )
  outer_vbox.minimal(grid, 5)
  outer_vbox.add_hsep
  outer_vbox.minimal(
    return_the_default_open_file_button(main_entry?),
    5
  )
  outer_vbox.add_hsep
  outer_vbox.minimal(
    return_open_the_pdf_file_button,
    5
  )
  outer_vbox.add_hsep
  # Add the quit button next
  outer_vbox.minimal(quit_button, 2)
  outer_vbox.add_hsep
  outer_vbox.minimal(
    text('The application that will be used for removing pages from the '\
         'pdf file is: '+
         PdfParadise.use_which_pdf_application_for_deleting_the_first_page_of_a_pdf_file?.to_s
    ),
    2
  )
  outer_vbox.add_hsep
  ::LibuiParadise.set_main_window(@window)
  @window.add(outer_vbox)
  @window.intelligent_exit
end

#sanitize_the_commandline_argumentsObject

#

sanitize_the_commandline_arguments

#


75
76
77
78
79
80
81
# File 'lib/pdf_paradise/gui/libui/remove_the_first_page_of_this_pdf_file/remove_the_first_page_of_this_pdf_file.rb', line 75

def sanitize_the_commandline_arguments
  if @commandline_arguments and !@commandline_arguments.empty?
    @commandline_arguments.map! {|entry|
      File.absolute_path(entry) unless entry.start_with?('--')
    }
  end
end