Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Help! Can't get the FXRuby clipboard example to work...

Reply
Thread Tools

Help! Can't get the FXRuby clipboard example to work...

 
 
Abe Vionas_MailingList
Guest
Posts: n/a
 
      10-05-2004
Essentially, when I select a customers name and click
on the Copy button and then go to notepad and press
CTRL-V (to paste) nothing happens. Anyone have any
ideas?

Here's my code as it stands...

# customer.rb

require 'fox'

include Fox



customer = Struct.new("Customer", :name, :address,
:zip)

$customers = []
$customers << customer.new("Reed Richards", "123
Maple, Central City, NY", 010111)
$customers << customer.new("Sue Storm", "123 Maple,
Anytown, NC", 12345)
$customers << customer.new("Benjamin J. Grimm", "124
Maple, Anytown, NC", 12345)
$customers << customer.new("Johnny Storm", "123 Maple,
Anytown, NC", 12324)

class ClipMainWindow < FXMainWindow
def initialize(anApp)
# Initialize base class first
super(anApp, "Clipboard Example", nil, nil,
DECOR_ALL, 0, 0, 400, 300)

# Horizontal frame contains buttons
buttons = FXHorizontalFrame.new(self,
LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDT H)

# Cut and paste buttons
copyButton = FXButton.new(buttons, "Copy")
pasteButton = FXButton.new(buttons, "Paste")

# Place the list in a sunken frame
sunkenFrame = FXVerticalFrame.new(self,
LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THI CK,
0, 0, 0, 0, 0, 0, 0, 0)

# Customer list
customerList = FXList.new(sunkenFrame, 6, nil, 0,
LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
$customers.each do |customer|
customerList.appendItem(customer.name, nil,
customer)
end
end

def create
super
show(PLACEMENT_SCREEN)
end
end

if __FILE__ == $0
FXApp.new("ClipboardExample", "FXRuby") do |theApp|
ClipMainWindow.new(theApp)
theApp.create
theApp.run
end
end

# User clicks Copy
copyButton.connect(SEL_COMMAND) do
customer =
customerList.getItemData(customerList.currentItem)
types = [ FXWindow.stringType ]
if acquireClipboard()
@clippedCustomer = customer
end
end

#Handle clipboard request
copyButton.connect(SEL_CLIPBOARD_REQUEST) do
setDNDDATA(FROM_CLIPBOARD, FXWindow.stringType,
Fox.fxencodeStringData(@clippedCustomer.to_s))
end




__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail


 
Reply With Quote
 
 
 
 
Richard Lyman
Guest
Posts: n/a
 
      10-05-2004
First off - the last 15 or so lines won't be 'processed' until after
the application terminates.

Once it hits 'theApp.run' the main program hangs and Fox takes over,
so you need to have everything setup before that.

-Rich


On Wed, 6 Oct 2004 04:42:01 +0900, Abe Vionas_MailingList
<(E-Mail Removed)> wrote:
> Essentially, when I select a customers name and click
> on the Copy button and then go to notepad and press
> CTRL-V (to paste) nothing happens. Anyone have any
> ideas?
>
> Here's my code as it stands...
>
> # customer.rb
>
> require 'fox'
>
> include Fox
>
> customer = Struct.new("Customer", :name, :address,
> :zip)
>
> $customers = []
> $customers << customer.new("Reed Richards", "123
> Maple, Central City, NY", 010111)
> $customers << customer.new("Sue Storm", "123 Maple,
> Anytown, NC", 12345)
> $customers << customer.new("Benjamin J. Grimm", "124
> Maple, Anytown, NC", 12345)
> $customers << customer.new("Johnny Storm", "123 Maple,
> Anytown, NC", 12324)
>
> class ClipMainWindow < FXMainWindow
> def initialize(anApp)
> # Initialize base class first
> super(anApp, "Clipboard Example", nil, nil,
> DECOR_ALL, 0, 0, 400, 300)
>
> # Horizontal frame contains buttons
> buttons = FXHorizontalFrame.new(self,
> LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDT H)
>
> # Cut and paste buttons
> copyButton = FXButton.new(buttons, "Copy")
> pasteButton = FXButton.new(buttons, "Paste")
>
> # Place the list in a sunken frame
> sunkenFrame = FXVerticalFrame.new(self,
> LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THI CK,
> 0, 0, 0, 0, 0, 0, 0, 0)
>
> # Customer list
> customerList = FXList.new(sunkenFrame, 6, nil, 0,
> LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
> $customers.each do |customer|
> customerList.appendItem(customer.name, nil,
> customer)
> end
> end
>
> def create
> super
> show(PLACEMENT_SCREEN)
> end
> end
>
> if __FILE__ == $0
> FXApp.new("ClipboardExample", "FXRuby") do |theApp|
> ClipMainWindow.new(theApp)
> theApp.create
> theApp.run
> end
> end
>
> # User clicks Copy
> copyButton.connect(SEL_COMMAND) do
> customer =
> customerList.getItemData(customerList.currentItem)
> types = [ FXWindow.stringType ]
> if acquireClipboard()
> @clippedCustomer = customer
> end
> end
>
> #Handle clipboard request
> copyButton.connect(SEL_CLIPBOARD_REQUEST) do
> setDNDDATA(FROM_CLIPBOARD, FXWindow.stringType,
> Fox.fxencodeStringData(@clippedCustomer.to_s))
> end
>
>
> __________________________________
> Do you Yahoo!?
> New and Improved Yahoo! Mail - 100MB free storage!
> http://promotions.yahoo.com/new_mail
>
>



 
Reply With Quote
 
 
 
 
Kevin Pratt
Guest
Posts: n/a
 
      10-05-2004
There were several mistakes in your code I corrected them and below is
the corrected program

Hope this helps.

# customer.rb
require 'fox'
include Fox

customer = Struct.new("Customer", :name, :address,:zip)

$customers = []
$customers << customer.new("Reed Richards", "123
Maple, Central City, NY", 010111)
$customers << customer.new("Sue Storm", "123 Maple,
Anytown, NC", 12345)
$customers << customer.new("Benjamin J. Grimm", "124
Maple, Anytown, NC", 12345)
$customers << customer.new("Johnny Storm", "123 Maple,
Anytown, NC", 12324)

class ClipMainWindow < FXMainWindow
def initialize(anApp)
# Initialize base class first
super(anApp, "Clipboard Example", nil, nil,DECOR_ALL, 0, 0, 400, 300)
#declare member variable clippedCustomer
@clippedCustomer=""
# Horizontal frame contains buttons
buttons = FXHorizontalFrame.new(self,
LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDT H)

# Cut and paste buttons
copyButton = FXButton.new(buttons, "Copy")
pasteButton = FXButton.new(buttons, "Paste")

# Place the list in a sunken frame
sunkenFrame = FXVerticalFrame.new(self,
LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THI CK,
0, 0, 0, 0, 0, 0, 0, 0)

# Customer list
customerList = FXList.new(sunkenFrame, 6, nil, 0,
LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
$customers.each do |customer|
customerList.appendItem(customer.name, nil,customer)
end
#Moved this code from the bottome of the file as in needs to be in the
initalization of the window.
#User clicks Copy
copyButton.connect(SEL_COMMAND) do
customer = customerList.getItemData(customerList.currentItem)
types = [ FXWindow.stringType ]
if acquireClipboard(types)
@clippedCustomer = customer
end
end

#moved this code as well.
#Must connect the the _Window_ SEL_CLIPBOARD_REQUREST not the buttons
#Handle clipboard request
self.connect(SEL_CLIPBOARD_REQUEST) do
#setDNDData was misspelled.
setDNDData(FROM_CLIPBOARD, FXWindow.stringType,
Fox.fxencodeStringData(@clippedCustomer.to_s))
end
end
def create
super
show(PLACEMENT_SCREEN)
end
end

if __FILE__ == $0
FXApp.new("ClipboardExample", "FXRuby") do |theApp|
ClipMainWindow.new(theApp)
theApp.create
theApp.run
end
end


 
Reply With Quote
 
Richard Lyman
Guest
Posts: n/a
 
      10-05-2004
Sorry for the extra reply...

I am also fairly certain that DND only works between Fox
applications... if I'm wrong, someone please correct me.

-Rich


On Tue, 5 Oct 2004 14:15:56 -0600, Richard Lyman <(E-Mail Removed)> wrote:
> First off - the last 15 or so lines won't be 'processed' until after
> the application terminates.
>
> Once it hits 'theApp.run' the main program hangs and Fox takes over,
> so you need to have everything setup before that.
>
> -Rich
>
>
>
>
> On Wed, 6 Oct 2004 04:42:01 +0900, Abe Vionas_MailingList
> <(E-Mail Removed)> wrote:
> > Essentially, when I select a customers name and click
> > on the Copy button and then go to notepad and press
> > CTRL-V (to paste) nothing happens. Anyone have any
> > ideas?
> >
> > Here's my code as it stands...
> >
> > # customer.rb
> >
> > require 'fox'
> >
> > include Fox
> >
> > customer = Struct.new("Customer", :name, :address,
> > :zip)
> >
> > $customers = []
> > $customers << customer.new("Reed Richards", "123
> > Maple, Central City, NY", 010111)
> > $customers << customer.new("Sue Storm", "123 Maple,
> > Anytown, NC", 12345)
> > $customers << customer.new("Benjamin J. Grimm", "124
> > Maple, Anytown, NC", 12345)
> > $customers << customer.new("Johnny Storm", "123 Maple,
> > Anytown, NC", 12324)
> >
> > class ClipMainWindow < FXMainWindow
> > def initialize(anApp)
> > # Initialize base class first
> > super(anApp, "Clipboard Example", nil, nil,
> > DECOR_ALL, 0, 0, 400, 300)
> >
> > # Horizontal frame contains buttons
> > buttons = FXHorizontalFrame.new(self,
> > LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDT H)
> >
> > # Cut and paste buttons
> > copyButton = FXButton.new(buttons, "Copy")
> > pasteButton = FXButton.new(buttons, "Paste")
> >
> > # Place the list in a sunken frame
> > sunkenFrame = FXVerticalFrame.new(self,
> > LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THI CK,
> > 0, 0, 0, 0, 0, 0, 0, 0)
> >
> > # Customer list
> > customerList = FXList.new(sunkenFrame, 6, nil, 0,
> > LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
> > $customers.each do |customer|
> > customerList.appendItem(customer.name, nil,
> > customer)
> > end
> > end
> >
> > def create
> > super
> > show(PLACEMENT_SCREEN)
> > end
> > end
> >
> > if __FILE__ == $0
> > FXApp.new("ClipboardExample", "FXRuby") do |theApp|
> > ClipMainWindow.new(theApp)
> > theApp.create
> > theApp.run
> > end
> > end
> >
> > # User clicks Copy
> > copyButton.connect(SEL_COMMAND) do
> > customer =
> > customerList.getItemData(customerList.currentItem)
> > types = [ FXWindow.stringType ]
> > if acquireClipboard()
> > @clippedCustomer = customer
> > end
> > end
> >
> > #Handle clipboard request
> > copyButton.connect(SEL_CLIPBOARD_REQUEST) do
> > setDNDDATA(FROM_CLIPBOARD, FXWindow.stringType,
> > Fox.fxencodeStringData(@clippedCustomer.to_s))
> > end
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > New and Improved Yahoo! Mail - 100MB free storage!
> > http://promotions.yahoo.com/new_mail
> >
> >

>



 
Reply With Quote
 
Kevin Pratt
Guest
Posts: n/a
 
      10-05-2004
Nope setDNDData works between other applications - can't vouch for the
other DND methods tho.

I tested the corrected code by copying and pasting the information
into an open gaim window running on windows xp.

kevin.


On Wed, 6 Oct 2004 05:17:53 +0900, Richard Lyman <(E-Mail Removed)> wrote:
> Sorry for the extra reply...
>
> I am also fairly certain that DND only works between Fox
> applications... if I'm wrong, someone please correct me.
>
> -Rich
>
>
>
>
> On Tue, 5 Oct 2004 14:15:56 -0600, Richard Lyman <(E-Mail Removed)> wrote:
> > First off - the last 15 or so lines won't be 'processed' until after
> > the application terminates.
> >
> > Once it hits 'theApp.run' the main program hangs and Fox takes over,
> > so you need to have everything setup before that.
> >
> > -Rich
> >
> >
> >
> >
> > On Wed, 6 Oct 2004 04:42:01 +0900, Abe Vionas_MailingList
> > <(E-Mail Removed)> wrote:
> > > Essentially, when I select a customers name and click
> > > on the Copy button and then go to notepad and press
> > > CTRL-V (to paste) nothing happens. Anyone have any
> > > ideas?
> > >
> > > Here's my code as it stands...
> > >
> > > # customer.rb
> > >
> > > require 'fox'
> > >
> > > include Fox
> > >
> > > customer = Struct.new("Customer", :name, :address,
> > > :zip)
> > >
> > > $customers = []
> > > $customers << customer.new("Reed Richards", "123
> > > Maple, Central City, NY", 010111)
> > > $customers << customer.new("Sue Storm", "123 Maple,
> > > Anytown, NC", 12345)
> > > $customers << customer.new("Benjamin J. Grimm", "124
> > > Maple, Anytown, NC", 12345)
> > > $customers << customer.new("Johnny Storm", "123 Maple,
> > > Anytown, NC", 12324)
> > >
> > > class ClipMainWindow < FXMainWindow
> > > def initialize(anApp)
> > > # Initialize base class first
> > > super(anApp, "Clipboard Example", nil, nil,
> > > DECOR_ALL, 0, 0, 400, 300)
> > >
> > > # Horizontal frame contains buttons
> > > buttons = FXHorizontalFrame.new(self,
> > > LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDT H)
> > >
> > > # Cut and paste buttons
> > > copyButton = FXButton.new(buttons, "Copy")
> > > pasteButton = FXButton.new(buttons, "Paste")
> > >
> > > # Place the list in a sunken frame
> > > sunkenFrame = FXVerticalFrame.new(self,
> > > LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THI CK,
> > > 0, 0, 0, 0, 0, 0, 0, 0)
> > >
> > > # Customer list
> > > customerList = FXList.new(sunkenFrame, 6, nil, 0,
> > > LIST_BROWSESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y)
> > > $customers.each do |customer|
> > > customerList.appendItem(customer.name, nil,
> > > customer)
> > > end
> > > end
> > >
> > > def create
> > > super
> > > show(PLACEMENT_SCREEN)
> > > end
> > > end
> > >
> > > if __FILE__ == $0
> > > FXApp.new("ClipboardExample", "FXRuby") do |theApp|
> > > ClipMainWindow.new(theApp)
> > > theApp.create
> > > theApp.run
> > > end
> > > end
> > >
> > > # User clicks Copy
> > > copyButton.connect(SEL_COMMAND) do
> > > customer =
> > > customerList.getItemData(customerList.currentItem)
> > > types = [ FXWindow.stringType ]
> > > if acquireClipboard()
> > > @clippedCustomer = customer
> > > end
> > > end
> > >
> > > #Handle clipboard request
> > > copyButton.connect(SEL_CLIPBOARD_REQUEST) do
> > > setDNDDATA(FROM_CLIPBOARD, FXWindow.stringType,
> > > Fox.fxencodeStringData(@clippedCustomer.to_s))
> > > end
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > New and Improved Yahoo! Mail - 100MB free storage!
> > > http://promotions.yahoo.com/new_mail
> > >
> > >

> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
$clipboard = Gtk::Clipboard.get('PRIMARY')... under windows Dan Bishop Ruby 0 08-26-2008 01:47 PM
[ANN] At InfoQ: Interview about FXRuby, plus an exclusive chapterfrom the FXRuby Book Lyle Johnson Ruby 0 05-20-2008 02:32 PM
clipboard.setContents destroys clipboard.getContents? spunibard@gmail.com Java 2 03-02-2007 07:52 PM
Using VB.Net or C#, utilizing the clipboard object, how to copy an MS Excel graphic from the clipboard to an image control and obtain its source reference TC ASP .Net 5 09-01-2004 04:49 AM
FXRuby and clipboard contents Steve Ruby 3 08-31-2003 05:43 PM



Advertisments