Class: Smartdict::Gui::TextView::Buffer

Inherits:
Gtk::TextBuffer
  • Object
show all
Defined in:
lib/smartdict/gui/text_view/buffer.rb

Constant Summary collapse

INDENT =
4

Instance Method Summary collapse

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



4
5
6
7
8
9
10
11
# File 'lib/smartdict/gui/text_view/buffer.rb', line 4

def initialize
  super
  create_tag("word"           , {"weight" => Pango::WEIGHT_BOLD , :scale => 1.3})
  create_tag("transcription"  , {"style"  => Pango::STYLE_ITALIC, :scale => 1.3})
  create_tag("word_class"     , {"weight" => Pango::WEIGHT_BOLD , :scale => 1.0})
  create_tag("translated_word", {:scale => 1.0})
  create_tag("text", {})
end

Instance Method Details

#set_error(error) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/smartdict/gui/text_view/buffer.rb', line 25

def set_error(error)
  self.text = ''
  insert_text "An error occured. Please report it: \n"
  insert_url "https://github.com/smartdict/smartdict-gtk/issues/new"
  insert_text "\n\nError information:\n" \
              "    #{error.class}:  #{error.message}\n\n" \
              "Backtrace:\n"
  insert_text "    " + error.backtrace.join("\n    ")
end

#set_translation(translation) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/smartdict/gui/text_view/buffer.rb', line 13

def set_translation(translation)
  self.text = ''

  insert(end_iter, translation.word, "word")
  insert(end_iter, " [#{translation.transcription}]", "transcription") if translation.transcription
  insert(end_iter, "\n")

  translation.translated.each do |word_class, words|
    add_word_class(word_class, words)
  end
end