Class: Tk::RbWidget::BalloonHelp

Inherits:
TkLabel
  • Object
show all
Defined in:
lib/tkxxs.rb,
ext/tkballoonhelp.rb,
ext/tkballoonhelp.rb,
ext/tkballoonhelp_ORIGINAL.rb,
ext/tkballoonhelp_ORIGINAL.rb

Constant Summary collapse

DEFAULT_FOREGROUND =
'black'
DEFAULT_BACKGROUND =
'white'
DEFAULT_INTERVAL =
750

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, keys = {}) ⇒ BalloonHelp

Setting defaults



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/tkxxs.rb', line 49

def initialize(parent=nil, keys={})
  @parent = parent || Tk.root

  @frame = TkToplevel.new(@parent)
  if defined?($tkxxs_) && $tkxxs_[:userscreenx]
    $balloonhlp_ = Hash.new
    $balloonhlp_[:userscreenx]      = $tkxxs_[:userscreenx]
    $balloonhlp_[:userscreeny]      = $tkxxs_[:userscreeny]
    $balloonhlp_[:userscreenwidth]  = $tkxxs_[:userscreenwidth]
    $balloonhlp_[:userscreenheight] = $tkxxs_[:userscreenheight]
  elsif !defined?($balloonhlp_) || !$balloonhlp_[:userscreenx]
    userscreen(@frame)
  end
  @frame.withdraw
  @frame.overrideredirect(true)
  @frame.transient(TkWinfo.toplevel(@parent))
  @epath = @frame.path

  if keys
    keys = _symbolkey2str(keys)
  else
    keys = {}
  end

  @command = keys.delete('command')

  @interval = keys.delete('interval'){DEFAULT_INTERVAL}
  _balloon_binding(@interval)

  # @label = TkLabel.new(@frame, 'background'=>'bisque').pack
  @label = TkLabel.new(@frame, 
                       ## :wraplength => '2i',  # Axel
                       'foreground'=>DEFAULT_FOREGROUND, 
                       ## 'background'=>DEFAULT_BACKGROUND).pack # -Axel
                       'background'=>DEFAULT_BACKGROUND).pack(:expand=>1, :fill=>:both)
  @label.configure(_symbolkey2str(keys)) unless keys.empty?
  @path = @label
end

Class Method Details

.interval(val) ⇒ Object



31
32
33
# File 'ext/tkballoonhelp.rb', line 31

def @timer.interval(val)
  @sleep_time = val
end

Instance Method Details

#command(cmd = Proc.new) ⇒ Object



144
145
146
147
# File 'ext/tkballoonhelp.rb', line 144

def command(cmd = Proc.new)
  @command = cmd
  self
end

#destroyObject



247
248
249
# File 'ext/tkballoonhelp.rb', line 247

def destroy
  @frame.destroy
end

#epathObject

userscreen



132
133
134
# File 'ext/tkballoonhelp.rb', line 132

def epath
  @epath
end

#eraseObject



237
238
239
240
241
242
243
244
245
# File 'ext/tkballoonhelp.rb', line 237

def erase
  ## @parent.cursor(@org_cursor) # -patch Nagai
  begin                                           # +patch Nagai
    @parent.configure('cursor', @org_cursor)      # +patch Nagai
  rescue                                          # +patch Nagai
    @parent.cursor(@org_cursor)                   # +patch Nagai
  end                                             # +patch Nagai
  @frame.withdraw
end

#geom(x, y, rw, rh, gapx = 1, gapy = 10) ⇒ Object

gap: pixels; may not be 0!



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'ext/tkballoonhelp.rb', line 196

def geom( x,y,rw,rh, gapx=1, gapy=10 ) # gap: pixels; may not be 0!
  xcorrected = false
  ## rw = TkWinfo.reqwidth(@frame)
  ## rh = TkWinfo.reqheight(@frame)
  xmin = $balloonhlp_[:userscreenx]
  ymin = $balloonhlp_[:userscreeny]
  xmax= xmin + $balloonhlp_[:userscreenwidth]
  ymax= ymin + $balloonhlp_[:userscreenheight]

  origx = x
  x += gapx
  y += gapy
  
  if x + rw > xmax
    x = [(xmax-rw), xmin].max # Shift left
    xcorrected = true
  end
  
  y = y - gapy - rh  if y + rh > ymax # Shift up

  if y < ymin # height will overlap pointer
    y = ymin
    x = origx - rw - gapx  if xcorrected # Shift left
  end

  if x < xmin # to big
    x = xmin
    wrap_help
  end
  geom = "+#{ x }+#{ y }" # balloon may not overlap cursor - why?
 
  geom
end

#interval(val) ⇒ Object



136
137
138
139
140
141
142
# File 'ext/tkballoonhelp.rb', line 136

def interval(val)
  if val
    @timer.interval(val)
  else
    @interval
  end
end

#orig_initializeBalloonHelp

:nodoc:

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tkxxs.rb', line 45

def initialize(parent=nil, keys={})
  @parent = parent || Tk.root

  @frame = TkToplevel.new(@parent)
  if defined?($tkxxs_) && $tkxxs_[:userscreenx]
    $balloonhlp_ = Hash.new
    $balloonhlp_[:userscreenx]      = $tkxxs_[:userscreenx]
    $balloonhlp_[:userscreeny]      = $tkxxs_[:userscreeny]
    $balloonhlp_[:userscreenwidth]  = $tkxxs_[:userscreenwidth]
    $balloonhlp_[:userscreenheight] = $tkxxs_[:userscreenheight]
  elsif !defined?($balloonhlp_) || !$balloonhlp_[:userscreenx]
    userscreen(@frame)
  end
  @frame.withdraw
  @frame.overrideredirect(true)
  @frame.transient(TkWinfo.toplevel(@parent))
  @epath = @frame.path

  if keys
    keys = _symbolkey2str(keys)
  else
    keys = {}
  end

  @command = keys.delete('command')

  @interval = keys.delete('interval'){DEFAULT_INTERVAL}
  _balloon_binding(@interval)

  # @label = TkLabel.new(@frame, 'background'=>'bisque').pack
  @label = TkLabel.new(@frame, 
                       ## :wraplength => '2i',  # Axel
                       'foreground'=>DEFAULT_FOREGROUND, 
                       ## 'background'=>DEFAULT_BACKGROUND).pack # -Axel
                       'background'=>DEFAULT_BACKGROUND).pack(:expand=>1, :fill=>:both)
  @label.configure(_symbolkey2str(keys)) unless keys.empty?
  @path = @label
end

#showObject



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'ext/tkballoonhelp.rb', line 149

def show
  x = TkWinfo.pointerx(@parent)
  y = TkWinfo.pointery(@parent)
  ## @frame.geometry("+#{x+1}+#{y+1}")

  if @command
    case @command.arity
    when 0
      @command.call
    when 2
      @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent))
    when 3
      @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent),
                    self)
    else
      @command.call(x - TkWinfo.rootx(@parent), y - TkWinfo.rooty(@parent),
                    self, @parent)
    end
  end

  @frame.geometry("+#{x+1}+#{y+1}")
  @frame.update

  rw = TkWinfo.reqwidth(@frame)
  rh = TkWinfo.reqheight(@frame)
  geom1 = geom(x,y,rw,rh) 
  @frame.geometry(geom1)

  @frame.deiconify
  @frame.raise

  ## @org_cursor = @parent['cursor'] # -patch Nagai
  ## @parent.cursor('crosshair')     # -patch Nagai
  begin                                        # +patch Nagai
    @org_cursor = @parent.cget('cursor')       # +patch Nagai
  rescue                                       # +patch Nagai
    @org_cursor = @parent['cursor']            # +patch Nagai
  end                                          # +patch Nagai
  begin                                        # +patch Nagai
    @parent.configure('cursor', 'crosshair')   # +patch Nagai
  rescue                                       # +patch Nagai
    @parent.cursor('crosshair')                # +patch Nagai
  end                                          # +patch Nagai

  @frame.update
end

#userscreen(root) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'ext/tkballoonhelp.rb', line 89

def userscreen( root )
  # TODO: Screen "pops"; other way?
  root.state('zoomed') 
  root.update

  if RUBY_PLATFORM[/mingw|mswin|bccwin/ix] # Windows
    root.state('zoomed') # OK on Windows, bad on Linux
  else
    # Linux: works
    # Other: not tested
    root.height = root.winfo_screenheight
    root.width = root.winfo_screenwidth
  end

  root.winfo_geometry  =~ /(\d+)x(\d+)\+([+-]?\d+)\+([+-]?\d+)/
  xwg = $3.to_i 
  ywg = $4.to_i
  root.geometry =~ /(\d+)x(\d+)\+([+-]?\d+)\+([+-]?\d+)/ 
  gw = $1.to_i 
  gh = $2.to_i 
  
  ## sw = root.winfo_screenwidth 
  ## sh = root.winfo_screenheight 
  
  rx = root.winfo_rootx 
  ry = root.winfo_rooty  # maybe, taskbar height 
  
  border = -[xwg,ywg].min
  userscreenx = xwg + border
  userscreeny= ywg + border
  userscreenwidth = gw
  userscreenheight = gh + ry - ywg - border

  $balloonhlp_ ||= Hash.new
  $balloonhlp_[:userscreenx     ] =  userscreenx
  $balloonhlp_[:userscreeny     ] =  userscreeny
  $balloonhlp_[:userscreenwidth ] =  userscreenwidth
  $balloonhlp_[:userscreenheight] =  userscreenheight

  root.state('normal')
  nil
end

#wrap_helpObject



231
232
233
234
# File 'ext/tkballoonhelp.rb', line 231

def wrap_help(  )
  #TODO: Introduce "wraplength"
  puts 'Cannot show balloon help: to big.'
end