M
Michal 'hramrach' Suchanek
Hello
I wanted some OpenGL demo for ruby and the first thing I found was
ruboids.
I had some problems compiling qtruby because it uses libtool. But now I
can run some qtruby examples so it should work.
But when I tried running ruboids I found some things are named
differently in my setup (see patch). I disabled those for which there
was no apparent equivalent to see if I get at least some window as a
start. For testing purposes I also symlinked Canvas.rb to MyCanvas.rb
The thing that fais is that there is no canvas= method in singleton
instance of World although it has attr_accessor for :canvas.
Also I can get a World instance by new() but I get nil from instance()
DISPLAY=:0 ruby ruboids.rb ../boids.properties
±./MyCanvas.rb:27: warning: don't put space before argument parentheses
QLayout: Adding MyCanvas/unnamed (top-level widget) to layout for
WorldWindow/unnamed
QLayout "unnamed" added to WorldWindow "unnamed", which already has a
layout
QLayout "unnamed" added to WorldWindow "unnamed", which already has a
layout
ruboids.rb:29: undefined method `canvas=' for nil:NilClass
(NoMethodError)
I get the expected behavior if I test with a simple class in irb but I
get non-singleton if I subclass Qt::Object.
suchanek:~ hramrach$ irb
irb(main):001:0> require "qt"
requi=> true
irb(main):002:0> require "singleton"
=> true
irb(main):003:0> class Single < Qt::Object
irb(main):004:1> include Singleton
irb(main):005:1> def initialize
irb(main):006:2> STDERR.puts inspect
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> Single.new
=> #<Qt::Object:0x7b685c>
irb(main):010:0> Single.instance
#<Single:0x7b4fd4>
=> nil
irb(main):011:0> Single.new
=> #<Qt::Object:0x7b3878>
irb(main):012:0>
Is it impossble to base singletons on QObject?
Thanks
Michal Suchanek
Just for reference:
http://www.io.com/~jimm/downloads/ruboids/
diff -ur ruboids-0.0.1.org/ruboids/BoidView.rb ruboids-0.0.1/ruboids/BoidView.rb
--- ruboids-0.0.1.org/ruboids/BoidView.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/BoidView.rb Tue Sep 28 03:33:09 2004
@@ -11,7 +11,7 @@
BODY_COLOR = [0, 0, 0]
BEAK_COLOR = [0.75, 0.5, 0.0]
- SHADOW_COLOR = [.25, .55, .25]
+ SHADOW_COLOR = [0.25, 0.55, 0.25]
HALF_WING_BASE = 3
HALF_LENGTH = 5
diff -ur ruboids-0.0.1.org/ruboids/CameraDialog.rb ruboids-0.0.1/ruboids/CameraDialog.rb
--- ruboids-0.0.1.org/ruboids/CameraDialog.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/CameraDialog.rb Tue Sep 28 16:46:27 2004
@@ -28,7 +28,7 @@
end
end
-class CameraDialog < QDialog
+class CameraDialog < Qt:ialog
def initialize(parent)
@locAdjustors = []
diff -ur ruboids-0.0.1.org/ruboids/Canvas.rb ruboids-0.0.1/ruboids/Canvas.rb
--- ruboids-0.0.1.org/ruboids/Canvas.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/Canvas.rb Tue Sep 28 17:34:00 2004
@@ -7,7 +7,7 @@
require 'qt'
require 'opengl'
-require 'qgl'
+#require 'qgl'
require 'World'
require 'Cloud'
require 'Flock'
@@ -16,16 +16,17 @@
include GL
-class Canvas < QRGLWidget
+class MyCanvas < Qt::GLWidget
- GRASS_COLOR = [0, .75, 0]
+ GRASS_COLOR = [0, 0.75, 0]
MDA_ROTATE = :MDA_ROTATE
MDA_ZOOM = :MDA_ZOOM
MDA_CHANGE_FOCUS = :MDA_CHANGE_FOCUS
def initialize(parent = nil, name = '')
+ super ()
@grassObject = nil
- catchEvent
+ #catchEvent
end
def update
diff -ur ruboids-0.0.1.org/ruboids/CloudView.rb ruboids-0.0.1/ruboids/CloudView.rb
--- ruboids-0.0.1.org/ruboids/CloudView.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/CloudView.rb Tue Sep 28 03:31:10 2004
@@ -5,7 +5,7 @@
# http://www.ruby-lang.org/en/LICENSE.txt.
#
-require 'qgl'
+require 'qt'
require 'View'
require 'Cloud'
require 'Params'
Only in ruboids-0.0.1/ruboids: MyCanvas.rb
diff -ur ruboids-0.0.1.org/ruboids/View.rb ruboids-0.0.1/ruboids/View.rb
--- ruboids-0.0.1.org/ruboids/View.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/View.rb Tue Sep 28 17:28:44 2004
@@ -8,7 +8,7 @@
# A lightweight view
class View
- SHADOW_COLOR = [ .25, .25, .25 ]
+ SHADOW_COLOR = [ 0.25, 0.25, 0.25 ]
attr_accessor :model, :color, bject, :shadow
@@ -74,7 +74,7 @@
shadowColor = []
SHADOW_COLOR.each_with_index { | c0, i |
min = c0
- max = Canvas::GRASS_COLOR
+ max = MyCanvas::GRASS_COLOR
if min > max
tmp = min
min = max
diff -ur ruboids-0.0.1.org/ruboids/World.rb ruboids-0.0.1/ruboids/World.rb
--- ruboids-0.0.1.org/ruboids/World.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/World.rb Tue Sep 28 17:29:32 2004
@@ -12,9 +12,9 @@
require 'Flock'
require 'Boid'
require 'Camera'
-require 'Canvas'
+require 'MyCanvas'
-class World < QObject
+class World < Qt::Object
include Singleton
@@ -48,8 +48,8 @@
@flock.add(b) # flock will delete boid
}
- @clock = QTimer.new()
- connect(@clock, QSIGNAL('timeout()'), self, 'slotMove')
+ @clock = Qt::Timer.new()
+ # connect(@clock, Qt::SIGNAL('timeout()'), self, 'slotMove')
@camera = Camera.new # Reads values from params
setupTranslation()
diff -ur ruboids-0.0.1.org/ruboids/WorldWindow.rb ruboids-0.0.1/ruboids/WorldWindow.rb
--- ruboids-0.0.1.org/ruboids/WorldWindow.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/WorldWindow.rb Tue Sep 28 17:32:54 2004
@@ -6,10 +6,10 @@
#
require 'qt'
-require 'Canvas'
+require 'MyCanvas'
require 'CameraDialog'
-class WorldWindow < QMainWindow
+class WorldWindow < Qt::MainWindow
MENU_CAMERA_DIALOG = 1
@@ -18,11 +18,11 @@
def initialize
super
setCaption("Boids")
- vLayout = QVBoxLayout.new(self, 0, 0, "vLayout")
+ vLayout = Qt::VBoxLayout.new(self, 0, 0, "vLayout")
mbar = setupMenubar()
vLayout.setMenuBar(mbar)
- @canvas = Canvas.new(self)
+ @canvas = MyCanvas.new(self,"TheDamnCanvas")
vLayout.addWidget(@canvas)
vLayout.activate()
@@ -33,23 +33,23 @@
def setupMenubar
# Create menu bar
- mbar = QMenuBar.new(self)
+ mbar = Qt::MenuBar.new(self)
# Create and populate file menu
- menu = QPopupMenu.new()
- menu.insertItemQObj("Exit", QApplication::qApp, QSLOT("quit()"),
- CTRL+Key_Q)
+ menu = Qt:opupMenu.new()
+ # menu.insertItemQObj("Exit", Qt::Application::qApp, Qt::SLOT("quit()"),
+ #CTRL+Key_Q)
# Add file menu to menu bar
mbar.insertItem("&File", menu)
# Create and populate options menu
- menu = QPopupMenu.new()
+ menu = Qt:opupMenu.new()
menu.insertItem("&Camera...", MENU_CAMERA_DIALOG, -1)
# Add options menu to menu bar and link it to method below
mbar.insertItem("&Options", menu)
- Qt::connect(menu, QSIGNAL("activated(int)"), self, 'slotMenuActivated')
+ # connect(menu, Qt::SIGNAL("activated(int)"), self, 'slotMenuActivated')
return mbar
end
Only in ruboids-0.0.1/ruboids: qtruby.bundle
Only in ruboids-0.0.1/ruboids: qui.bundle
diff -ur ruboids-0.0.1.org/ruboids/ruboids.rb ruboids-0.0.1/ruboids/ruboids.rb
--- ruboids-0.0.1.org/ruboids/ruboids.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/ruboids.rb Tue Sep 28 17:42:44 2004
@@ -7,20 +7,21 @@
#
require 'qt'
-require 'qgl'
+#require 'qgl'
require 'World'
require 'WorldWindow'
-require 'Canvas'
+require 'MyCanvas'
require 'Params'
-app = QApplication.new([$0] + ARGV)
-if (!QGLFormat::hasOpenGL())
+app = Qt::Application.new([$0] + ARGV)
+if (!Qt::GLFormat::hasOpenGL())
warning("This system has no OpenGL support. Exiting.")
exit -1
end
Params.readParamsFromFile(ARGV[0] || 'boids.properties')
-world = World.instance() # Force creation
+#world = World.instance() # Force creation
+world = World.instance
win = WorldWindow.new()
app.setMainWidget(win)
I wanted some OpenGL demo for ruby and the first thing I found was
ruboids.
I had some problems compiling qtruby because it uses libtool. But now I
can run some qtruby examples so it should work.
But when I tried running ruboids I found some things are named
differently in my setup (see patch). I disabled those for which there
was no apparent equivalent to see if I get at least some window as a
start. For testing purposes I also symlinked Canvas.rb to MyCanvas.rb
The thing that fais is that there is no canvas= method in singleton
instance of World although it has attr_accessor for :canvas.
Also I can get a World instance by new() but I get nil from instance()
DISPLAY=:0 ruby ruboids.rb ../boids.properties
±./MyCanvas.rb:27: warning: don't put space before argument parentheses
QLayout: Adding MyCanvas/unnamed (top-level widget) to layout for
WorldWindow/unnamed
QLayout "unnamed" added to WorldWindow "unnamed", which already has a
layout
QLayout "unnamed" added to WorldWindow "unnamed", which already has a
layout
ruboids.rb:29: undefined method `canvas=' for nil:NilClass
(NoMethodError)
I get the expected behavior if I test with a simple class in irb but I
get non-singleton if I subclass Qt::Object.
suchanek:~ hramrach$ irb
irb(main):001:0> require "qt"
requi=> true
irb(main):002:0> require "singleton"
=> true
irb(main):003:0> class Single < Qt::Object
irb(main):004:1> include Singleton
irb(main):005:1> def initialize
irb(main):006:2> STDERR.puts inspect
irb(main):007:2> end
irb(main):008:1> end
=> nil
irb(main):009:0> Single.new
=> #<Qt::Object:0x7b685c>
irb(main):010:0> Single.instance
#<Single:0x7b4fd4>
=> nil
irb(main):011:0> Single.new
=> #<Qt::Object:0x7b3878>
irb(main):012:0>
Is it impossble to base singletons on QObject?
Thanks
Michal Suchanek
Just for reference:
http://www.io.com/~jimm/downloads/ruboids/
diff -ur ruboids-0.0.1.org/ruboids/BoidView.rb ruboids-0.0.1/ruboids/BoidView.rb
--- ruboids-0.0.1.org/ruboids/BoidView.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/BoidView.rb Tue Sep 28 03:33:09 2004
@@ -11,7 +11,7 @@
BODY_COLOR = [0, 0, 0]
BEAK_COLOR = [0.75, 0.5, 0.0]
- SHADOW_COLOR = [.25, .55, .25]
+ SHADOW_COLOR = [0.25, 0.55, 0.25]
HALF_WING_BASE = 3
HALF_LENGTH = 5
diff -ur ruboids-0.0.1.org/ruboids/CameraDialog.rb ruboids-0.0.1/ruboids/CameraDialog.rb
--- ruboids-0.0.1.org/ruboids/CameraDialog.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/CameraDialog.rb Tue Sep 28 16:46:27 2004
@@ -28,7 +28,7 @@
end
end
-class CameraDialog < QDialog
+class CameraDialog < Qt:ialog
def initialize(parent)
@locAdjustors = []
diff -ur ruboids-0.0.1.org/ruboids/Canvas.rb ruboids-0.0.1/ruboids/Canvas.rb
--- ruboids-0.0.1.org/ruboids/Canvas.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/Canvas.rb Tue Sep 28 17:34:00 2004
@@ -7,7 +7,7 @@
require 'qt'
require 'opengl'
-require 'qgl'
+#require 'qgl'
require 'World'
require 'Cloud'
require 'Flock'
@@ -16,16 +16,17 @@
include GL
-class Canvas < QRGLWidget
+class MyCanvas < Qt::GLWidget
- GRASS_COLOR = [0, .75, 0]
+ GRASS_COLOR = [0, 0.75, 0]
MDA_ROTATE = :MDA_ROTATE
MDA_ZOOM = :MDA_ZOOM
MDA_CHANGE_FOCUS = :MDA_CHANGE_FOCUS
def initialize(parent = nil, name = '')
+ super ()
@grassObject = nil
- catchEvent
+ #catchEvent
end
def update
diff -ur ruboids-0.0.1.org/ruboids/CloudView.rb ruboids-0.0.1/ruboids/CloudView.rb
--- ruboids-0.0.1.org/ruboids/CloudView.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/CloudView.rb Tue Sep 28 03:31:10 2004
@@ -5,7 +5,7 @@
# http://www.ruby-lang.org/en/LICENSE.txt.
#
-require 'qgl'
+require 'qt'
require 'View'
require 'Cloud'
require 'Params'
Only in ruboids-0.0.1/ruboids: MyCanvas.rb
diff -ur ruboids-0.0.1.org/ruboids/View.rb ruboids-0.0.1/ruboids/View.rb
--- ruboids-0.0.1.org/ruboids/View.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/View.rb Tue Sep 28 17:28:44 2004
@@ -8,7 +8,7 @@
# A lightweight view
class View
- SHADOW_COLOR = [ .25, .25, .25 ]
+ SHADOW_COLOR = [ 0.25, 0.25, 0.25 ]
attr_accessor :model, :color, bject, :shadow
@@ -74,7 +74,7 @@
shadowColor = []
SHADOW_COLOR.each_with_index { | c0, i |
min = c0
- max = Canvas::GRASS_COLOR
+ max = MyCanvas::GRASS_COLOR
if min > max
tmp = min
min = max
diff -ur ruboids-0.0.1.org/ruboids/World.rb ruboids-0.0.1/ruboids/World.rb
--- ruboids-0.0.1.org/ruboids/World.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/World.rb Tue Sep 28 17:29:32 2004
@@ -12,9 +12,9 @@
require 'Flock'
require 'Boid'
require 'Camera'
-require 'Canvas'
+require 'MyCanvas'
-class World < QObject
+class World < Qt::Object
include Singleton
@@ -48,8 +48,8 @@
@flock.add(b) # flock will delete boid
}
- @clock = QTimer.new()
- connect(@clock, QSIGNAL('timeout()'), self, 'slotMove')
+ @clock = Qt::Timer.new()
+ # connect(@clock, Qt::SIGNAL('timeout()'), self, 'slotMove')
@camera = Camera.new # Reads values from params
setupTranslation()
diff -ur ruboids-0.0.1.org/ruboids/WorldWindow.rb ruboids-0.0.1/ruboids/WorldWindow.rb
--- ruboids-0.0.1.org/ruboids/WorldWindow.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/WorldWindow.rb Tue Sep 28 17:32:54 2004
@@ -6,10 +6,10 @@
#
require 'qt'
-require 'Canvas'
+require 'MyCanvas'
require 'CameraDialog'
-class WorldWindow < QMainWindow
+class WorldWindow < Qt::MainWindow
MENU_CAMERA_DIALOG = 1
@@ -18,11 +18,11 @@
def initialize
super
setCaption("Boids")
- vLayout = QVBoxLayout.new(self, 0, 0, "vLayout")
+ vLayout = Qt::VBoxLayout.new(self, 0, 0, "vLayout")
mbar = setupMenubar()
vLayout.setMenuBar(mbar)
- @canvas = Canvas.new(self)
+ @canvas = MyCanvas.new(self,"TheDamnCanvas")
vLayout.addWidget(@canvas)
vLayout.activate()
@@ -33,23 +33,23 @@
def setupMenubar
# Create menu bar
- mbar = QMenuBar.new(self)
+ mbar = Qt::MenuBar.new(self)
# Create and populate file menu
- menu = QPopupMenu.new()
- menu.insertItemQObj("Exit", QApplication::qApp, QSLOT("quit()"),
- CTRL+Key_Q)
+ menu = Qt:opupMenu.new()
+ # menu.insertItemQObj("Exit", Qt::Application::qApp, Qt::SLOT("quit()"),
+ #CTRL+Key_Q)
# Add file menu to menu bar
mbar.insertItem("&File", menu)
# Create and populate options menu
- menu = QPopupMenu.new()
+ menu = Qt:opupMenu.new()
menu.insertItem("&Camera...", MENU_CAMERA_DIALOG, -1)
# Add options menu to menu bar and link it to method below
mbar.insertItem("&Options", menu)
- Qt::connect(menu, QSIGNAL("activated(int)"), self, 'slotMenuActivated')
+ # connect(menu, Qt::SIGNAL("activated(int)"), self, 'slotMenuActivated')
return mbar
end
Only in ruboids-0.0.1/ruboids: qtruby.bundle
Only in ruboids-0.0.1/ruboids: qui.bundle
diff -ur ruboids-0.0.1.org/ruboids/ruboids.rb ruboids-0.0.1/ruboids/ruboids.rb
--- ruboids-0.0.1.org/ruboids/ruboids.rb Wed May 30 17:39:43 2001
+++ ruboids-0.0.1/ruboids/ruboids.rb Tue Sep 28 17:42:44 2004
@@ -7,20 +7,21 @@
#
require 'qt'
-require 'qgl'
+#require 'qgl'
require 'World'
require 'WorldWindow'
-require 'Canvas'
+require 'MyCanvas'
require 'Params'
-app = QApplication.new([$0] + ARGV)
-if (!QGLFormat::hasOpenGL())
+app = Qt::Application.new([$0] + ARGV)
+if (!Qt::GLFormat::hasOpenGL())
warning("This system has no OpenGL support. Exiting.")
exit -1
end
Params.readParamsFromFile(ARGV[0] || 'boids.properties')
-world = World.instance() # Force creation
+#world = World.instance() # Force creation
+world = World.instance
win = WorldWindow.new()
app.setMainWidget(win)