gave 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +1061 -0
- data/README +52 -0
- data/bin/gave +1983 -0
- data/data/gave/glade/fileselection.glade +196 -0
- data/data/locale/ja/LC_MESSAGES/gave.mo +0 -0
- data/lib/numru/gave/draw.rb +173 -0
- data/lib/numru/gave/draw_dcl.rb +574 -0
- data/lib/numru/gave/draw_vtk.rb +326 -0
- data/lib/numru/gave/fileselection.rb +188 -0
- data/lib/numru/gave/gave_config.rb +2 -0
- data/lib/numru/gave/pre-install.rb +7 -0
- data/setup.rb +1360 -0
- metadata +69 -0
@@ -0,0 +1,326 @@
|
|
1
|
+
require "numru/gave/draw"
|
2
|
+
require "vtk/Gtk"
|
3
|
+
|
4
|
+
GAVE_GTK_VERSION = 2
|
5
|
+
|
6
|
+
Gtk.init
|
7
|
+
Gtk::GL.init
|
8
|
+
|
9
|
+
class GtkGLExtVTKRenderWindow
|
10
|
+
def OnKeyPress(wid, event=nil)
|
11
|
+
if (event.keyval == Gdk::Keyval.from_name("q")) ||
|
12
|
+
(event.keyval == Gdk::Keyval.from_name("Q"))
|
13
|
+
self.parent.hide
|
14
|
+
elsif (event.keyval == Gdk::Keyval.from_name('r')) ||
|
15
|
+
(event.keyval == Gdk::Keyval.from_name('R'))
|
16
|
+
self.Reset
|
17
|
+
return true
|
18
|
+
elsif (event.keyval == Gdk::Keyval.from_name('w')) ||
|
19
|
+
(event.keyval == Gdk::Keyval.from_name('W'))
|
20
|
+
self.Wireframe
|
21
|
+
return true
|
22
|
+
elsif (event.keyval == Gdk::Keyval.from_name('s')) ||
|
23
|
+
(event.keyval == Gdk::Keyval.from_name('S'))
|
24
|
+
self.Surface
|
25
|
+
return true
|
26
|
+
elsif (event.keyval == Gdk::Keyval.from_name('p')) ||
|
27
|
+
(event.keyval == Gdk::Keyval.from_name('P'))
|
28
|
+
m = pointer
|
29
|
+
self.PickActor(m[0], m[1])
|
30
|
+
return true
|
31
|
+
else
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Draw
|
38
|
+
alias :_initialize :initialize
|
39
|
+
def initialize(n)
|
40
|
+
_initialize(n)
|
41
|
+
end
|
42
|
+
alias :_clear :clear
|
43
|
+
def clear
|
44
|
+
_clear
|
45
|
+
end
|
46
|
+
def open_graphics
|
47
|
+
@draw_area = GtkGLExtVTKRenderWindow.new
|
48
|
+
@draw_area.set_size_request(@width,@height)
|
49
|
+
@ren = Vtk::Renderer.new
|
50
|
+
@draw_area.GetRenderWindow.AddRenderer(@ren)
|
51
|
+
@window = Gtk::Window.new(Gtk::Window::TOPLEVEL).set_resizable(true)
|
52
|
+
@window.signal_connect("delete-event"){|w,p| w.hide; true}
|
53
|
+
@window.signal_connect("destroy"){exit}
|
54
|
+
@window.add(@draw_area)
|
55
|
+
names = @gphys.funcs[0]
|
56
|
+
@window.set_title("#{@winno}: #{names[2]}@#{names[0]}")
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
private
|
61
|
+
def draw_1d(title,xtitle,ytitle)
|
62
|
+
@fig.figure_set("title = \"#{title}\"", __FILE__,__LINE__)
|
63
|
+
@fig.figure_set("xtitle = \"#{xtitle}\"", __FILE__,__LINE__)
|
64
|
+
@fig.figure_set("ytitle = \"#{ytitle}\"", __FILE__,__LINE__)
|
65
|
+
@fig.figure_set('x = gphys0.coord(0).val', __FILE__,__LINE__)
|
66
|
+
@fig.figure_set('grid = Vtk::RectilinearGrid.new', __FILE__,__LINE__)
|
67
|
+
@fig.figure_set('length = gphys0.length', __FILE__,__LINE__)
|
68
|
+
@fig.figure_set('grid.SetDimensions(length,1,1)', __FILE__,__LINE__)
|
69
|
+
@fig.figure_set('grid.SetXCoordinates(x.to_va)', __FILE__,__LINE__)
|
70
|
+
@fig.figure_set('data = gphys0.val', __FILE__,__LINE__)
|
71
|
+
@fig.figure_set('data = data.get_array! if NArrayMiss===data', __FILE__,__LINE__)
|
72
|
+
@fig.figure_set('grid.GetPointData.SetScalars(data.to_va)', __FILE__,__LINE__)
|
73
|
+
@fig.figure_set('xyplot = Vtk::XYPlotActor.new', __FILE__,__LINE__)
|
74
|
+
@fig.figure_set('xyplot.AddInput(grid)', __FILE__,__LINE__)
|
75
|
+
@fig.figure_set('xyplot.GetProperty.SetColor(0,0,0)', __FILE__,__LINE__)
|
76
|
+
@fig.figure_set('xyplot.SetTitle(title)', __FILE__,__LINE__)
|
77
|
+
@fig.figure_set('xyplot.SetXTitle(xtitle)', __FILE__,__LINE__)
|
78
|
+
@fig.figure_set('xyplot.SetYTitle(ytitle)', __FILE__,__LINE__)
|
79
|
+
# @fig.figure_set('xyplot.PlotPointsOn', __FILE__,__LINE__)
|
80
|
+
@fig.figure_set('tprop = xyplot.GetTitleTextProperty', __FILE__,__LINE__)
|
81
|
+
@fig.figure_set('tprop.SetColor(*xyplot.GetProperty.GetColor)', __FILE__,__LINE__)
|
82
|
+
@fig.figure_set('xyplot.SetAxisTitleTextProperty(tprop)', __FILE__,__LINE__)
|
83
|
+
@fig.figure_set('xyplot.SetAxisLabelTextProperty(tprop)', __FILE__,__LINE__)
|
84
|
+
@fig.figure_set('ren.AddActor2D(xyplot)', __FILE__,__LINE__)
|
85
|
+
@fig.figure_set('ren.SetBackground(1, 1, 1)', __FILE__,__LINE__)
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
def draw_2d(title,type)
|
90
|
+
@fig.figure_set('x = gphys0.coord(0).val', __FILE__,__LINE__)
|
91
|
+
@fig.figure_set('xmin = x.min', __FILE__,__LINE__)
|
92
|
+
@fig.figure_set('xmax = x.max', __FILE__,__LINE__)
|
93
|
+
@fig.figure_set('x = x/(xmax-xmin)', __FILE__,__LINE__)
|
94
|
+
@fig.figure_set('y = gphys0.coord(1).val', __FILE__,__LINE__)
|
95
|
+
@fig.figure_set('ymin = y.min', __FILE__,__LINE__)
|
96
|
+
@fig.figure_set('ymax = y.max', __FILE__,__LINE__)
|
97
|
+
@fig.figure_set('y = y/(ymax-ymin)', __FILE__,__LINE__)
|
98
|
+
# @fig.figure_set('yfact = (xmax-xmin)/(ymax-ymin)', __FILE__,__LINE__)
|
99
|
+
@fig.figure_set('grid = Vtk::RectilinearGrid.new', __FILE__,__LINE__)
|
100
|
+
@fig.figure_set('shape = gphys0.shape', __FILE__,__LINE__)
|
101
|
+
@fig.figure_set('grid.SetDimensions(shape[0],shape[1],1)', __FILE__,__LINE__)
|
102
|
+
@fig.figure_set('grid.SetXCoordinates(x.to_va)', __FILE__,__LINE__)
|
103
|
+
@fig.figure_set('grid.SetYCoordinates(y.to_va)', __FILE__,__LINE__)
|
104
|
+
@fig.figure_set('data = gphys0.val', __FILE__,__LINE__)
|
105
|
+
@fig.figure_set('data = data.get_array! if NArrayMiss===data', __FILE__,__LINE__)
|
106
|
+
@fig.figure_set('grid.GetPointData.SetScalars(data.reshape!(data.length).to_va)', __FILE__,__LINE__)
|
107
|
+
@fig.figure_set('outline = Vtk::OutlineFilter.new', __FILE__,__LINE__)
|
108
|
+
@fig.figure_set('outline.SetInput(grid)', __FILE__,__LINE__)
|
109
|
+
@fig.figure_set('outlineMapper = Vtk::PolyDataMapper.new', __FILE__,__LINE__)
|
110
|
+
@fig.figure_set('outlineMapper.SetInput(outline.GetOutput)', __FILE__,__LINE__)
|
111
|
+
@fig.figure_set('outlineActor = Vtk::Actor.new', __FILE__,__LINE__)
|
112
|
+
@fig.figure_set('outlineActor.SetMapper(outlineMapper)', __FILE__,__LINE__)
|
113
|
+
# @fig.figure_set('outlineActor.SetScale(1,yfact,1)', __FILE__,__LINE__)
|
114
|
+
@fig.figure_set('outlineActor.GetProperty.SetColor(0,0,0)', __FILE__,__LINE__)
|
115
|
+
@fig.figure_set('contour = Vtk::ContourFilter.new', __FILE__,__LINE__)
|
116
|
+
@fig.figure_set('contour.SetInput(grid)', __FILE__,__LINE__)
|
117
|
+
@fig.figure_set('contour.GenerateValues(40, data.min, data.max)', __FILE__,__LINE__)
|
118
|
+
@fig.figure_set('mapper = Vtk::PolyDataMapper.new', __FILE__,__LINE__)
|
119
|
+
@fig.figure_set('mapper.SetInput(contour.GetOutput)', __FILE__,__LINE__)
|
120
|
+
@fig.figure_set('mapper.SetScalarRange(data.min,data.max)', __FILE__,__LINE__)
|
121
|
+
@fig.figure_set('actor = Vtk::Actor.new', __FILE__,__LINE__)
|
122
|
+
@fig.figure_set('actor.SetMapper(mapper)', __FILE__,__LINE__)
|
123
|
+
# @fig.figure_set('actor.SetScale(1,yfact,1)', __FILE__,__LINE__)
|
124
|
+
@fig.figure_set('ren.AddActor(actor)', __FILE__,__LINE__)
|
125
|
+
@fig.figure_set('ren.AddActor(outlineActor)', __FILE__,__LINE__)
|
126
|
+
@fig.figure_set('ren.SetBackground(1, 1, 1)', __FILE__,__LINE__)
|
127
|
+
# @fig.figure_set('tprop = Vtk::TextProperty.new', __FILE__,__LINE__)
|
128
|
+
# @fig.figure_set('tprop.SetColor(0,0,0)', __FILE__,__LINE__)
|
129
|
+
@fig.figure_set('axes = Vtk::CubeAxesActor2D.new', __FILE__,__LINE__)
|
130
|
+
@fig.figure_set('axes.SetCornerOffset(0)', __FILE__,__LINE__)
|
131
|
+
@fig.figure_set('axes.SetInput(grid)', __FILE__,__LINE__)
|
132
|
+
@fig.figure_set('axes.SetCamera(ren.GetActiveCamera)', __FILE__,__LINE__)
|
133
|
+
@fig.figure_set('axes.SetFontFactor(1.2)', __FILE__,__LINE__)
|
134
|
+
# @fig.figure_set('axes.SetAxisTitleTextProperty(tprop)', __FILE__,__LINE__)
|
135
|
+
# @fig.figure_set('axes.SetAxisLabelTextProperty(tprop)', __FILE__,__LINE__)
|
136
|
+
@fig.figure_set('axes.GetProperty.SetColor(0,0,0)', __FILE__,__LINE__)
|
137
|
+
@fig.figure_set('axes.UseRangesOn', __FILE__,__LINE__)
|
138
|
+
@fig.figure_set('axes.SetRanges(xmin,xmax,ymin,ymax,0,0)', __FILE__,__LINE__)
|
139
|
+
@fig.figure_set('ren.AddProp(axes)', __FILE__,__LINE__)
|
140
|
+
end
|
141
|
+
|
142
|
+
def draw_3d(title)
|
143
|
+
@fig.figure_set('x = gphys0.coord(0).val', __FILE__,__LINE__)
|
144
|
+
@fig.figure_set('xmin = x.min', __FILE__,__LINE__)
|
145
|
+
@fig.figure_set('xmax = x.max', __FILE__,__LINE__)
|
146
|
+
@fig.figure_set('x = x/(xmax-xmin)', __FILE__,__LINE__)
|
147
|
+
@fig.figure_set('y = gphys0.coord(1).val', __FILE__,__LINE__)
|
148
|
+
@fig.figure_set('ymin = y.min', __FILE__,__LINE__)
|
149
|
+
@fig.figure_set('ymax = y.max', __FILE__,__LINE__)
|
150
|
+
@fig.figure_set('y = y/(ymax-ymin)', __FILE__,__LINE__)
|
151
|
+
@fig.figure_set('z = gphys0.coord(2).val', __FILE__,__LINE__)
|
152
|
+
@fig.figure_set('zmin = z.min', __FILE__,__LINE__)
|
153
|
+
@fig.figure_set('zmax = z.max', __FILE__,__LINE__)
|
154
|
+
@fig.figure_set('z = z/(zmax-zmin)', __FILE__,__LINE__)
|
155
|
+
# @fig.figure_set('yfact = (xmax-xmin)/(ymax-ymin)', __FILE__,__LINE__)
|
156
|
+
# @fig.figure_set('zfact = (xmax-xmin)/(zmax-zmin)', __FILE__,__LINE__)
|
157
|
+
@fig.figure_set('grid = Vtk::RectilinearGrid.new', __FILE__,__LINE__)
|
158
|
+
@fig.figure_set('shape = gphys0.shape', __FILE__,__LINE__)
|
159
|
+
@fig.figure_set('grid.SetDimensions(*shape)', __FILE__,__LINE__)
|
160
|
+
@fig.figure_set('grid.SetXCoordinates(x.to_va)', __FILE__,__LINE__)
|
161
|
+
@fig.figure_set('grid.SetYCoordinates(y.to_va)', __FILE__,__LINE__)
|
162
|
+
@fig.figure_set('grid.SetZCoordinates(z.to_va)', __FILE__,__LINE__)
|
163
|
+
|
164
|
+
@fig.figure_set('data = gphys0.val', __FILE__,__LINE__)
|
165
|
+
@fig.figure_set('data = data.get_array! if NArrayMiss===data', __FILE__,__LINE__)
|
166
|
+
@fig.figure_set('data = (data-data.min)/(data.max-data.min)', __FILE__,__LINE__)
|
167
|
+
@fig.figure_set('grid.GetPointData.SetScalars(data.reshape!(data.length).to_va)', __FILE__,__LINE__)
|
168
|
+
@fig.figure_set('outline = Vtk::OutlineFilter.new', __FILE__,__LINE__)
|
169
|
+
@fig.figure_set('outline.SetInput(grid)', __FILE__,__LINE__)
|
170
|
+
@fig.figure_set('outlineMapper = Vtk::PolyDataMapper.new', __FILE__,__LINE__)
|
171
|
+
@fig.figure_set('outlineMapper.SetInput(outline.GetOutput)', __FILE__,__LINE__)
|
172
|
+
@fig.figure_set('outlineActor = Vtk::Actor.new', __FILE__,__LINE__)
|
173
|
+
@fig.figure_set('outlineActor.SetMapper(outlineMapper)', __FILE__,__LINE__)
|
174
|
+
# @fig.figure_set('outlineActor.SetScale(1,yfact,zfact)', __FILE__,__LINE__)
|
175
|
+
# @fig.figure_set('outlineActor.GetProperty.SetColor(0,0,0)', __FILE__,__LINE__)
|
176
|
+
@fig.figure_set('surface = Vtk::ContourFilter.new', __FILE__,__LINE__)
|
177
|
+
@fig.figure_set('surface.SetInput(grid)', __FILE__,__LINE__)
|
178
|
+
if @surface
|
179
|
+
@fig.figure_set("surface.SetValue(0,#{@surface})", __FILE__,__LINE__)
|
180
|
+
else
|
181
|
+
@fig.figure_set('surface.SetValue(0,0.5)', __FILE__,__LINE__)
|
182
|
+
end
|
183
|
+
@fig.figure_set('mapper = Vtk::PolyDataMapper.new', __FILE__,__LINE__)
|
184
|
+
@fig.figure_set('mapper.SetInput(surface.GetOutput)', __FILE__,__LINE__)
|
185
|
+
@fig.figure_set('mapper.SetScalarModeToUsePointFieldData', __FILE__,__LINE__)
|
186
|
+
@fig.figure_set('actor = Vtk::Actor.new', __FILE__,__LINE__)
|
187
|
+
@fig.figure_set('actor.SetMapper(mapper)', __FILE__,__LINE__)
|
188
|
+
@fig.figure_set('actor.GetProperty.SetOpacity(0.5)', __FILE__,__LINE__)
|
189
|
+
# @fig.figure_set('actor.SetScale(1,yfact,zfact)', __FILE__,__LINE__)
|
190
|
+
@fig.figure_set('ren.AddActor(outlineActor)', __FILE__,__LINE__)
|
191
|
+
@fig.figure_set('ren.AddActor(actor)', __FILE__,__LINE__)
|
192
|
+
@fig.figure_set('ren.SetBackground(0.1, 0.2, 0.4)', __FILE__,__LINE__)
|
193
|
+
# @fig.figure_set('tprop = Vtk::TextProperty.new', __FILE__,__LINE__)
|
194
|
+
# @fig.figure_set('tprop.SetColor(1,1,1)', __FILE__,__LINE__)
|
195
|
+
@fig.figure_set('axes = Vtk::CubeAxesActor2D.new', __FILE__,__LINE__)
|
196
|
+
@fig.figure_set('axes.SetCornerOffset(0)', __FILE__,__LINE__)
|
197
|
+
@fig.figure_set('axes.SetInput(grid)', __FILE__,__LINE__)
|
198
|
+
@fig.figure_set('axes.SetCamera(ren.GetActiveCamera)', __FILE__,__LINE__)
|
199
|
+
@fig.figure_set('axes.SetFontFactor(1.2)', __FILE__,__LINE__)
|
200
|
+
# @fig.figure_set('axes.SetAxisTitleTextProperty(tprop)', __FILE__,__LINE__)
|
201
|
+
# @fig.figure_set('axes.SetAxisLabelTextProperty(tprop)', __FILE__,__LINE__)
|
202
|
+
@fig.figure_set('axes.UseRangesOn', __FILE__,__LINE__)
|
203
|
+
@fig.figure_set('axes.SetRanges(xmin,xmax,ymin,ymax,zmin,zmax)', __FILE__,__LINE__)
|
204
|
+
@fig.figure_set('ren.AddProp(axes)', __FILE__,__LINE__)
|
205
|
+
end
|
206
|
+
|
207
|
+
private
|
208
|
+
def draw(drawing_area)
|
209
|
+
@fig.figure_clear
|
210
|
+
acts = @ren.GetActors
|
211
|
+
for i in 0...acts.GetNumberOfItems
|
212
|
+
act = Vtk::Actor.SafeDownCast(acts.GetItemAsObject(0))
|
213
|
+
@ren.RemoveActor(act)
|
214
|
+
end
|
215
|
+
|
216
|
+
if @type == LINE
|
217
|
+
draw_1d(@title,@x_title,@y_title)
|
218
|
+
elsif @type == CONTOUR
|
219
|
+
draw_2d(@title,@type)
|
220
|
+
elsif @type == SURFACE
|
221
|
+
draw_3d(@title)
|
222
|
+
end
|
223
|
+
|
224
|
+
root = @window
|
225
|
+
gphys0 = @gphys
|
226
|
+
renWin = @draw_area
|
227
|
+
ren = @ren
|
228
|
+
codes = @fig.draw_eval
|
229
|
+
for j in 0...codes.length
|
230
|
+
eval *codes[j]
|
231
|
+
end
|
232
|
+
@draw_area.Render
|
233
|
+
@window.show_all
|
234
|
+
end
|
235
|
+
|
236
|
+
private
|
237
|
+
class Fig
|
238
|
+
attr_reader :head, :var, :open, :close
|
239
|
+
def initialize
|
240
|
+
@var = ""
|
241
|
+
@figure = Array.new
|
242
|
+
@head = <<"END"
|
243
|
+
require "numru/gphys"
|
244
|
+
require "vtk"
|
245
|
+
|
246
|
+
include NumRu
|
247
|
+
END
|
248
|
+
@open = <<"END"
|
249
|
+
renWin = Vtk::RenderWindow.new
|
250
|
+
ren = Vtk::Renderer.new
|
251
|
+
renWin.AddRenderer(ren)
|
252
|
+
|
253
|
+
END
|
254
|
+
@close = <<"END"
|
255
|
+
iren = Vtk::RenderWindowInteractor.new
|
256
|
+
iren.SetRenderWindow(renWin)
|
257
|
+
iren.Initialize
|
258
|
+
renWin.Render
|
259
|
+
iren.Start
|
260
|
+
END
|
261
|
+
end
|
262
|
+
def var_set(funcs,mapping,n)
|
263
|
+
@var = "" if n==0
|
264
|
+
filename, filetype, varname = funcs[0]
|
265
|
+
if filename.length==1
|
266
|
+
@var += "filename = \"#{filename[0]}\"\n"
|
267
|
+
else
|
268
|
+
@var += "filename = [\"#{filename.join('", "')}\"]\n"
|
269
|
+
end
|
270
|
+
@var += "varname = \"#{varname}\"\n"
|
271
|
+
|
272
|
+
|
273
|
+
if filetype.nil?
|
274
|
+
@var += "gphys#{n} = GPhys::IO.open(filename,varname)\n"
|
275
|
+
elsif filetype=="druby"
|
276
|
+
@var += "require \"drb/drb\"\n"
|
277
|
+
@var += "DRb.start_service\n"
|
278
|
+
@var += "class NArray\n"
|
279
|
+
@var += " def self._load(o) to_na(*Marshal::load(o)).ntoh end\n"
|
280
|
+
@var += "end\n"
|
281
|
+
@var += "ary = filename.split('/')\n"
|
282
|
+
@var += "host = 'druby://'+ary[2]\n"
|
283
|
+
@var += "path = ary[3..-1].join('/')\n"
|
284
|
+
@var += "tree = DRbObject.new(nil,host)\n"
|
285
|
+
@var += "gphys#{n} = tree.data(path)\n"
|
286
|
+
else
|
287
|
+
raise "filetype is invalid"
|
288
|
+
end
|
289
|
+
|
290
|
+
if funcs.length!=0
|
291
|
+
funcs[1..-1].each{|func|
|
292
|
+
@var += "gphys#{n} = gphys#{n}.cut(#{func[2].join(",")})\n"
|
293
|
+
@var += "gphys#{n} = gphys#{n}.#{func[0]}(#{func[1]})\n"
|
294
|
+
}
|
295
|
+
end
|
296
|
+
str = mapping.collect{|a|
|
297
|
+
if NArray===a
|
298
|
+
"NArray[#{a.to_a.join(",")}]"
|
299
|
+
else
|
300
|
+
a
|
301
|
+
end
|
302
|
+
}.join(",")
|
303
|
+
@var += "gphys#{n} = gphys#{n}[#{str}]\n"
|
304
|
+
end
|
305
|
+
|
306
|
+
def title_set(xt,xu,yt,yu, file,line)
|
307
|
+
end
|
308
|
+
|
309
|
+
def figure_clear
|
310
|
+
@figure.clear
|
311
|
+
end
|
312
|
+
def figure_set(str,file,line)
|
313
|
+
@figure.push([str,file,line])
|
314
|
+
end
|
315
|
+
def draw_parm
|
316
|
+
end
|
317
|
+
def draw
|
318
|
+
@figure.collect{|c| c[0]}.join("\n")
|
319
|
+
end
|
320
|
+
def draw_eval
|
321
|
+
codes = Array.new
|
322
|
+
@figure.each{|c| codes.push [c[0], nil, c[1], c[2]]}
|
323
|
+
codes
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
enable = true
|
3
|
+
begin
|
4
|
+
require 'libglade2'
|
5
|
+
rescue LoadError
|
6
|
+
begin
|
7
|
+
require "lglade"
|
8
|
+
rescue LoadError
|
9
|
+
enable = false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
if enable
|
14
|
+
begin
|
15
|
+
require "gnomevfs"
|
16
|
+
require "drb/drb"
|
17
|
+
require "narray"
|
18
|
+
rescue LoadError
|
19
|
+
enable = false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if enable
|
24
|
+
|
25
|
+
DRb.start_service
|
26
|
+
|
27
|
+
class NArray
|
28
|
+
def self._load(o) to_na(*Marshal::load(o)).ntoh end
|
29
|
+
end
|
30
|
+
class NArrayMiss
|
31
|
+
def self._load(o)
|
32
|
+
ary, mask = Marshal::load(o)
|
33
|
+
ary = NArray._load(ary)
|
34
|
+
mask = NArray._load(mask)
|
35
|
+
NArrayMiss.to_nam_no_dup(ary,mask)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
class DFileSelection
|
41
|
+
Glade_file = DATA_PATH+"/gave/glade/fileselection.glade"
|
42
|
+
def initialize(title="FileSelection")
|
43
|
+
glade = GladeXML.new(Glade_file) {|handler| method(handler)}
|
44
|
+
@window = glade.get_widget("Fileselection")
|
45
|
+
@window.hide
|
46
|
+
@window.title = title
|
47
|
+
@ok = glade.get_widget("ok")
|
48
|
+
@entry = glade.get_widget("entry")
|
49
|
+
hpaned = glade.get_widget("hpaned1")
|
50
|
+
hpaned.position=245
|
51
|
+
@dirlist = glade.get_widget("dirlist")
|
52
|
+
@filelist = glade.get_widget("filelist")
|
53
|
+
column = Gtk::TreeViewColumn.new("Dir", Gtk::CellRendererText.new,
|
54
|
+
{:text=>0})
|
55
|
+
@dirlist.append_column(column)
|
56
|
+
column = Gtk::TreeViewColumn.new("File", Gtk::CellRendererText.new,
|
57
|
+
{:text=>0})
|
58
|
+
@filelist.append_column(column)
|
59
|
+
@dirlist.show_all
|
60
|
+
@filelist.show_all
|
61
|
+
@dirmodel = Gtk::TreeStore.new(String)
|
62
|
+
@filemodel = Gtk::TreeStore.new(String)
|
63
|
+
@dirlist.model = @dirmodel
|
64
|
+
@filelist.model = @filemodel
|
65
|
+
GnomeVFS.init
|
66
|
+
@uri = GnomeVFS::URI.new(File.expand_path("."))
|
67
|
+
make_models
|
68
|
+
end
|
69
|
+
|
70
|
+
def on_dirlist_cursor_changed(widget)
|
71
|
+
path = widget.cursor[0]
|
72
|
+
name = @dirmodel.get_iter(path)[0]
|
73
|
+
if GnomeVFS::URI===@uri
|
74
|
+
uri = @uri.append_path(name)
|
75
|
+
return until uri.exists?
|
76
|
+
return if @uri.to_s==uri.to_s
|
77
|
+
@uri = uri
|
78
|
+
else
|
79
|
+
return until @uri.list_dirs.index(name) || name=="." || name==".."
|
80
|
+
uri = @uri.dir(name)
|
81
|
+
return if @uri.path==uri.path
|
82
|
+
@uri = uri
|
83
|
+
end
|
84
|
+
make_models
|
85
|
+
end
|
86
|
+
def on_filelist_cursor_changed(widget)
|
87
|
+
path = widget.cursor[0]
|
88
|
+
name = @filemodel.get_iter(path)[0]
|
89
|
+
if GnomeVFS::URI===@uri
|
90
|
+
uri = @uri.append_path(name)
|
91
|
+
return until uri.exists?
|
92
|
+
@entry.text = uri.to_s
|
93
|
+
else
|
94
|
+
return until @uri.list_data.index(name)
|
95
|
+
@entry.text = @uri.__drburi+@uri.path+name
|
96
|
+
end
|
97
|
+
end
|
98
|
+
def on_entry_activate
|
99
|
+
jump
|
100
|
+
end
|
101
|
+
def on_jump_clicked(widget)
|
102
|
+
jump
|
103
|
+
end
|
104
|
+
def jump
|
105
|
+
if @entry.text =~ /^druby:\/\//
|
106
|
+
path = @entry.text
|
107
|
+
uri = DRbObject.new(nil,path)
|
108
|
+
return until uri
|
109
|
+
@uri = uri
|
110
|
+
else
|
111
|
+
uri = GnomeVFS::URI.new(@entry.text)
|
112
|
+
if uri.exists?
|
113
|
+
@uri = uri
|
114
|
+
else
|
115
|
+
return
|
116
|
+
end
|
117
|
+
end
|
118
|
+
make_models
|
119
|
+
end
|
120
|
+
def on_cancel_clicked(widget)
|
121
|
+
hide
|
122
|
+
end
|
123
|
+
def on_Fileselection_delete_event(widget, arg0)
|
124
|
+
hide
|
125
|
+
end
|
126
|
+
|
127
|
+
def make_models
|
128
|
+
@dirmodel.clear
|
129
|
+
@filemodel.clear
|
130
|
+
items = Array.new
|
131
|
+
if GnomeVFS::URI===@uri
|
132
|
+
GnomeVFS::Directory.open(@uri).each{|i| items.push i}
|
133
|
+
items = [".",".."]+items if items[0].name != "."
|
134
|
+
items.each{|item|
|
135
|
+
if String===item || item.directory?
|
136
|
+
iter = @dirmodel.append(nil)
|
137
|
+
else
|
138
|
+
iter = @filemodel.append(nil)
|
139
|
+
end
|
140
|
+
item = item.name until String===item
|
141
|
+
iter[0] = item
|
142
|
+
}
|
143
|
+
@entry.text = @uri.to_s
|
144
|
+
else
|
145
|
+
@dirmodel.append(nil)[0] = "."
|
146
|
+
# @dirmodel.append(nil)[0] = ".." if @uri.dir("..")
|
147
|
+
@dirmodel.append(nil)[0] = ".."
|
148
|
+
@uri.list_dirs.each{|name| @dirmodel.append(nil)[0] = name}
|
149
|
+
@uri.list_data.each{|name| @filemodel.append(nil)[0] = name}
|
150
|
+
@entry.text = @uri.__drburi+@uri.path
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def ok_button
|
155
|
+
@ok
|
156
|
+
end
|
157
|
+
def show
|
158
|
+
@window.show
|
159
|
+
end
|
160
|
+
def hide
|
161
|
+
@window.hide
|
162
|
+
end
|
163
|
+
def selection
|
164
|
+
[@entry.text]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
if $0 == __FILE__
|
170
|
+
|
171
|
+
|
172
|
+
#If you use only Ruby/GTK2 widgets, call Gtk.init here.
|
173
|
+
#Gtk.init
|
174
|
+
#If you use Ruby/GNOME2 widgets, call Gnome::Program.new here.
|
175
|
+
if enable
|
176
|
+
Gnome::Program.new("Druby selection", "0.0")
|
177
|
+
|
178
|
+
fs = DFileSelection.new("test")
|
179
|
+
fs.show
|
180
|
+
fs.ok_button.signal_connect("clicked"){|w|
|
181
|
+
fs.hide
|
182
|
+
p fs.selection
|
183
|
+
}
|
184
|
+
|
185
|
+
Gtk.main
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|