Class: KeepYourHead::WindowQuestion
- Inherits:
-
Object
- Object
- KeepYourHead::WindowQuestion
- 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
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#training ⇒ Object
readonly
Returns the value of attribute training.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #flashcard ⇒ Object
-
#initialize(parent, training) ⇒ WindowQuestion
constructor
A new instance of WindowQuestion.
- #onDestroy ⇒ Object
- #onEdit ⇒ Object
- #onHelp ⇒ Object
- #onKnown ⇒ Object
- #onQuit ⇒ Object
- #onUnknown ⇒ Object
- #updateView ⇒ Object
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..hide if self.parent @updateImagesMutex = Mutex.new @glade = GladeXML.new(Resources::system("glade/WindowTrain.glade")) { |handler| method(handler) } Widgets.each { |name| = @glade.(name) assert eval("@#{name} = widget") } @window = @glade.("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
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
22 23 24 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 22 def parent @parent end |
#training ⇒ Object (readonly)
Returns the value of attribute training.
23 24 25 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 23 def training @training end |
#window ⇒ Object (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
#flashcard ⇒ Object
118 119 120 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 118 def flashcard self.training.flashcard end |
#onDestroy ⇒ Object
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 = <<END Zeit: $(time.used) min / $(time.max) min Karteikarten gefragt: $(flashcards.asked) gewußt/nicht gewußt: $(flashcards.known) / $(flashcards.unknown) END = .clone .gsub!( "$(time.used)", (training.timeUsed / 60.0).to_i.to_s ) .gsub!( "$(time.max)", (training.timeMax / 60.0).to_i.to_s ) .gsub!( "$(flashcards.asked)", training.flashcardsAsked.length.to_s ) .gsub!( "$(flashcards.known)", training.flashcardsKnown.length.to_s ) .gsub!( "$(flashcards.unknown)", training.flashcardsUnknown.length.to_s ) dialog = Gtk::MessageDialog.new( @window, Gtk::Dialog::MODAL, Gtk::MessageDialog::INFO, Gtk::MessageDialog::BUTTONS_OK, ) dialog.title = "Training beendet" response = dialog.run dialog.destroy self.parent..show if self.parent end |
#onEdit ⇒ Object
83 84 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 83 def onEdit end |
#onHelp ⇒ Object
69 70 71 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 69 def onHelp @notebook.page = (@notebook.page + 1).modulo 2 end |
#onKnown ⇒ Object
73 74 75 76 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 73 def onKnown self.training.onKnown updateView end |
#onQuit ⇒ Object
114 115 116 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 114 def onQuit @window.destroy end |
#onUnknown ⇒ Object
78 79 80 81 |
# File 'lib/Keepyourhead/gui/WindowTrain.rb', line 78 def onUnknown self.training.onUnknown updateView end |
#updateView ⇒ Object
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 |