Class: JLDrill::Gtk::ExampleWindow
- Inherits:
-
Gtk::Window
- Object
- Gtk::Window
- JLDrill::Gtk::ExampleWindow
show all
- Includes:
- Context::Gtk::Widget
- Defined in:
- lib/jldrill/views/gtk/widgets/ExampleWindow.rb
Instance Attribute Summary
#gtkWidgetMainWindow
Instance Method Summary
collapse
#addToThisWidget, #afterWidgetIsAdded, #afterWidgetIsRemoved, #expandWidgetHeight, #expandWidgetHeight?, #expandWidgetWidth, #expandWidgetWidth?, #gtkAddWidget, #gtkRemoveWidget, #isAMainWindow, #isInTests?, #removeFromThisWidget, #setupWidget, #widgetWasAddedTo, #widgetWasRemovedFrom
Constructor Details
Returns a new instance of ExampleWindow.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 11
def initialize(view)
@view = view
@context = @view.context
@closed = false
super("Examples")
@accel = Gtk::AccelGroup.new
@kanjiPopupFactory = KanjiPopupFactory.new(view)
@vocabPopupFactory = VocabPopupFactory.new(view)
@popupFactory = @kanjiPopupFactory
@lastEvent = nil
sw = Gtk::ScrolledWindow.new
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
sw.shadow_type = Gtk::SHADOW_IN
self.add(sw)
@contents = Gtk::TextView.new
@contents.wrap_mode = Gtk::TextTag::WRAP_WORD
@contents.editable = false
@contents.cursor_visible = false
sw.add(@contents)
self.set_default_size(400, 360)
connectSignals unless @view.nil?
createTags
end
|
Instance Method Details
#close ⇒ Object
99
100
101
102
103
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 99
def close
if !@closed
@view.close
end
end
|
#connectSignals ⇒ Object
53
54
55
56
57
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
96
97
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 53
def connectSignals
@accel = Gtk::AccelGroup.new
@accel.connect(Gdk::Keyval::GDK_Escape, 0,
Gtk::ACCEL_VISIBLE) do
self.close
end
add_accel_group(@accel)
signal_connect('delete_event') do
false
end
signal_connect('destroy') do
self.close
end
@contents.add_events(Gdk::Event::POINTER_MOTION_MASK)
@contents.add_events(Gdk::Event::LEAVE_NOTIFY_MASK)
@contents.signal_connect('motion_notify_event') do |widget, motion|
@lastEvent = MotionEvent.new(widget, motion)
@popupFactory.notify(@lastEvent)
end
@contents.signal_connect('leave_notify_event') do
@popupFactory.
end
@accel.connect(Gdk::Keyval::GDK_space, 0, Gtk::ACCEL_VISIBLE) do
@popupFactory.
if @context.dictionaryLoaded?
if @popupFactory == @kanjiPopupFactory
@popupFactory = @vocabPopupFactory
else
@popupFactory = @kanjiPopupFactory
end
if !@lastEvent.nil?
@popupFactory.notify(@lastEvent)
end
end
end
end
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 37
def createTags
@contents.buffer.create_tag("normal",
"size" => 12 * Pango::SCALE,
"background" => "#ffffff")
@contents.buffer.create_tag("checked",
"size" => 12 * Pango::SCALE,
"background" => "#e0f0ff")
@contents.buffer.create_tag("h1",
"size" => 20 * Pango::SCALE,
"justification" => Gtk::JUSTIFY_CENTER)
@contents.buffer.create_tag("h2",
"size" => 15 * Pango::SCALE,
"justification" => Gtk::JUSTIFY_CENTER)
end
|
#explicitDestroy ⇒ Object
105
106
107
108
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 105
def explicitDestroy
@closed = true
self.destroy
end
|
#getTag(example) ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 146
def getTag(example)
if (example.key.checked)
tag = "checked"
else
tag = "normal"
end
end
|
#insert(text, tag) ⇒ Object
190
191
192
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 190
def insert(text, tag)
@contents.buffer.insert(@contents.buffer.end_iter, text, tag)
end
|
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 123
def (section, example)
if example.key.checked
if section == -2
section = -1
insert("Checked Examples\n", "h1")
insertVSpace
end
else
if section < 0
insert("Unchecked Examples\n", "h1")
insertVSpace
end
if section != example.key.sense
section = example.key.sense
if section != 0
insertVSpace
insert("Examples for sense ##{section}\n", "h2")
end
end
end
return section
end
|
#insertVSpace ⇒ Object
194
195
196
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 194
def insertVSpace
insert("\n", "normal")
end
|
#showBusy(bool) ⇒ Object
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 198
def showBusy(bool)
subwindow = @contents.get_window(Gtk::TextView::WINDOW_TEXT)
if bool
subwindow.set_cursor(Gdk::Cursor.new(Gdk::Cursor::WATCH))
else
subwindow.set_cursor(nil)
end
Gdk::flush()
end
|
#sortExamples(examples) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 110
def sortExamples(examples)
return examples.sort do |x, y|
retVal = x.key.sense <=> y.key.sense
if y.key.checked && !x.key.checked
retVal = 1
end
if x.key.checked && !y.key.checked
retVal = -1
end
retVal
end
end
|
#updateContents(examples) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 178
def updateContents(examples)
@contents.buffer.text = ""
if !examples.nil?
section = -2
sortExamples(examples).each do |example|
section = (section, example)
insert(example.to_s + "\n", getTag(example))
insertVSpace
end
end
end
|
#updateNativeOnly(examples) ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 154
def updateNativeOnly(examples)
@contents.buffer.text = ""
if !examples.nil?
section = -2
sortExamples(examples).each do |example|
section = (section, example)
insert(example.nativeOnly_to_s + "\n", getTag(example))
insertVSpace
end
end
end
|
#updateTargetOnly(examples) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/jldrill/views/gtk/widgets/ExampleWindow.rb', line 166
def updateTargetOnly(examples)
@contents.buffer.text = ""
if !examples.nil?
section = -2
sortExamples(examples).each do |example|
section = (section, example)
insert(example.targetOnly_to_s + "\n", getTag(example))
insertVSpace
end
end
end
|