Class: TKXXS::OutW

Inherits:
TKXXS_CLASSES::TextW show all
Defined in:
lib/tkxxs.rb

Overview

You create an Output Window like this:

@outW = OutW.new

You can write to the Output Window like this:

@outW.puts "Hallo"

OR, you can redirect stdout to @outW:

$stdout = @outW

Then you can simply write:

puts "Hallo"

to write to the Output Window. This means, if you have an existing application which uses puts to write to the console, you can easily make it to write to the Output Window! BUT: Unfortunately, this is not compatible with OCRA and pry (as of 2013-12). When you want to use OCRA or pry, you cannot use this redirection of stdout.

Direct Known Subclasses

LogW

Constant Summary collapse

CONF =
nil

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ OutW

Returns a new instance of OutW.



80
81
82
83
84
85
86
87
88
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
# File 'lib/tkxxs.rb', line 80

def initialize( hash={} )
  @alive = true
  teardownDone = false
  at_exit { self.destroy  }

  #----  Root
  img = TkPhotoImage.new(:file=>"#{ DIR_OF_TKXXS }/icon.gif")
  @root = TkRoot.new(:iconphoto_default=>img )

  userscreen(@root)  unless $tkxxs_[:userscreenx]
  if CONF
    @root.geometry = 
      CONF.or_default( :outWGeom, '400x300+100+0' ) 
  end
  #----  Root-bindings
  @root.bind('Destroy') {
    unless teardownDone
      notify_dying
      if CONF
        CONF[:outWGeom] = @root.geometry
        STDOUT.puts "Saving config to #{ CONF.filename.gsub('/', $FILE_SEP) }"
        CONF.save
      end
      teardownDone = true
    end # unless
  }
  
  #----  TopFrame
  top = Frame.new.pack(:expand=>true, :fill=>:both)
  
  #----  outWindow
  ##/ @outW = TextW.new(top)
  super(top, hash) 
  @tagH2 = TkTextTag.new(self, :font=>"Courier 14 bold")
  @tagSel = TkTextTagSel.new(self)
  bind('Control-Key-a') {
    # From:
    # "Using Control-a to select all text in a text widget : TCL",
    # http://objectmix.com/tcl/35276-using-control-select-all-text-text-widget.html
    @tagSel.add('0.0', :end)
    Kernel.raise TkCallbackBreak
  }
  @tkxxs_buffer = StringIO.new

end

Instance Method Details

#alive?Boolean

“private”

Returns:

  • (Boolean)


244
245
246
# File 'lib/tkxxs.rb', line 244

def alive?(  )
  @alive
end

#flushObject

:nodoc:



177
178
179
# File 'lib/tkxxs.rb', line 177

def flush
  self.update
end

#notify_dyingObject

“private”



238
239
240
# File 'lib/tkxxs.rb', line 238

def notify_dying(  )
  @alive = false
end

#output_with(method, tag, *args) ⇒ Object

initialize



126
127
128
129
130
131
# File 'lib/tkxxs.rb', line 126

def output_with(method, tag, *args)
  @tkxxs_buffer.reopen
  @tkxxs_buffer.send(method, *args)
  self.insert(:end, @tkxxs_buffer.string, tag)
  self.see :end
end

#p(arg) ⇒ Object

Like Kernel::p. For each object, directly writes obj.inspect followed by a newline to the program’s standard output.



154
155
156
# File 'lib/tkxxs.rb', line 154

def p( arg )
  output_with(:puts, nil, arg.inspect)
end

Like Kernel::print. Print a String to the Output Window.



147
148
149
# File 'lib/tkxxs.rb', line 147

def print( *args )
  output_with(:print, nil, *args)
end

#printf(*args) ⇒ Object

Like Kernel::printf. Print object based on given format string.



160
161
162
# File 'lib/tkxxs.rb', line 160

def printf( *args )
  output_with(:printf, nil, *args)
end

#private____________________________Object

:nodoc:



188
189
# File 'lib/tkxxs.rb', line 188

def private____________________________(  )
end

#puts(*args) ⇒ Object

Like Kernel::puts. Write a String to the Output Window.



135
136
137
# File 'lib/tkxxs.rb', line 135

def puts( *args )
  output_with(:puts, nil, *args)
end

#puts_h2(*args) ⇒ Object

puts, formated as heading level 2



141
142
143
# File 'lib/tkxxs.rb', line 141

def puts_h2( *args )
  output_with(:puts, @tagH2, *args)
end

#sync=(x) ⇒ Object

:nodoc: Does nothing, just for compatibility



172
173
174
# File 'lib/tkxxs.rb', line 172

def sync=( x )
  # nothing to do
end

#tty?Boolean

:nodoc:

Returns:

  • (Boolean)


182
183
184
# File 'lib/tkxxs.rb', line 182

def tty?(  )
  false
end

#userscreen(root) ⇒ Object

“private”



193
194
195
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
229
230
231
232
233
234
# File 'lib/tkxxs.rb', line 193

def userscreen( root )
  if Platform::OS == :win32
    root.state('zoomed') # OK on Windows
    ##/ root.wm_state('zoomed') # OK on Windows
    ##/ root.wm_zoomed # method missing
    ##/ root.wm_attributes('zoomed')
    ##/ root.wm_maximized # method missing
  else
    # Linux: works
    # Other: not tested
    root.height = root.winfo_screenheight
    root.width = root.winfo_screenwidth
  end
  root.update

  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

  $tkxxs_[:userscreenx     ] =  userscreenx
  $tkxxs_[:userscreeny     ] =  userscreeny
  $tkxxs_[:userscreenwidth ] =  userscreenwidth
  $tkxxs_[:userscreenheight] =  userscreenheight

  root.state('normal')
  nil
end

#write(str) ⇒ Object

:nodoc:



165
166
167
# File 'lib/tkxxs.rb', line 165

def write( str )
  output_with(:write, nil, str)
end