diff --git a/NOTES b/NOTES index 2eef10c..6e9aa2d 100644 --- a/NOTES +++ b/NOTES @@ -2210,3 +2210,34 @@ I will have to think of other ways of simplifying. * * * * * * * * + +Subject: constructors +--------------------- +Date: 2014-03-25 22:33 + +For the purpose of simplifying, I was looking at the libtcltk ruby code. +They essentially use the same approach as I have done. +They also use a hash for options, but i doesn't look like they set it +into vars. they keep it in a hash. +the first param is checked for if its a hash then it is taken to be the +options. this way one doesn't have to pass form as nil. + +all symbols are converted to strings. we sort of do the opposite and +prefer symbols. + +however, if we only keep in a hash, then any processing that needs to be +done cannot be done. i am concerned about property_changed etc. + +to update the hash, there is a configure method. + +i suppose the configure method could check for an array of +property_change elements and call the handler. but still no special +processing can be done if we keep a hash only. + +Keeping in a hash means that no documentation will be generated. + +Interestingly, the menubar uses a spec which is an array with elements +and a proc, so the entire menu can be defined. each menu also can take a +spec as an optional param. + +* * * * * * * * diff --git a/examples/testcombo.rb b/examples/testcombo.rb index d42ae7b..64057bb 100644 --- a/examples/testcombo.rb +++ b/examples/testcombo.rb @@ -43,7 +43,7 @@ def help_text colors = Ncurses.COLORS $log.debug "START #{colors} colors testcombo.rb --------- #{@window} " @form = Form.new @window - title = (" "*30) + "Demo of Combo (F10 quits, F1 help) " + Rbcurse::VERSION + title = (" "*30) + "Demo of Combo (F10 quits, F1 help, SPACE to popup combo) " + Rbcurse::VERSION Label.new @form, {:text => title, :row => 1, :col => 0, :color => :green, :bgcolor => :black} r = 3; fc = 12; diff --git a/examples/testprogress.rb b/examples/testprogress.rb new file mode 100644 index 0000000..d007712 --- /dev/null +++ b/examples/testprogress.rb @@ -0,0 +1,116 @@ +# ----------------------------------------------------------------------------- # +# File: testprogress.rb +# Description: a test program for progress bar widget +# creates two progress bars, one old style and one new +# Keeps running till 'q' pressed. +# Author: rkumar http://github.com/rkumar/rbcurse-core/ +# Date: 2014-03-27 - 23:31 +# License: Same as Ruby's License (http://www.ruby-lang.org/LICENSE.txt) +# Last update: 2014-03-27 23:33 +# ----------------------------------------------------------------------------- # +# testprogress.rb Copyright (C) 2012-2014 rahul kumar +require 'logger' +require 'rbcurse' +require 'rbcurse/core/widgets/rprogress' +if $0 == __FILE__ + + #include RubyCurses + + begin + # Initialize curses + VER::start_ncurses # this is initializing colors via ColorMap.setup + path = File.join(ENV["LOGDIR"] || "./" ,"rbc13.log") + file = File.open(path, File::WRONLY|File::TRUNC|File::CREAT) + $log = Logger.new(path) + $log.level = Logger::DEBUG + + @window = VER::Window.root_window + + catch(:close) do + @form = Form.new @window + title = (" "*30) + "Demo of Progress Bar (q quits, s - slow down) " + Rbcurse::VERSION + Label.new @form, {:text => title, :row => 1, :col => 0, :color => :green, :bgcolor => :black} + Label.new @form, {:text => "Press q to quit, s/f make slow or fast", :row => 10, :col => 10} + Label.new @form, {:text => "Old style and modern style progress bars", :row => 12, :col => 10} + r = 14; fc = 12; + + pbar1 = Progress.new @form, {:width => 20, :row => r, :col => fc, + :name => "pbar1", :style => :old} + #:bgcolor => 'white', :color => 'red', :name => "pbar1", :style => :old} + pbar = Progress.new @form, {:width => 20, :row => r+2, :col => fc, + :bgcolor => 'white', :color => 'red', :name => "pbar"} + + pbar.visible false + pb = @form.by_name["pbar"] + pb.visible true + len = 1 + ct = (100) * 1.00 + pb.fraction(len/ct) + pbar1.fraction(len/ct) + i = ((len/ct)*100).to_i + i = 100 if i > 100 + pb.text = "completed:#{i}" + + + @form.repaint + @window.wrefresh + Ncurses::Panel.update_panels + + # the main loop + + # this is so there's no wait for a key, i want demo to proceed without key press, but + # respond if there is one + Ncurses::nodelay(@window.get_window, bf = true) + + # sleep seconds between refresh of progress + slp = 0.1 + ##while((ch = @window.getchar()) != FFI::NCurses::KEY_F10 ) + #break if ch == ?\C-q.getbyte(0) + while((ch = @window.getch()) != 27) + break if ch == "q".ord + ## slow down + if ch == "s".ord + slp *= 2 + elsif ch == "f".ord + ## make faster + slp /= 2.0 + end + begin + + sleep(slp) + len += 1 + if len > 100 + len = 1 + sleep(1.0) + end + ct = (100) * 1.00 + pb.fraction(len/ct) + pbar1.fraction(len/ct) + i = ((len/ct)*100).to_i + i = 100 if i > 100 + pb.text = "completed:#{i}" + + #@form.handle_key(ch) + @form.repaint + @window.wrefresh + Ncurses::Panel.update_panels + #end + + rescue => err + break + end + + @window.wrefresh + end # while loop + end # catch + rescue => ex + ensure + $log.debug " -==== EXCEPTION =====-" + $log.debug( ex) if ex + $log.debug(ex.backtrace.join("\n")) if ex + @window.destroy if !@window.nil? + VER::stop_ncurses + puts ex if ex + puts(ex.backtrace.join("\n")) if ex + end +end diff --git a/lib/rbcurse/core/util/rdialogs.rb b/lib/rbcurse/core/util/rdialogs.rb index 2c82a7f..9e66760 100644 --- a/lib/rbcurse/core/util/rdialogs.rb +++ b/lib/rbcurse/core/util/rdialogs.rb @@ -59,9 +59,8 @@ def textdialog mess, config={} # # This uses the new messagebox 2011-11-19 v 1.5.0 # NOTE: The earlier get_string had only an OK button, this seems to have a CANCEL -# Are we doing anyhting to let caller know, cancel was pressed. FIXME # @param [String] a label such as "Enter name:" -# @return [String] value entered by user +# @return [String] value entered by user, nil if cancel pressed # @yield [Field] field created by messagebox def get_string label, config={} # yield Field config[:title] ||= "Entry" @@ -166,8 +165,6 @@ def print_status_message text, aconfig={}, &block # new version with a window created on 2011-10-1 12:30 AM # Now can be separate from window class, needing nothing, just a util class -# Why are we dealing with $error_message, that was due to old idea which failed -# scrap it and send the message. # @param [String] text to print # @param [Hash] config: :color :bgcolor :color_pair # :wait (numbr of seconds to wait for a key press and then close) if not givn @@ -374,6 +371,9 @@ def progress_dialog aconfig={}, &block # Display a popup and return the seliected index from list # Config includes row and col and title of window # You may also pass bgcolor and color +# Returns index of selected row on pressing ENTER or space +# In case of multiple selection, returns array of selected indices only on ENTER +# Returns nil if C-q pressed # @since 1.4.1 2011-11-1 def popuplist list, config={}, &block raise ArgumentError, "Nil list received by popuplist" unless list