Class: RSokoban::UI::SetDialog

Inherits:
TkToplevel
  • Object
show all
Includes:
RSokoban
Defined in:
lib/rsokoban/ui/tk_dialogs.rb

Overview

As dialog box, I allow the user to choose a set name.

Constant Summary

Constants included from RSokoban

CONFIG_FILE, CONFIG_FOLDER, CRATE, CRATE_ON_STORAGE, FLOOR, MAN, MAN_ON_STORAGE, OUTSIDE, RECORD_FOLDER, STORAGE, WALL

Instance Method Summary collapse

Constructor Details

#initialize(root, title) ⇒ SetDialog

Create and show the dialog

Parameters:

  • root (TkRoot|TkToplevel)

    the Tk widget I belong to

  • title (String)

    my window title



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
# File 'lib/rsokoban/ui/tk_dialogs.rb', line 166

def initialize(root, title)
	super(root)
	title(title)
	width(300)
	height(400)
	@state = 'CANCEL'
	grab
	self['resizable'] = false, false
	
	@xsb = get_xsb
	$listval = TkVariable.new(@xsb)
	@value = @xsb[0]
	
	# A frame for the listbox
	@frame_north = Tk::Tile::Frame.new(self) do
		grid(:row => 0, :column => 0, :columnspan => 2, :sticky => :we)
		padding 10
	end
	
	@list = TkListbox.new(@frame_north) do
		width 40
	 	height 8
	 	listvariable $listval
	 	grid(:row => 0, :column => 0, :sticky => :we)
	end
	
	@list.bind '<ListboxSelect>', proc{ show_description }
	@list.bind 'Double-1', proc{ ok_on_clic }
	@list.bind 'Return', proc{ ok_on_clic }

	
	scroll = Tk::Tile::Scrollbar.new(@frame_north) do
		orient 'vertical'
		grid(:row => 0, :column => 1, :sticky => :ns)
	end

	@list.yscrollcommand(proc { |*args| scroll.set(*args) })
	scroll.command(proc { |*args| @list.yview(*args) })
	
	# A frame for the set description
	@frame_desc = Tk::Tile::Frame.new(self) do
		grid(:row => 1, :column => 0, :columnspan => 2, :sticky => :we)
		padding 10
	end
	
	@desc = TkText.new(@frame_desc) do
		borderwidth 1
		font TkFont.new('times 12')
		width 40
		height 10
		wrap :word
	 	grid(:row => 0, :column => 0)
	end
	
	scroll2 = Tk::Tile::Scrollbar.new(@frame_desc) do
		orient 'vertical'
		grid(:row => 0, :column => 1, :sticky => :ns)
	end

	@desc.yscrollcommand(proc { |*args| scroll2.set(*args) })
	scroll2.command(proc { |*args| @desc.yview(*args) }) 
	
	# The buttons
	@ok = Tk::Tile::Button.new(self) do
		text 'OK'
		grid(:row => 2, :column => 0)
		default :active
	end
	@ok.command { ok_on_clic }
	
	@cancel = Tk::Tile::Button.new(self) do
		text 'Cancel'
		grid(:row => 2, :column => 1)
	end
	@cancel.command { cancel_on_clic }
	
	@list.focus
	wait_destroy
end

Instance Method Details

#ok?Boolean

Returns true if user clicked the OK button.

Returns:

  • (Boolean)

    true if user clicked the OK button



247
248
249
# File 'lib/rsokoban/ui/tk_dialogs.rb', line 247

def ok?
	@state == 'OK'
end

#valueString

Returns the name of the set.

Returns:

  • (String)

    the name of the set



252
253
254
# File 'lib/rsokoban/ui/tk_dialogs.rb', line 252

def value
	@value
end