Class: Watobo::Plugin::Crawler::Gui::HooksFrame
- Inherits:
-
FXVerticalFrame
- Object
- FXVerticalFrame
- Watobo::Plugin::Crawler::Gui::HooksFrame
- Defined in:
- plugins/crawler/gui/hooks_frame.rb
Instance Method Summary collapse
-
#initialize(owner) ⇒ HooksFrame
constructor
A new instance of HooksFrame.
- #pre_conn_code ⇒ Object
- #pre_conn_hook ⇒ Object
- #pre_conn_valid? ⇒ Boolean
- #selected ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(owner) ⇒ HooksFrame
Returns a new instance of HooksFrame.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'plugins/crawler/gui/hooks_frame.rb', line 74 def initialize(owner) super(owner, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_RAISED|FRAME_THICK, :padding => 0) main = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y) gbframe = FXGroupBox.new(main, "Pre-Connection", LAYOUT_SIDE_RIGHT|FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0) frame = FXVerticalFrame.new(gbframe, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 0) #text_frame = FXHorizontalFrame.new(frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_NONE, :padding =>0) fxtext = FXText.new(frame, :opts => LAYOUT_FILL_X|TEXT_WORDWRAP) fxtext.backColor = fxtext.parent.backColor fxtext.disable text = "You can define a script which gets executed just before each connection. So you are able to modify the Mechanize::Agent and Mechanize::Requests just before the request is sent to the server.\n" text << "For more information about pre_connection_hooks check the Mechanize homepage (http://mechanize.rubyforge.org/)." fxtext.setText(text) FXLabel.new(frame, "lambda{ |agent, request|") txt_frame = FXVerticalFrame.new(frame, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0) @pre_txt = FXText.new(txt_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|TEXT_WORDWRAP) FXLabel.new(frame, "}") @pre_txt.setText("") # cannot set the focus here because of a crash on ubuntu systems # https://bugs.launchpad.net/ubuntu/+source/fox1.6/+bug/887038 # @pre_txt.setFocus() end |
Instance Method Details
#pre_conn_code ⇒ Object
67 68 69 70 71 72 |
# File 'plugins/crawler/gui/hooks_frame.rb', line 67 def pre_conn_code return "" if @pre_txt.text.empty? code = "lambda { |agent,request|\n" code << @pre_txt.text code << "\n}" end |
#pre_conn_hook ⇒ Object
36 37 38 39 40 41 |
# File 'plugins/crawler/gui/hooks_frame.rb', line 36 def pre_conn_hook return nil unless pre_conn_valid? hook = eval(pre_conn_code) hook end |
#pre_conn_valid? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'plugins/crawler/gui/hooks_frame.rb', line 47 def pre_conn_valid? return false if pre_conn_code.empty? begin eval(pre_conn_code) return true rescue SyntaxError, LocalJumpError, NameError => e # puts "Error in PreConnCode!!" # puts e # puts e.backtrace raise SyntaxError, "SyntaxError in Pre-Connect-Code'#{expr}'" #return false rescue => bang puts bang puts bang.backtrace return false #raise bang end end |
#selected ⇒ Object
43 44 45 |
# File 'plugins/crawler/gui/hooks_frame.rb', line 43 def selected @pre_txt.setFocus() end |
#to_h ⇒ Object
29 30 31 32 33 34 35 |
# File 'plugins/crawler/gui/hooks_frame.rb', line 29 def to_h hooks = {} pch = pre_conn_hook hooks[:pre_connect_hook] = pch if pch.respond_to? :call hooks end |