[Kde-bindings] KDE/kdebindings/ruby/plasma
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Sun Jun 29 15:11:16 UTC 2008
SVN commit 825878 by rdale:
* If a method call is invoked on a PlasmaScripting::Applet, then relay it to
the underlying Plasma::Applet in the script engine.
* Add an event filter to the RubyAppletScript::Applet class so that scripting
applets can implement event method handling overrides.
* Change various methods in the QGraphicsView and Plasma api so that they can
accept instances of PlasmaScripting::Applet, and the instance is substituted
for the underlying Plasma::Applet in the ScriptEngine.
CCMAIL: kde-bindings at kde.org
M +9 -1 ChangeLog
M +394 -1 src/applet.rb
M +19 -0 src/data_engine.rb
M +15 -0 src/lib/KDE/plasma.rb
M +19 -0 src/package_ruboid.rb
--- trunk/KDE/kdebindings/ruby/plasma/ChangeLog #825877:825878
@@ -1,4 +1,12 @@
+2008-06-29 Richard Dale <richard.j.dale at gmail.com>
+* If a method call is invoked on a PlasmaScripting::Applet, then relay it to
+ the underlying Plasma::Applet in the script engine.
+* Add an event filter to the RubyAppletScript::Applet class so that scripting
+ applets can implement event method handling overrides.
+* Change various methods in the QGraphicsView and Plasma api so that they can
+ accept instances of PlasmaScripting::Applet, and the instance is substituted
+ for the underlying Plasma::Applet in the ScriptEngine.
+
2008-06-28 Richard Dale <richard.j.dale at gmail.com>
-
* Make the Ruby ScriptEngine based plugins work
* Add a Ruby version of the Javascript Tiger applet
--- trunk/KDE/kdebindings/ruby/plasma/src/applet.rb #825877:825878
@@ -1,3 +1,22 @@
+=begin
+ * Copyright 2008 by Richard Dale <richard.j.dale at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+=end
+
require 'plasma_applet'
module RubyAppletScript
@@ -12,6 +31,7 @@
def init
applet.resize(200, 200)
+
puts "RubyAppletScript::Applet#init mainScript: #{mainScript}"
program = Qt::FileInfo.new(mainScript)
load Qt::File.encodeName(program.filePath).to_s
@@ -21,6 +41,8 @@
klass = Object.const_get(moduleName.to_sym).const_get(className.to_sym)
@applet_script = klass.new(self)
@applet_script.init
+
+ set_up_event_handlers
return true
end
@@ -37,7 +59,378 @@
end
def showConfigurationInterface
- @applet_script.showConfigurationInterface
+ if @applet_script.respond_to?(:createConfigurationInterface)
+ dialogId = "#{applet.id}settings#{applet.name}"
+ windowTitle = KDE::i18nc("@title:window", "%s Settings" % applet.name)
+ @nullManager = KDE::ConfigSkeleton.new(nil)
+ dialog = KDE::ConfigDialog.new(nil, dialogId, @nullManager)
+ dialog.faceType = KDE::PageDialog::Auto
+ dialog.windowTitle = windowTitle
+ dialog.setAttribute(Qt::WA_DeleteOnClose, true)
+ @applet_script.createConfigurationInterface(dialog)
+ # TODO: would be nice to not show dialog if there are no pages added?
+ connect(dialog, SIGNAL(:finished), @nullManager, SLOT(:deleteLater))
+ # TODO: Apply button does not correctly work for now, so do not show it
+ dialog.showButton(KDE::Dialog::Apply, false)
+ dialog.show
+ else
+ @applet_script.showConfigurationInterface
+ end
end
+
+ def set_up_event_handlers
+ @event_handlers = {}
+
+ if @applet_script.respond_to?(:mousePressEvent)
+ @event_handlers[Qt::Event::GraphicsSceneMousePress.to_i] = :mousePressEvent
+ end
+
+ if @applet_script.respond_to?(:contextMenuEvent)
+ @event_handlers[Qt::Event::GraphicsSceneContextMenu.to_i] = :contextMenuEvent
+ end
+
+ if @applet_script.respond_to?(:dragEnterEvent)
+ @event_handlers[Qt::Event::GraphicsSceneDragEnter.to_i] = :dragEnterEvent
+ end
+
+ if @applet_script.respond_to?(:dragLeaveEvent)
+ @event_handlers[Qt::Event::GraphicsSceneDragLeave.to_i] = :dragLeaveEvent
+ end
+
+ if @applet_script.respond_to?(:dragMoveEvent)
+ @event_handlers[Qt::Event::GraphicsSceneDragMove.to_i] = :dragMoveEvent
+ end
+
+ if @applet_script.respond_to?(:dropEvent)
+ @event_handlers[Qt::Event::GraphicsSceneDrop.to_i] = :dropEvent
+ end
+
+ if @applet_script.respond_to?(:focusInEvent)
+ @event_handlers[Qt::Event::FocusIn.to_i] = :focusInEvent
+ end
+
+ if @applet_script.respond_to?(:focusOutEvent)
+ @event_handlers[Qt::Event::FocusOut.to_i] = :focusOutEvent
+ end
+
+ if @applet_script.respond_to?(:hoverEnterEvent)
+ @event_handlers[Qt::Event::GraphicsSceneHoverEnter.to_i] = :hoverEnterEvent
+ end
+
+ if @applet_script.respond_to?(:hoverLeaveEvent)
+ @event_handlers[Qt::Event::GraphicsSceneHoverLeave.to_i] = :hoverLeaveEvent
+ end
+
+ if @applet_script.respond_to?(:hoverMoveEvent)
+ @event_handlers[Qt::Event::GraphicsSceneHoverMove.to_i] = :hoverMoveEvent
+ end
+
+ if @applet_script.respond_to?(:inputMethodEvent)
+ @event_handlers[Qt::Event::InputMethod.to_i] = :inputMethodEvent
+ end
+
+ if @applet_script.respond_to?(:keyPressEvent)
+ @event_handlers[Qt::Event::KeyPress.to_i] = :keyPressEvent
+ end
+
+ if @applet_script.respond_to?(:keyReleaseEvent)
+ @event_handlers[Qt::Event::KeyRelease.to_i] = :keyReleaseEvent
+ end
+
+ if @applet_script.respond_to?(:mouseDoubleClickEvent)
+ @event_handlers[Qt::Event::GraphicsSceneMouseDoubleClick.to_i] = :mouseDoubleClickEvent
+ end
+
+ if @applet_script.respond_to?(:mouseMoveEvent)
+ @event_handlers[Qt::Event::GraphicsSceneMouseMove.to_i] = :mouseMoveEvent
+ end
+
+ if @applet_script.respond_to?(:mousePressEvent)
+ @event_handlers[Qt::Event::GraphicsSceneMousePress.to_i] = :mousePressEvent
+ end
+
+ if @applet_script.respond_to?(:mouseReleaseEvent)
+ @event_handlers[Qt::Event::GraphicsSceneMouseRelease.to_i] = :mouseReleaseEvent
+ end
+
+ if @applet_script.respond_to?(:wheelEvent)
+ @event_handlers[Qt::Event::GraphicsSceneWheel.to_i] = :wheelEvent
+ end
+
+ if !@event_handlers.empty?
+ applet.installEventFilter(self)
+ end
+ end
+
+ def eventFilter(obj, event)
+ handler = @event_handlers[event.type.to_i]
+ if handler
+ @applet_script.send(handler, event)
+ return true
+ else
+ return false
+ end
+ end
+
end
+end
+
+module Plasma
+ #
+ # Because a PlasmaScript::Applet is not actually a Plasma::Applet we
+ # need to 'cheat' in the api, to pretend that it is. So the constructors
+ # in the Plasma widget classes will substitute any PlasmaScript::Applet
+ # argument passed for the real Plasma::Applet in the ScriptEngine
+ #
+
+ class CheckBox < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class ComboBox < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class Flash < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class GroupBox < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class Icon < Qt::Base
+ def initialize(*args)
+ sargs = []
+ for i in 0...args.length do
+ if args[i].kind_of?(PlasmaScripting::Applet)
+ sargs << args[i].applet_script.applet
+ else
+ sargs << args[i]
+ end
+ end
+ super(*sargs)
+ end
+ end
+
+ class Label < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class LineEdit < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class Meter < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class PushButton < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class RadioButton < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class SignalPlotter < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class TextEdit < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+ class WebContent < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
+
+end
+
+module Qt
+ class GraphicsWidget < Qt::Base
+ def initialize(parent = nil, wFlags = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet, wFlags)
+ else
+ super
+ end
+ end
+ end
+
+ class GraphicsGridLayout < Qt::Base
+ def initialize(parent = nil)
+ if parent.kind_of?(PlasmaScripting::Applet)
+ super(parent.applet_script.applet)
+ else
+ super
+ end
+ end
+
+ def addItem(*args)
+ sargs = []
+ for i in 0...args.length do
+ if args[i].kind_of?(PlasmaScripting::Applet)
+ sargs << args[i].applet_script.applet
+ else
+ sargs << args[i]
+ end
+ end
+ super(*sargs)
+ end
+
+ def alignment(item)
+ if item.kind_of?(PlasmaScripting::Applet)
+ super(item.applet_script.applet)
+ else
+ super
+ end
+ end
+
+ def setAlignment(item, alignment)
+ if item.kind_of?(PlasmaScripting::Applet)
+ super(item.applet_script.applet, alignment)
+ else
+ super
+ end
+ end
+ end
+
+ class GraphicsLinearLayout < Qt::Base
+ def initialize(*args)
+ sargs = []
+ for i in 0...args.length do
+ if args[i].kind_of?(PlasmaScripting::Applet)
+ sargs << args[i].applet_script.applet
+ else
+ sargs << args[i]
+ end
+ end
+ super(*sargs)
+ end
+
+ def addItem(*args)
+ sargs = []
+ for i in 0...args.length do
+ if args[i].kind_of?(PlasmaScripting::Applet)
+ sargs << args[i].applet_script.applet
+ else
+ sargs << args[i]
+ end
+ end
+ super(*sargs)
+ end
+
+ def alignment(item)
+ if item.kind_of?(PlasmaScripting::Applet)
+ super(item.applet_script.applet)
+ else
+ super
+ end
+ end
+
+ def insertItem(index, item)
+ if item.kind_of?(PlasmaScripting::Applet)
+ super(index, item.applet_script.applet)
+ else
+ super
+ end
+ end
+
+ def setAlignment(item, alignment)
+ if item.kind_of?(PlasmaScripting::Applet)
+ super(item.applet_script.applet, alignment)
+ else
+ super
+ end
+ end
+
+ def setStretchFactor(item, stretch)
+ if item.kind_of?(PlasmaScripting::Applet)
+ super(item.applet_script.applet, stretch)
+ else
+ super
+ end
+ end
+
+ def stretchFactor(item)
+ if item.kind_of?(PlasmaScripting::Applet)
+ super(item.applet_script.applet)
+ else
+ super
+ end
+ end
+ end
end
\ No newline at end of file
--- trunk/KDE/kdebindings/ruby/plasma/src/data_engine.rb #825877:825878
@@ -1,3 +1,22 @@
+=begin
+ * Copyright 2008 by Richard Dale <richard.j.dale at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+=end
+
require 'plasma_applet'
module RubyAppletScript
--- trunk/KDE/kdebindings/ruby/plasma/src/lib/KDE/plasma.rb #825877:825878
@@ -75,6 +75,16 @@
@applet_script = parent
end
+ # If a method is called on a PlasmaScripting::Applet instance is found to be missing
+ # then try calling the method on the underlying Plasma::Applet in the ScriptEngine.
+ def method_missing(method, *args)
+ begin
+ super(method, *args)
+ rescue
+ applet_script.applet.method_missing(method, *args)
+ end
+ end
+
def paintInterface(painter, option, contentsRect)
end
@@ -82,6 +92,10 @@
@applet_script.size
end
+ def shape
+ @applet_script.shape
+ end
+
def constraintsEvent(constraints)
end
@@ -103,6 +117,7 @@
class DataEngine < Qt::Object
def initialize(parent, args)
+ super(parent)
end
def sourceRequestEvent(name)
--- trunk/KDE/kdebindings/ruby/plasma/src/package_ruboid.rb #825877:825878
@@ -1,3 +1,22 @@
+=begin
+ * Copyright 2008 by Richard Dale <richard.j.dale at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+=end
+
require 'plasma_applet'
module RubyAppletScript
More information about the Kde-bindings
mailing list