Ruby/Tk code critique

Discussion in 'Ruby' started by rubist __, Jul 28, 2006.

  1. rubist __

    rubist __ Guest

    I have a bunch of Tk buttons tied to code. They're wrapped in an array
    to process later.

    What I'd like to do is set each one to have a visual indicator that it
    was used. So after it's clicked, it gets configured to have relief
    "flat" or background "yellow" etc.

    And then later, when a new row is being processed, I can iterate thru
    button_array and reset their color/relief etc. -- this is to aid the
    user in knowing which buttons they've already used.

    The simple/ugly way I suppose would be to make each button be like:
    TkButton.new(frame) {
    text "bleh"
    command proc {
    self.configure("relief","flat")
    run_code:)buttoncode)
    }
    }

    What I'm looking for is basically an elegant way to do this. Rather than
    modify each proc to add code to change the relief, I'd like an 'around'
    method to put around run_code. Or in run_code if I could identify the
    button that was clicked.

    #Random status label changes
    pru=proc{@status.configure('text'=>"Processing...")}
    prr=proc{@status.configure('text'=>"Ready...")}

    ## Proc for ETL tasks
    retl = proc{run_code:)etl)}
    etlre = proc{run_code:)etlreuse)}
    idsre = proc{run_code:)idsreuse)}
    edwre = proc{run_code:)edwreuse)}
    sorre = proc{run_code:)sorreuse)}
    #Buttons - ETL reuse
    lxxs_4 = TkButton.new(reusefr) { text "Reuse-ETL"; command etlre}
    lxxs_5 = TkButton.new(reusefr) { text "Reuse-IDS"; command idsre}
    lxxs_6 = TkButton.new(reusefr) { text "Reuse-EDW"; command edwre}
    lxxs_7 = TkButton.new(reusefr) { text "Reuse-SOR"; command sorre}

    button_array = [lxxs_4, lxxs_5 etc.]

    Incidentally, run_code looks like this:
    def run_code(par)
    @controller.dispatcher(par)
    end


    --
    Posted via http://www.ruby-forum.com/.
    rubist __, Jul 28, 2006
    #1
    1. Advertising

  2. Probably, using `bindtag' is not so bad idea.

    From: rubist __ <>
    Subject: Ruby/Tk code critique
    Date: Sat, 29 Jul 2006 04:07:46 +0900
    Message-ID: <>
    > button_array = [lxxs_4, lxxs_5 etc.]


    btag = TkBindTag.new
    btag.bind('ButtonRelease-1', proc{|w| w['relief'] = 'flat'}, '%W')
    button_array.each{|b| b.bindtags_unshift(btag) }

    --
    Hidetoshi NAGAI ()
    Hidetoshi NAGAI, Jul 28, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Stewart

    Code critique (no URL available)

    Ryan Stewart, Apr 26, 2004, in forum: HTML
    Replies:
    3
    Views:
    461
    Ryan Stewart
    Apr 26, 2004
  2. Ryan Stewart

    Code critique (again)

    Ryan Stewart, May 4, 2004, in forum: HTML
    Replies:
    4
    Views:
    391
    Toby A Inkster
    May 4, 2004
  3. Michael Strorm
    Replies:
    26
    Views:
    768
    J. Campbell
    Nov 10, 2003
  4. Rv5

    Code Critique Please

    Rv5, Nov 16, 2003, in forum: C++
    Replies:
    3
    Views:
    360
    Benny Hill
    Nov 16, 2003
  5. Martin Eisenberg

    Code critique

    Martin Eisenberg, Apr 6, 2004, in forum: C++
    Replies:
    27
    Views:
    823
    Martin Eisenberg
    Apr 9, 2004
Loading...

Share This Page