]> Dogcows Code - chaz/homebank/blob - plugins/hello.pl
add plugin engine (supports C and Perl plugins)
[chaz/homebank] / plugins / hello.pl
1
2 # NAME: Hello World
3 # VERSION: 0.01
4 # ABSTRACT: This is the "hello world" of HomeBank plugins.
5 # AUTHOR: Charles McGarvey <chazmcgarvey@brokenzipper.com>
6 # WEBSITE: http://acme.tld/
7 # (These comments are read, before the plugin is executed, to provide some
8 # information to HomeBank and the user about what this plugin is.)
9
10 eval { HomeBank->version } or die "Cannot run outside of HomeBank";
11
12 use warnings;
13 use strict;
14
15 use Scalar::Util qw/weaken/;
16
17 #use Moose;
18
19 #has "cool_beans",
20 #is => 'rw',
21 #isa => 'Str',
22 #lazy => 1,
23 #default => "Booya!!!";
24
25
26 our $counter = 0;
27 our $temp;
28
29 my $ACC;
30
31 sub new {
32 my $class = shift;
33 my $self = $class->SUPER::new(@_);
34
35 $self->on(account_inserted => sub {
36 my $acc = shift;
37 print "account inserted: ", Dumper($acc);
38 print "account name is ", $acc->name, " and balance is ", $acc->bank_balance, "\n";
39 #$acc->name("FOOOOBAR!");
40 if ($acc->name eq 'Vacation') {
41 $acc->remove;
42 $ACC = $acc;
43 }
44 print Dumper($acc->is_inserted);
45 if ($acc->is_inserted) {
46 print "IT IS INSERTED\n";
47 } else {
48 print "not inserted\n";
49 }
50 print Dumper($acc->transactions);
51 });
52
53 #print $self->cool_beans, "\n";
54 #$self->cool_beans(123);
55 #print $self->cool_beans, "\n";
56
57 $self->create_menuitem;
58
59 $self;
60 }
61
62 sub on_create_main_window {
63 my $self = shift;
64 my $window = shift;
65
66 if (!$window) {
67 require Gtk2;
68 $window = HomeBank->main_window;
69 }
70
71 Dump($window);
72 print Dumper($window);
73 $window->set_title("foo bar baz");
74 print $window->get_title, "\n";
75
76 HomeBank->hook("my_hook", $window);
77
78 $self->create_menuitem;
79 }
80
81 my $test_win;
82
83 sub on_test {
84 my $self = shift;
85 require Gtk2;
86
87 my $window = Gtk2::Window->new('toplevel');
88 use Devel::Peek;
89 Dump($window);
90 print Dumper($window);
91 $window->set_title("Hello World");
92 #$window->signal_connect(delete_event => sub { Gtk2->main_quit });
93 $window->signal_connect(delete_event => sub { undef $test_win });
94
95 my $button = Gtk2::Button->new('Click Me!');
96 Dump($button);
97 print Dumper($button);
98 $button->signal_connect(clicked => sub {
99 print "Hello Gtk2-Perl: $counter (perl plugin: $self)\n";
100 $counter++;
101 #if ($temp->is_inserted) {
102 #print "$temp is inserted\n";
103 #} else {
104 #print "$temp is NOT inserted\n";
105 #}
106 #if ($counter == 5) {
107 #$temp = undef;
108 #}
109 my $acc = HomeBank::Account->get(rand(10));
110 print "Changin account named ", $acc->name, " to ", $acc->name($acc), "\n";
111 HomeBank->main_window->queue_draw;
112
113 });
114 $window->add($button);
115
116 $window->show_all;
117 $test_win = $window;
118
119 weaken $self;
120 }
121
122 sub on_enter_main_loop {
123 my $self = shift;
124
125 use Data::Dumper;
126 print Dumper(\@_);
127 my $t = HomeBank::Transaction->new;
128 print "Transaction:::::::: $t: ", $t->amount, "\n";
129
130 $temp = HomeBank::Account->get(7);
131 print "retained account: ", $temp->name, "\n";
132
133 #require Gtk2;
134 #
135 my $txn = HomeBank::Transaction->new;
136 $txn->amount(12.3456);
137 print Dumper($txn), $txn->amount, "\n";
138 #$txn->open;
139
140 my @ret = HomeBank->hook("my_hook", @_, $temp, [qw/foo bar baz/, $txn], { asf => 42, quux => \1, meh => HomeBank->main_window });
141 #my @ret = HomeBank->hook("my_hook", @_, HomeBank->main_window, {
142 #foo => 'bar', baz => 42
143 #});
144 print Dumper(\@ret);
145
146 print "adding back account...\n";
147 $ACC->name("vacation with a different name");
148 $ACC->insert;
149 HomeBank::Account->compute_balances;
150 print "account name is ", $ACC->name, " and balance is ", $ACC->balance, "\n";
151 print Dumper($ACC->transactions);
152
153 my $cloned = $ACC->clone;
154 $cloned->name("vacation copy");
155 $cloned->insert;
156 #my $asdf = $cloned->open;
157 #$asdf->set_title("this is a new friggin account");
158
159 #my $z = HomeBank::Account->get_by_name('Checking');
160 for my $xc (HomeBank::File->transactions) {
161 use DateTime;
162 my $num = $xc->date;
163 my $date = DateTime->new($xc->date)->datetime;
164 print "transaction of amount: ", $xc->amount, "\t", $xc->wording, ", ", $xc->info, ", $num, $date\n";
165 }
166
167 HomeBank::File->owner('Billy Murphy');
168 #HomeBank::File->anonymize;
169 print HomeBank::File->owner, "\n";
170
171 HomeBank::File->baz($ACC);
172 }
173
174 sub on_deep_hook_recursion {
175 my $self = shift;
176 my $level = shift;
177 print STDERR "recursion is too deep ($level)\n";
178 exit -2;
179 }
180
181 sub on_my_hook {
182 my $self = shift;
183 print "This is MY HOOK!!!!!!\n";
184 print Dumper(\@_);
185
186 print Dumper($_[2]);
187 Dump($_[2]);
188 if ($_[2]) {
189 print "meh\n";
190 }
191 if ($_[2]->isa('HomeBank::Boolean')) {
192 print "it is a home;;boolean\n";
193 }
194 if ($_[2]->isa('Types::Serialiser::Boolean')) {
195 print "it is a types serialiser thingy\n";
196 }
197 if ($_[2]->isa('HomeBank::BooleanBase')) {
198 print "it is a base bool\n";
199 }
200
201 my $win = $_[6];
202 if ($win && ref($win) eq 'HASH') {
203 my $w = $win->{meh};
204 if ($w) {
205 $w->set_title("this is MY HOOK setting a window title");
206 }
207 }
208 #print Dumper($acc);
209 #print "transferred account: ", $acc->name, "\n";
210
211 #my $fff = HomeBank::File->foo({foo => 'asdf', bar => 123456789});
212 my $fff = HomeBank::File->meh([qw/hello this is a test 82/, \1, {foo => 'bar'}, 48]);
213 print Dumper($fff);
214
215 print "my hook done\n";
216 }
217
218 sub on_unhandled {
219 my ($self, $hook) = @_;
220 warn "Unhandled hook '$hook'\n";
221 #HomeBank->warn($hook, 'Hook not handled.');
222 }
223
224 sub on_main_window_disposal {
225 my $self = shift;
226 print "main window disposed so forgetting about merge id et al.\n";
227 delete $self->{merge_id};
228 delete $self->{action_group};
229 }
230
231 sub DESTROY {
232 my $self = shift;
233 print "DESTROYING HELLO WORLD!!!!!!\n";
234 if ($test_win) {
235 print "there is a test_win...\n";
236 }
237 $test_win->destroy if $test_win;
238
239 $self->destroy_menuitem;
240 }
241
242 sub destroy_menuitem {
243 my $self = shift;
244
245 return unless $self->{merge_id};
246
247 my $ui_manager = HomeBank->main_ui_manager;
248 $ui_manager->remove_action_group($self->{action_group});
249 $ui_manager->remove_ui($self->{merge_id});
250 }
251
252 sub create_menuitem {
253 my $self = shift;
254
255 return if $self->{merge_id};
256
257 require Gtk2;
258
259 my $ui_manager = HomeBank->main_ui_manager;
260 print Dumper($ui_manager);
261 return unless $ui_manager;
262
263 $self->{merge_id} = $ui_manager->new_merge_id;
264 $self->{action_group} = Gtk2::ActionGroup->new('HelloActionGroup');
265
266 my $action = Gtk2::Action->new(name => 'HelloPlugin', label => 'Booyah!', stock_id => 'prf-plugins', tooltip => 'blaaaargh');
267 $action->signal_connect(activate => sub { print "hello!!!!!!!!\n" });
268 $self->{action_group}->add_action($action);
269
270 $ui_manager->insert_action_group($self->{action_group}, -1);
271 $ui_manager->add_ui($self->{merge_id}, 'ui/MenuBar/PluginMenu', 'HelloPlugin', 'HelloPlugin', 'auto', '');
272 #$self->{merge_id} = $ui_manager->new_merge_id;
273 $ui_manager->add_ui($self->{merge_id}, 'ui/ToolBar', 'HelloPluginTool', 'HelloPlugin', 'auto', '');
274 }
275
276 sub EXECUTE {
277 print "the perl plugin is being configured.....\n";
278 HomeBank->info("Hello Prefs", "YEEEEEARGGH!!!!!");
279 }
280
281 #__PACKAGE__->meta->make_immutable;
This page took 0.052813 seconds and 4 git commands to generate.