Class: JLDrill::Gtk::VocabPopup

Inherits:
Popup
  • Object
show all
Defined in:
lib/jldrill/views/gtk/widgets/VocabPopup.rb

Instance Attribute Summary

Attributes inherited from Popup

#character, #x, #y

Instance Method Summary collapse

Methods inherited from Popup

#display

Constructor Details

#initialize(char, entries, mainWindow, x, y) ⇒ VocabPopup

Returns a new instance of VocabPopup.



8
9
10
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
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
# File 'lib/jldrill/views/gtk/widgets/VocabPopup.rb', line 8

def initialize(char, entries, mainWindow, x, y)
    super(char, mainWindow, x, y)
    
    color = Gdk::Color.parse("lightblue1")
    @strokes = Gtk::TextView.new
    @strokes.wrap_mode = Gtk::TextTag::WRAP_CHAR
    @strokes.editable = false
    @strokes.cursor_visible = false
    @strokes.set_pixels_above_lines(0)
    @strokes.set_pixels_below_lines(0)
    @strokes.modify_base(Gtk::STATE_NORMAL, color)
    
    @strokeBuffer = @strokes.buffer
    @strokeBuffer.create_tag("kanji",
                             "size" => 32 * Pango::SCALE,
                             "justification" => Gtk::JUSTIFY_CENTER)
    @strokeBuffer.insert(@strokeBuffer.start_iter, 
                         char, "kanji")
    @hbox.add(@strokes)
    spacer = Gtk::TextView.new
    spacer.set_width_request(10)
    spacer.modify_base(Gtk::STATE_NORMAL, color)
    @hbox.add(spacer)

    if !entries.empty?
        @contents = Gtk::TextView.new
        @contents.wrap_mode = Gtk::TextTag::WRAP_WORD
        @contents.editable = false
        @contents.cursor_visible = false
        @contents.set_pixels_above_lines(0)
        @contents.modify_base(Gtk::STATE_NORMAL, color)
        @contents.set_width_request(420)
        
        @buffer = @contents.buffer
        @buffer.create_tag("japanese", 
                           "size" => 12 * Pango::SCALE,
                           "justification" => Gtk::JUSTIFY_LEFT)
        @buffer.create_tag("definition", 
                           "size" => 8 * Pango::SCALE,
                           "justification" => Gtk::JUSTIFY_LEFT)
        entries.each do |word|
            if !word.kanji.nil?
                @buffer.insert(@buffer.end_iter, word.kanji, "japanese")
                @buffer.insert(@buffer.end_iter, "    ", "japanese")
            end
            @buffer.insert(@buffer.end_iter, word.reading, "japanese")
            @buffer.insert(@buffer.end_iter, "\n", "japanese")
            @buffer.insert(@buffer.end_iter, word.toMeaning, 
                           "definition")
            @buffer.insert(@buffer.end_iter, "\n", "definition")
        end
        @hbox.add(@contents)
    end
    @popup.set_default_size(450, 30)
    display 
end

Instance Method Details

#closeObject



65
66
67
# File 'lib/jldrill/views/gtk/widgets/VocabPopup.rb', line 65

def close
    @popup.destroy                
end

#showBusy(bool) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/jldrill/views/gtk/widgets/VocabPopup.rb', line 69

def showBusy(bool)
    # TextViews have a hidden subwindow that houses the cursor
    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()
    super(bool)
end