Menu

[c54480]: / scripts / vym-ruby.rb  Maximize  Restore  History

Download this file

185 lines (158 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  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
 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
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
require 'dbus'
require 'pp'
$debug = false
class Vym
def initialize (name)
@dbus = DBus::SessionBus.instance
@service = @dbus.service(name)
@service.introspect
@main = @service.object('/vym')
@main.introspect
@main.default_iface = "org.insilmaril.vym.main.adaptor"
# Use metaprogramming to create methods for commands in vym
# Getting commands for mainwindow via DBUS
puts "Vym::initialize Retrieving commands via dbus..." if $debug
s = @main.listCommands
@vym_commands = s[0].split ","
@vym_commands.each do |c|
puts "Creating vym command: #{c}" if $debug
self.class.send(:define_method, c) do |*pars|
if pars.length == 0
# No parameters
com = "vym.#{c}();"
puts " * Calling vym: \"#{com}\":" if $debug
ret = @main.execute( com )
else
# with parameters
p = "";
a = []
pars.each do |p|
if p.kind_of? String
a << "'#{p}'"
else
a << p
end
end
com = "vym.#{c} (#{a.join(',')});"
puts " ** Calling vym: \"#{com}\":" if $debug
ret = @main.execute( com )
end
#FIXME-0 err = m.errorLevel[0]
if $debug
puts " Returned: #{ret[0]}" if ret[0] != ""
# puts " Error: #{err}" if err > 0
end
ret[0]
end
end # Creating vym commands
end
def modelCount
@main.modelCount[0]
end
def currentModel
@main.currentModel
end
def map (n)
map = @service.object("/vymmodel_#{n}")
map.introspect
map.default_iface = "org.insilmaril.vym.model.adaptor"
if modelCount > 0 && n>=0
return VymMap.new(map, n )
else
raise "Error: Map #{n} not accessible in #{@instance}!"
end
end
def currentMapX () # Overloads method from scripting.h, which would return QObject
n = @main.currentMapIndex.first
return map(n)
end
def show_methods
puts "Main methods:"
@main[@main.default_iface].methods.each do |k,v|
puts " #{k}"
end
if modelCount > 0
@model= @service.object 'vymmodel_1'
@model.default_iface = "org.insilmaril.vym.model.adaptor"
puts "Model methods:"
@model[@model.default_iface].methods.each do |k,v|
puts " #{k}"
end
else
puts "No model!"
end
end
end
class VymMap
def initialize(map, n )
@map = map
# Getting commands for model via DBUS
#if modelCount > 0
# m = model(1)
s = @map.listCommands
puts "VymMap::initialize Retrieving commands via dbus..." if $debug
@model_commands = s[0].split ","
@model_commands.each do |c|
#puts "Creating map command: #{c}" if $debug
self.class.send(:define_method, c) do |*pars|
if pars.length == 0
# No parameters
com = "vym.currentMap().#{c}();"
puts " * Calling model: \"#{com}\":" if $debug
ret = @map.execute( com )
else
# Build string with parameters
p = "";
a = []
pars.each do |p|
if p.kind_of? String
a << "'#{p}'"
else
a << p
end
end
# com = "vym.clearConsole(); print( vym.currentMap().#{c} (#{a.join(',')}));"
com = " vym.currentMap().#{c} (#{a.join(',')});"
puts " ** Calling model: \"#{com}\":" if $debug
ret = @map.execute( com )
puts "Done calling" if $debug
end
#FIXME-0 err = m.errorLevel[0]
if $debug
puts " Returned: #{ret[0]}" if ret[0] != ""
#puts " Error: #{err}" if err > 0
end
ret[0]
end
end
end # Initialize
end # VymMap
class VymManager
def initialize
@dbus = DBus::SessionBus.instance
end
def running
list = @dbus.proxy.ListNames[0].find_all{|item| item =~/org\.insilmaril\.vym/ }
end
def show_running
puts "Running vym instances:\n #{running.join "\n "}"
end
def find (name)
list = running
if list.length == 0
return nil
end
for i in (0...list.length)
vym_service = @dbus.service(list.at(i))
vym_main_obj = vym_service.object("/vym");
vym_main_obj.introspect
vym_main_obj.default_iface = "org.insilmaril.vym.main.adaptor"
if vym_main_obj.getInstanceName[0] == name
puts "VymManager: Found instance named '#{name}': #{list.at(i)}" if $debug
return Vym.new list.at(i)
end
end
raise "Could not find instance named \"test\""
return nil
end
end
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.