Showing posts with label Wx::Declarative. Show all posts
Showing posts with label Wx::Declarative. Show all posts

Friday, October 12, 2012

Citrus Perl

I think this isn't actually new, but Citrus Perl is a thing: a distribution of Perl specifically designed to support Wx - and to repackage itself as your standalone application.  This is a gamechanger.

If I were to finish (or quasi-finish) Wx::Declarative, then repackage a Citrus-like distribution as Decl, I could really have something pretty powerful, right out of the box.

That deserves thought. (Note: Mark Dootson's blog is here.)

Tuesday, November 15, 2011

Wx task

There's a Wx CPAN shell app that would probably be a great Decl target when I resume Wx development.

Wednesday, August 3, 2011

Shell under Wx

I really want a Perl REPL inside Decl, but in a Wx or other GUI environment, I want to be able to put it into a separate window. Until now, somehow I've managed never to be able to figure out how it's done. But there is a CPAN shell in such a Wx app. What I really want, then, is to do that, but for a generic shell. (There is also such a thing for Tk, by the way.)

In the larger scheme of things, it would be nice to be able to define the "operating environment" in some way, and pop up semantically specified things like "a shell" in a way that's appropriate to that environment. In a remote context, it could even be some kind of AJAX thing. (I know it's no longer de rigeur to call it AJAX, but hey, I'm old.)

While researching it this time, I also ran across the kitchen-sink REPL Devel::REPL, based on Moose and importing lots of stuff, and PPI, which is a Perl kind-of parser that looks pretty darned interesting.

Saturday, May 28, 2011

Rosetta Code

So there's this site Rosetta Code that shows snippets of how to do Task X in lots of different languages. I find that pretty fascinating from the semantic-programming standpoint; in a certain sense, each set of solutions encodes the same thing, the same meaning.

The link goes to "open a window"; Perl has five ways of doing it, depending on the GUI framework you're using, and I'd like to explore that parallelism in Decl.

Monday, April 12, 2010

Rebuild complete

I've been doing some kind of neat stuff with unit testing in the Wx::Declarative domain, although timing makes the tests kind of brittle - sometimes you're testing a condition before everything in the tested process has set things up, so you always have to remember to wait a little bit for applications to start, stop, etc. But Wx is working again! So there's that.

And I've been working a little more with it. It occurs to me that you could set up a runtime modification thing using the Wx facilities pretty easily - that and a command line and runtime object editor, and ... you got a lot of what makes Lisp so cool, but in Perl.

Food for thought.

Wednesday, February 17, 2010

Dialogs, fields, and magic variables

So I've obviously been spending too much time with this, but I added magic variables to Class::Declarative today, and used them for text controls in Wx.

A magic variable is one for which a handler is registered with the context. When we read or write that variable in the context, our handler is called. That means that code can get or write field contents just by referring to the field as the variable it's tied to - and you tie a field to a variable just by naming it.

So the wxPerl dialogs.pl sample is this code:

#!/usr/bin/perl
#############################################################################
## Name: samples/dialog/dialog.pl
## Purpose: Dialog wxPerl sample
## Author: Mattia Barbon
## Modified by:
## Created: 12/11/2000
## RCS-ID: $Id: dialog.pl,v 1.4 2004/10/19 20:28:13 mbarbon Exp $
## Copyright: (c) 2000 Mattia Barbon
## Licence: This program is free software; you can redistribute it and/or
## modify it under the same terms as Perl itself
#############################################################################

use Wx;

package MyApp;

use strict;
use vars qw(@ISA);

@ISA=qw(Wx::App);

use Wx qw(wxDefaultSize wxDefaultPosition);

sub OnInit {
my( $this ) = @_;

my( $dialog ) = MyDialog->new( "wxPerl dialog sample",
wxDefaultPosition,
);

$this->SetTopWindow( $dialog );

$dialog->Show( 1 );

1;
}

package MyDialog;

use strict;
use vars qw(@ISA);

@ISA=qw(Wx::Dialog);

use Wx::Event qw(EVT_CLOSE EVT_BUTTON);
use Wx qw(wxDefaultSize wxDefaultValidator);

sub new {
my( $class ) = shift;
my( $this ) = $class->SUPER::new( undef, -1, $_[0], $_[1], [250, 110] );

# $this->SetIcon( Wx::GetWxPerlIcon() );

my( $ct ) = $this->{CELSIUS} =
Wx::TextCtrl->new( $this, -1, '0', [20, 20], [100, -1] );
my( $cb ) = Wx::Button->new( $this, -1, 'Celsius', [130, 20] );
my( $ft ) = $this->{FAHRENHEIT} =
Wx::TextCtrl->new( $this, -1, '32', [20, 50], [100, -1] );
my( $fb ) = Wx::Button->new( $this, -1, 'Fahrenheit', [130, 50] );

EVT_BUTTON( $this, $cb, \&CelsiusToFahrenheit );
EVT_BUTTON( $this, $fb, \&FahrenheitToCelsius );

EVT_CLOSE( $this, \&OnClose );

$this;
}

sub CelsiusToFahrenheit {
my( $this, $event ) = @_;

$this->{FAHRENHEIT}->SetValue( ( $this->{CELSIUS}->GetValue() /
100.0 ) * 180 + 32 );
}

sub FahrenheitToCelsius {
my( $this, $event ) = @_;

$this->{CELSIUS}->SetValue( ( ( $this->{FAHRENHEIT}->GetValue()-32 ) /
180.0 ) * 100 );
}

sub OnClose {
my( $this, $event ) = @_;

$this->Destroy();
}

package main;

my( $app ) = MyApp->new();

$app->MainLoop();

# Local variables: #
# mode: cperl #
# End: #


In the Wx::Declarative framework, that becomes this:

use Class::Declarative qw(Wx::Declarative);

dialog (xsize=250, ysize=110) "Wx::Declarative dialog sample"
field celsius (size=100, x=20, y=20) "0"
button celsius (x=130, y=20) "Celsius" { $^fahrenheit = ($^celsius / 100.0) * 180 + 32; }
field fahrenheit (size=100, x=20, y=50) "32"
button fahrenheit (x=130, y=50) "Fahrenheit" { $^celsius = (($^fahrenheit - 32) / 180.0) * 100; }


And it works, as of right now.

Tuesday, February 16, 2010

Wx::Declarative back where I was

Well, I've successfully factored the Class::Declarative out of Wx::DefinedUI (which is dead, long may it live) and I'm back to having all the stuff work that I had working last week. (!)

Going forward should be way easier now, and the hard stuff is factored out and unit tested so I can't break it as easily, but I feel oddly as though nothing had happened for a week. Except, of course, Class::Declarative is on CPAN now, which is very cool indeed.

So this is what works: code/closures, events (those are the core semantics), buttons, menus, message boxes (hardcoded text only), frames, sizers, dialogs. Next up is the status bar. Then I set out into serious wilderness by subclassing a window for the frame's client. Yikes!