Class: Tk::Tcllib::ChatWidget

Inherits:
TkText
  • Object
show all
Defined in:
lib/tkextlib/tcllib/chatwidget.rb,
lib/tkextlib/tcllib/chatwidget.rb

Constant Summary collapse

PACKAGE_NAME =
'chatwidget'.freeze
TkCommandNames =
['::chatwidget::chatwidget'.freeze].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.package_nameObject



19
20
21
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 19

def self.package_name
  PACKAGE_NAME
end

.package_versionObject



23
24
25
26
27
28
29
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 23

def self.package_version
  begin
    TkPackage.require('chatwidget')
  rescue
    ''
  end
end

Instance Method Details

#add_name(nick, opts = {}) ⇒ Object



63
64
65
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 63

def add_name(nick, opts={})
  tk_send('name', 'add', nick, *(hash_kv(opts)))
end

#chat_widgetObject



148
149
150
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 148

def chat_widget
  window(tk_send('chat'))
end

#delete_name(nick) ⇒ Object



67
68
69
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 67

def delete_name(nick)
  tk_send('name', 'delete', nick)
end

#entry_widgetObject



144
145
146
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 144

def entry_widget
  window(tk_send('entry'))
end

#get_name(nick) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 71

def get_name(nick)
  lst = tk_send('name', 'get', nick)
  return nil if lst.empty?
  nick, *opts = tk_split_simplelist(lst)
  h_opt = {}
  opts.slice(2){|k, v| h_opt[k[1..-1]] = tk_tcl2ruby(v)}
  [nick, h_opt]
end

#hide_namesObject



135
136
137
138
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 135

def hide_names
  tk_send('names', 'hide')
  self
end

#hide_topicObject



41
42
43
44
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 41

def hide_topic
  tk_send_without_enc('topic', 'hide')
  self
end

#hook_add(type, *args, &blk) ⇒ Object

args -> [prior, cmd], [prior], [cmd]



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 93

def hook_add(type, *args, &blk) # args -> [prior, cmd], [prior], [cmd]
  #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url'

  if prior = args.shift
    if !prior.kind_of?(Numeric)
      cmd = prior
      if (prior = args.shift) && !prior.kind_of?(Numeric)  # error
        args.unshift(prior)
      end
      args.unshift(cmd)
    end
    prior ||= 50  # default priority
  end

  cmd = args.shift || blk

  fail ArgumentError, "invalid arguments" unless args.empty?
  fail ArgumentError, "no callback is given" unless cmd

  _parse_hook_list(tk_send('hook', 'add', type, cmd, prior))
end

#hook_list(type) ⇒ Object



125
126
127
128
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 125

def hook_list(type)
  #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url'
  _parse_hook_list(tk_send('hook', 'list', type))
end

#hook_remove(type, cmd) ⇒ Object



115
116
117
118
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 115

def hook_remove(type, cmd)
  #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url'
  _parse_hook_list(tk_send('hook', 'remove', type, cmd))
end

#hook_run(type, *cmd_args) ⇒ Object



120
121
122
123
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 120

def hook_run(type, *cmd_args)
  #type -> 'message', 'post', 'names_group', 'names_nick', 'chatstate', 'url'
  tk_send('hook', 'run', type, *cmd_args)
end

#list_nameObject



50
51
52
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 50

def list_name
  tk_split_simplelist(tk_send('name', 'list'))
end

#list_name_fullObject



54
55
56
57
58
59
60
61
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 54

def list_name_full
  tk_split_simplelist(tk_send('name', 'list')).map{|lst|
    nick, *opts = tk_split_simplelist(lst)
    h_opt = {}
    opts.slice(2){|k, v| h_opt[k[1..-1]] = tk_tcl2ruby(v)}
    [nick, h_opt]
  }
end

#message(msg, opts = {}) ⇒ Object



80
81
82
83
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 80

def message(msg, opts={})
  tk_send('message', msg, *(hash_kv(opts)))
  self
end

#names_widgetObject



140
141
142
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 140

def names_widget
  window(tk_send('names'))
end

#set_topic(topic) ⇒ Object



46
47
48
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 46

def set_topic(topic)
  tk_send('topic', 'set', topic)
end

#show_namesObject



130
131
132
133
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 130

def show_names
  tk_send('names', 'show')
  self
end

#show_topicObject



36
37
38
39
# File 'lib/tkextlib/tcllib/chatwidget.rb', line 36

def show_topic
  tk_send_without_enc('topic', 'show')
  self
end