Class: JLDrill::Gtk::GtkVocabView

Inherits:
Gtk::VBox
  • Object
show all
Defined in:
lib/jldrill/oldUI/GtkVocabView.rb

Instance Method Summary collapse

Constructor Details

#initialize(vocab) ⇒ GtkVocabView

Returns a new instance of GtkVocabView.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 8

def initialize(vocab)
    super()
    @acceptReadingBlock = nil
    @acceptKanjiBlock = nil
    @kanjiField = createField("Kanji: ", vocab.kanji) do
        @acceptKanjiBlock.call
    end
    @hintField = createField("Hint: ", vocab.hint)
    @readingField = createField("Reading: ", vocab.reading) do
        @acceptReadingBlock.call
    end
    @definitionsBox = createBox("Definitions: ", 
                                vocab.definitionsRaw)
    @markersBox = createField("Markers: ", vocab.markers)
    
    pack_start(@kanjiField, false, false, 5)
    pack_start(@hintField, false, false, 5)
    pack_start(@readingField, false, false, 5)
    pack_start(@definitionsBox, true, true, 5)
    pack_start(@markersBox, false, true, 5)
end

Instance Method Details

#createBox(label, value, &block) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 168

def createBox(label, value, &block)
    if !label then label = "" end
    if !value then value = "" end

    hbox = Gtk::HBox.new()
    alignment1 = Gtk::Alignment.new(0,0,0,0.5)
    alignment1.add(Gtk::Label.new(label))
    hbox.pack_start(alignment1, false, false, 5)

    entry = Gtk::ScrolledWindow.new
    entry.shadow_type = Gtk::SHADOW_IN
    entry.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
    contents = Gtk::TextView.new
    contents.wrap_mode = Gtk::TextTag::WRAP_WORD
    contents.editable = true
    contents.cursor_visible = true
    entry.add(contents)
    contents.buffer.text = value

    alignment2 = Gtk::Alignment.new(0,0.5,1,1)
    alignment2.add(entry)

    hbox.pack_start(alignment2, true, true, 5)
    return hbox
end

#createField(label, value, &block) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 150

def createField(label, value, &block)
    if !label then label = "" end
    if !value then value = "" end

    hbox = Gtk::HBox.new()
    hbox.pack_start(Gtk::Label.new(label), false, false, 5)
    entry = Gtk::Entry.new
    entry.editable = true
    entry.text = value
    hbox.pack_start(entry, true, true, 5)
    if !block.nil?
        entry.signal_connect('activate') do |widget|
            block.call
        end
    end
    return hbox
end

#definitionsObject



91
92
93
94
95
96
97
98
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 91

def definitions
    widget = definitionsWidget
    if !widget.nil?
        return widget.buffer.text
    else
        return ""
    end
end

#definitions=(string) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 100

def definitions=(string)
    if string.nil? then string = "" end
    widget = definitionsWidget
    if !widget.nil?
        widget.buffer.set_text(string)
    end
end

#definitionsWidgetObject

For some reason I am losing the entry in my boxes I think it’s a GTK bug, but I’m not sure.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 44

def definitionsWidget
    retVal = nil
    a2 = @definitionsBox.children[1]
    if !a2.nil?
        entry = a2.children[0]
        if !entry.nil?
            retVal = entry.children[0]
        else
            print "Error: definitionsWidget Entry is nil!!!\n"
        end
    else
        print "Error: definitionsWidget Alignment is nil!!!\n"
    end
    return retVal
end

#focusReadingObject



202
203
204
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 202

def focusReading
    readingWidget.grab_focus
end

#getVocabObject



117
118
119
120
121
122
123
124
125
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 117

def getVocab
    vocab = JLDrill::Vocabulary.new
    vocab.kanji = kanji
    vocab.hint = hint
    vocab.reading = reading
    vocab.definitions = definitions
    vocab.markers = markers
    return vocab
end

#hintObject



73
74
75
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 73

def hint
    hintWidget.text
end

#hint=(string) ⇒ Object



77
78
79
80
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 77

def hint=(string)
    if string.nil? then string = "" end
    hintWidget.set_text(string)
end

#hintWidgetObject



34
35
36
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 34

def hintWidget
    @hintField.children[1]
end

#kanjiObject



64
65
66
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 64

def kanji
    kanjiWidget.text
end

#kanji=(string) ⇒ Object



68
69
70
71
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 68

def kanji=(string)
    if string.nil? then string = "" end
    kanjiWidget.set_text(string)
end

#kanjiWidgetObject



30
31
32
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 30

def kanjiWidget
    @kanjiField.children[1]
end

#markersObject



108
109
110
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 108

def markers
    markersWidget.text
end

#markers=(string) ⇒ Object



112
113
114
115
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 112

def markers=(string)
    if string.nil? then string = "" end
    markersWidget.set_text(string)
end

#markersWidgetObject



60
61
62
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 60

def markersWidget
    @markersBox.children[1]
end

#readingObject



82
83
84
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 82

def reading
    readingWidget.text
end

#reading=(string) ⇒ Object



86
87
88
89
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 86

def reading=(string)
    if string.nil? then string = "" end
    readingWidget.set_text(string)
end

#readingWidgetObject



38
39
40
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 38

def readingWidget
    @readingField.children[1]
end

#setAcceptKanji(&block) ⇒ Object



198
199
200
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 198

def setAcceptKanji(&block)
    @acceptKanjiBlock = block
end

#setAcceptReading(&block) ⇒ Object



194
195
196
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 194

def setAcceptReading(&block)
    @acceptReadingBlock = block
end

#setDictionaryVocab(vocab) ⇒ Object

Sets the fields to the vocabulary listed, but doesn’t set the hint. This is used to populate the views from a dictionary entry (which doesn’t have hints) rather than the user’s enter.



141
142
143
144
145
146
147
148
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 141

def setDictionaryVocab(vocab)
    if vocab
        self.kanji = vocab.kanjiRaw
        self.reading = vocab.readingRaw
        self.definitions = vocab.definitionsRaw
        self.markers = vocab.markersRaw
    end
end

#setVocab(vocab) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 127

def setVocab(vocab)
    if vocab
        self.kanji = vocab.kanjiRaw
        self.hint = vocab.hintRaw
        self.reading = vocab.readingRaw
        self.definitions = vocab.definitionsRaw
        self.markers = vocab.markersRaw
    end
end

#showBusy(bool) ⇒ Object



206
207
208
209
210
# File 'lib/jldrill/oldUI/GtkVocabView.rb', line 206

def showBusy(bool)
    # This remains unimplemented since I would have to rewrite
    # the entire class to make it work.  I will postpone it until
    # I rewrite the class.
end