http://qs321.pair.com?node_id=236467

I am trying to teach my daughter Perl. In order to improve her experience with Perl, I tried together with her to make an IDE for her.

What I posted here is just where we started, and we will surely continue to work on it, and use it for ourselves.

For the next revision, we will try to:
  1. make STDIN work
  2. visually link compilation errors with source code
  3. try to connect to debug
use Tk; use IPC::Open3; use Hash::Util (lock_keys); use strict; use warnings; $main::self = {}; $main::self->{OPEN_FILE} = undef; $main::self->{MAIN_WINDOW} = new MainWindow(title => "My Program - Unt +iled"); my $tools_frame = $main::self->{MAIN_WINDOW} ->Frame(border => 1, relief => "sunken") ->pack(fill => "x", padx => 5, pady => 5, side => "top"); my $run = $tools_frame->Button(text => "Run", background => "light blue", activebackground => "pink", command => \&run) ->pack(side => "left", padx => 5, pady => 5); $tools_frame->Button(text => "New", background => "light blue", activebackground => "pink", command => \&new_file) ->pack(side => "left", pady => 5); $tools_frame->Button(text => "Open", background => "light blue", activebackground => "pink", command => \&open_file) ->pack(side => "left", pady => 5); $tools_frame->Button(text => "Save", background => "light blue", activebackground => "pink", command => \&save) ->pack(side => "left", pady => 5); $tools_frame->Button(text => "Save As", background => "light blue", activebackground => "pink", command => \&save_as) ->pack(side => "left", pady => 5); $main::self->{PROGRAM_TEXT} = $main::self->{MAIN_WINDOW} ->Scrolled("Text", font => ["Times", 16], -scrollbars => "e", background => "cyan", width => 70, height => 20) ->pack(side => "top", fill => "x"); lock_keys(%{$main::self}); $main::result = $main::self->{MAIN_WINDOW} ->Scrolled("Text", font => ["Times", 16], -scrollbars => "e", background => "light green", width => 70, height => 8) ->pack(side => "top", fill => "x"); $main::self->{PROGRAM_TEXT}->focus(); MainLoop; sub run { my $program = $main::self->{PROGRAM_TEXT}->get("1.0", "end"); open(PROGRAM, ">", "program.pl"); print PROGRAM $program; close(PROGRAM); open3(\*WRITER, \*READER, \*READER, "perl", "-w", "program.pl"); $main::result->delete("1.0", "end"); while (my $content = <READER>) { $main::result->insert("end", $content); } } sub save_file { open(FILE, ">", $main::self->{OPEN_FILE}); my $program = $main::self->{PROGRAM_TEXT}->get("1.0", "end"); print FILE $program; close(FILE); } sub save { if ($main::self->{OPEN_FILE}) { save_file(); } else { save_as(); } } sub save_as { my $file_name = $main::self->{MAIN_WINDOW}->getSaveFile(); if ($file_name ne "") { $main::self->{OPEN_FILE} = $file_name; save_file(); display_file_name(); } } sub open_file { if ($main::self->{OPEN_FILE} = $main::self->{MAIN_WINDOW}->getOpen +File()) { open(FILE, "<", $main::self->{OPEN_FILE}); local $/; my $program = <FILE>; close(FILE); $main::self->{PROGRAM_TEXT}->delete("1.0", "end"); $main::self->{PROGRAM_TEXT}->insert("end", $program); display_file_name(); } } sub new_file { $main::self->{OPEN_FILE} = undef; $main::self->{PROGRAM_TEXT}->delete("1.0", "end"); display_file_name(); } sub display_file_name { if ($main::self->{OPEN_FILE}) { $main::self->{MAIN_WINDOW} ->configure("title", "My Porgram - $main::self->{OPEN_FILE}" +); } else { $main::self->{MAIN_WINDOW} ->configure("title", "My Porgram - Untiled"); } }

Replies are listed 'Best First'.
Re: perl IDE in perl
by belg4mit (Prior) on Feb 19, 2003 at 05:40 UTC
    You might want to take a look at ptkdb, to help with your TODO list.

    --
    I'm not belgian but I play one on TV.

Re: perl IDE in perl
by rob_au (Abbot) on Feb 19, 2003 at 11:28 UTC
    For simplicity in a Perl text editor its hard to look past this one-line wonder from hiseldl ... :-)

    perl -MTk -MTk::TextUndo -e "(tkinit)->Scrolled('TextUndo')->pack;Main +Loop"

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000001000110001"))'

Re: perl IDE in perl
by castaway (Parson) on Feb 19, 2003 at 13:09 UTC
    Nice idea!
    There might be some ideas/tips in ptked which is a little editor written with Perl-Tk..

    C.

Re: perl IDE in perl
by Tomte (Priest) on Feb 19, 2003 at 10:18 UTC

    ++ for the idea and for sharing it here, pg.
    you'll get another ++ from me, if this were possible, for using tcl/tk instead of win32 or the like.
    PerlQT might be an option, though, for a modern look on unix-flavours ;-), never liked the motif-style *shudder*

    regards,
    tomte


Re: perl IDE in perl
by hiseldl (Priest) on Feb 19, 2003 at 19:56 UTC

    Grapht is an IDE written entirely in perl. Since you are teaching perl, you may find Regex Evaluator useful too. It allows you to interactively test regexes.

    --
    hiseldl
    What time is it? It's Camel Time!