Development/Tutorials/Plasma4/Ruby/SimplePasteAppletCompleted: Difference between revisions
Appearance
This is the result the Ruby student gets when expanding SimplePasteApplet as instructed. |
m D ed moved page Development/Tutorials/Plasma/Ruby/SimplePasteAppletCompleted to Development/Tutorials/Plasma4/Ruby/SimplePasteAppletCompleted |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
This is what the completed code for the Simple Paste Applet looks like: | This is what the completed code for the [http://techbase.kde.org/Development/Tutorials/Plasma/Ruby/SimplePasteApplet Simple Paste Applet] looks like: | ||
< | <syntaxhighlight lang="ruby"> | ||
require 'plasma_applet' | require 'plasma_applet' | ||
Line 46: | Line 46: | ||
end | end | ||
end | end | ||
</ | </syntaxhighlight> |
Latest revision as of 23:27, 11 September 2014
This is what the completed code for the Simple Paste Applet looks like:
require 'plasma_applet'
module RubyTest
class Main < PlasmaScripting::Applet
def initialize parent
super parent
end
def init
set_minimum_size 150, 150
layout = Qt::GraphicsLinearLayout.new Qt::Vertical, self
self.layout = layout
# Three items being laid out:
label = Plasma::Label.new self
label.text = 'This plasmoid will copy the text you enter below to the clipboard.'
layout.add_item label
line_edit = Plasma::LineEdit.new self
begin # only possible in Plasma 4.3 and up
line_edit.clear_button_shown = true
rescue
end
layout.add_item line_edit
button = Plasma::PushButton.new self
button.text = 'Copy to clipboard'
layout.add_item button
# The layout is done now comes the action:
button.connect(SIGNAL(:clicked)) do
Qt::Application.clipboard.text = line_edit.text
end
line_edit.connect(SIGNAL(:returnPressed)) do
Qt::Application.clipboard.text = line_edit.text
end
end
end
end