mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8821 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									aeac7335ea
								
							
						
					
					
						commit
						c83264c3f9
					
				
					 4 changed files with 1082 additions and 0 deletions
				
			
		
							
								
								
									
										445
									
								
								ext/tk/MANUAL_tcltklib.eng
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										445
									
								
								ext/tk/MANUAL_tcltklib.eng
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,445 @@
 | 
			
		|||
(tof)
 | 
			
		||||
                                    2005/07/05  Hidetoshi NAGAI
 | 
			
		||||
 | 
			
		||||
This document discribes about the 'tcltklib' library. Although there
 | 
			
		||||
is the 'tcltk' library (tcltk.rb) under this directory, no description
 | 
			
		||||
in this document (because it is not maintained recently). 
 | 
			
		||||
 | 
			
		||||
==============================================================
 | 
			
		||||
module TclTklib
 | 
			
		||||
  : Defines methods to do operations which are independed on 
 | 
			
		||||
  : Tcl/Tk interpreters
 | 
			
		||||
 | 
			
		||||
  module TclTkLib::EventFlag
 | 
			
		||||
    : Defines flags to define taget events on 'do_one_event' methos. 
 | 
			
		||||
    : When to give, please use bit-operator (e.g. WINDOW | DONT_WAIT). 
 | 
			
		||||
 | 
			
		||||
    [constants]
 | 
			
		||||
       NONE
 | 
			
		||||
         : Is 0. It means "there is no target". But on the real
 | 
			
		||||
         : operation, it is same to ALL.
 | 
			
		||||
 | 
			
		||||
       WINDOW
 | 
			
		||||
         : 'window' event is processed.
 | 
			
		||||
 | 
			
		||||
       FILE
 | 
			
		||||
         : 'file' event is processed.
 | 
			
		||||
 | 
			
		||||
       TIMER
 | 
			
		||||
         : 'timer' event is processed.
 | 
			
		||||
 | 
			
		||||
       IDLE
 | 
			
		||||
         : 'idle' operation (e.g. 're-draw'; the operations when the
 | 
			
		||||
         : other kinds of events doesn't occur) is processed. 
 | 
			
		||||
 | 
			
		||||
       ALL
 | 
			
		||||
         : All kinds of events are processed. 
 | 
			
		||||
         : Same to 'WINDOW | FILE | TIMER | IDLE'. 
 | 
			
		||||
 | 
			
		||||
       DONT_WAIT
 | 
			
		||||
         : Without this flag, 'do_one_event' waits the occurence of 
 | 
			
		||||
         : a target event. With this flag, doesn't wait and returns 
 | 
			
		||||
         : false if there is no target event for processing. 
 | 
			
		||||
 | 
			
		||||
  module TclTkLib::VarAccessFlag
 | 
			
		||||
    : Defines flags to give '_get_variable' and so on. When to give, 
 | 
			
		||||
    : please use bit-operator (e.g. GLOBAL_ONLY | LEAVE_ERR_MSG ). 
 | 
			
		||||
 | 
			
		||||
    [constants]
 | 
			
		||||
       NONE
 | 
			
		||||
         : Is 0. It means "set no flag". 
 | 
			
		||||
 | 
			
		||||
       GLOBAL_ONLY
 | 
			
		||||
         : (site Tcl/Tk's man page)
 | 
			
		||||
         : Under normal circumstances the procedures look up 
 | 
			
		||||
         : variables as follows: If a procedure call is active 
 | 
			
		||||
         : in interp, a variable is looked up at the current
 | 
			
		||||
         : level of procedure call. Otherwise, a variable is
 | 
			
		||||
         : looked up first in the current namespace,  then  in
 | 
			
		||||
         : the global namespace. However, if this bit is set
 | 
			
		||||
         : in flags then the variable is looked up only in the
 | 
			
		||||
         : global namespace even if there is a procedure call
 | 
			
		||||
         : active. If both GLOBAL_ONLY and NAMESPACE_ONLY are
 | 
			
		||||
         : given, GLOBAL_ONLY is ignored.
 | 
			
		||||
         :
 | 
			
		||||
         :  *** ATTENTION ***
 | 
			
		||||
         : Tcl7.6 doesn't have namespaces. So NAMESPACE_ONLY 
 | 
			
		||||
         : is defined as 0, and then GLOBAL_ONLY is available
 | 
			
		||||
         : even if flag is (GLOBAL_ONLY | NAMESPACE_ONLY). 
 | 
			
		||||
 | 
			
		||||
       NAMESPACE_ONLY
 | 
			
		||||
         : (site Tcl/Tk's man page)
 | 
			
		||||
         : Under normal circumstances the procedures look up
 | 
			
		||||
         : variables as follows: If a procedure call is active
 | 
			
		||||
         : in interp, a variable is looked up at the current
 | 
			
		||||
         : level of procedure call. Otherwise, a variable is
 | 
			
		||||
         : looked up first in the current namespace, then in
 | 
			
		||||
         : the global namespace. However, if this bit is set
 | 
			
		||||
         : in flags then the variable is looked up only in the
 | 
			
		||||
         : current namespace even if there is a procedure call
 | 
			
		||||
         : active.
 | 
			
		||||
         :
 | 
			
		||||
         :  *** ATTENTION ***
 | 
			
		||||
         : Tcl7.6 doesn't have namespaces. So NAMESPACE_ONLY 
 | 
			
		||||
         : is defined as 0.
 | 
			
		||||
 | 
			
		||||
       LEAVE_ERR_MSG
 | 
			
		||||
         : (site Tcl/Tk's man page)
 | 
			
		||||
         : If an error is returned and this bit is set in flags, 
 | 
			
		||||
         : then an error message will be left in the interpreter's
 | 
			
		||||
         : result, where it can be retrieved with Tcl_GetObjResult
 | 
			
		||||
         : or Tcl_GetStringResult. If this flag bit isn't set then 
 | 
			
		||||
         : no error message is left and the interpreter's result 
 | 
			
		||||
         : will not be modified.
 | 
			
		||||
 | 
			
		||||
       APPEND_VALUE
 | 
			
		||||
         : (site Tcl/Tk's man page)
 | 
			
		||||
         : If this bit is set then newValue is appended to the
 | 
			
		||||
         : current value, instead of replacing it. If the variable
 | 
			
		||||
         : is currently undefined, then this bit is ignored.
 | 
			
		||||
 | 
			
		||||
       LIST_ELEMENT
 | 
			
		||||
         : (site Tcl/Tk's man page)
 | 
			
		||||
         : If this bit is set, then newValue is converted to a
 | 
			
		||||
         : valid Tcl list element before setting (or appending
 | 
			
		||||
         : to) the variable. A separator space is appended before
 | 
			
		||||
         : the new list element unless the list element is going
 | 
			
		||||
         : to be the first element in a list or sublist (i.e. the 
 | 
			
		||||
         : variable's current value is empty, or contains the 
 | 
			
		||||
         : single character ``{'', or ends  in `` }'').
 | 
			
		||||
 | 
			
		||||
       PARSE_VARNAME
 | 
			
		||||
         : (site Tcl/Tk's man page)
 | 
			
		||||
         : If this bit is set when calling _set_variable and so 
 | 
			
		||||
         : on, var_name argument may contain both an array and an
 | 
			
		||||
         : element name: if the name contains an open parenthesis 
 | 
			
		||||
         : and ends with a close parenthesis, then the value 
 | 
			
		||||
         : between the parentheses is treated as an element name 
 | 
			
		||||
         : (which can have any string value) and the characters
 | 
			
		||||
         : before  the first open parenthesis are treated as the 
 | 
			
		||||
         : name of an array variable. If the flag PARSE_VARNAME
 | 
			
		||||
         : is given, index_name argument should be 'nil' since the 
 | 
			
		||||
         : array and element names are taken from var_name.
 | 
			
		||||
         :
 | 
			
		||||
         :  *** ATTENTION ***
 | 
			
		||||
         : Tcl7.6 doesn't have this flag. So PARSE_VARNAME is 
 | 
			
		||||
         : defined as 0. 
 | 
			
		||||
 | 
			
		||||
  [module methods]
 | 
			
		||||
     mainloop(check_root = true)
 | 
			
		||||
       : Starts the eventloop. If 'check_root' is true, this method 
 | 
			
		||||
       : doesn't return when a root widget exists. 
 | 
			
		||||
       : If 'check_root' is false, doen't return by the other
 | 
			
		||||
       : reasons than exceptions.
 | 
			
		||||
 | 
			
		||||
    mainloop_thread?
 | 
			
		||||
       : Returns whether the current thread executes the eventloop. 
 | 
			
		||||
       : If true, the eventloop is working on the current thread. 
 | 
			
		||||
       : If no eventloop is working, this method returns nil.
 | 
			
		||||
       : And if the other thread executes the eventloop, returns false.
 | 
			
		||||
       : 
 | 
			
		||||
       :  *** ATTENTION ***
 | 
			
		||||
       : When this methods returns false, it is dangerous to call a Tk 
 | 
			
		||||
       : interpreter directly.
 | 
			
		||||
 | 
			
		||||
    mainloop_watchdog(check_root = true)
 | 
			
		||||
       : On the normal eventloop, some kinds of callback operations 
 | 
			
		||||
       : cause deadlock. To avoid some of such deadlocks, this
 | 
			
		||||
       : method starts an eventloop and a watchdog-thread.
 | 
			
		||||
 | 
			
		||||
    do_one_event(flag = TclTkLib::EventFlag::ALL | 
 | 
			
		||||
                          TclTkLib::EventFlag::DONT_WAIT)
 | 
			
		||||
       : Do one event for processing. When processed an event, 
 | 
			
		||||
       : returns true. 
 | 
			
		||||
       : If NOT set DONT_WAIT flag, this method waits occurrence of
 | 
			
		||||
       : a target event. 
 | 
			
		||||
       : If set DONT_WAIT flag and no event for processing, returns 
 | 
			
		||||
       : false immediately. 
 | 
			
		||||
       : If $SAFE >= 4,  or $SAFE >= 1 and the flag is tainted, 
 | 
			
		||||
       : force to set DONT_WAIT flag.
 | 
			
		||||
 | 
			
		||||
    set_eventloop_tick(timer_tick)
 | 
			
		||||
       : Define the interval of thread-switching with an integer
 | 
			
		||||
       : value of mili-seconds. 
 | 
			
		||||
       : Default timer_tick is 0. It means that thread-switching 
 | 
			
		||||
       : is based on the count of processed events. 
 | 
			
		||||
       : ( see 'set_eventloop_weight' method )
 | 
			
		||||
       : However, if the eventloop thread is the only thread, 
 | 
			
		||||
       : timer_tick cannt be set to 0. If 0, then is set to 100 ms 
 | 
			
		||||
       : automatically (see NO_THREAD_INTERRUPT_TIME on tcltklib.c). 
 | 
			
		||||
       : On $SAFE >= 4, cannot call this method. 
 | 
			
		||||
 | 
			
		||||
    get_eventloop_tick
 | 
			
		||||
       : Get current value of 'timer_tick'
 | 
			
		||||
 | 
			
		||||
    set_no_event_wait(no_event_wait)
 | 
			
		||||
       : Define sleeping time of the eventloop when two or more 
 | 
			
		||||
       : thread are running and there is no event for processing. 
 | 
			
		||||
       : Default value is 20 (ms).
 | 
			
		||||
       : If the eventloop thread is the only thread, this value is 
 | 
			
		||||
       : invalid. 
 | 
			
		||||
       : On $SAFE >= 4, cannot call this method. 
 | 
			
		||||
 | 
			
		||||
    get_no_event_wait
 | 
			
		||||
       : Get current value of 'no_event_wait'.
 | 
			
		||||
 | 
			
		||||
    set_eventloop_weight(loop_max, no_event_tick)
 | 
			
		||||
       : Define the weight parameters for the eventloop thread. 
 | 
			
		||||
       : That is invalid when the eventloop is the only thread. 
 | 
			
		||||
       : 'loop_max' is the max events for thread-switching. 
 | 
			
		||||
       : 'no_event_tick' is the increment value of the event count 
 | 
			
		||||
       : when no event for processing (And then, the eventloop thead
 | 
			
		||||
       : sleeps 'no_event_wait' mili-seconds). 
 | 
			
		||||
       : 'loop_max == 800' and 'no_event_tick == 10' are defalut. 
 | 
			
		||||
       : On $SAFE >= 4, cannot call this method. 
 | 
			
		||||
 | 
			
		||||
    get_eventloop_weight
 | 
			
		||||
       : Get current values of 'loop_max' and 'no_event_tick'.
 | 
			
		||||
 | 
			
		||||
    mainloop_abort_on_exception=(bool)
 | 
			
		||||
       : Define whether the eventloop stops on exception or not. 
 | 
			
		||||
       : If true (default value), stops on exception. 
 | 
			
		||||
       : If false, show a warinig message but ignore the exception.
 | 
			
		||||
       : If nil, no warning message and ignore the excepsion. 
 | 
			
		||||
       : This parameter is sometimes useful when multiple Tk
 | 
			
		||||
       : interpreters are working. Because the only one eventloop 
 | 
			
		||||
       : admins all Tk interpreters, sometimes exception on a
 | 
			
		||||
       : interpreter kills the eventloop thread. Even if such
 | 
			
		||||
       : situation, when abort_on_exception == false or nil, 
 | 
			
		||||
       : the eventloop ignores the exception and continue to working. 
 | 
			
		||||
       : On $SAFE >= 4, cannot call this method. 
 | 
			
		||||
 | 
			
		||||
    mainloop_abort_on_exception
 | 
			
		||||
       : Get current status of that. 
 | 
			
		||||
 | 
			
		||||
    num_of_mainwindows
 | 
			
		||||
       : Returns the number of main-windows (root-widget). 
 | 
			
		||||
       : Because there is only one main-window for one Tk interpreter, 
 | 
			
		||||
       : the value is same to the number of interpreters which has 
 | 
			
		||||
       : available Tk functions.
 | 
			
		||||
 | 
			
		||||
    _merge_tklist(str, str, ... )
 | 
			
		||||
       : Get a Tcl's list string from arguments with a Tcl/Tk's 
 | 
			
		||||
       : library function. Each arguemnt is converted to a valid 
 | 
			
		||||
       : Tcl list element. 
 | 
			
		||||
 | 
			
		||||
    _conv_listelement(str)
 | 
			
		||||
       : Convert the argument to a valid Tcl list element with
 | 
			
		||||
       : Tcl/Tk's library function.
 | 
			
		||||
 | 
			
		||||
    _toUTF8(str, encoding=nil)
 | 
			
		||||
    _fromUTF8(str, encoding=nil)
 | 
			
		||||
       : Call the function (which is internal function of Tcl/Tk) to
 | 
			
		||||
       : convert to/from a UTF8 string.
 | 
			
		||||
 | 
			
		||||
    _subst_UTF_backslash(str)
 | 
			
		||||
    _subst_Tcl_backslash(str)
 | 
			
		||||
       : Substitute backslash sequence with Tcl's rule (include \uhhhh;
 | 
			
		||||
       : give a sixteen-bit hexadecimal value for Unicode character).
 | 
			
		||||
       : _subst_Tcl_backslash method parses all backslash sequence. 
 | 
			
		||||
       : _subst_UTF_backslash method parses \uhhhh only.
 | 
			
		||||
 | 
			
		||||
    encoding_system
 | 
			
		||||
    encoding_system=(encoding)
 | 
			
		||||
       : Get and set Tcl's system encoding.
 | 
			
		||||
 | 
			
		||||
    encoding
 | 
			
		||||
    encoding=(encoding)
 | 
			
		||||
       : alias of encoding_system / encoding_system=
 | 
			
		||||
       : ( probably, Ruby/Tk's tk.rb will override them )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TclTkIp
 | 
			
		||||
  [class methods]
 | 
			
		||||
    new(ip_name=nil, options='')
 | 
			
		||||
       : Generate an instance of TclTkIp class. 
 | 
			
		||||
       : If 'ip_name' argument is given as a string, it is the name
 | 
			
		||||
       : of the Tk interpreter which is shown by 'winfo interps'
 | 
			
		||||
       : command. 
 | 
			
		||||
       : 'options' argument accepts a string which is the command 
 | 
			
		||||
       : line options of wish; such as '-geometry' or '-use'. 
 | 
			
		||||
       : The information is used to generate the root widget of the 
 | 
			
		||||
       : interpreter. 
 | 
			
		||||
       : ( e.g. TclTkIp.new('FOO', '-geometry 500x200 -use 0x2200009') )
 | 
			
		||||
       : If is given nil or falsr for the 'option' argument, generates
 | 
			
		||||
       : the Tcl interpreter without Tk library. Then the interpreter 
 | 
			
		||||
       : doesn't need GUI environment. Therefore, even if a window
 | 
			
		||||
       : system doesn't exist or cannot be used, Ruby can control the
 | 
			
		||||
       : Tcl interpreter and the extention libraries loaded on the 
 | 
			
		||||
       : interpreter. 
 | 
			
		||||
 | 
			
		||||
  [instance methods]
 | 
			
		||||
    create_slave(name, safe=false)
 | 
			
		||||
       : Create a slave interpreter. 
 | 
			
		||||
       : The parent of the interpreter is the receiver of this method.
 | 
			
		||||
       : The name of the slave interpreter is given by 'name' argument. 
 | 
			
		||||
       : The 'safe' argument decides whether the slave interpreter is
 | 
			
		||||
       : created as a safe interpreter or not. If true, create a safe
 | 
			
		||||
       : interpreter. Default is false. However, if the parent
 | 
			
		||||
       : interpreter is a safe interpreter, the created interpreter is
 | 
			
		||||
       : a safe interpreter (ignore 'safe' argument value). 
 | 
			
		||||
       : If $SAFE >= 4, can create a safe interpreter only. 
 | 
			
		||||
 | 
			
		||||
    make_safe
 | 
			
		||||
       : Make the interpreter to the safe interpreter, and returns
 | 
			
		||||
       : self. If fail, raise RuntimeError.
 | 
			
		||||
 | 
			
		||||
    safe?
 | 
			
		||||
       : Check whether the interpreter is the safe interpreter. 
 | 
			
		||||
       : If is the safe interpreter, returns true. 
 | 
			
		||||
 | 
			
		||||
    allow_ruby_exit?
 | 
			
		||||
       : Return the mode whether 'exit' function of ruby or 'exit' 
 | 
			
		||||
       : command of Tcl/Tk can quit the ruby process or not on the 
 | 
			
		||||
       : interpreter. If false, such a command quit the interpreter 
 | 
			
		||||
       : only.
 | 
			
		||||
       : The default value for a master interpreter is true, and 
 | 
			
		||||
       : for a slave interpreter is false.
 | 
			
		||||
 | 
			
		||||
    allow_ruby_exit=(mode)
 | 
			
		||||
       : Change the mode of 'allow_ruby_exit?'.
 | 
			
		||||
       : If $SAFE >= 4 or the interpreter is a "safe" interpreter, 
 | 
			
		||||
       : this is not permitted (raise an exception). 
 | 
			
		||||
 | 
			
		||||
    delete
 | 
			
		||||
       : Delete the interpreter. 
 | 
			
		||||
       : The deleted interpreter doesn't accept command and then
 | 
			
		||||
       : raise an exception.
 | 
			
		||||
 | 
			
		||||
    deleted?
 | 
			
		||||
       : Check whether the interpreter is already deleted.
 | 
			
		||||
       : If deleted, returns true. 
 | 
			
		||||
 | 
			
		||||
    has_mainwindow?
 | 
			
		||||
       : Check whether the interpreter has a MainWindow (root widget).
 | 
			
		||||
       : If has, returns true. If doesn't, returns false.  
 | 
			
		||||
       : If IP is already deleted, returns nil. 
 | 
			
		||||
 | 
			
		||||
    restart
 | 
			
		||||
       : Restart Tk part of the interpreter. 
 | 
			
		||||
       : Use this when you need Tk functions after destroying the
 | 
			
		||||
       : root widget. 
 | 
			
		||||
       : On $SAFE >= 4, cannot call this method. 
 | 
			
		||||
 | 
			
		||||
    _eval(str)
 | 
			
		||||
    _invoke(*args)
 | 
			
		||||
       : Estimates the arguments as a command on the Tk interpreter. 
 | 
			
		||||
       : The argument of _eval is a script of Tcl/Tk.
 | 
			
		||||
       : Each argument of _invoke is a token of one command line of
 | 
			
		||||
       : Tcl/Tk. 
 | 
			
		||||
       : Because the operation of _invoke doesn't through the
 | 
			
		||||
       : command line parser of Tk interpreter, the cost of
 | 
			
		||||
       : estimation is smaller than _eval. However, auto_load
 | 
			
		||||
       : mechanism of the Tk interpreter doesn't work on _invoke. 
 | 
			
		||||
       : So _invoke can call only the command which already
 | 
			
		||||
       : registered on the interpreter by 'load' command and so on. 
 | 
			
		||||
       : On _eval command, auto_load mechanism words. So if succeed 
 | 
			
		||||
       : to _eval and regist the command once, after that, the
 | 
			
		||||
       : command can be called by _invoke. 
 | 
			
		||||
 | 
			
		||||
    _toUTF8(str, encoding=nil)
 | 
			
		||||
    _fromUTF8(str, encoding=nil)
 | 
			
		||||
       : Call the function (which is internal function of Tcl/Tk) to
 | 
			
		||||
       : convert to/from a UTF8 string.
 | 
			
		||||
 | 
			
		||||
    _thread_vwait(var_name)
 | 
			
		||||
    _thread_tkwait(mode, target)
 | 
			
		||||
       : 'vwait' or 'tkwait' with thread support. 
 | 
			
		||||
       : The difference from normal 'vwait' or 'tkwait' command is 
 | 
			
		||||
       : doing independent wait from the vwait stack when they are
 | 
			
		||||
       : called on the other thread than the eventloop thread.
 | 
			
		||||
       : In the case of Tcl/Tk's vwait / tkwait, if 2nd vwait /
 | 
			
		||||
       : tkwait is called on waiting for 1st vwait / tkwait, 
 | 
			
		||||
       : returns the order of [2nd]->[1st] regardless of the order
 | 
			
		||||
       : of when the wait condition was fulfilled.  
 | 
			
		||||
       : If _thread_vwait / _thread_tkwait is called on the
 | 
			
		||||
       : eventloop thread, there is no difference from vwait /
 | 
			
		||||
       : tkwait. But if called on the other thread than the
 | 
			
		||||
       : eventloop, stops the thread.  And when the wait condition 
 | 
			
		||||
       : is fulfilled, the thread restarts. The meaning of
 | 
			
		||||
       : "independent from the vwait stack" is that the timing of 
 | 
			
		||||
       : restarting is independent from the waiting status of the 
 | 
			
		||||
       : other threads. That is, even if the eventloop thread is 
 | 
			
		||||
       : waiting by vwait and is not fulfilled the condition, 
 | 
			
		||||
       : _thread_vwait completes the waiting when its waiting
 | 
			
		||||
       : condition is fulfilled and the thread which stopped by
 | 
			
		||||
       : _thread_vwait can continue the operation. 
 | 
			
		||||
 | 
			
		||||
    _return_value
 | 
			
		||||
       : Get the last result value on the interpreter. 
 | 
			
		||||
 | 
			
		||||
    _get_variable(var_name, flag)
 | 
			
		||||
    _get_variable2(var_name, index_name, flag)
 | 
			
		||||
       : Get the current value of a variable. If specified a 
 | 
			
		||||
       : index_name (see also the PARSE_VARNAME flag), get the 
 | 
			
		||||
       : value of the index_name element. 
 | 
			
		||||
 | 
			
		||||
    _set_variable(var_name, value, flag)
 | 
			
		||||
    _set_variable2(var_name, index_name, value, flag)
 | 
			
		||||
       : Create or modify a variable. If specified a index_name 
 | 
			
		||||
       : (see also the PARSE_VARNAME flag), create or modify the 
 | 
			
		||||
       : index_name element. 
 | 
			
		||||
 | 
			
		||||
    _unset_variable(var_name)
 | 
			
		||||
    _unset_variable2(var_name, index_name)
 | 
			
		||||
       : Remove a variable. If specified a index_name (see also 
 | 
			
		||||
       : the PARSE_VARNAME flag), remove the index_name element. 
 | 
			
		||||
 | 
			
		||||
    _get_global_var(var_name)
 | 
			
		||||
    _get_global_var2(var_name, index_name)
 | 
			
		||||
    _set_global_var(var_name, value)
 | 
			
		||||
    _set_global_var2(var_name, index_name, value)
 | 
			
		||||
    _unset_global_var(var_name)
 | 
			
		||||
    _unset_global_var2(var_name, index_name)
 | 
			
		||||
       : Call the associated method with the flag argument
 | 
			
		||||
       : (GLOBAL_ONLY | LEAVE_ERR_MSG).
 | 
			
		||||
 | 
			
		||||
    _split_tklist(str)
 | 
			
		||||
       : Split the argument with Tcl/Tk's library function and 
 | 
			
		||||
       : get an array as a list of Tcl list elements.
 | 
			
		||||
 | 
			
		||||
    _merge_tklist(str, str, ... )
 | 
			
		||||
       : Get a Tcl's list string from arguments with a Tcl/Tk's 
 | 
			
		||||
       : library function. Each arguemnt is converted to a valid 
 | 
			
		||||
       : Tcl list element. 
 | 
			
		||||
 | 
			
		||||
    _conv_listelement(str)
 | 
			
		||||
       : Convert the argument to a valid Tcl list element with
 | 
			
		||||
       : Tcl/Tk's library function.
 | 
			
		||||
 | 
			
		||||
    mainloop
 | 
			
		||||
    mainloop_watchdog
 | 
			
		||||
       : If on the slave interpreter, never start an eventloop and
 | 
			
		||||
       : returns nil. 
 | 
			
		||||
       : With the exception that, same to the TclTkLib module method
 | 
			
		||||
       : with the same name. 
 | 
			
		||||
 | 
			
		||||
    do_one_event
 | 
			
		||||
       : With the exception that the argument is forced to set
 | 
			
		||||
       : DONT_WAIT flag on the slave interpreter, same to
 | 
			
		||||
       : TclTkLib#do_one_event. 
 | 
			
		||||
 | 
			
		||||
    set_eventloop_tick
 | 
			
		||||
    get_eventloop_tick
 | 
			
		||||
    set_no_event_wait
 | 
			
		||||
    get_no_event_wait
 | 
			
		||||
    set_eventloop_weight
 | 
			
		||||
    get_eventloop_weight
 | 
			
		||||
    mainloop_abort_on_exception
 | 
			
		||||
    mainloop_abort_on_exception=
 | 
			
		||||
       : With the exception that it is ignored to set value on the
 | 
			
		||||
       : slave interpreter, same to the TclTkLib module method with
 | 
			
		||||
       : the same name. 
 | 
			
		||||
 | 
			
		||||
class TkCallbackBreak < StandardError
 | 
			
		||||
class TkCallbackContinue < StandardError
 | 
			
		||||
  : They are exception classes to break or continue the Tk callback 
 | 
			
		||||
  : operation. 
 | 
			
		||||
  : If raise TkCallbackBreak on the callback procedure, Ruby returns 
 | 
			
		||||
  : 'break' code to Tk interpreter (Then the Tk interpreter will 
 | 
			
		||||
  : break the operation for the current event). 
 | 
			
		||||
  : If raise TkCallbackContinue, returns 'continue' code (Then the Tk
 | 
			
		||||
  : interpreter will break the operateion for the current bindtag and 
 | 
			
		||||
  : starts the operation for the next buindtag for the current event).
 | 
			
		||||
 | 
			
		||||
(eof)
 | 
			
		||||
							
								
								
									
										557
									
								
								ext/tk/MANUAL_tcltklib.eucj
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										557
									
								
								ext/tk/MANUAL_tcltklib.eucj
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,557 @@
 | 
			
		|||
(tof)
 | 
			
		||||
                                    2005/07/05  Hidetoshi NAGAI
 | 
			
		||||
 | 
			
		||||
本ドキュメントには古い tcltk ライブラリ,tcltklib ライブラリの説明
 | 
			
		||||
が含まれていますが,その記述内容は古いものとなっています.
 | 
			
		||||
 | 
			
		||||
tcltk ライブラリ(tcltk.rb)は現在ではメンテナンスが事実上行われて
 | 
			
		||||
いないため,古いドキュメントの説明がそのまま有効です.それに対し,
 | 
			
		||||
tcltklib ライブラリについては,現在の Ruby/Tk(tk.rb 以下のライブラ
 | 
			
		||||
リ群)を稼働させるための中心としてメンテナンスされているため,少々
 | 
			
		||||
違いが生じています.
 | 
			
		||||
 | 
			
		||||
そこで,まず古い説明文書を示した後,現在の tcltklib ライブラリにつ
 | 
			
		||||
いての説明を加えます.
 | 
			
		||||
 | 
			
		||||
以下がライブラリの古い説明文書です.
 | 
			
		||||
==============================================================
 | 
			
		||||
	MANUAL.euc
 | 
			
		||||
		Sep. 19, 1997	Y. Shigehiro
 | 
			
		||||
 | 
			
		||||
以下, 「tcl/tk」という表記は, tclsh や wish を実現している, 一般でいう
 | 
			
		||||
ところの tcl/tk を指します. 「tcltk ライブラリ」, 「tcltklib ライブラ
 | 
			
		||||
リ」という表記は, 本パッケージに含まれる ruby 用のライブラリを指します.
 | 
			
		||||
 | 
			
		||||
<< tcltk ライブラリ >>
 | 
			
		||||
 | 
			
		||||
tcl/tk の C ライブラリを利用するための高(中?)水準インターフェースを提
 | 
			
		||||
供します.
 | 
			
		||||
 | 
			
		||||
このライブラリは ruby から tcl/tk ライブラリを利用するためのもので, 内
 | 
			
		||||
部で tcltklib ライブラリを利用しています.
 | 
			
		||||
 | 
			
		||||
[説明]
 | 
			
		||||
 | 
			
		||||
tcl/tk インタプリタでは, ウィジェットに何か指示を送るには, ウィジェッ
 | 
			
		||||
ト名に続いてパラメータを書きます. したがって, ウィジェットがオブジェク
 | 
			
		||||
トであり, それに対してメソッドを送っている, とみなすことができます. さ
 | 
			
		||||
て, tcl/tk インタプリタでは, 組み込みコマンドも, 前述のウィジェットと
 | 
			
		||||
同じような書式の命令で実行されます. すなわち, コマンドもオブジェクトで
 | 
			
		||||
あると考えることができます.
 | 
			
		||||
 | 
			
		||||
このような考えに基づき, tcltk ライブラリでは, tcl/tk のコマンドやウィ
 | 
			
		||||
ジェットに対応するオブジェクトを生成します. オブジェクトに対するメソッ
 | 
			
		||||
ド呼び出しは, e() メソッドにより実行されます. 例えば, tcl/tk の info 
 | 
			
		||||
コマンドに対応する ruby のオブジェクトが info という名前であるとすると,
 | 
			
		||||
tcl/tk の
 | 
			
		||||
	info commands
 | 
			
		||||
という命令は tcltk ライブラリでは
 | 
			
		||||
	info.e("commands")
 | 
			
		||||
と記述されます. また, 「.」というウィジェット (wish 実行時に自動的に生
 | 
			
		||||
成されるルートウィジェット) に対応する ruby のオブジェクトが root とい
 | 
			
		||||
う名前であるとすると,
 | 
			
		||||
	. configure -height 300 -width 300
 | 
			
		||||
という tcl/tk の命令は
 | 
			
		||||
	root.e("configure -height 300 -width 300")
 | 
			
		||||
と記述されます. このような記述は, 見ためには美しくありませんが, そして, 
 | 
			
		||||
スクリプトを読む人には見づらいかも知れませんが, 実際にスクリプトを書い
 | 
			
		||||
てみると予想外に手軽です.
 | 
			
		||||
 | 
			
		||||
[使用法]
 | 
			
		||||
 | 
			
		||||
1. ライブラリを読み込む.
 | 
			
		||||
     require "tcltk"
 | 
			
		||||
 | 
			
		||||
2. tcl/tk インタプリタを生成する.
 | 
			
		||||
     ip = TclTkInterpreter.new()
 | 
			
		||||
 | 
			
		||||
3. tcl/tk のコマンドに対応するオブジェクトを変数に代入しておく.
 | 
			
		||||
     # コマンドに対応するオブジェクトが入った Hash を取り出す.
 | 
			
		||||
     c = ip.commands()
 | 
			
		||||
     # 使いたいコマンドに対応するオブジェクトを個別の変数に代入する.
 | 
			
		||||
     bind, button, info, wm = c.indexes("bind", "button", "info", "wm")
 | 
			
		||||
 | 
			
		||||
4. 必要な処理を行う.
 | 
			
		||||
     詳しくは, サンプルを参照のこと.
 | 
			
		||||
 | 
			
		||||
5. 準備ができたら, イベントループに入る.
 | 
			
		||||
     TclTk.mainloop()
 | 
			
		||||
 | 
			
		||||
(( 以下, モジュール, クラス等の説明を書く予定.))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<< tcltklib ライブラリ >>
 | 
			
		||||
 | 
			
		||||
tcl/tk の C ライブラリを利用するための低水準インターフェースを提供しま
 | 
			
		||||
す.
 | 
			
		||||
 | 
			
		||||
コンパイル/実行には, tcl/tk の C ライブラリが必要です.
 | 
			
		||||
 | 
			
		||||
[説明]
 | 
			
		||||
 | 
			
		||||
このライブラリを用いると, ruby から tcl/tk の C ライブラリを利用できま
 | 
			
		||||
す. 具体的には, ruby インタプリタから tcl/tk インタプリタを呼び出すこ
 | 
			
		||||
とができます. さらに, その(ruby インタプリタから呼び出した) tcl/tk イ
 | 
			
		||||
ンタプリタから, 逆に ruby インタプリタを呼び出すこともできます.
 | 
			
		||||
 | 
			
		||||
[使用法]
 | 
			
		||||
 | 
			
		||||
require "tcltklib" すると, 以下のモジュール, クラスが利用可能です.
 | 
			
		||||
 | 
			
		||||
モジュール TclTkLib
 | 
			
		||||
    tcl/tk ライブラリを呼び出すメソッドを集めたモジュールです. ただし,
 | 
			
		||||
    tcl/tk インタプリタ関係のメソッドはクラス TclTkIp にあります.
 | 
			
		||||
 | 
			
		||||
  モジュールメソッド mainloop()
 | 
			
		||||
      Tk_MainLoop を実行します. 全ての tk のウインドウが無くなると終了
 | 
			
		||||
      します(例えば, tcl/tk で書くところの "destroy ." をした場合等).
 | 
			
		||||
    引数: 無し
 | 
			
		||||
    戻り値: nil
 | 
			
		||||
 | 
			
		||||
クラス TclTkIp
 | 
			
		||||
    インスタンスが tcl/tk のインタプリタに対応します. tcl/tk のライブ
 | 
			
		||||
    ラリの仕様通り, インスタンスを複数個生成しても正しく動作します(そ
 | 
			
		||||
    んなことをする必要はあまり無いはずですが). インタプリタは wish の
 | 
			
		||||
    tcl/tk コマンドを実行できます. さらに, 以下のコマンドを実行できま
 | 
			
		||||
    す.
 | 
			
		||||
      コマンド ruby
 | 
			
		||||
	引数を ruby で実行します(ruby_eval_string を実行します). 引数
 | 
			
		||||
	は 1 つでなければなりません. 戻り値は ruby の実行結果です.
 | 
			
		||||
	ruby の実行結果は nil か String でなければなりません.
 | 
			
		||||
 | 
			
		||||
  クラスメソッド new()
 | 
			
		||||
      TclTkIp クラスのインスタンスを生成します
 | 
			
		||||
    引数: 無し
 | 
			
		||||
    戻り値 (TclTkIp): 生成されたインスタンス
 | 
			
		||||
 | 
			
		||||
  メソッド _eval(script)
 | 
			
		||||
      インタプリタで script を評価します(Tcl_Eval を実行します). 前述
 | 
			
		||||
      のように, ruby コマンドにより script 内から ruby スクリプトを実
 | 
			
		||||
      行できます.
 | 
			
		||||
    引数: script (String) - インタプリタで評価するスクリプト文字列
 | 
			
		||||
    戻り値 (String): 評価結果 ((Tcl_Interp *)->result)
 | 
			
		||||
 | 
			
		||||
  メソッド _return_value()
 | 
			
		||||
      直前の Tcl_Eval の戻り値を返します. 0(TCL_OK) で正常終了です.
 | 
			
		||||
    引数: 無し
 | 
			
		||||
    戻り値 (Fixnum): 直前の Tcl_Eval() が返した値.
 | 
			
		||||
 | 
			
		||||
==============================================================
 | 
			
		||||
 | 
			
		||||
以下が本ドキュメント作成時点での tcltklib ライブラリの説明です.
 | 
			
		||||
==============================================================
 | 
			
		||||
モジュール TclTkLib
 | 
			
		||||
   : 個々の Tcl/Tk インタープリタに依存しない処理 ( == イベントルー
 | 
			
		||||
   : プに関する処理 ) を呼び出すメソッドを定義したモジュール.
 | 
			
		||||
 | 
			
		||||
   モジュール TclTkLib::EventFlag
 | 
			
		||||
      : do_one_event を呼び出す際の処理対象イベントを指定するための
 | 
			
		||||
      : フラグ ( WINDOW|DONT_WAIT というようにビット演算子で連結して
 | 
			
		||||
      : 指定 ) を定数として定義したモジュール.以下の定数が含まれる.
 | 
			
		||||
 | 
			
		||||
      定数  NONE
 | 
			
		||||
         : 値は 0 で,値としてはいかなる種類のイベントも指定していない
 | 
			
		||||
         : ことになるが,実際の処理上は ALL と同じとして扱われる.
 | 
			
		||||
 | 
			
		||||
      定数  WINDOW
 | 
			
		||||
         : window イベントを処理対象とする
 | 
			
		||||
 | 
			
		||||
      定数  FILE
 | 
			
		||||
         : file イベントを処理対象とする
 | 
			
		||||
 | 
			
		||||
      定数  TIMER
 | 
			
		||||
         : timer イベントを処理対象とする
 | 
			
		||||
 | 
			
		||||
      定数  IDLE
 | 
			
		||||
         : アイドルループ処理 ( 再描画など,他の種類のイベントが発生
 | 
			
		||||
         : していないときに行われる処理 ) を処理対象とする
 | 
			
		||||
 | 
			
		||||
      定数  ALL
 | 
			
		||||
         : すべての種類のイベントを処理対象とする
 | 
			
		||||
         : WINDOW|FILE|TIMER|IDLE と同じ
 | 
			
		||||
 | 
			
		||||
      定数  DONT_WAIT
 | 
			
		||||
         : 処理対象イベントが存在しない場合に,イベント発生を待たず
 | 
			
		||||
         : に do_one_event を終了 ( false を返す ) する 
 | 
			
		||||
 | 
			
		||||
   モジュール TclTkLib::VarAccessFlag
 | 
			
		||||
      : _get_variable などでのフラグを指定するためのもの.フラグに
 | 
			
		||||
      : は以下の定数を OR で連結して与える.
 | 
			
		||||
 | 
			
		||||
      定数  NONE
 | 
			
		||||
         : 値は 0 で,何もフラグを指定していないのに等しい.
 | 
			
		||||
 | 
			
		||||
      定数  GLOBAL_ONLY
 | 
			
		||||
         : 通常,変数の検索はまず手続き呼び出しを行ったレベルで検
 | 
			
		||||
         : 索し,次に現在の名前空間で検索,最後にグローバル空間で
 | 
			
		||||
         : 検索を行う.しかし,このフラグが指定された場合には,グ
 | 
			
		||||
         : ローバル空間でのみ検索する.
 | 
			
		||||
         : もし GLOBAL_ONLY と NAMESPACE_ONLY とが両方指定された場
 | 
			
		||||
         : 合には,GLOBAL_ONLY の指定は無視される.
 | 
			
		||||
 | 
			
		||||
      定数  NAMESPACE_ONLY
 | 
			
		||||
         : このフラグが指定された場合には,現在の名前空間でのみ変
 | 
			
		||||
         : 数の検索を行う.GLOBAL_ONLY の説明も参照すること.
 | 
			
		||||
 | 
			
		||||
      定数  LEAVE_ERR_MSG
 | 
			
		||||
         : 変数アクセスにおいてエラーが発生した場合,このフラグが
 | 
			
		||||
         : 指定されていれば,実行結果として Tcl インタープリタにエ
 | 
			
		||||
         : ラーメッセージが残される.このフラグが指定されていなけ
 | 
			
		||||
         : れば,エラーメッセージは一切残されない.
 | 
			
		||||
 | 
			
		||||
      定数  APPEND_VALUE
 | 
			
		||||
         : このフラグが指定されていた場合,変数の値を置き換えので
 | 
			
		||||
         : はなく,現在の値に代入値が追加 (append; 文字列連結) さ
 | 
			
		||||
         : れる.変数が未定義あった場合,このフラグは無視される.
 | 
			
		||||
 | 
			
		||||
      定数  LIST_ELEMENT
 | 
			
		||||
         : このフラグが指定されていた場合,代入値はまず Tcl のリス
 | 
			
		||||
         : ト要素として適切となるように変換される.代入値がリスト
 | 
			
		||||
         : (またはサブリスト) の最初の要素となるのでない限り,代入
 | 
			
		||||
         : 値の直前には空白文字が追加される.
 | 
			
		||||
 | 
			
		||||
      定数  PARSE_VARNAME
 | 
			
		||||
         : _set_variable などの呼び出しにおいてこのフラグが指定さ
 | 
			
		||||
         : れていた場合,var_name 引数が連想配列名と要素名とを両方
 | 
			
		||||
         : 含む可能性がある (開き括弧を含み,閉じ括弧で終わる) こ
 | 
			
		||||
         : とを示す.その場合,括弧の間が要素名指定,最初の開き括
 | 
			
		||||
         : 弧までが連想配列名として扱われる._set_variable2 などで
 | 
			
		||||
         : このフラグを指定する場合,連想配列名と要素名は var_name 
 | 
			
		||||
         : から抽出されるはずであるから,index_name 引数は nil と
 | 
			
		||||
         : せねばならない.
 | 
			
		||||
 | 
			
		||||
   モジュールメソッド
 | 
			
		||||
      mainloop(check_root = true)
 | 
			
		||||
         : イベントループを起動する.check_root が true であれば,
 | 
			
		||||
         : root widget が存在する限り,このメソッドは終了しない.
 | 
			
		||||
         : check_root が false の場合は,root widget が消滅しても
 | 
			
		||||
         : このメソッドは終了しない ( root widget が消滅しても,
 | 
			
		||||
         : WINDOW 以外のイベントは発生しうるため ).終了には,外部
 | 
			
		||||
         : からの働き掛け ( スレッドを活用するなど ) が必要.
 | 
			
		||||
 | 
			
		||||
      mainloop_thread?
 | 
			
		||||
         : カレントスレッドがイベントループを実行しているスレッド
 | 
			
		||||
         : かどうかを返す.
 | 
			
		||||
         : イベントループを実行しているスレッドであれば true を,
 | 
			
		||||
         : どのスレッドでもイベントループが実行されていない場合は 
 | 
			
		||||
         : nil を,他のスレッドでイベントループが実行されている場
 | 
			
		||||
         : 合は false を返す.
 | 
			
		||||
         : false の際に Tk インタープリタを直接呼ぶのは危険である.
 | 
			
		||||
 | 
			
		||||
      mainloop_watchdog(check_root = true)
 | 
			
		||||
         : 通常のイベントループでは,イベント処理の内容によっては
 | 
			
		||||
         : デッドロックを引き起こす可能性がある (例えばイベントに
 | 
			
		||||
         : 対するコールバック処理中で widget 操作をし,その終了を
 | 
			
		||||
         : 待つなど).このメソッドは,そうしたデッドロックを回避す
 | 
			
		||||
         : るための監視スレッド付きでイベントループを起動する
 | 
			
		||||
         : ( 監視スレッドを生成した後にイベントループを実行する ).
 | 
			
		||||
         : 引数の意味は mainloop と同じである.
 | 
			
		||||
 | 
			
		||||
      do_one_event(flag = TclTkLib::EventFlag::ALL | 
 | 
			
		||||
                            TclTkLib::EventFlag::DONT_WAIT)
 | 
			
		||||
         : 処理待ちのイベント 1 個を実行する.
 | 
			
		||||
         : イベントを処理した場合は true を返す.
 | 
			
		||||
         : フラグで DONT_WAIT を指定していない場合,フラグで処理対
 | 
			
		||||
         : 象となっている種類のイベントが発生するまで待ち続ける.
 | 
			
		||||
         : DONT_WAIT を指定していた場合,処理対象イベントがなくても
 | 
			
		||||
         : すぐに終了し false を返す.
 | 
			
		||||
         : $SAFE >= 4 か,$SAFE >= 1 かつ flag が汚染されているならば
 | 
			
		||||
         : flag には DONT_WAIT が強制的に付けられる.
 | 
			
		||||
 | 
			
		||||
      set_eventloop_tick(timer_tick)
 | 
			
		||||
         : イベントループと同時に別スレッドが稼働している場合に,時
 | 
			
		||||
         : 間に基づいた強制的なスレッドスイッチングをどの程度の頻度
 | 
			
		||||
         : ( 時間間隔 ) で発生させるかをミリ秒単位の整数値で指定する.
 | 
			
		||||
         : 0 を指定すると,この強制的なスイッチングは行われない.
 | 
			
		||||
         : 標準では 0 に設定されており,イベント処理数に基づくスイッ
 | 
			
		||||
         : チングだけが行われる ( see set_eventloop_weight ).
 | 
			
		||||
         : ただし,稼働しているスレッドがイベントループだけの場合,
 | 
			
		||||
         : timer_tick を 0 に設定することはできない.もし設定されて
 | 
			
		||||
         : いたら,100 ms ( see NO_THREAD_INTERRUPT_TIME ) に自動設
 | 
			
		||||
         : 定される.
 | 
			
		||||
         : 詳細な説明は略すが,これは CPU パワーを節約しつつ安全で
 | 
			
		||||
         : 安定した動作を実現するために実装した仕様である.
 | 
			
		||||
         : $SAFE >= 4 では実行が禁止される.
 | 
			
		||||
 | 
			
		||||
      get_eventloop_tick
 | 
			
		||||
         : timer_tick の現在値を返す.
 | 
			
		||||
 | 
			
		||||
      set_no_event_wait(no_event_wait)
 | 
			
		||||
         : 複数のスレッドが稼働している場合で,処理待ちイベントが全
 | 
			
		||||
         : く存在しなかった際に sleep 状態に入る時間長を指定する.
 | 
			
		||||
         : 稼働スレッドがイベントループだけの場合には意味をなさない.
 | 
			
		||||
         : デフォルトの値は 20 (ms)
 | 
			
		||||
         : $SAFE >= 4 では実行が禁止される.
 | 
			
		||||
 | 
			
		||||
      get_no_event_wait
 | 
			
		||||
         : no_event_wait の現在値を返す.
 | 
			
		||||
 | 
			
		||||
      set_eventloop_weight(loop_max, no_event_tick)
 | 
			
		||||
         : 複数のスレッドが稼働している際に Ruby/Tk のイベントルー
 | 
			
		||||
         : プに割り当てる比重を定めるためのパラメータを設定する.
 | 
			
		||||
         : 稼働スレッドがイベントループだけの場合には意味をなさない.
 | 
			
		||||
         : 一度のスレッド切り替えの間に処理するイベントの最大数と,
 | 
			
		||||
         : 処理待ちのイベントが存在しない際の加算数とを設定する.
 | 
			
		||||
         : 処理待ちイベントが存在しない場合は no_event_wait ( see 
 | 
			
		||||
         : set_no_event_wait ) だけの間 sleep 状態に入る.
 | 
			
		||||
         : デフォルトではそれぞれ 800 回と 10 回,つまり,800 個のイ
 | 
			
		||||
         : ベント (アイドルイベントを含む) を処理するとか,イベント
 | 
			
		||||
         : が全く発生しないままに 80 回の処理待ちイベント検査が完了
 | 
			
		||||
	 : するとかでカウントが 800 以上になるとスレッドスイッチング
 | 
			
		||||
         : が発生することになる.
 | 
			
		||||
         : $SAFE >= 4 では実行が禁止される.
 | 
			
		||||
 | 
			
		||||
      get_eventloop_weight
 | 
			
		||||
         : 現在の loop_max と no_event_tick との値を返す.
 | 
			
		||||
         : ( see set_eventloop_wait )
 | 
			
		||||
 | 
			
		||||
      mainloop_abort_on_exception=(bool)
 | 
			
		||||
         : Tk インタープリタ上で例外を発生した際に,イベントループを
 | 
			
		||||
         : エラー停止させるかどうかを指定する.true を指定した場合は
 | 
			
		||||
         : エラー停止するが,false の場合は例外を無視してイベントルー
 | 
			
		||||
         : プを継続する.さらに nil の場合は警告モードでない限りはエ
 | 
			
		||||
         : ラーメッセージの出力すら省略して,例外を無視する.
 | 
			
		||||
	 : デフォルトでは true に設定されている.
 | 
			
		||||
         : 1個のインタープリタだけを使っている場合にはエラー時にその
 | 
			
		||||
         : まま停止しても通常は問題ないが,複数のインタープリタが同時
 | 
			
		||||
         : に動作している場合には,それらを管理するイベントループは1
 | 
			
		||||
         : 個だけであるため,いずれかのインタープリタのエラーが原因で,
 | 
			
		||||
         : 他のインタープリタの処理継続が不可能になることがある.その
 | 
			
		||||
         : ような場合でもエラーを無視してイベントループが稼働を続ける
 | 
			
		||||
         : ことで,他のインタープリタが正常に動作し続けることができる.
 | 
			
		||||
         : $SAFE >= 4 では実行が禁止される.
 | 
			
		||||
 | 
			
		||||
      mainloop_abort_on_exception
 | 
			
		||||
         : Tk インタープリタ上で例外を発生した際に,イベントループをエ
 | 
			
		||||
         : ラー停止させるかどうかの設定状態を true/false で得る.
 | 
			
		||||
 | 
			
		||||
      num_of_mainwindows
 | 
			
		||||
         : 現在のメインウィンドウ (ルートウィジェット) の数を返す.
 | 
			
		||||
         : メインウィンドウは一つのインタープリタに付き最大一つである
 | 
			
		||||
         : ので,この値は現在 Tk の機能が有効であるインタープリタの総
 | 
			
		||||
         : 数に等しい.
 | 
			
		||||
 | 
			
		||||
      _merge_tklist(str, str, ... )
 | 
			
		||||
         : Tcl/Tk のライブラリ関数を使って,引数の文字列がそれぞれ
 | 
			
		||||
         : 正しく一つのリスト要素となるように連結した文字列を返す.
 | 
			
		||||
 | 
			
		||||
      _conv_listelement(str)
 | 
			
		||||
         : Tcl/Tk のライブラリ関数を使って,引数の文字列が Tcl の
 | 
			
		||||
         : 一つのリスト要素として適切な表現になるように変換した文
 | 
			
		||||
         : 字列を返す.
 | 
			
		||||
 | 
			
		||||
      _toUTF8(str, encoding=nil)
 | 
			
		||||
      _fromUTF8(str, encoding=nil)
 | 
			
		||||
         : Tcl/Tk が内蔵している UTF8 変換処理を呼び出す.
 | 
			
		||||
 | 
			
		||||
      _subst_UTF_backslash(str)
 | 
			
		||||
      _subst_Tcl_backslash(str)
 | 
			
		||||
         : Tcl のルールでバックスラッシュ記法 ( \uhhhh による 
 | 
			
		||||
         : Unicode 文字表現を含む ) を解析する.
 | 
			
		||||
         : _subst_Tcl_backslash はすべてのバックスラッシュ記法を
 | 
			
		||||
         : 置き換えるのに対し,_subst_UTF_backslash は \uhhhh 
 | 
			
		||||
         : による Unicode 文字表現だけを置き換える.
 | 
			
		||||
 | 
			
		||||
      encoding_system
 | 
			
		||||
      encoding_system=(encoding)
 | 
			
		||||
         : Tcl の system encoding の獲得および設定
 | 
			
		||||
 | 
			
		||||
      encoding
 | 
			
		||||
      encoding=(encoding)
 | 
			
		||||
         : encoding_system / encoding_system= の alias
 | 
			
		||||
         : ( Ruby/Tk の tk.rb では置き換えられる予定のもの.)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
クラス TclTkIp
 | 
			
		||||
   クラスメソッド
 | 
			
		||||
      new(ip_name=nil, options='')
 | 
			
		||||
         : TclTkIp クラスのインスタンスを生成する.
 | 
			
		||||
         : ip_name に文字列を与えた場合は,それが winfo interps などで
 | 
			
		||||
         : 表示される名前になる.
 | 
			
		||||
         : options には,-geometry や -use など,wish のコマンドライン
 | 
			
		||||
         : 引数として与えるオプションと同様の情報を文字列として与える.
 | 
			
		||||
         : 与えられた情報は,root widget 生成の際に用いられる.
 | 
			
		||||
         : ( e.g. TclTkIp.new('FOO', '-geometry 500x200 -use 0x2200009') )
 | 
			
		||||
         : もし options に敢えて nil または false を与えた場合,Tk ライ
 | 
			
		||||
         : ブラリが導入されていない (つまりは Tcl のみの) インタープリ
 | 
			
		||||
         : タを生成する.この場合は GUI 環境は必要ないため,ウインドウ
 | 
			
		||||
         : システムが存在しない,または使用できない環境でも Tcl インター
 | 
			
		||||
         : プリタを生成し,Tcl やその拡張ライブラリを活用することができる.
 | 
			
		||||
 | 
			
		||||
   インスタンスメソッド
 | 
			
		||||
      create_slave(name, safe=false)
 | 
			
		||||
         : レシーバを親とする name という名前のスレーブインタープリタを
 | 
			
		||||
	 : 生成する.
 | 
			
		||||
	 : safe には生成するインタープリタを safe インタープリタとする
 | 
			
		||||
         : かを指定する.デフォルトは false ということになっているが,
 | 
			
		||||
         : たとえ明確に false を指定していたとしても,親となるインター
 | 
			
		||||
         : プリタが safe インタープリタであれば,その設定を引き継いで 
 | 
			
		||||
         : safe インタープリタとして生成される.
 | 
			
		||||
         : $SAFE >= 4 では,safe インタープリタ以外の生成が禁止される.
 | 
			
		||||
 | 
			
		||||
      make_safe
 | 
			
		||||
         : Tcl/Tk インタープリタを safe インタープリタに変更する.
 | 
			
		||||
         : 戻り値はレシーバであるインタープリタ自身である.
 | 
			
		||||
         : 失敗した場合は RuntimeError の例外を発生する.
 | 
			
		||||
 | 
			
		||||
      safe?
 | 
			
		||||
         : Tcl/Tk インタープリタが safe インタープリタであるかを調べる.
 | 
			
		||||
         : safe インタープリタであれば true を返す.
 | 
			
		||||
 | 
			
		||||
      allow_ruby_exit?
 | 
			
		||||
         : 対象となるインタープリタ上の評価で,ruby の exit 関数または 
 | 
			
		||||
         : Tcl/Tk 上の exit コマンドによって ruby 自体を終了させること
 | 
			
		||||
         : を許すかどうかを返す.
 | 
			
		||||
	 : 許さない場合は対象のインタープリタだけが終了する.
 | 
			
		||||
         : マスターインタープリタのデフォルト値は true,スレーブインター
 | 
			
		||||
         : プリタのデフォルト値は false である.
 | 
			
		||||
 | 
			
		||||
      allow_ruby_exit=(mode)
 | 
			
		||||
         : 対象となるインタープリタの allow_ruby_exit? の状態を変更する.
 | 
			
		||||
	 : $SAFE >= 4 またはインタープリタが safe インタープリタの場合は
 | 
			
		||||
	 : 変更が許されない (例外を発生).
 | 
			
		||||
 | 
			
		||||
      delete
 | 
			
		||||
         : Tcl/Tk インタープリタを delete する.
 | 
			
		||||
         : delete されたインタープリタは,以後一切の操作ができなくなり,
 | 
			
		||||
         : コマンドを送っても例外を発生するようになる.
 | 
			
		||||
 | 
			
		||||
      deleted?
 | 
			
		||||
         : Tcl/Tk インタープリタがすでに delete されているかを調べる.
 | 
			
		||||
         : delete 済みでコマンドを受け付けない状態になっているならば
 | 
			
		||||
         : true を返す.
 | 
			
		||||
 | 
			
		||||
      has_mainwindow?
 | 
			
		||||
         : Tcl/Tk インタープリタにメインウィンドウ (root widget) が
 | 
			
		||||
         : 存在すれば true を,存在しなければ false を返す.
 | 
			
		||||
         : インタープリタが既に delete 済みであれば nil を返す.
 | 
			
		||||
 | 
			
		||||
      restart
 | 
			
		||||
         : Tcl/Tk インタープリタの Tk 部分の初期化,再起動を行う.
 | 
			
		||||
         : 一旦 root widget を破壊した後に再度 Tk の機能が必要と
 | 
			
		||||
         : なった場合に用いる.
 | 
			
		||||
         : $SAFE >= 4 では実行が禁止される.
 | 
			
		||||
 | 
			
		||||
      _eval(str)
 | 
			
		||||
      _invoke(*args)
 | 
			
		||||
         : Tcl/Tk インタープリタ上で評価を行う.
 | 
			
		||||
         : _eval は評価スクリプトが一つの文字列であることに対し,
 | 
			
		||||
         : _invoke は評価スクリプトの token ごとに一つの引数とな
 | 
			
		||||
         : るように与える.
 | 
			
		||||
         : _invoke の方は Tcl/Tk インタープリタの字句解析器を用い
 | 
			
		||||
         : ないため,評価の負荷がより少なくてすむ.ただし,その代
 | 
			
		||||
         : わりに auto_load のような機構は働かず,load 等によって
 | 
			
		||||
         : Tcl/Tk インタープリタ上に既に登録済みのコマンドしか呼
 | 
			
		||||
         : び出すことができない.
 | 
			
		||||
         : _eval では auto_load 機構が働くため,一度 _eval を実行
 | 
			
		||||
         : して登録に成功しさえすれば,以降は _invoke でも利用で
 | 
			
		||||
         : きるようになる.
 | 
			
		||||
 | 
			
		||||
      _toUTF8(str, encoding=nil)
 | 
			
		||||
      _fromUTF8(str, encoding=nil)
 | 
			
		||||
         : Tcl/Tk が内蔵している UTF8 変換処理を呼び出す.
 | 
			
		||||
 | 
			
		||||
      _thread_vwait(var_name)
 | 
			
		||||
      _thread_tkwait(mode, target)
 | 
			
		||||
         : スレッド対応の vwait あるいは tkwait 相当のメソッド.
 | 
			
		||||
         : 通常の vwait あるいは tkwait コマンドと異なるのは,イベン
 | 
			
		||||
         : トループとは異なるスレッドから呼び出した場合に vwait 等の
 | 
			
		||||
         : スタックとは独立に条件の成立待ちがなされることである.
 | 
			
		||||
         : 通常の vwait / tkwait では,vwait / tkwait (1) の待ちの途
 | 
			
		||||
         : 中でさらに vwait / tkwait (2) が呼ばれた場合,待ちの対象
 | 
			
		||||
         : となっている条件の成立順序がどうあれ,(2)->(1) の順で待ち
 | 
			
		||||
         : を終了して戻ってくる.
 | 
			
		||||
         : _thread_vwait / _thread_tkwait は,イベントループのスレッ
 | 
			
		||||
         : ドで呼ばれた場合は通常の vwait / tkwait と同様に動作する
 | 
			
		||||
         : が,イベントループ以外のスレッドで呼ばれた場合にはそのス
 | 
			
		||||
         : レッドを停止させて待ちに入り,条件が成立した時にスレッド
 | 
			
		||||
         : の実行を再開する.「vwait 等の待ちスタックとは独立」とい
 | 
			
		||||
         : う意味は,この再開のタイミングが他のスレッドでの待ち状況
 | 
			
		||||
         : とは無関係ということである.つまり,イベントループ等の他
 | 
			
		||||
         : のスレッドで vwait 等で待ちの状態にあったとしてもその完了
 | 
			
		||||
         : を待つことなく,自らの待ち条件が成立次第,処理を継続する
 | 
			
		||||
         : ことになる.
 | 
			
		||||
 | 
			
		||||
      _return_value
 | 
			
		||||
         : 直前の Tcl/Tk 上での評価の実行結果としての戻り値を返す.
 | 
			
		||||
 | 
			
		||||
      _get_variable(var_name, flag)
 | 
			
		||||
      _get_variable2(var_name, index_name, flag)
 | 
			
		||||
         : Tcl/Tk 上の var という変数名の変数の値を返す.
 | 
			
		||||
         : もし index_name が指定 (PARSE_VARNAME フラグの説明も参照) 
 | 
			
		||||
         : された場合は連想配列 var_name の index_name の要素を返す.
 | 
			
		||||
         : flag には変数を検索する際の条件を指定する.flag に与える
 | 
			
		||||
         : 値はモジュール TclTkLib::VarAccessFlag を参照すること.
 | 
			
		||||
 | 
			
		||||
      _set_variable(var_name, value, flag)
 | 
			
		||||
      _set_variable2(var_name, index_name, value, flag)
 | 
			
		||||
         : Tcl/Tk 上の var という変数名の変数に値を設定する.
 | 
			
		||||
         : もし index_name が指定 (PARSE_VARNAME フラグの説明も参照) 
 | 
			
		||||
         : された場合は連想配列 var_name の index_name の要素を設定
 | 
			
		||||
         : する.
 | 
			
		||||
         : flag には変数を検索する際の条件を指定する.flag に与える
 | 
			
		||||
         : 値はモジュール TclTkLib::VarAccessFlag を参照すること.
 | 
			
		||||
 | 
			
		||||
      _unset_variable(var_name)
 | 
			
		||||
      _unset_variable2(var_name, index_name)
 | 
			
		||||
         : Tcl/Tk 上の var_name という変数名の変数を消去する.
 | 
			
		||||
         : もし index_name が指定 (PARSE_VARNAME フラグの説明も参照) 
 | 
			
		||||
         : された場合は連想配列 var_name から index_name の要素だけ
 | 
			
		||||
         : を消去する.
 | 
			
		||||
 | 
			
		||||
      _get_global_var(var_name)
 | 
			
		||||
      _get_global_var2(var_name, index_name)
 | 
			
		||||
      _set_global_var(var_name, value)
 | 
			
		||||
      _set_global_var2(var_name, index_name, value)
 | 
			
		||||
      _unset_global_var(var_name)
 | 
			
		||||
      _unset_global_var2(var_name, index_name)
 | 
			
		||||
         : それぞれ,対応する変数アクセスメソッドの flag に対して
 | 
			
		||||
         : (GLOBAL_ONLY | LEAVE_ERR_MSG) を与えたもの.
 | 
			
		||||
 | 
			
		||||
      _split_tklist(str)
 | 
			
		||||
         : Tcl/Tk のライブラリ関数を使って,文字列 str をリストに
 | 
			
		||||
         : 分割する (文字列の配列として返す).
 | 
			
		||||
 | 
			
		||||
      _merge_tklist(str, str, ... )
 | 
			
		||||
         : Tcl/Tk のライブラリ関数を使って,引数の文字列がそれぞれ
 | 
			
		||||
         : 正しく一つのリスト要素となるように連結した文字列を返す.
 | 
			
		||||
 | 
			
		||||
      _conv_listelement(str)
 | 
			
		||||
         : Tcl/Tk のライブラリ関数を使って,引数の文字列が Tcl の
 | 
			
		||||
         : 一つのリスト要素として適切な表現になるように変換した文
 | 
			
		||||
         : 字列を返す.
 | 
			
		||||
 | 
			
		||||
      mainloop
 | 
			
		||||
      mainloop_watchdog
 | 
			
		||||
         : スレーブ IP の場合にはイベントループを起動せずに nil を返す.
 | 
			
		||||
         : それ以外の点では引数を含めて TclTkLib の同名メソッドに同じ.
 | 
			
		||||
 | 
			
		||||
      do_one_event
 | 
			
		||||
         : スレーブ IP の場合には引数のイベントフラグに DONT_WAIT が
 | 
			
		||||
         : 強制的に追加される (イベント待ちでスリープすることは禁止).
 | 
			
		||||
         : それ以外の点では引数を含めて TclTkLib の同名メソッドに同じ.
 | 
			
		||||
 | 
			
		||||
      set_eventloop_tick
 | 
			
		||||
      get_eventloop_tick
 | 
			
		||||
      set_no_event_wait
 | 
			
		||||
      get_no_event_wait
 | 
			
		||||
      set_eventloop_weight
 | 
			
		||||
      get_eventloop_weight
 | 
			
		||||
      mainloop_abort_on_exception
 | 
			
		||||
      mainloop_abort_on_exception=
 | 
			
		||||
         : スレーブ IP の場合には値の設定が許されない (無視される).
 | 
			
		||||
         : それ以外の点では引数を含めて TclTkLib の同名メソッドに同じ.
 | 
			
		||||
 | 
			
		||||
クラス TkCallbackBreak < StandardError
 | 
			
		||||
クラス TkCallbackContinue < StandardError
 | 
			
		||||
   : これらはイベントコールバックにおいて,コールバック処理を適切に中
 | 
			
		||||
   : 断したり,次のバインドタグのバインディング処理に進めたりすること
 | 
			
		||||
   : を可能にするための例外クラスである.
 | 
			
		||||
   : コールバックで break や continue を実現するためには,コールバック
 | 
			
		||||
   : である Ruby 手続きが Tcl/Tk インタープリタ側に適切なリターンコー
 | 
			
		||||
   : ドを返す必要がある.Ruby の手続きが普通に値を返すのでは,それが普
 | 
			
		||||
   : 通の戻り値であるのか否かを区別ができないため,例外発生を利用した
 | 
			
		||||
   : 実装を行っている.
 | 
			
		||||
 | 
			
		||||
(eof)
 | 
			
		||||
							
								
								
									
										16
									
								
								lib/rss.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								lib/rss.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
# Copyright (c) 2003-2005 Kouhei Sutou.  You can redistribute it and/or
 | 
			
		||||
# modify it under the same terms as Ruby.
 | 
			
		||||
#
 | 
			
		||||
# Author:: Kouhei Sutou <kou@cozmixng.org>
 | 
			
		||||
# Tutorial:: http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en
 | 
			
		||||
 | 
			
		||||
require 'rss/1.0'
 | 
			
		||||
require 'rss/2.0'
 | 
			
		||||
require 'rss/content'
 | 
			
		||||
require 'rss/dublincore'
 | 
			
		||||
require 'rss/image'
 | 
			
		||||
require 'rss/syndication'
 | 
			
		||||
#require 'rss/taxonomy'
 | 
			
		||||
require 'rss/trackback'
 | 
			
		||||
 | 
			
		||||
require "rss/maker"
 | 
			
		||||
							
								
								
									
										64
									
								
								sample/rss/re_read.rb
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										64
									
								
								sample/rss/re_read.rb
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,64 @@
 | 
			
		|||
#!/usr/bin/env ruby
 | 
			
		||||
 | 
			
		||||
require "rss"
 | 
			
		||||
 | 
			
		||||
def error(exception)
 | 
			
		||||
  mark = "=" * 20
 | 
			
		||||
  mark = "#{mark} error #{mark}"
 | 
			
		||||
  puts mark
 | 
			
		||||
  puts exception.class
 | 
			
		||||
  puts exception.message
 | 
			
		||||
  puts exception.backtrace
 | 
			
		||||
  puts mark
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
verbose = false
 | 
			
		||||
before_time = Time.now
 | 
			
		||||
 | 
			
		||||
ARGV.each do |fname|
 | 
			
		||||
  if fname == '-v'
 | 
			
		||||
    verbose = true
 | 
			
		||||
    next
 | 
			
		||||
  end
 | 
			
		||||
  source = nil
 | 
			
		||||
  File.open(fname) do |f|
 | 
			
		||||
    source = f.read
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  rss = nil
 | 
			
		||||
  read = false
 | 
			
		||||
  begin
 | 
			
		||||
    rss = RSS::Parser.parse(source)
 | 
			
		||||
    puts "Re-read valid RSS: #{fname}"
 | 
			
		||||
    RSS::Parser.parse(rss.to_s)
 | 
			
		||||
    read = true
 | 
			
		||||
  rescue RSS::InvalidRSSError
 | 
			
		||||
    error($!) if verbose
 | 
			
		||||
    ## do non validate parse for invalid RSS 1.0
 | 
			
		||||
    begin
 | 
			
		||||
      rss = RSS::Parser.parse(source, false)
 | 
			
		||||
    rescue RSS::Error
 | 
			
		||||
      ## invalid RSS.
 | 
			
		||||
      error($!) if verbose
 | 
			
		||||
    end
 | 
			
		||||
  rescue RSS::Error
 | 
			
		||||
    error($!) if verbose
 | 
			
		||||
  end
 | 
			
		||||
  
 | 
			
		||||
  if rss.nil?
 | 
			
		||||
    puts "Invalid RSS: #{fname}"
 | 
			
		||||
  elsif !read
 | 
			
		||||
    puts "Re-read invalid RSS: #{fname}"
 | 
			
		||||
    begin
 | 
			
		||||
      RSS::Parser.parse(rss.to_s)
 | 
			
		||||
    rescue RSS::Error
 | 
			
		||||
      puts "  Error occurred: #{fname}"
 | 
			
		||||
      error($!) if verbose
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
processing_time = Time.now - before_time
 | 
			
		||||
 | 
			
		||||
puts "Used XML parser: #{RSS::Parser.default_parser}"
 | 
			
		||||
puts "Processing time: #{processing_time}s"
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue