Class: PdfParadise::GUI::Libui::StatisticsWidget

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb

Overview

PdfParadise::GUI::Libui::StatisticsWidget

Constant Summary collapse

TITLE =
#

TITLE

#
'Show statistics about the .pdf file at hand'

Instance Method Summary collapse

Constructor Details

#initializeStatisticsWidget

#

initialize

#


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 36

def initialize
  reset
  create_skeleton
  # ======================================================================= #
  # === @main_window
  # ======================================================================= #
  @main_window = ui_main_window(
    TITLE, 560, 240, 0
  )
  outer_vbox = ui_padded_vbox

  # ======================================================================= #
  # === First row
  # ======================================================================= #
  hbox = ui_padded_hbox
  @button_auto_title = ui_button('Automatic Title')
  @button_auto_title.on_clicked {
    do_automatically_determine_the_title_for_the_pdf_file_at_hand
  }
  hbox.minimal(@button_auto_title)
  @button_open_via_a_pdf_reader = ui_button('Open via a pdf-reader')
  @button_open_via_a_pdf_reader.on_clicked {
    do_open_the_local_pdf_file_in_the_pdf_reader
  }
  hbox.minimal(@button_open_via_a_pdf_reader)
  hbox.minimal(ui_quit_button)
  outer_vbox.minimal(hbox)

  # ======================================================================= #
  # === Second row
  # ======================================================================= #
  outer_vbox.minimal(
    text(
      'This small widget will show some information about '\
      'the .pdf file at hand.'
    )
  )
  # ======================================================================= #
  # === Third row
  # ======================================================================= #
  hbox = ui_padded_hbox
  hbox.minimal(left_arrow?)
  hbox.maximal(@entry_use_this_pdf_file)
  outer_vbox.maximal(hbox)

  # ======================================================================= #
  # === Fourth row
  # ======================================================================= #
  hbox = ui_padded_hbox
  button_open_file = ui_button('Open File')
  button_open_file.on_clicked {
    begin
      @filename = ui_open_file(@main_window).to_s # This is the part that will open a local file.
    rescue Exception => error
      @filename = nil # To prevent "Null pointer given" errors.
      # =================================================================== #
      # The error specifically is:
      #
      #   #<ArgumentError: NULL pointer given>
      #
      # =================================================================== #
    end
    if @filename and File.exist?(@filename)
      @entry_use_this_pdf_file.set_text(@filename)
    end
  }
  hbox.minimal(button_open_file)
  # ======================================================================= #
  # === button_analyse_the_pdf_file
  # ======================================================================= #
  button_analyse_the_pdf_file = ui_button('Analyse the .pdf file')
  button_analyse_the_pdf_file.on_clicked {
e 'TODO Analyse the pdf file'
  }
  hbox.minimal(button_analyse_the_pdf_file)
  outer_vbox.minimal(hbox)

  # ======================================================================= #
  # === Fifth row
  # ======================================================================= #
  @label = ui_text
  outer_vbox.minimal(@label)
  @main_window.child = outer_vbox
  @main_window.intelligent_exit
end

Instance Method Details

#create_all_buttonsObject

#

create_all_buttons

#


226
227
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 226

def create_all_buttons
end

#create_all_entriesObject

#

create_all_entries

#


143
144
145
146
147
148
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 143

def create_all_entries
  # ======================================================================= #
  # === @entry_use_this_pdf_file
  # ======================================================================= #
  @entry_use_this_pdf_file = ui_entry
end

#create_skeletonObject

#

create_skeleton

#


135
136
137
138
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 135

def create_skeleton
  create_all_entries
  create_all_buttons
end

#do_analyse_the_pdf_file(this_pdf_file = main_entry?.text.to_s) ⇒ Object

#

do_analyse_the_pdf_file

This is the method that will analyse the .pdf file at hand.

#


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 180

def do_analyse_the_pdf_file(
    this_pdf_file = main_entry?.text.to_s
  )
  _ = ''.dup
  _ << "This .pdf file has the following characteristics:\n\n"
  _ << '    <b>n pages</b>: '+::PdfParadise.n_pages?(this_pdf_file).to_s
  _ << "\n"
  use_this_title = ::PdfParadise.title?(this_pdf_file).to_s
  if use_this_title.empty?
    use_this_title = '(This .pdf file has no title)'
  end
  _ << "    <b>title</b>: #{use_this_title}"
  _ << "\n"
  @label.set_text(_)
end

#do_automatically_determine_the_title_for_the_pdf_file_at_hand(this_pdf_file = main_entry?.text?) ⇒ Object

#

do_automatically_determine_the_title_for_the_pdf_file_at_hand

#


160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 160

def do_automatically_determine_the_title_for_the_pdf_file_at_hand(
    this_pdf_file = main_entry?.text?
  )
  if this_pdf_file and !this_pdf_file.empty?
    ::PdfParadise.automatic_pdf_title(this_pdf_file)
    do_analyse_the_pdf_file
  else
    popup_over_this_widget(
      @main_window,
      'Please first assign a .pdf file, before '\
      'this functionality can be used.'
    )
  end
end

#do_open_the_local_pdf_file_in_the_pdf_reader(this_pdf_file = main_entry?.text?) ⇒ Object

#

do_open_the_local_pdf_file_in_the_pdf_reader

#


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 199

def do_open_the_local_pdf_file_in_the_pdf_reader(
    this_pdf_file = main_entry?.text?
  )
  if this_pdf_file and !this_pdf_file.empty?
    Thread.new {
      esystem("evince #{this_pdf_file}")
    }
  else
    popup_over_this_widget(
      @main_window,
      'Please first assign a .pdf file, before '\
      'this functionality can be used.'
    )
  end
end

#esystem(i) ⇒ Object

#

esystem

#


218
219
220
221
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 218

def esystem(i)
  e i
  system i
end

#main_entry?Boolean

#

main_entry?

#

Returns:

  • (Boolean)


153
154
155
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 153

def main_entry?
  @entry_use_this_pdf_file
end

#resetObject

#

reset (reset tag)

#


125
126
127
128
129
130
# File 'lib/pdf_paradise/gui/libui/statistics_widget/statistics_widget.rb', line 125

def reset
  # ======================================================================= #
  # === @filename
  # ======================================================================= #
  @filename = nil
end