ruby/ext/tk/sample/demos-jp/ixset2
nagai aff4ce9c77 * ext/tk/*: full update Ruby/Tk to support Ruby(1.9|1.8) and Tc/Tk8.5.
* ext/tk/lib/tkextlib/tile.rb: [incompatible] remove TileWidgets' 
  instate/state/identify method to avoid the conflict with standard
  widget options. Those methods are renamed to ttk_instate/ttk_state/
  ttk_identify (tile_instate/tile_state/tile_identify are available 
  too). Although I don't recommend, if you realy need old methods, 
  please define "Tk::USE_OBSOLETE_TILE_STATE_METHOD = true" before 
  "require 'tkextlib/tile'".

* ext/tk/lib/tkextlib/tile.rb: "Tk::Tile::__Import_Tile_Widgets__!"
  is obsolete. It outputs warning. To control default widget set, 
  use "Tk.default_widget_set = :Ttk".

* ext/tk/lib/tk.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and 
  __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind 
  as module methods of TkConfigMethod. It may help users to wrap old 
  Ruby/Tk scripts (use standard widgets) to force to use Ttk widgets.
  Ttk widgets don't have some options of standard widgets which are 
  control the view of widgets. When set ignore-mode true, configure 
  method tries to ignoure such unknown options with no exception. 
  Of course, it may raise other troubles on the GUI design. 
  So, those are a little danger methods. 

* ext/tk/lib/tk/itemconfig.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ 
  method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method 
  are defind as module methods of TkItemConfigMethod as the same 
  purpose as TkConfigMethod's ones.

* ext/tk/sample/ttk_wrapper.rb: A new example. This is a tool for 
  wrapping old Ruby/Tk scripts (which use standard widgets) to use 
  Ttk (Tile) widgets as default.

* ext/tk/sample/tkextlib/tile/demo.rb: use ttk_instate/ttk_state 
  method instead of instate/state method.

* ext/tk/lib/tk/root, ext/tk/lib/tk/namespace.rb,
  ext/tk/lib/tk/text.rb, ext/tk/lib/tkextlib/*: some 'instance_eval's  
  are replaced to "instance_exec(self)".

* ext/tk/lib/tk/event.rb: bug fix on KEY_TBL and PROC_TBL (?x is not 
  a character code on Ruby1.9).

* ext/tk/lib/tk/variable.rb: support new style of operation argument 
  on Tcl/Tk's 'trace' command for variables. 

* ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget: bug fix

* ext/tk/sammple/demos-jp/textpeer.rb, 
  ext/tk/sammple/demos-en/textpeer.rb: new widget demo.

* ext/tk/tcltklib.c: decrase SEGV troubles (probably)

* ext/tk/lib/tk.rb: remove Thread.critical access if Ruby1.9

* ext/tk/lib/tk/multi-tk.rb: support Ruby1.9 (probably)

* ext/tk/lib/tkextlib/tile.rb: add method to define Tcl/Tk command 
  to make Tcl/Tk theme sources (based on different version of Tile 
  extension) available. 
  (Tk::Tile::__define_LoadImages_proc_for_comaptibility__)

* ext/tk/lib/tk.rb, ext/tk/lib/tk/wm.rb: support dockable frames
  (Tcl/Tk8.5 feature). 'wm' command can treat many kinds of widgets 
  as toplevel widgets.

* ext/tk/lib/tkextlib/tile/style.rb: ditto.
  (Tk::Tile::Style.__define_wrapper_proc_for_compatibility__)

* ext/tk/lib/tk/font.rb: add actual_hash and metrics_hash to get 
  properties as a hash. metrics_hash method returns a boolean value 
  for 'fixed' option. But metrics method returns numeric value 
  (0 or 1) for 'fixed' option, because of backward compatibility. 

* ext/tk/lib/tk/timer.rb: somtimes fail to set callback procedure.

* ext/tk/lib/tk.rb: add Tk.sleep and Tk.wakeup method. Tk.sleep 
  doesn't block the eventloop. It will be better to use the method 
  in event callbacks.

* ext/tk/sample/tksleep_sample.rb: sample script about Tk.sleep.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@15849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-03-29 05:25:45 +00:00

369 lines
8.3 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env ruby
# -*- coding: euc-jp -*-
#
# ixset --
# A nice interface to "xset" to change X server settings
#
require 'tk'
class Xsettings
#
# Button actions
#
def quit
@root.destroy
end
def ok
writesettings
quit
end
def cancel
readsettings
dispsettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
# apply is just "writesettings"
def apply
writesettings
@btn_APPLY.state(:disabled)
@btn_CANCEL.state(:disabled)
end
#
# Read current settings
#
def readsettings
xfd = open("|xset q", 'r')
xfd.readlines.each{|line|
fields = line.chomp.strip.split(/\s+/)
case fields[0]
when "auto"
if fields[1] == 'repeat:'
@kbdrep = fields[2]
@w_kbdrep.set(@kbdrep)
@kbdcli = fields[6]
end
when "bell"
@bellvol = fields[2]
@bellpit = fields[5]
@belldur = fields[8]
when "acceleration:"
@mouseacc = fields[1]
@mousethr = fields[3]
when "prefer"
if fields[2] == 'yes'
@screenbla = 'blank'
else
@screenbla = 'noblank'
end
@w_screenbla.set(@screenbla)
when "timeout:"
@screentim = fields[1]
@screencyc = fields[3]
end
}
xfd.close
end
#
# Write settings into the X server
#
def writesettings
@bellvol = @w_bellvol.get
@bellpit = @w_bellpit.get
@belldur = @w_belldur.get
@kbdrep = @w_kbdrep.get
if @kbdrep == 'on'
@kbdcli = @w_kbdcli.get
else
@kbdcli = 'off'
end
@mouseacc = @w_mouseacc.get
@mousethr = @w_mousethr.get
@screentim = @w_screentim.get
@screencyc = @w_screencyc.get
@screenbla = @w_screenbla.get
system("xset \
b #{@bellvol} #{@bellpit} #{@belldur} \
c #{@kbdcli} \
r #{@kbdrep} \
m #{@mouseacc} #{@mousethr} \
s #{@screentim} #{@screencyc} \
s #{@screenbla}")
end
#
# Sends all settings to the window
#
def dispsettings
@w_bellvol.set(@bellvol)
@w_bellpit.set(@bellpit)
@w_belldur.set(@belldur)
@w_kbdonoff.set(@w_kbdrep.get)
@w_kbdcli.set(@kbdcli)
@w_mouseacc.set(@mouseacc)
@w_mousethr.set(@mousethr)
@w_screenblank.set(@w_screenbla.get)
@w_screenpat.set(@w_screenbla.get)
@w_screentim.set(@screentim)
@w_screencyc.set(@screencyc)
end
#
# Create all windows, and pack them
#
class LabelEntry
def initialize(parent, text, length, range=[])
@frame = TkFrame.new(parent)
TkLabel.new(@frame, 'text'=>text).pack('side'=>'left')
if range.size > 0
@entry = TkSpinbox.new(@frame, 'width'=>length, 'relief'=>'sunken',
'from'=>range[0], 'to'=>range[1])
else
@entry = TkEntry.new(@frame, 'width'=>length, 'relief'=>'sunken')
end
@entry.pack('side'=>'right','expand'=>'y', 'fill'=>'x')
end
def epath
@frame
end
def pack(keys)
@frame.pack(keys)
end
def get
@entry.value
end
def set(value)
@entry.delete(0,'end')
@entry.insert(0, value)
end
end
def createwindows
win = self
#
# Buttons
#
btn_frame = TkFrame.new(@root)
buttons = [
@btn_OK = TkButton.new(btn_frame, 'command'=>proc{win.ok},
'default'=>'active', 'text'=><><CEBB>'),
@btn_APPLY = TkButton.new(btn_frame, 'command'=>proc{win.writesettings},
'default'=>'normal', 'text'=><><C5AC>',
'state'=>'disabled'),
@btn_CANCEL = TkButton.new(btn_frame, 'command'=>proc{win.cancel},
'default'=>'normal', 'text'=>'<27><><EFBFBD><EFBFBD>',
'state'=>'disabled'),
@btn_QUIT = TkButton.new(btn_frame, 'command'=>proc{win.quit},
'default'=>'normal', 'text'=>'<27><><EFBFBD><EFBFBD>')
]
buttons.each{|b| b.pack('side'=>'left', 'expand'=>'yes', 'pady'=>5) }
@root.bind('Return', proc{@btn_OK.flash; @btn_OK.invoke})
@root.bind('Escape', proc{@btn_QUIT.flash; @btn_QUIT.invoke})
@root.bind('1', proc{|w|
unless buttons.index(w)
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
}, '%W')
@root.bind('Key', proc{|w, k|
unless buttons.index(w)
case k
when 'Return', 'Escape', 'Tab', /.*Shift.*/
# do nothing
else
@btn_APPLY.state(:normal)
@btn_CANCEL.state(:normal)
end
end
}, '%W %K')
#
# Bell settings
#
bell = TkLabelframe.new(@root, 'text'=>'<27>٥<EFBFBD><D9A5><EFBFBD><EFBFBD><EFBFBD>',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_bellvol = TkScale.new(bell, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>"<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (%)")
f = TkFrame.new(bell)
@w_bellpit = LabelEntry.new(f, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (Hz)", 6, [25, 20000])
@w_bellpit.pack('side'=>'left', 'padx'=>5)
@w_belldur = LabelEntry.new(f, "<EFBFBD><EFBFBD>³<EFBFBD><EFBFBD><EFBFBD><EFBFBD> (ms)", 6, [1, 10000])
@w_belldur.pack('side'=>'right', 'padx'=>5)
@w_bellvol.pack('side'=>'top', 'expand'=>'yes')
f.pack('side'=>'top', 'expand'=>'yes')
#
# Keyboard settings
#
kbdonoff = nil
kbdcli = nil
kbd = TkLabelframe.new(@root, 'text'=>'<27><><EFBFBD><EFBFBD><EFBFBD>ܡ<EFBFBD><DCA1>ɥ<EFBFBD><C9A5>ԡ<EFBFBD><D4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(kbd)
@w_kbdonoff = TkCheckButton.new(f, 'text'=>'<27><><EFBFBD><EFBFBD><EFBFBD>å<EFBFBD><C3A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
'relief'=>'flat',
'onvalue'=>'on', 'offvalue'=>'off',
'variable'=>@w_kbdrep ) {
def self.set(value)
if value == 'on'
self.select
else
self.deselect
end
end
pack('side'=>'left', 'expand'=>'yes', 'fill'=>'x', 'padx'=>[0, '1m'])
}
@w_kbdcli = TkScale.new(f, 'from'=>0, 'to'=>100, 'length'=>200,
'tickinterval'=>20, 'orient'=>'horizontal',
'label'=>'<27><><EFBFBD><EFBFBD><EFBFBD>å<EFBFBD><C3A5><EFBFBD><EFBFBD><EFBFBD> (%)')
@w_kbdcli.pack('side'=>'left', 'expand'=>'yes',
'fill'=>'x', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes', 'pady'=>2, 'fill'=>'x')
#
# Mouse settings
#
mouse = TkLabelframe.new(@root, 'text'=>'<27>ޥ<EFBFBD><DEA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
'padx'=>'1.5m', 'pady'=>'1.5m')
f = TkFrame.new(mouse)
@w_mouseacc = LabelEntry.new(f, '<27><>®<EFBFBD><C2AE>', 5)
@w_mouseacc.pack('side'=>'left', 'padx'=>[0, '1m'])
@w_mousethr = LabelEntry.new(f, '<27><><EFBFBD><EFBFBD> (pixels)', 3, [1, 2000])
@w_mousethr.pack('side'=>'right', 'padx'=>['1m', 0])
f.pack('side'=>'top', 'expand'=>'yes')
#
# Screen Saver settings
#
screen = TkLabelframe.new(@root, 'text'=>'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󥻡<EFBFBD><F3A5BBA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>',
'padx'=>'1.5m', 'pady'=>'1.5m')
@w_screenblank = TkRadioButton.new(screen, 'text'=>'<27>֥<EFBFBD><D6A5><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'blank') {
def self.set(value)
if value == 'blank'
self.select
else
self.deselect
end
end
}
@w_screenpat = TkRadioButton.new(screen, 'text'=>'<27>ѥ<EFBFBD><D1A5><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><C9BD>',
'relief'=>'flat', 'anchor'=>'w',
'variable'=>@w_screenbla,
'value'=>'noblank') {
def self.set(value)
if value != 'blank'
self.select
else
self.deselect
end
end
}
@w_screentim = LabelEntry.new(screen, '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0A5A2><EFBFBD><EFBFBD> (s)', 5, [1, 100000])
@w_screencyc = LabelEntry.new(screen, '<27><><EFBFBD><EFBFBD> (s)', 5, [1, 100000])
Tk.grid(@w_screenblank, @w_screentim, 'sticky'=>'e')
Tk.grid(@w_screenpat, @w_screencyc, 'sticky'=>'e')
TkGrid.configure(@w_screenblank, @w_screenpat, 'sticky'=>'ew')
#
# Main window
#
param = {
'side'=>'top', 'fill'=>'both', 'expand'=>'yes',
'padx'=>'1m', 'pady'=>'1m'
}
btn_frame.pack('side'=>'top', 'fill'=>'both')
bell.pack(param)
kbd.pack(param)
mouse.pack(param)
screen.pack(param)
#
# Let the user resize our window
#
@root.minsize(10,10)
end
def initialize(title)
@root = TkRoot.new('title'=>title)
@kbdrep = 'on'
@w_kbdrep = TkVariable.new(@kbdrep)
def @w_kbdrep.get
self.value
end
def @w_kbdrep.set(val)
self.value=val
end
@kbdcli = 0
@bellvol = 100
@bellpit = 440
@belldur = 100
@mouseacc = "3/1"
@mousethr = 4
@screenbla = "blank"
@w_screenbla = TkVariable.new(@screenbla)
def @w_screenbla.get
self.value
end
def @w_screenbla.set(val)
self.value=val
end
@screentim = 600
@screencyc = 600
#
# Listen what "xset" tells us...
#
readsettings
#
# Create all windows
#
createwindows
#
# Write xset parameters
#
dispsettings
end
end
Xsettings.new(File.basename($0,'.rb'))
Tk.mainloop