Refactor.

This commit is contained in:
Sergiotarxz 2024-10-13 05:02:23 +02:00
parent 13da0736ba
commit 4bd58e1763
2 changed files with 77 additions and 63 deletions

View File

@ -259,60 +259,17 @@ sub _on_preview($self) {
}
}
sub _activate($self) {
Glib::Timeout->add(
1000,
sub {
$self->_monitor_run;
return 1;
}
);
my $app = $self->_app;
my $win = Gtk4::ApplicationWindow->new($app);
$self->_win($win);
my $box_vertical = Gtk4::Box->new( 'vertical', 0 );
sub _populate_editor($self, $box_editor_preview) {
my $editor = Gtk4::Source::View->new;
$self->_editor($editor);
$editor->set_hexpand(1);
$editor->set_vexpand(1);
$editor->set_property( 'width-request', 800 );
$editor->set_insert_spaces_instead_of_tabs(1);
$editor->set_tab_width(4);
$editor->set_auto_indent(1);
$editor->set_smart_backspace(1);
my $execute_log = Gtk4::TextView->new;
my $run_button = Gtk4::Button->new_with_label('Run');
my $preview_button = Gtk4::Button->new_with_label('Preview');
Glib::Timeout->add(
1000,
sub {
$self->_on_preview;
return 1;
}
);
$preview_button->signal_connect(
'clicked',
sub {
$self->_generate_preview_file;
}
);
$self->_execute_log($execute_log);
$self->_editor($editor);
$run_button->signal_connect(
clicked => sub {
$self->_run_script( undef, 1 );
}
);
$execute_log->set_editable(0);
$execute_log->set_cursor_visible(0);
$win->set_title('Exd (Thermal Printer)');
$win->set_default_size( 1200, 900 );
$editor->set_hexpand(1);
$editor->set_vexpand(1);
$editor->set_property( 'width-request', 800 );
$execute_log->set_hexpand(1);
$execute_log->set_vexpand(1);
$editor->set_show_line_numbers(1);
my $buffer = $editor->get_buffer();
$buffer->set_text( <<'EOF', -1 );
sub ($printer) {
@ -327,35 +284,90 @@ sub ($printer) {
$printer->print;
}
EOF
my $box_editor_preview = Gtk4::Box->new( 'horizontal', 0 );
my $preview_picture = Gtk4::Picture->new;
$self->_preview_widget($preview_picture);
$self->_generate_preview_file;
$box_vertical->set_vexpand(1);
$buffer->set_language(
Gtk4::Source::LanguageManager::get_default()->get_language('perl') );
$buffer->set_highlight_syntax(1);
my $editor_scroll_window = Gtk4::ScrolledWindow->new;
$editor_scroll_window->set_halign('fill');
$editor_scroll_window->set_child($editor);
$editor->set_show_line_numbers(1);
$buffer->signal_connect(
'changed',
sub {
$self->_generate_preview_file(0);
}
);
my $editor_scroll_window = Gtk4::ScrolledWindow->new;
$editor_scroll_window->set_halign('fill');
$editor_scroll_window->set_child($editor);
$box_editor_preview->append($editor_scroll_window);
}
my $box_buttons = Gtk4::Box->new( 'horizontal', 0 );
$box_buttons->append($run_button);
$box_buttons->append($preview_button);
$box_vertical->append($box_buttons);
sub _populate_editor_and_preview($self, $box_vertical) {
my $box_editor_preview = Gtk4::Box->new( 'horizontal', 10 );
$self->_populate_editor($box_editor_preview);
$self->_populate_preview($box_editor_preview);
$box_vertical->append($box_editor_preview);
Glib::Timeout->add(
1000,
sub {
$self->_on_preview;
return 1;
}
);
}
sub _populate_preview($self, $box_editor_preview) {
my $preview_picture = Gtk4::Picture->new;
$self->_preview_widget($preview_picture);
my $preview_scroll_window = Gtk4::ScrolledWindow->new;
$preview_scroll_window->set_child($preview_picture);
$preview_scroll_window->set_property( 'width-request', 380 );
$box_editor_preview->append($editor_scroll_window);
$box_editor_preview->append($preview_scroll_window);
$self->_generate_preview_file;
}
sub _activate($self) {
Glib::Timeout->add(
1000,
sub {
$self->_monitor_run;
return 1;
}
);
my $app = $self->_app;
my $win = Gtk4::ApplicationWindow->new($app);
$self->_win($win);
my $box_vertical = Gtk4::Box->new( 'vertical', 10 );
my $execute_log = Gtk4::TextView->new;
my $run_button = Gtk4::Button->new_with_label('Run');
my $preview_button = Gtk4::Button->new_with_label('Preview');
$preview_button->signal_connect(
'clicked',
sub {
$self->_generate_preview_file;
}
);
$self->_execute_log($execute_log);
$run_button->signal_connect(
clicked => sub {
$self->_run_script( undef, 1 );
}
);
$execute_log->set_editable(0);
$execute_log->set_cursor_visible(0);
$win->set_title('Exd (Thermal Printer)');
$win->set_default_size( 1200, 900 );
$execute_log->set_hexpand(1);
$execute_log->set_vexpand(1);
$box_vertical->set_vexpand(1);
my $box_buttons = Gtk4::Box->new( 'horizontal', 10 );
$box_buttons->append($run_button);
$box_buttons->append($preview_button);
$self->_populate_editor_and_preview($box_vertical);
$box_vertical->append($box_buttons);
my $execute_log_window = Gtk4::ScrolledWindow->new;
$execute_log_window->set_vexpand(0);
$execute_log_window->set_property('height-request', 300);

View File

@ -274,6 +274,8 @@ sub _get_next_line($self, $lines) {
}
sub print_text( $self, $text, $font_size ) {
my ($none, $file_code, $line) = caller(0);
die "The bare minimum for font size is 4 at $file_code line $line" if $font_size < 4;
if ( !( ref $text ) ) {
$text = $text;
}