wxruby 1.9.6-universal-darwin-9 → 1.9.7-universal-darwin-9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wx/version.rb +1 -1
- data/lib/wxruby2.bundle +0 -0
- data/samples/dragdrop/dragdrop.rb +177 -0
- metadata +4 -2
data/lib/wx/version.rb
CHANGED
data/lib/wxruby2.bundle
CHANGED
Binary file
|
@@ -0,0 +1,177 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
|
3
|
+
# Freely reusable code: see SAMPLES-LICENSE.TXT for details
|
4
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
# This sample demonstrates the use of the Clipboard and Drag and Drop
|
11
|
+
# classes. Whilst the functionality of these is slightly different, they
|
12
|
+
# are both based around the use of the DataObject classes to exchange
|
13
|
+
# data of various sorts between applications (i.e. into and out of
|
14
|
+
# wxRuby)
|
15
|
+
|
16
|
+
# A ListBox that collects file names dropped onto it
|
17
|
+
class FileDropList < Wx::ListBox
|
18
|
+
def initialize(*args)
|
19
|
+
super
|
20
|
+
# Set the handler for drag and drop actions
|
21
|
+
self.drop_target = ListFileDropTarget.new(self)
|
22
|
+
end
|
23
|
+
|
24
|
+
# The class that actually handles the dropped files; it keeps a
|
25
|
+
# reference to the ListBox, and appends items as they are added
|
26
|
+
class ListFileDropTarget < Wx::FileDropTarget
|
27
|
+
def initialize(list)
|
28
|
+
super()
|
29
|
+
@list = list
|
30
|
+
end
|
31
|
+
|
32
|
+
# This method is overridden to specify what happens when a file is
|
33
|
+
# dropped
|
34
|
+
def on_drop_files(x, y, files)
|
35
|
+
files.each { | file | @list.append(file) }
|
36
|
+
true # currently need to return boolean from this method
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class FileDropPane < Wx::Panel
|
42
|
+
LABEL = "Drag and drop files from Explorer/Finder/etc to here\n" +
|
43
|
+
"to add them to the list."
|
44
|
+
def initialize(parent)
|
45
|
+
super
|
46
|
+
sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
47
|
+
txt = Wx::StaticText.new( self, :label => LABEL)
|
48
|
+
sizer.add(txt, 0, Wx::ALL, 4)
|
49
|
+
|
50
|
+
@drop = FileDropList.new(self)
|
51
|
+
sizer.add(@drop, 1, Wx::GROW|Wx::ALL, 4)
|
52
|
+
self.sizer = sizer
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# A canvas which can display a pasted image
|
57
|
+
class PasteCanvas < Wx::Window
|
58
|
+
attr_accessor :bitmap
|
59
|
+
def initialize(parent)
|
60
|
+
super(parent, :style => Wx::SUNKEN_BORDER)
|
61
|
+
self.size = [ 200, 200 ]
|
62
|
+
@bitmap = Wx::NULL_BITMAP
|
63
|
+
evt_paint :on_paint
|
64
|
+
end
|
65
|
+
|
66
|
+
def on_paint(evt)
|
67
|
+
paint do | dc |
|
68
|
+
dc.clear
|
69
|
+
if bitmap.ok?
|
70
|
+
dc.draw_bitmap(bitmap, 0, 0, false)
|
71
|
+
end
|
72
|
+
dc.pen = Wx::BLACK_PEN
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# A Notebook panel to hold an image-paste canvas
|
78
|
+
class PastePane < Wx::Panel
|
79
|
+
LABEL = "Use the buttons below to paste text and images from\n" +
|
80
|
+
"the system clipboard, and then to copy them back."
|
81
|
+
def initialize(parent)
|
82
|
+
super
|
83
|
+
sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
84
|
+
txt = Wx::StaticText.new( self, :label => LABEL)
|
85
|
+
sizer.add(txt, 0, Wx::ALL, 4)
|
86
|
+
|
87
|
+
# Sizer for displaying text and image from the clipboard
|
88
|
+
paste_sizer = Wx::FlexGridSizer.new(2, 2, 2, 2)
|
89
|
+
paste_sizer.add_growable_col(0, 1)
|
90
|
+
paste_sizer.add_growable_col(1, 1)
|
91
|
+
paste_sizer.add_growable_row(1)
|
92
|
+
|
93
|
+
paste_sizer.add( Wx::StaticText.new(self, :label => 'Clipboard text') )
|
94
|
+
paste_sizer.add( Wx::StaticText.new(self, :label => 'Clipboard image') )
|
95
|
+
|
96
|
+
# Target for displaying text from the clipboard
|
97
|
+
@text = Wx::TextCtrl.new(self, :style => Wx::TE_MULTILINE)
|
98
|
+
paste_sizer.add(@text, 1, Wx::GROW)
|
99
|
+
|
100
|
+
# Target for displaying images from the clipboard
|
101
|
+
@canvas = PasteCanvas.new(self)
|
102
|
+
paste_sizer.add(@canvas, 1, Wx::GROW)
|
103
|
+
|
104
|
+
sizer.add(paste_sizer, 1, Wx::ALL|Wx::GROW, 4)
|
105
|
+
|
106
|
+
button_sizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
|
107
|
+
|
108
|
+
@paste_bt = Wx::Button.new(self, :label => 'Paste')
|
109
|
+
evt_button @paste_bt, :on_paste
|
110
|
+
button_sizer.add(@paste_bt, 0, Wx::ALL, 4)
|
111
|
+
|
112
|
+
@copy_img_bt = Wx::Button.new(self, :label => 'Copy image')
|
113
|
+
evt_button @copy_img_bt, :on_copy_image
|
114
|
+
button_sizer.add(@copy_img_bt, 0, Wx::ALL, 4)
|
115
|
+
|
116
|
+
@copy_txt_bt = Wx::Button.new(self, :label => 'Copy text')
|
117
|
+
evt_button @copy_txt_bt, :on_copy_text
|
118
|
+
button_sizer.add(@copy_txt_bt, 0, Wx::ALL, 4)
|
119
|
+
|
120
|
+
sizer.add(button_sizer, 0)
|
121
|
+
self.sizer = sizer
|
122
|
+
end
|
123
|
+
|
124
|
+
# Receive data from the clipboard
|
125
|
+
def on_paste(evt)
|
126
|
+
# Temporarily open the clipboard
|
127
|
+
Wx::Clipboard.open do | clip |
|
128
|
+
# Test if bitmap data is available on the clipboard; if so, copy
|
129
|
+
if clip.supported?(Wx::DF_BITMAP)
|
130
|
+
bmp = Wx::BitmapDataObject.new
|
131
|
+
clip.get_data(bmp) # Fill the data object with bitmap`
|
132
|
+
@canvas.bitmap = bmp.bitmap
|
133
|
+
@canvas.refresh
|
134
|
+
end
|
135
|
+
# Test if text data is available on the clipboard; if so, copy
|
136
|
+
if clip.supported?(Wx::DF_TEXT)
|
137
|
+
txt = Wx::TextDataObject.new
|
138
|
+
clip.get_data(txt) # Fill the data object with text
|
139
|
+
@text.value = txt.text
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Paste an image to the clipboard
|
145
|
+
def on_copy_image
|
146
|
+
Wx::Clipboard.open do | clip |
|
147
|
+
clip.data = Wx::BitmapDataObject.new(@canvas.bitmap)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Paste text to the clipboard
|
152
|
+
def on_copy_text
|
153
|
+
Wx::Clipboard.open do | clip |
|
154
|
+
clip.data = Wx::TextDataObject.new(@text.value)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
class DataObjectFrame < Wx::Frame
|
160
|
+
def initialize(parent)
|
161
|
+
super
|
162
|
+
panel = Wx::Panel.new(self)
|
163
|
+
panel.sizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
164
|
+
nb = Wx::Notebook.new(panel)
|
165
|
+
panel.sizer.add(nb, 1, Wx::ALL|Wx::GROW, 8)
|
166
|
+
fd = FileDropPane.new(nb)
|
167
|
+
nb.add_page(fd, 'Drag and Drop')
|
168
|
+
cv = PastePane.new(nb)
|
169
|
+
nb.add_page(cv, 'Clipboard')
|
170
|
+
# urldrop = URLDropList.new(self)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
Wx::App.run do
|
175
|
+
frame = DataObjectFrame.new(nil)
|
176
|
+
frame.show
|
177
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wxruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.7
|
5
5
|
platform: universal-darwin-9
|
6
6
|
authors:
|
7
7
|
- wxRuby development team
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-05-
|
12
|
+
date: 2008-05-10 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -217,6 +217,8 @@ files:
|
|
217
217
|
- samples/dialogs
|
218
218
|
- samples/dialogs/dialogs.rb
|
219
219
|
- samples/dialogs/tips.txt
|
220
|
+
- samples/dragdrop
|
221
|
+
- samples/dragdrop/dragdrop.rb
|
220
222
|
- samples/drawing
|
221
223
|
- samples/drawing/graphics_drawing.rb
|
222
224
|
- samples/drawing/images.rb
|