Class: ParsifalTk

Inherits:
Object
  • Object
show all
Includes:
TkComm
Defined in:
ext/ae-rad/lib/tk/al-tk.rb

Instance Method Summary collapse

Constructor Details

#initialize(_code = nil, _filename = nil, _language = 'ruby') ⇒ ParsifalTk

Returns a new instance of ParsifalTk.


1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 1312

def initialize(_code=nil, _filename=nil, _language='ruby')
  @filename = _filename;
  @code = _code
  if (@filename)&&(File.exist?(@filename))
    @code =''
    IO.foreach(@filename) { |line| @code += line };
  end
  @root =  TkWinfo.widget(Tk.tk_call('winfo', 'id', '.'))
  @top_level_banned = Array.new
  TkWinfo.children(@root).each{|_c|
    if _c.kind_of?(TkToplevel)
      @top_level_banned << _c
      print "\n"+Tk.tk_call('wm', 'title', _c)
    end
  }

  case _language
  when 'ruby'
    if !@code.gsub!('TkRoot','TkToplevelRoot')
      eval('@preudo_root=TkToplevelRoot.new')
      @code.gsub!('.new(nil','.new(@preudo_root')
    end
    @code.gsub!('Tk.mainloop','')
    eval(@code)
  when 'tcl'
    Tk.tk_call( "eval", @code)
  end
  tk_tree
end

Instance Method Details

#ag_create(_obj, _obj_name = nil, _ag_parent_name = nil, _filename = nil) ⇒ Object


1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 1398

def ag_create(_obj, _obj_name=nil, _ag_parent_name=nil, _filename=nil)
  if !_ag_parent_name
    _ag_parent_name='nil'
  end
  @filename = _filename
  if !_obj_name
    _obj_name = 'j'+_obj.id.to_s
  end
  _agclass=ArcadiaLibs.wrapper_class(_obj.class)
  if _agclass
    cod = '@'+_obj_name+"=_obj\n"
    if @filename && _obj.kind_of?(TkToplevel)
      cod = cod + '@ag'+ _obj_name + "="+ _agclass+".new("+_ag_parent_name+", _obj"+",nil,'"+_filename+"'){\n"
    else
      cod = cod +  '@ag'+ _obj_name + "="+ _agclass+".new("+_ag_parent_name+", _obj"+",nil){\n"
    end
    cod = cod + "|_self|\n"
    cod = cod + "  _self.i_name='"+_obj_name+"'\n"
    cod = cod + "  _self.i_ag='"+'ag'+_obj_name+"'\n"
    cod = cod + '}'
    eval(cod)
  end
end

#ag_wrap_dynasty_of(_root, _rootname = name(_root)) ⇒ Object


1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 1385

def ag_wrap_dynasty_of(_root, _rootname=name(_root))
  if _rootname
    _rootname = '@ag'+_rootname
  end
  if @sons_of[_root]
    @sons_of[_root].each{|_son|
      print "\nwrappo -->"+_son.to_s
      ag_create(_son, name(_son), _rootname, @filename)
      ag_wrap_dynasty_of(_son)
    }
  end
end

#dynasty_of(_root, sons_of = Hash.new) ⇒ Object


1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 1422

def dynasty_of(_root, sons_of = Hash.new)
  _childrens = TkWinfo.children(_root)
  if (_childrens != nil)&&(_childrens.length > 0)
    sons_of[_root] = _childrens
    sons_of[_root].delete_if {
      |_s|
      @top_level_banned.include?(_s)||
      ((_root.kind_of?(TkRoot))&&(!_s.kind_of?(TkToplevel)))
    }
    sons_of[_root].each{|son|
      dynasty_of(son, sons_of)
    }
  end
  return sons_of
end

#name(_obj) ⇒ Object


1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 1374

def name(_obj)
  if !defined?(@names)
    @names = names_dynasty_of(@root)
  end
  _name = @names[_obj]
  if !_name&&(_obj!=@root)
    _name = 'j'+_obj.id.to_s
  end
  return _name
end

#names_dynasty_of(_root, _names = Hash.new) ⇒ Object


1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 1353

def names_dynasty_of(_root, _names=Hash.new)
  if _root == @root
    iv = self.instance_variables
  else
    iv = _root.instance_variables
  end
  if @sons_of[_root]
    @sons_of[_root].each{|tkobj|
      iv.each{|i|
        eval("@bingo = "+i+"==tkobj")
        if @bingo
          _names[tkobj]=i.delete!('@')
          break
        end
      }
      names_dynasty_of(tkobj, _names)
    }
  end
  return _names
end

#tk_treeObject


1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
# File 'ext/ae-rad/lib/tk/al-tk.rb', line 1342

def tk_tree
  if defined?(@sons_of)
    return @sons_of
  else
    begin
      @sons_of = dynasty_of(@root)
    end
    ag_wrap_dynasty_of(@root)
  end
end