Class: KeepYourHead::WindowQuestion

Inherits:
Object
  • Object
show all
Defined in:
lib/Keepyourhead/gui/WindowTrain.rb

Constant Summary collapse

Widgets =
[
	"imageFront", "imageBack", "notebook", "scrolledwindowNotebook",
	"hboxFront", "hboxBack", "hscaleFront", "hscaleBack",
	"progressbarFlashcards", "progressbarTime",
]
Timeout =
(1000 * 0.2).to_i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, training) ⇒ WindowQuestion

Returns a new instance of WindowQuestion.



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
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 33

def initialize( parent, training )
	@parent = parent
	self.parent.widget.hide if self.parent

	@updateImagesMutex = Mutex.new
	@glade = GladeXML.new(Resources::system("glade/WindowTrain.glade")) { |handler| method(handler) }

	Widgets.each { |name|
		widget = @glade.get_widget(name)
		assert widget
		eval("@#{name} = widget")
	}
	@window = @glade.get_widget("window_train")
#		@window.maximize
	
	@training = training 


	@flashcardViewControllerFront = FlashcardViewController.new @imageFront, @hscaleFront, @hboxFront
	@flashcardViewControllerBack = FlashcardViewController.new @imageBack, @hscaleBack, @hboxBack

	@running = true
	Gtk.timeout_add(10000) {
		if @running then
			@progressbarTime.fraction = @training.progressTime

			true
		else
			false
		end
	}

	@window.show
	updateView
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



22
23
24
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 22

def parent
  @parent
end

#trainingObject (readonly)

Returns the value of attribute training.



23
24
25
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 23

def training
  @training
end

#windowObject (readonly)

Returns the value of attribute window.



25
26
27
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 25

def window
  @window
end

Instance Method Details

#flashcardObject



118
119
120
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 118

def flashcard
	self.training.flashcard
end

#onDestroyObject



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
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 86

def onDestroy
	@running = false

	@training.close
		
	message = <<END
Zeit: $(time.used) min / $(time.max) min
Karteikarten gefragt: $(flashcards.asked)
gewußt/nicht gewußt: $(flashcards.known) / $(flashcards.unknown)
END

	message = message.clone
	message.gsub!( "$(time.used)",          (training.timeUsed / 60.0).to_i.to_s )
	message.gsub!( "$(time.max)",           (training.timeMax / 60.0).to_i.to_s )
	message.gsub!( "$(flashcards.asked)",   training.flashcardsAsked.length.to_s )
	message.gsub!( "$(flashcards.known)",   training.flashcardsKnown.length.to_s )
	message.gsub!( "$(flashcards.unknown)", training.flashcardsUnknown.length.to_s )

	dialog = Gtk::MessageDialog.new( 
		@window, Gtk::Dialog::MODAL, Gtk::MessageDialog::INFO, 
		Gtk::MessageDialog::BUTTONS_OK, message )
	dialog.title = "Training beendet"
	response = dialog.run
	dialog.destroy

	self.parent.widget.show if self.parent
end

#onEditObject



83
84
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 83

def onEdit
end

#onHelpObject



69
70
71
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 69

def onHelp
	@notebook.page = (@notebook.page + 1).modulo 2
end

#onKnownObject



73
74
75
76
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 73

def onKnown
	self.training.onKnown
	updateView
end

#onQuitObject



114
115
116
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 114

def onQuit
	@window.destroy
end

#onUnknownObject



78
79
80
81
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 78

def onUnknown
	self.training.onUnknown
	updateView
end

#updateViewObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 124

def updateView
	if flashcard then
		@notebook.page = 0

#			@scrolledwindowNotebook.width_request = (ImageWidth * 1.1).to_i
		@progressbarFlashcards.fraction = @training.progressFlashcards

		Thread.new {
			begin
				$cache.getCacheItem( flashcard, Database::FRONT )
				$cache.getCacheItem( flashcard, Database::BACK )
			rescue
				puts $!.backtrace, $!
			end
		}

		Gtk.timeout_add( Timeout ) {
			ret = true
			if @running then
				[Database::FRONT, Database::BACK].each { |type|
					$cache.hasCacheItem( flashcard, type ) { |cacheItem|
						ret &&= cacheItem

						filenames = Images.fromCacheItem type, cacheItem
						
						case type
						when Database::FRONT
							@flashcardViewControllerFront.filenames = filenames
						when Database::BACK
							@flashcardViewControllerBack.filenames = filenames
						end
					}
				}
			end
			not ret
		}
	else
		@window.destroy
	end
end