Tk StatusBar help

  • Thread starter Jayson Williams
  • Start date
J

Jayson Williams

Is anyone familiar at all with Ruby Tk's StatusBar. I have not been
able to find out how to implement a StatusBar in my Ruby code. Could
someone lend me a hand?

Thanks
Jayson
 
J

Joel VanderWerf

Jayson said:
Is anyone familiar at all with Ruby Tk's StatusBar. I have not been
able to find out how to implement a StatusBar in my Ruby code. Could
someone lend me a hand?

If you're on windows look for something in your ruby dir like

doc\ruby\ruby-1.8.6\sample\tk\tkextlib\bwidget\demo.rb

I believe bwidgets is pure tcl/tk, so there isn't any additional C
library to build/install.

Anyway, the demo seems to work for me, and it has a nice little status bar.

HTH.
 
H

Hidetoshi NAGAI

From: "Jayson Williams" <[email protected]>
Subject: Tk StatusBar help
Date: Sat, 6 Oct 2007 03:30:11 +0900
Message-ID: said:
Is anyone familiar at all with Ruby Tk's StatusBar. I have not been
able to find out how to implement a StatusBar in my Ruby code. Could
someone lend me a hand?

If you can use some Tk extension libraries (e.g. BWidget),
it will be a simple and easy way to use a progressbar widget
on such libraries.
But, if you have to create a GUI with pure Tcl/Tk (without
extensions), the following source may be useful.
---------------------------------------------------------------
require 'tk'

class MyProgressBar < TkWindow
include TkComposite

def initialize_composite(keys = {})
# defaults
bar_color = 'gray60'
trough_color = 'gray90'
text_color = 'black'
reverse_color = 'white'

font_size = -12

@width = 150
@height = 20

# create widgets
@font = TkFont.new(['Helvetica', font_size])

@var = TkVariable.new('')

@frame.configure:)borderwidth=>3, :relief=>:ridge)

@size_base = TkFrame.new(@frame, :width=>@width, :height=>@height,
:borderwidth=>0).pack:)expand=>false,
:fill=>:none)

@size_base.pack_propagate(false)

@base_label = TkLabel.new(@size_base, :textvariable=>@var, :font=>@font,
:highlightthickness=>0, :borderwidth=>0,
:foreground=>text_color,
:background=>trough_color,
:padx=>1, :pady=>1).pack:)fill=>:both,
:expand=>true)
@prog_bar = TkFrame.new(@base_label,
:highlightthickness=>0, :borderwidth=>0
).place:)x=>0, :y=>0,
:anchor=>:nw,
:relwidth=>0.0, :relheight=>1.0)

@prog_label = TkLabel.new(@prog_bar, :textvariable=>@var, :font=>@font,
:foreground=>reverse_color,
:background=>bar_color,
:highlightthickness=>0, :borderwidth=>0,
:padx=>1, :pady=>1).place:)x=>0, :y=>0,
:width=>@width,
:height=>@height,
:anchor=>:nw)

# for bindings
@size_base.bindtags <<= @frame
@base_label.bindtags <<= @frame
@prog_bar.bindtags <<= @frame
@prog_label.bindtags <<= @frame

# delegates
delegate('DEFAULT', @frame)
delegate('background', @prog_label)
delegate('foreground', @base_label)

delegate_alias('barcolor', 'background', @prog_label)
delegate_alias('troughcolor', 'background', @base_label)
delegate_alias('textcolor', 'foreground', @base_label)
delegate_alias('reversecolor', 'foreground', @prog_label)

delegate_alias('fontfamily', 'family', @font)
delegate_alias('fontsize', 'size', @font)
delegate_alias('fontweight', 'weight', @font)
delegate_alias('fontslant', 'slant', @font)

option_methods:)width, :height, :font)

configure(keys) unless keys.empty?
end

def set(rate, text=nil)
@prog_bar.place:)relwidth=>rate.to_f)
@var.value = text if text
end

def get
[TkPlace.current_configinfo(@prog_bar, :relwidth)['relwidth'], @var.value]
end

def width(size=nil)
if size
@size_base.width = size
@prog_label.place:)width=>size)
@width = size
else
@width
end
end

def height(size=nil)
if size
@size_base.height = size
@prog_label.place:)height=>size)
@height = size
else
@height
end
end

def font(fnt=nil)
if fnt
if fnt.kind_of?(Hash)
@font.configure(fnt)
else
fnt = TkComm.simplelist(fnt) if fnt.kind_of?(String)
conf = {}
conf['family'] = fnt.shift if fnt[0]
conf['size'] = fnt.shift if fnt[0]
fnt.each{|param|
case param.to_s
when 'normal', 'bold'
conf['weight'] = param
when 'roman', 'italic'
conf['slant'] = param
when 'underline'
conf['underine'] = true
when 'overstrike'
conf['overstrike'] = true
end
}

@font.configure(conf)
end
else
@font
end
end
end

if __FILE__ == $0
bar1 = MyProgressBar.new.pack
bar2 = MyProgressBar.new:)width=>120, :height=>30,
:barcolor=>'blue', :troughcolor=>'white',
:fontsize=>14, :fontweight=>:bold).pack
bar3 = MyProgressBar.new:)font=>'courier 8 bold',
:textcolor=>'red', :reversecolor=>'yellow',
:width=>250, :height=>12).pack

bar1.set(0.0, '0%')
bar2.set(0.0, '0%')
bar3.set(0.0, '0%')

bar1.bind('1'){p bar1.get}

timer = TkTimer.new(50, 100){|timerobj|
cnt = timerobj.return_value + 1
bar1.set(cnt/100.0, "#{cnt}%")
bar2.set(cnt/100.0, "#{cnt}%")
bar3.set(cnt/100.0, "#{cnt}%")
cnt
}

b = TkButton.new:)text=>'restart', :command=>proc{
bar1.set(0.0, '0%')
bar2.set(0.0, '0%')
bar3.set(0.0, '0%')
timer.restart{0}
}).pack
b.invoke

Tk.mainloop
end
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

tk canvas drag items 0
Qt problems 3
tk canvas drag items 3
Stupid TK 2
Ruby/Tk 5
Help JQuery 1
Ruby/tk Help Please 19
Help 1

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top