Tk::ObjScanner(3pm)
Tk::ObjScanner π β¨
okay bestie, gather round, because this is the Tk::ObjScanner page from the User Contributed Perl Documentation and it is genuinely one of the most useful little gremlins in the Tk toolbox π«Ά
β¨ NAME β¨
Tk::ObjScanner β a GUI to scan any perl data structure or object. like, any. it's giving "graphical Data::Dumper" and we are obsessed π
πΈ SYNOPSIS πΈ
# regular use
use Tk::ObjScanner;
my $mw = MainWindow->new;
my $scanner1 = $mw->ObjScanner(
-caller => $object,
-title=>"windows"
)->pack;
my $scanner2 = $mw->ObjScanner(
-caller => $object,
-title => 'demo setting the scanner options',
-background => 'white',
-selectbackground => 'beige',
-foldImage => $mw->Photo(-file => Tk->findINC('folder.xpm')),
-openImage => $mw->Photo(-file => Tk->findINC('openfolder.xpm')),
-itemImage => $mw->Photo(-file => Tk->findINC('textfile.xpm')),
)->pack( -expand => 1, -fill => 'both' ) ;
# non-intrusive scan style
# user code to produce data
Tk::ObjScanner::scan_object($mydata) ;
# resume user code
π¦ DESCRIPTION π¦
The scanner hands you a whole GUI to poke at the attributes of an object π. It can also scan the elements of a hash or an array, so it's not just an object girlie β it does it all.
This widget can be dropped into a Tk application like any regular widget, or it can be an autonomous popup widget that just shows you the content of a data structure. That second vibe is basically a call to a graphical Data::Dumper. And if you want it fully autonomous, there's the scan_object function for that π
The scanner is a composite widget β a menubar plus Tk::HList β and it acts as a scanner pointed at the object (or hash ref) you hand over in the 'caller' parameter. It goes and grabs all the keys of that hash/object and inserts them into the HList. periodt.
When you double click on a key, the matching value gets added into the HList β¨
If that value is a multi-line scalar, it'll pop up in a text window. Code refs get deparsed and shown in that pop-up window too. fancy.
Tied scalars, hashes or arrays β their internals can also be scanned: just click the middle button to open them up π
Weak references are recognized too (go read WeakRef for the details, iykyk).
π§ Autonomous widget π§
scan_object( data )
This function is not exported, so you have to call it the long way, like this:
Tk::ObjScanner::scan_object($data);
Calling it loads Tk and pops up a scanner widget for you π«. When the user destroys that widget (via the "File -" destroy> menu), your user code just... resumes. no cap. π«Ά
π Constructor parameters π
"caller"β the ref of the object or hash or array you want to scan (mandatory). and yes, you can also use"-caller".-titleβ the title of the menu that the scanner creates (optional).-backgroundβ the background color for the subwidgets (optional).-selectbackgroundβ the select background color for the HList (optional).-itemImageβ the image used for a scalar item (optional, default'file.xbm').-foldImageβ the image for a composite item (array or hash) while it's closed (optional, default'folder.xbm').-openImageβ the image for a composite item (array or hash) while it's open (optional, default'openfolder.xbm').-show_menuβ ObjScanner can show a menu with a'reload'button and'show tied info'(optional, default0).-destroyableβ if you set this, a menu entry lets the user destroy the scanner widget (optional, default1). you might wanna set it to0if the destroy is handled by some higher-level object instead. heads up: this parameter is ignored ifshow_menuis unset β οΈ-destroy_labelβ the label used for the"destroy"menu entry.-show_tiedβ if set, it'll tell you whether a variable is a tied variable. and you can see the internal data of that tied variable by double clicking the middle button (default1).
π WIDGET-SPECIFIC METHODS π
updateListBox
Updates the keys of the listbox π. This method is handy when the scanned object wants to refresh the scanner's listbox after the scanned object picks up new attributes. like a lil glow-up for your list, love that for it.
π CAVEATS π
The name of this widget is misleading β any data can be scanned, not just objects. This thing is, in fact, a DataScanner. the audacity of the naming fr fr π
ObjScanner may fail if an object involves a lot of internal perl magic. if that happens, the author would be glad to hear about it and will try to fix the problem π
ObjScanner does not detect recursive data structures. it will just keep on displaying the tree until the user gets tired of clicking HList items π (which, honestly, is a whole mood)
The icon used for a tied scalar changes from the scalar icon to a folder icon when you open the object hiding behind the tied scalar (that's the middle button, remember). and yes, a better icon for tied items would be lovely. (hint hint) π
π THANKS π
To Rudi Farkas for all the improvements provided to ObjScanner.
To Slaven Rezic for:
- The idea to use
B::Deparseto view code ref.
π CONTRIBUTORS π
Many thanks to Achim Bohnet for all the tests, patches (and reports) he made. Many improvements were made thanks to his efforts π«Ά
Thanks to Rudi Farkas for the 'watch' patch.
Thanks to heytitle for the documentation fixes.
β AUTHOR β
Dominique Dumont, ddumont@cpan.org
π SEE ALSO π
perl, Tk, Tk::HList, B::Deparse, data_viewer
and that's the whole page bestie β brought to you by perl v5.36.0, dated 2023-10-27, and it's a Tk::ObjScanner(3pm) situation π now go scan something slay β¨
π¦ where this page comes from
- debian trixie: libtk-objscanner-perl 2.018-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtk-objscanner-perl 2.018-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtk-objscanner-perl 2.018-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtk-objscanner-perl 2.018-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms