Top Level Namespace

Includes:
Merrol::CommandDispatcher

Defined Under Namespace

Modules: Gtk, Merrol, YAML Classes: File, LibNotFoundError

Constant Summary collapse

APP_NAME =
"Merrol"
WORKING_DIR =
Dir.getwd

Instance Method Summary collapse

Instance Method Details

#check_packagesObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/prerequisites.rb', line 3

def check_packages
  selections = `dpkg --get-selections`
  libs = %w(libglib2.0-dev libatk1.0-dev libpango1.0-dev libgtk2.0-dev libgtksourceview2.0-dev)
  libs.each do |lib|
    raise LibNotFoundError unless selections =~ Regexp.new(lib)
  end
rescue LibNotFoundError => e
  puts 'Some packages needed for installation are missing'
  puts 'To install the rquired packages please run:'
  puts '    sudo apt-get install libglib2.0-dev libatk1.0-dev libpango1.0-dev libgtk2.0-dev libgtksourceview2.0-dev'
  puts
  exit
end

#command_for(key) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/merrol/keyboard_map.rb', line 125

def command_for key
  modifiers = ''
  modifiers << 'CTRL+' if $modifiers[2].active?
  modifiers << 'ALT+' if $modifiers[3].active?
  modifiers << 'SHIFT+' if $modifiers[0].active?
  @commands[modifiers + key] || []
end

#install_ruby_gnome2Object



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
# File 'lib/prerequisites.rb', line 17

def install_ruby_gnome2
  trap("INT") { puts "\rAborted."; exit }

  puts "Some ruby libraries need to be compiled and installed to run merrol (gtk2 and gtksourceview2)"
  puts "Press ENTER to install or CTRL+C to abort"
  gets

  logfile = '/tmp/ruby-gnome2-install.log'

  package = 'ruby-gnome2-all-0.90.4'
  system "gem install pkg-config > #{logfile}"
  puts 'pkg-config installed'

  puts 'Downloading sources...'
  system "cd /tmp && wget http://downloads.sourceforge.net/ruby-gnome2/#{package}.tar.gz >> #{logfile}"

  puts 'Extracting sources...'
  system "cd /tmp && tar xf #{package}.tar.gz"

  puts 'Configuring ...'
  system "cd /tmp/#{package} && ruby extconf.rb >> #{logfile}"

  puts 'Building ...'
  system "cd /tmp/#{package} && sudo make >> #{logfile}"

  puts 'Installing ...'
  system "cd /tmp/#{package} && sudo make install >> #{logfile}"

  puts 'Done.'
end

#key_from_event(e) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/merrol/keyboard_map.rb', line 63

def key_from_event e
  unmodified_keyval = Gdk::Keymap.default.lookup_key(e.hardware_keycode, 0, 0)
  key = Gdk::Keyval.to_name(unmodified_keyval).upcase
  {'RETURN' => 'ENTER', 'ESCAPE' => 'ESC',
    'CONTROL_L' => 'CTRL', 'ALT_L' => 'ALT', 'SHIFT_L' => 'SHIFT',
    'CONTROL_R' => 'CTRL', 'ALT_R' => 'ALT', 'SHIFT_R' => 'SHIFT'
  }[key] || key
end

#render_keysObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/merrol/keyboard_map.rb', line 39

def render_keys
  $rows.children[0..-2].each do |row|
    row.children.each do |button|
      next if button.is_a?(Gtk::Label)
      label = button.children.first
      key = label.text.split("\n").first
      command = command_for(key).first
      button.sensitive = !command.nil? unless %w(CTRL SHIFT ALT).include?(key)
      label.markup = "<small><b>#{key}</b>\n#{command}</small>"
    end
  end
end

#shortcut(shortcut) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/merrol/keyboard_map.rb', line 52

def shortcut shortcut
  keys = []
  key = key_from_event(shortcut)
  return key if %w(CTRL SHIFT ALT).include?(key)
  keys << "CTRL" if shortcut.state.control_mask?
  keys << "ALT" if shortcut.state.mod1_mask?
  keys << "SHIFT" if shortcut.state.shift_mask?
  keys << key
  keys.join('+')
end

#toggle_button(modifier, active) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/merrol/keyboard_map.rb', line 27

def toggle_button modifier, active
  if %w(CTRL ALT SHIFT).include?(modifier)
    $modifiers.each do |button|
      button.active = active if button.children.first.text.split("\n").first == modifier
    end
    render_keys
    true
  else
    false
  end
end