Class: Makeconf::GUI
- Inherits:
-
Object
- Object
- Makeconf::GUI
- Defined in:
- lib/makeconf/gui.rb
Instance Method Summary collapse
- #build_page(display) ⇒ Object
-
#initialize(project) ⇒ GUI
constructor
A new instance of GUI.
- #install_prefix_page(display) ⇒ Object
- #intro_page(display) ⇒ Object
- #license_page(display) ⇒ Object
- #main_loop ⇒ Object
- #next_page ⇒ Object
- #outro_page(display) ⇒ Object
- #prev_page ⇒ Object
-
#update_buttons ⇒ Object
Update the Back and Next buttons based on the position in the pagelist.
Constructor Details
#initialize(project) ⇒ GUI
Returns a new instance of GUI.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 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 |
# File 'lib/makeconf/gui.rb', line 3 def initialize(project) require 'tk' @project = project @page = [ 'intro_page', 'license_page', # TODO:'install_prefix_page', 'build_page', 'outro_page', ] @pageIndex = 0 @mainTitle = TkVariable.new @mainMessage = TkVariable.new @root = TkRoot.new() { title "Installation" } @mainTitleWidget = TkLabel.new(@root) { pack('side' => 'top') } @mainTitleWidget.configure('textvariable', @mainTitle) @mainFrame = TkFrame.new(@root) { height 600 width 600 background 'white' borderwidth 5 relief 'groove' padx 10 pady 10 pack('side' => 'top') } @mainLabel = TkLabel.new(@mainFrame) { background 'white' } @mainLabel.configure('textvariable', @mainMessage) @mainText = TkText.new(@mainFrame) { background 'white' } @cancelButton = TkButton.new(@root) { text "Cancel" command proc { exit 1 } pack('side' => 'left') } @nextButton = TkButton.new(@root) { text "Next" pack('side' => 'right') } @nextButton.configure('command', method(:next_page)) #nextButton.configure('command', proc { mainMessage.set_value 'You click it' }) @nextButtonEnable = true @backButton = TkButton.new(@root) { text "Back" command proc { prev_page } state 'disabled' pack('side' => 'right') } @backButton.configure('command', method(:prev_page)) @backButtonEnable = true end |
Instance Method Details
#build_page(display) ⇒ Object
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 172 173 174 175 176 |
# File 'lib/makeconf/gui.rb', line 145 def build_page(display) if display @nextButtonEnable = false @mainTitle.set_value 'Checking Configuration' @mainText.delete(1.0, 'end') @mainText.place('relx'=>0.0, 'rely' => 0.0) Thread.new { @mainText.insert('end', "Configuring.. ") Makeconf.configure_project @project @mainText.insert('end', "done\n") make = Platform.is_windows? ? 'nmake' : 'make' @mainText.insert('end', "Building.. ") system "#{make}" @mainText.insert('end', "done\n") @mainText.insert('end', "Installing.. ") system "#{make} install" @mainText.insert('end', "done\n") @mainText.insert('end', "\nAll tasks completed.") @nextButtonEnable = true } else TkPlace.forget(@mainText) @mainText.delete(1.0, 'end') end end |
#install_prefix_page(display) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/makeconf/gui.rb', line 133 def install_prefix_page(display) if display @mainTitle.set_value 'Installation Path' @mainText.insert('end', "choose an installation path") @mainText.place('relx'=>0.0, 'rely' => 0.0) Tk.getOpenFile else TkPlace.forget(@mainText) @mainText.delete(1.0, 'end') end end |
#intro_page(display) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/makeconf/gui.rb', line 112 def intro_page(display) if display @mainTitle.set_value 'Welcome' @mainLabel.place('relx'=>0.0, 'rely' => 0.0) @mainMessage.set_value "This will install #{@project.id} on your computer" else TkPlace.forget(@mainLabel) end end |
#license_page(display) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/makeconf/gui.rb', line 122 def license_page(display) if display @mainTitle.set_value 'License Agreement' @mainText.insert('end', File.read(@project.license_file)) @mainText.place('relx'=>0.0, 'rely' => 0.0) else TkPlace.forget(@mainText) @mainText.delete(1.0, 'end') end end |
#main_loop ⇒ Object
107 108 109 110 |
# File 'lib/makeconf/gui.rb', line 107 def main_loop eval "#{@page[0]}(true)" Tk.mainloop() end |
#next_page ⇒ Object
75 76 77 78 79 80 |
# File 'lib/makeconf/gui.rb', line 75 def next_page eval "#{@page[@pageIndex]}(false)" @pageIndex = @pageIndex + 1 eval "#{@page[@pageIndex]}(true)" end |
#outro_page(display) ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/makeconf/gui.rb', line 178 def outro_page(display) if display @mainTitle.set_value 'Installation Complete' @mainLabel.place('relx'=>0.0, 'rely' => 0.0) @mainMessage.set_value "Installation is complete." else TkPlace.forget(@mainLabel) end end |
#prev_page ⇒ Object
82 83 84 85 86 87 |
# File 'lib/makeconf/gui.rb', line 82 def prev_page eval "#{@page[@pageIndex]}(false)" @pageIndex = @pageIndex - 1 eval "#{@page[@pageIndex]}(true)" end |
#update_buttons ⇒ Object
Update the Back and Next buttons based on the position in the pagelist
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/makeconf/gui.rb', line 90 def if @pageIndex == 0 @backButton.configure('state', 'disabled') @nextButton.configure('state', 'normal') @nextButton.configure('text', 'Next') elsif @pageIndex == @page.length - 1 @nextButton.configure('text', 'Finish') @nextButton.configure('command', proc { exit 0 }) @backButton.configure('state', 'disabled') @cancelButton.configure('state', 'disabled') else @nextButton.configure('text', 'Next') @nextButton.configure('state', @nextButtonEnable ? 'normal' : 'disabled') @backButton.configure('state', @backButtonEnable ? 'normal' : 'disabled') end end |