Class: JLDrill::Gtk::ProblemPane
- Inherits:
-
Gtk::ScrolledWindow
- Object
- Gtk::ScrolledWindow
- JLDrill::Gtk::ProblemPane
show all
- Includes:
- Context::Gtk::Widget
- Defined in:
- lib/jldrill/views/gtk/widgets/ProblemPane.rb
Overview
This is a scrolled window that shows information from a problem. There are two kinds of problem pane: the QuestionPane and the AnswerPane. The QuestionPane shows the question for the problem and the AnswerPane shows the answer
Constant Summary
collapse
- NORMAL_COLOR =
Gdk::Color.parse("#ffffc0")
- DISPLAY_ONLY_COLOR =
Gdk::Color.parse("#e0f0ff")
- PREVIEW_COLOR =
Gdk::Color.parse("#ffe0ff")
- EXPIRED_COLOR =
Gdk::Color.parse("#f07070")
Instance Attribute Summary collapse
#gtkWidgetMainWindow
Instance Method Summary
collapse
#addToThisWidget, #afterWidgetIsAdded, #afterWidgetIsRemoved, #expandWidgetHeight, #expandWidgetHeight?, #expandWidgetWidth, #expandWidgetWidth?, #gtkAddWidget, #gtkRemoveWidget, #isAMainWindow, #isInTests?, #removeFromThisWidget, #setupWidget, #widgetWasAddedTo, #widgetWasRemovedFrom
Constructor Details
#initialize(display) ⇒ ProblemPane
Returns a new instance of ProblemPane.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 22
def initialize(display)
super()
@display = display
setupWidget
self.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
self.shadow_type = Gtk::SHADOW_IN
@contents = Gtk::TextView.new
@contents.wrap_mode = Gtk::TextTag::WRAP_WORD
@contents.editable = false
@contents.cursor_visible = false
@contents.set_pixels_above_lines(5)
normalMode
self.add(@contents)
@buffer = @contents.buffer
createTags
@images = []
end
|
Instance Attribute Details
#contents ⇒ Object
Returns the value of attribute contents.
20
21
22
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 20
def contents
@contents
end
|
Instance Method Details
#addImage(filename) ⇒ Object
Adds an image to the bottom of the pane
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 81
def addImage(filename)
filename = @display.expandWithSavePath(filename)
image = Gtk::Image.new(filename)
@buffer.insert(@buffer.end_iter," ", "image")
if !image.pixbuf.nil?
@buffer.insert(@buffer.end_iter, image.pixbuf)
@images.push(image)
else
@buffer.insert(@buffer.end_iter, filename + " not found.",
"image")
end
@buffer.insert(@buffer.end_iter," ", "image")
end
|
#bufferSize ⇒ Object
Returns the height of the buffer in buffer coordinates. Note: This method must be called after all drawing has taken place. The easiest way to do this is to put the calculation into an Gtk.idle_add block.
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 130
def bufferSize
iter = @buffer.end_iter
y, height = @contents.get_line_yrange(iter)
size = y + height
windowType = Gtk::TextView::WINDOW_TEXT
winx, winy = @contents.buffer_to_window_coords(windowType, 0, size)
return winy
end
|
#clear(problem) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 98
def clear(problem)
if !problem.nil? && problem.preview?
previewMode
elsif !problem.nil? && problem.displayOnly?
displayOnlyMode
else
normalMode
end
@buffer.text = ""
@images = []
end
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 57
def createTags
@buffer.create_tag("kanji",
"size" => 36 * Pango::SCALE,
"justification" => Gtk::JUSTIFY_CENTER,
"family" => "Kochi Mincho")
@buffer.create_tag("reading",
"size" => 18 * Pango::SCALE,
"justification" => Gtk::JUSTIFY_CENTER,
"family" => "Kochi Mincho",
"foreground" => "blue")
@buffer.create_tag("definitions",
"size" => 16 * Pango::SCALE,
"justification" => Gtk::JUSTIFY_CENTER,
"family" => "Sans")
@buffer.create_tag("hint",
"size" => 14 * Pango::SCALE,
"justification" => Gtk::JUSTIFY_CENTER,
"family" => "Sans",
"foreground" => "red")
@buffer.create_tag("image",
"justification" => Gtk::JUSTIFY_CENTER)
end
|
#displayOnlyMode ⇒ Object
49
50
51
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 49
def displayOnlyMode
@contents.modify_base(Gtk::STATE_NORMAL, DISPLAY_ONLY_COLOR)
end
|
#expiredMode ⇒ Object
53
54
55
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 53
def expiredMode
@contents.modify_base(Gtk::STATE_NORMAL, EXPIRED_COLOR)
end
|
#normalMode ⇒ Object
41
42
43
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 41
def normalMode
@contents.modify_base(Gtk::STATE_NORMAL, NORMAL_COLOR)
end
|
#previewMode ⇒ Object
45
46
47
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 45
def previewMode
@contents.modify_base(Gtk::STATE_NORMAL, PREVIEW_COLOR)
end
|
#receive(type, string) ⇒ Object
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 115
def receive(type, string)
if !string.nil? && !string.empty?
if (string.start_with?("image:"))
addImage(string[6..string.size])
else
@buffer.insert(@buffer.end_iter, string, type)
end
@buffer.insert(@buffer.end_iter, "\n", type)
end
end
|
#showBusy(bool) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 141
def showBusy(bool)
subwindow = @contents.get_window(Gtk::TextView::WINDOW_TEXT)
if bool
self.window.set_cursor(Gdk::Cursor.new(Gdk::Cursor::WATCH))
subwindow.set_cursor(Gdk::Cursor.new(Gdk::Cursor::WATCH))
else
self.window.set_cursor(nil)
subwindow.set_cursor(nil)
end
Gdk::flush()
end
|
#text ⇒ Object
111
112
113
|
# File 'lib/jldrill/views/gtk/widgets/ProblemPane.rb', line 111
def text
@buffer.text
end
|