[fxruby-users] Class with looping objects
Douglas Allen
kb9agt at gmail.com
Wed Mar 3 19:41:31 EST 2010
I used the tabs in scite here:
require 'fox16'
include Fox
require "find"
require "fileutils"
#SUBCLASS FOR CREATING A WINDOW, CONTAINS ALL THE CUSTOMISATION INFORMATION
class ScriptGui < FXMainWindow
def initialize(app)
super(app, "Script", :width => 700, :height => 200)
frame = FXVerticalFrame.new(self, LAYOUT_LEFT|LAYOUT_FILL_X)
#FRAMES FOR INPUT
frame1 = FXHorizontalFrame.new(frame,
LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y)
inputFileA = FXButton.new(frame1, "Input File")
inputFileA.connect(SEL_COMMAND) do #the connect will ensure the
following block is performed
dialog = FXFileDialog.new(self, "Select file")
dialog.patternList = ["Text Files (*.txt)", "All Files (*)"]
#recognised file types
dialog.selectMode =
SELECTFILE_EXISTING #select a file
if dialog.execute !=
0 #display
the box and wait for user response
@aInput.text =
dialog.filename #if the user
selects a file, write it in inputfield
end
end
@aInput = FXTextField.new(frame1, 90, :opts =>
JUSTIFY_LEFT|FRAME_SUNKEN|FRAME_THICK)
FXHorizontalSeparator.new(frame, :opts =>
LAYOUT_FILL_X|SEPARATOR_GROOVE)
buttonCode = FXButton.new(frame, "Run").connect(SEL_COMMAND,
method(:matcher)) #call method matcher to commence
process
end
def matcher(sender, selector, data)
#set up hash for itemC and doc ID
@hashMapping = Hash.new {|h,k| h[k] = []}
#process loadfile to capture doc ID's & itemC values.
IO.foreach(@aInput.to_s) do
|data| #go through the input
concordance loadfile
fields = data.split("
") #split the
field on this
itemA =
fields[13].delete("þ").downcase
itemB =
fields[0].delete("þ,\"")
itemC =
fields[35].delete("þ,\"")
if itemA.to_s.downcase == "pdf"
@hashMapping[itemC] <<
itemB
end
end
Find.find(@aInput.to_s) do
|curPath2|
if File.file?(curPath2) and curPath2[/\.txt$/]
itemCFN = File.basename(curPath2,
".txt").strip.to_s.downcase #grabs the file name stripping
whitespace
finditemC(curPath2,
itemCFN)
end
end
end
def finditemC(curPath2,
itemCFN)
@hashMapping.each do |itemDetail|
@entryArray =
[]
entry =
itemDetail.to_s.strip
@entryArray <<
itemDetail.to_s.strip
if
entry.match(/#{itemCFN}/)
puts itemCFN
end
end
end
def create
super
show(PLACEMENT_SCREEN) #SHOW THE GUI ON THE SCREEN
end
end
#CONSTRUCTOR
if __FILE__ == $0
FXApp.new do |app|
ScriptGui.new(app)
app.create#CALLS THE METHOD CREATE TO ENSURE ALL NEEDED INFO IS
ADDED
app.run#STARTS THE CREATION OF THE WINDOWS
end
end
and here is the go:
>ruby ScriptGui.rb
ScriptGui.rb:42:in `matcher': undefined method `delete' for nil:NilClass
(NoMethodError)
from ScriptGui.rb:40:in `foreach'
from ScriptGui.rb:40:in `matcher'
from
C:/allruby/rubyinstaller/sandbox/ruby18_mingw/lib/ruby/site_ruby/1.8/fox16/responder2.rb:55:in
`call'
from
C:/allruby/rubyinstaller/sandbox/ruby18_mingw/lib/ruby/site_ruby/1.8/fox16/responder2.rb:55:in
`onHandleMsg'
from ScriptGui.rb:80:in `run'
from ScriptGui.rb:80
from
C:/allruby/rubyinstaller/sandbox/ruby18_mingw/lib/ruby/site_ruby/1.8/fox16/kwargs.rb:269:in
`old_initialize'
from
C:/allruby/rubyinstaller/sandbox/ruby18_mingw/lib/ruby/site_ruby/1.8/fox16/kwargs.rb:269:in
`initialize'
from ScriptGui.rb:77:in `new'
from ScriptGui.rb:77
>Exit code: 1
On 3/3/10, Douglas Allen <kb9agt at gmail.com> wrote:
>
> here is another little tidbit:
> theButton.connect(SEL_COMMAND) {
> puts "You have clicked the button. Good bye!"
> exit}
> There are many ways to do blocks.
>
>
> On 3/3/10, Douglas Allen <kb9agt at gmail.com> wrote:
>>
>> I'm too inexperienced with FXRuby to really help you but have you ever
>> worked with the foxGUIb?
>>
>> I can almost see the same things going on but with different approaches. I
>> like that it uses more attribute_reader after building all the widgets. It
>> just has such a nice clean format. here's a simple app:
>>
>> # source generated by foxGUIb 1.0.0
>>
>> class MainWindow
>> def initialize( parent)
>> construct_widget_tree( parent)
>> init if respond_to? 'init'
>> end
>>
>> def construct_widget_tree( parent)
>> @topwin=
>> FX::MainWindow.new(parent){|w|
>> @MainWindow=w
>> w.wdg_name='MainWindow'
>> w.backColor=Fox::FXRGBA(212,208,200,255)
>> w.width=216
>> w.hSpacing=0
>> w.shown=true
>> w.y=167
>> w.height=218
>> w.title="MainWindow"
>> w.vSpacing=0
>> w.x=262
>> FX::VerticalFrame.new(@MainWindow){|w|
>> @VerticalFrame=w
>> w.wdg_name='VerticalFrame'
>> w.baseColor=Fox::FXRGBA(212,208,200,255)
>> w.backColor=Fox::FXRGBA(212,208,200,255)
>> w.width=216
>> w.height=218
>> w.shadowColor=Fox::FXRGBA(139,137,132,255)
>> FX::Button.new(@VerticalFrame){|w|
>> @Button=w
>> w.wdg_name='Button'
>> w.baseColor=Fox::FXRGBA(212,208,200,255)
>> w.text="click to see what happens!"
>> w.backColor=Fox::FXRGBA(212,208,200,255)
>>
>> w.font=FX::Font.new.from_s('Sans|90|0|0|0|0|0').to_FXFont
>> w.width=153
>> w.height=23
>> w.shadowColor=Fox::FXRGBA(139,137,132,255)
>> @Button.connect(Fox::SEL_LEFTBUTTONRELEASE){
>> @Text.appendText "lmb up\n"
>> 0 # this prevents fox from blocking the builtin
>> event handler for leftbuttonpress
>> }
>> @Button.connect(Fox::SEL_LEFTBUTTONPRESS){
>> @Text.appendText "lmb down\n"
>> 0 # this prevents fox from blocking the builtin
>> event handler for leftbuttonpress
>> }
>> @Button.connect(Fox::SEL_COMMAND){
>> @Text.appendText "click!\n"
>> }
>> }
>> FX::Text.new(@VerticalFrame){|w|
>> @Text=w
>> w.wdg_name='Text'
>>
>> w.font=FX::Font.new.from_s('Sans|90|0|0|0|0|0').to_FXFont
>> w.width=216
>> w.selBackColor=Fox::FXRGBA(10,36,106,255)
>> w.y=23
>> w.height=195
>> }
>> }
>> }
>> end
>> attr_reader :topwin
>> attr_reader :MainWindow
>> attr_reader :VerticalFrame
>> attr_reader :Button
>> attr_reader :Text
>> end
>>
>> #unit test
>> if __FILE__==$0
>> require 'libGUIb16'
>> app=FX::App.new
>> w=MainWindow.new app
>> w.topwin.show(Fox::PLACEMENT_SCREEN)
>> app.create
>> app.run
>> end
>>
>> notice require 'libGUIb16' and then it uses 'fox16' or 'fox14' in its'
>> system.
>> I'm amazed at the size of the GUI builder app. Nothing large like Glade or
>> IronRuby.
>>
>>
>> On 3/3/10, Stuart Clarke <stuart_clarke86 at yahoo.com> wrote:
>>>
>>> See code below, many thanks:
>>>
>>> require 'fox16'
>>> include Fox
>>>
>>> require "find"
>>> require "fileutils"
>>>
>>> class ScriptGui < FXMainWindow #SUBCLASS FOR CREATING A WINDOW, CONTAINS
>>> ALL THE CUSTOMISATION INFORMATION
>>> def initialize(app)
>>> super(app, "Script", :width => 700, :height => 200)
>>> frame = FXVerticalFrame.new(self, LAYOUT_LEFT|LAYOUT_FILL_X)
>>> #FRAMES FOR INPUT
>>> frame1 = FXHorizontalFrame.new(frame,
>>> LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y)
>>>
>>>
>>> inputFileA = FXButton.new(frame1, "Input File")
>>> inputFileA.connect(SEL_COMMAND) do
>>> #the connect will ensure the following block is performed
>>> dialog = FXFileDialog.new(self, "Select file")
>>> dialog.patternList = ["Text Files (*.txt)", "All Files (*)"]
>>> #recognised file types
>>> dialog.selectMode = SELECTFILE_EXISTING
>>> #select a file
>>> if dialog.execute != 0
>>> #display the box and wait fot user response
>>> @aInput.text = dialog.filename
>>> #if the user selects a file it write it in inputfield
>>> end
>>> end
>>> @aInput = FXTextField.new(frame1, 90, :opts =>
>>> JUSTIFY_LEFT|FRAME_SUNKEN|FRAME_THICK)
>>>
>>> FXHorizontalSeparator.new(frame, :opts =>
>>> LAYOUT_FILL_X|SEPARATOR_GROOVE)
>>>
>>> buttonCode = FXButton.new(frame, "Run").connect(SEL_COMMAND,
>>> method(:matcher)) #call method matcher to commence
>>> process
>>> end
>>>
>>> def matcher(sender, sel, ptr)
>>> #set up hash for itemC and doc ID
>>> @hashMapping = Hash.new {|h,k| h[k] = []}
>>>
>>> #process loadfile to capture doc ID's & itemC values.
>>> IO.foreach(@aInput.to_s) do |data|
>>> #go through the input concordance loadfile
>>> fields = data.split(" ")
>>> #split the field on this
>>> itemA = fields[13].delete("þ").downcase
>>>
>>> itemB = fields[0].delete("þ,\"")
>>>
>>> itemC = fields[35].delete("þ,\"")
>>>
>>> if itemA.to_s.downcase == "pdf"
>>> @hashMapping[itemC] << itemB
>>>
>>> end
>>> end
>>>
>>> Find.find(@aInput.to_s) do |curPath2|
>>>
>>> if File.file?(curPath2) and curPath2[/\.txt$/]
>>> itemCFN = File.basename(curPath2, ".txt").strip.to_s.downcase
>>> #grabs the file name stripping whitespace
>>> finditemC(curPath2, itemCFN)
>>>
>>> end
>>> end
>>> end
>>>
>>> def finditemC(curPath2, itemCFN)
>>>
>>> @hashMapping.each do |itemDetail|
>>> @entryArray = []
>>>
>>> entry = itemDetail.to_s.strip
>>>
>>> @entryArray << itemDetail.to_s.strip
>>>
>>> if entry.match(/#{itemCFN}/)
>>>
>>> puts itemCFN
>>> end
>>> end
>>> end
>>>
>>> def create
>>> super
>>> show(PLACEMENT_SCREEN)
>>> #SHOW THE GUI ON THE SCREEN
>>> end
>>> end
>>>
>>> #CONSTRUCTOR
>>> if __FILE__ == $0
>>> FXApp.new do |app|
>>> ScriptGui.new(app)
>>> app.create#CALLS THE METHOD CREATE TO ENSURE ALL NEEDED INFO IS ADDED
>>> app.run#STARTS THE CREATION OF THE WINDOWS
>>> end
>>> end
>>>
>>> --- On *Tue, 2/3/10, Joey Kinsella <jkinsella at ancillaryservices.com>*wrote:
>>>
>>>
>>> From: Joey Kinsella <jkinsella at ancillaryservices.com>
>>> Subject: Re: [fxruby-users] Class with looping objects
>>> To: fxruby-users at rubyforge.org
>>> Date: Tuesday, 2 March, 2010, 13:58
>>>
>>> It would be much easier to help you if we could see at least example code
>>> (similar to what your doing.)
>>> However, the error you displayed below tells me your doing something
>>> incorrectly. Are you sure self.close() is really what you want to do?
>>> Perhaps you should try self.hide()/self.show(). I don't know, without actual
>>> code it's hard to tell what you are trying to do. But I hope this helps.
>>>
>>> On Tue, Mar 2, 2010 at 4:34 AM, Stuart Clarke <stuart_clarke86 at yahoo.com<http://mc/compose?to=stuart_clarke86@yahoo.com>
>>> > wrote:
>>>
>>>> Hi,
>>>>
>>>> Thanks for your reply.
>>>>
>>>> I have tried this previously and I get the following error:
>>>>
>>>> C:/Ruby/lib/ruby/gems/1.8/gems/fxruby-1.6.16-x86-mswin32-60/lib/fox16/aliases.rb:4812:in
>>>> `getText': This FXTextField * already released (RuntimeError)
>>>>
>>>> Code is:
>>>>
>>>> buttonCode = FXButton.new(frame, "Run").connect(SEL_COMMAND,
>>>> method(:matcher))
>>>> end
>>>> def matcher(sender, sel, ptr)
>>>> self.close(true)
>>>> #....
>>>>
>>>> Just to clarify, when matcher runs, it does
>>>>
>>>> Matcher object - get first item and call object2
>>>> Object2 does stuff and then we go back to object matcher and get the
>>>> next item
>>>> This loop continues until all items have been through both objects then
>>>> once finished the run button pops up again and the processing is done, at
>>>> this point I want a GUI.
>>>>
>>>> Thanks a lot
>>>>
>>>> Stuart
>>>>
>>>>
>>>> --- On *Mon, 1/3/10, Joey Kinsella <jkinsella at ancillaryservices.com<http://mc/compose?to=jkinsella@ancillaryservices.com>
>>>> >* wrote:
>>>>
>>>>
>>>> From: Joey Kinsella <jkinsella at ancillaryservices.com<http://mc/compose?to=jkinsella@ancillaryservices.com>
>>>> >
>>>> Subject: Re: [fxruby-users] Class with looping objects
>>>>
>>>> To: fxruby-users at rubyforge.org<http://mc/compose?to=fxruby-users@rubyforge.org>
>>>> Date: Monday, 1 March, 2010, 14:43
>>>>
>>>> Couldn't you just do:
>>>>
>>>> def initialize
>>>> # ...
>>>> button = FXButton.new(frame, "Run").connect(SEL_COMMAND,
>>>> method(:matcher))
>>>> # ...
>>>> end
>>>>
>>>> def matcher(sender, selector, data)
>>>> # ...
>>>> self.close # (true) # if you want to notify the messaging system.
>>>> end
>>>>
>>>> or well, something along those lines.. button is a reference to an
>>>> FXButton object, It should never equal SEL_KEYRELEASE in this respect. Also
>>>> the code above is assuming that it's an object which extends FXMainWindow.
>>>>
>>>> Hope this helps,
>>>> -Joey
>>>>
>>>> On Mon, Mar 1, 2010 at 6:09 AM, Stuart Clarke <
>>>> stuart_clarke86 at yahoo.com<http://mc/compose?to=stuart_clarke86@yahoo.com>
>>>> > wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I have a GUI which triggers an object to do some stuff, when you press
>>>>> the FXButton it calls matcher e.g.
>>>>>
>>>>> button = FXButton.new(frame, "Run").connect(SEL_COMMAND,
>>>>> method(:matcher))
>>>>>
>>>>> This button remains in a pressed state until the object has finished
>>>>> running, when it is complete the button pops back up. I am trying to add a
>>>>> popup box to respond to the button popping up (or processing finished) like
>>>>> so:
>>>>>
>>>>> if button == SEL_KEYRELEASE
>>>>> FXMessageBox.information(self, MBOX_OK, "Complete")
>>>>> mainwindow.close
>>>>> end
>>>>>
>>>>> This however does not work, any ideas how I can acheive this?
>>>>>
>>>>> Many thanks
>>>>>
>>>>> --- On *Fri, 26/2/10, Stuart Clarke <stuart_clarke86 at yahoo.com<http://mc/compose?to=stuart_clarke86@yahoo.com>
>>>>> >* wrote:
>>>>>
>>>>>
>>>>> From: Stuart Clarke <stuart_clarke86 at yahoo.com<http://mc/compose?to=stuart_clarke86@yahoo.com>
>>>>> >
>>>>> Subject: [fxruby-users] Class with looping objects
>>>>> To: fxruby-users at rubyforge.org<http://mc/compose?to=fxruby-users@rubyforge.org>
>>>>> Date: Friday, 26 February, 2010, 19:38
>>>>>
>>>>>
>>>>> Hi all,
>>>>>
>>>>> Apologies if this is a stupid question but it is getting the best of
>>>>> me.
>>>>>
>>>>> I have a class which contains a GUI object which has serveral text
>>>>> fields and buttons which when used trigger the use of further objects which
>>>>> all loop through data, the structure is as follows:
>>>>>
>>>>> class
>>>>> def GUI
>>>>> GUI calls object1
>>>>> end
>>>>> def object1 loops through some data one entry at a time and for each
>>>>> entry passes to a new object
>>>>> end
>>>>> def object2 loops through passed data and does stuff
>>>>> end
>>>>> then the next bit of data does the same thing in object1
>>>>>
>>>>>
>>>>> What I need is a gui that pops up when my script runs through all of
>>>>> objects for each bit of data. Any ideas? I just need to know when the loop
>>>>> is complete, at present I press the go button on my fx GUI and it stays
>>>>> pressed in until all processing is done then pops back out. At this point I
>>>>> need a Gui.
>>>>>
>>>>> I hope this makes sense,
>>>>>
>>>>> Many thanks
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> fxruby-users mailing list
>>>>> fxruby-users at rubyforge.org<http://mc/compose?to=fxruby-users@rubyforge.org>
>>>>> http://rubyforge.org/mailman/listinfo/fxruby-users
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> fxruby-users mailing list
>>>>> fxruby-users at rubyforge.org<http://mc/compose?to=fxruby-users@rubyforge.org>
>>>>> http://rubyforge.org/mailman/listinfo/fxruby-users
>>>>>
>>>>
>>>> --
>>>> If you are not the intended recipient, you are hereby notified
>>>> that any dissemination, distribution, copying or other use of
>>>> this communication is strictly prohibited. If you have
>>>> received this communication in error, please notify us
>>>>
>>>>
>>>> immediately.
>>>>
>>>>
>>>> -----Inline Attachment Follows-----
>>>>
>>>>
>>>> _______________________________________________
>>>> fxruby-users mailing list
>>>> fxruby-users at rubyforge.org<http://mc/compose?to=fxruby-users@rubyforge.org>
>>>> http://rubyforge.org/mailman/listinfo/fxruby-users
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> fxruby-users mailing list
>>>> fxruby-users at rubyforge.org<http://mc/compose?to=fxruby-users@rubyforge.org>
>>>> http://rubyforge.org/mailman/listinfo/fxruby-users
>>>>
>>>
>>> --
>>> If you are not the intended recipient, you are hereby notified
>>> that any dissemination, distribution, copying or other use of
>>> this communication is strictly prohibited. If you have
>>> received this communication in error, please notify us
>>>
>>>
>>> immediately.
>>>
>>>
>>> -----Inline Attachment Follows-----
>>>
>>> _______________________________________________
>>> fxruby-users mailing list
>>> fxruby-users at rubyforge.org<http://mc/compose?to=fxruby-users@rubyforge.org>
>>> http://rubyforge.org/mailman/listinfo/fxruby-users
>>>
>>>
>>>
>>> _______________________________________________
>>> fxruby-users mailing list
>>> fxruby-users at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/fxruby-users
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20100303/320f2b49/attachment-0001.html>
More information about the fxruby-users
mailing list