class MyFileChooserButton
this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)
Attributes
ftp[RW]
pc[RW]
progress[RW]
Public Class Methods
new(pc)
click to toggle source
Calls superclass method
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 8 def initialize(pc) @pc=pc action=case item['action'] when 'load' then Gtk::FileChooser::Action::OPEN when 'save' then Gtk::FileChooser::Action::SAVE end super(action) # set_select_multiple(false) path=get_conf(0,item['id'],"path") set_current_folder(path) if !path.nil? preview=Gtk::Image.new set_preview_widget(preview) signal_connect("update-preview") { filename = preview_filename begin have_pixbuf=true pixbuf = Gdk::Pixbuf.new(filename, 128, 128) rescue have_pixbuf=false end preview_widget.set_pixbuf(pixbuf) set_preview_widget_active(have_pixbuf) } begin @ftp=eval(pc.gtk_attribute("ftp-access").to_s) rescue =>err ewarn(err) end pack_start(@progress=Gtk::ProgressBar.new,false,true,1) if @ftp.class==Array end
Public Instance Methods
ftp_get()
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 100 def ftp_get unless @ftp.class==Array warn("no ftp access defined") return false end set_conf(0,item['id'],"path",current_folder) ftp=Net::FTP.new(@ftp[0],@ftp[1],@ftp[2]) @ftp[3].each("/"){|s| einfo("changing ftp dir: #{s}","form") ftp.chdir(s) } if @ftp[3] perc=0 einfo(item["initial"],"form") ftp.getbinaryfile(item["initial"],filename,ftp.size(item["initial"])/100){ progress.set_fraction(perc/100.0) Gtk.show_thread_changes perc+=1 } ftp.close end
ftp_store()
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 74 def ftp_store unless @ftp.class==Array warn("no ftp access defined") return false end set_conf(0,item['id'],"path",current_folder) ftp=Net::FTP.new(@ftp[0],@ftp[1],@ftp[2]) @ftp[3].each("/"){|s| begin einfo("changing ftp dir: #{s}","form") ftp.chdir(s) rescue =>err einfo("creating ftp dir: #{s}","form") ftp.mkdir(s) retry end } if @ftp[3] perc=0 ftp.putbinaryfile(filename,text,File.size(filename)/100){ progress.set_fraction(perc/100.0) Gtk.show_thread_changes perc+=1 } ftp.close end
item()
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 41 def item @pc.item end
load()
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 56 def load ret=String.new file = File.new(filename, "rb") ret=file.read file.close edebug("loaded","list-filechooser","debug") set_conf(0,item['id'],"path",current_folder) ret end
loadPixbuf()
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 122 def loadPixbuf set_conf(0,item['id'],"path",current_folder) pixdata=Gdk::Pixdata.from_pixbuf(Gdk::Pixbuf.new(filename),true) pixdata.serialize.pack("c*") end
save(content)
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 66 def save(content) file = File.new(filename, "wb+") file.write(content) file.close edebug("saved","list-filechooser","debug") set_conf(0,item['id'],"path",current_folder) end
text()
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 52 def text filename[current_folder.length() +1 .. filename.length()] end
update(nfilename=item['default'])
click to toggle source
# File lib/FormHolder/Form/InputHolder/FileChooser.rb, line 45 def update(nfilename=item['default']) run_events(item['id'],'info_item-BeforeUpdate') edebug("filename to set: |#{nfilename}|","list-filechooser","debug") set_current_name(nfilename) if nfilename run_events(item['id'],'info_item-AfterUpdate') end