Class: JLDrill::Gtk::ProblemDisplay
- Inherits:
-
Context::Gtk::VBox
- Object
- Context::Gtk::VBox
- JLDrill::Gtk::ProblemDisplay
- Defined in:
- lib/jldrill/views/gtk/widgets/ProblemDisplay.rb
Overview
This is the widget that displays the problem. The display is made up of 2 pieces: the QuestionPane, which shows the question for the problem and the AnswerPane which shows the answer. The ProblemDisplay also interacts with the PopupFactory to display the kanji/kana Popup when hovering over a character.
Instance Attribute Summary collapse
-
#accel ⇒ Object
readonly
Returns the value of attribute accel.
-
#answer ⇒ Object
readonly
Returns the value of attribute answer.
-
#question ⇒ Object
readonly
Returns the value of attribute question.
Instance Method Summary collapse
-
#adjustSizeForAnswer ⇒ Object
Try to accomodate the answer size.
-
#adjustSizeForQuestion ⇒ Object
Attempt to adjust the size of the question pane to accomodate the size of the question Note: This method is in an idle_add block because we have to wait until the pane has been redrawn before we calculate the size.
- #connectSignals ⇒ Object
- #expandWithSavePath(filename) ⇒ Object
- #expire ⇒ Object
-
#initialize(view) ⇒ ProblemDisplay
constructor
A new instance of ProblemDisplay.
- #newProblem(problem) ⇒ Object
- #packVPane ⇒ Object
- #removeVPane ⇒ Object
- #showAnswer ⇒ Object
- #showBusy(bool) ⇒ Object
- #showingAnswer? ⇒ Boolean
- #updateProblem(problem) ⇒ Object
Constructor Details
#initialize(view) ⇒ ProblemDisplay
Returns a new instance of ProblemDisplay.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 19 def initialize(view) @view = view @context = @view.context super() @vpane = nil @question = QuestionPane.new(self) @answer = AnswerPane.new(self) @problem = nil @kanjiPopupFactory = KanjiPopupFactory.new(view) @vocabPopupFactory = VocabPopupFactory.new(view) # Default to Kanji Popups @popupFactory = @kanjiPopupFactory @lastEvent = nil @accel = Gtk::AccelGroup.new packVPane connectSignals afterWidgetIsAdded do gtkWidgetMainWindow.add_accel_group(@accel) end end |
Instance Attribute Details
#accel ⇒ Object (readonly)
Returns the value of attribute accel.
17 18 19 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 17 def accel @accel end |
#answer ⇒ Object (readonly)
Returns the value of attribute answer.
17 18 19 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 17 def answer @answer end |
#question ⇒ Object (readonly)
Returns the value of attribute question.
17 18 19 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 17 def question @question end |
Instance Method Details
#adjustSizeForAnswer ⇒ Object
Try to accomodate the answer size. Always keep 10% of the panel for the question, though. Note: This method is in an idle_add block because we have to wait until the pane has been redrawn before we calculate the size. By putting it in an idle_add block we can ensure that the events that draw the pane have finished.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 137 def adjustSizeForAnswer Gtk.idle_add do maxPos = @vpane.max_position minPos = (maxPos.to_f * 0.10).to_i pos = maxPos - @answer.bufferSize if pos < minPos pos = minPos end # Don't adjust the size unnecessarily if pos < @vpane.position @vpane.position = pos end end end |
#adjustSizeForQuestion ⇒ Object
Attempt to adjust the size of the question pane to accomodate the size of the question Note: This method is in an idle_add block because we have to wait until the pane has been redrawn before we calculate the size. By putting it in an idle_add block we can ensure that the events that draw the pane have finished.
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 112 def adjustSizeForQuestion Gtk.idle_add do pos = @question.bufferSize # But don't adjust the size unnecessarily if pos > @vpane.position @vpane.position = pos end false end end |
#connectSignals ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 58 def connectSignals @question.contents.add_events(Gdk::Event::POINTER_MOTION_MASK) @question.contents.add_events(Gdk::Event::LEAVE_NOTIFY_MASK) @answer.contents.add_events(Gdk::Event::POINTER_MOTION_MASK) @answer.contents.add_events(Gdk::Event::LEAVE_NOTIFY_MASK) @accel.connect(Gdk::Keyval::GDK_space, 0, Gtk::ACCEL_VISIBLE) do @popupFactory.closePopup if @context.dictionaryLoaded? if @popupFactory == @kanjiPopupFactory @popupFactory = @vocabPopupFactory else @popupFactory = @kanjiPopupFactory end if !@lastEvent.nil? @popupFactory.notify(@lastEvent) end end end @question.contents.signal_connect('motion_notify_event') do |, motion| @lastEvent = MotionEvent.new(, motion) @popupFactory.notify(@lastEvent) end @answer.contents.signal_connect('motion_notify_event') do |, motion| @lastEvent = MotionEvent.new(, motion) @popupFactory.notify(@lastEvent) end @question.contents.signal_connect('leave_notify_event') do @popupFactory.closePopup end @answer.contents.signal_connect('leave_notify_event') do @popupFactory.closePopup end end |
#expandWithSavePath(filename) ⇒ Object
171 172 173 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 171 def (filename) @context.(filename) end |
#expire ⇒ Object
153 154 155 156 157 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 153 def expire if !@problem.nil? @question.expire end end |
#newProblem(problem) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 97 def newProblem(problem) @popupFactory.closePopup @problem = problem @answer.clear(@problem) @question.update(problem) adjustSizeForQuestion end |
#packVPane ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 49 def packVPane @vpane = Gtk::VPaned.new @vpane.set_border_width(5) @vpane.pack1(@question, true, true) @vpane.pack2(@answer, true, true) self.pack_end(@vpane, true, true) @vpane.show end |
#removeVPane ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 40 def removeVPane if !@vpane.nil? @vpane.remove(@question) @vpane.remove(@answer) self.remove(@vpane) @vpane = nil end end |
#showAnswer ⇒ Object
123 124 125 126 127 128 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 123 def showAnswer if !@problem.nil? @answer.update(@problem) adjustSizeForAnswer end end |
#showBusy(bool) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 175 def showBusy(bool) if bool @vpane.window.set_cursor(Gdk::Cursor.new(Gdk::Cursor::WATCH)) self.window.set_cursor(Gdk::Cursor.new(Gdk::Cursor::WATCH)) else @vpane.window.set_cursor(nil) self.window.set_cursor(nil) end Gdk::flush @popupFactory.showBusy(bool) @question.showBusy(bool) @answer.showBusy(bool) end |
#showingAnswer? ⇒ Boolean
159 160 161 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 159 def showingAnswer? !@answer.clear? end |
#updateProblem(problem) ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/jldrill/views/gtk/widgets/ProblemDisplay.rb', line 163 def updateProblem(problem) needToDisplayAnswer = showingAnswer? newProblem(problem) if needToDisplayAnswer showAnswer end end |