Fixing blocking.

This commit is contained in:
Sergiotarxz 2024-10-13 03:27:40 +02:00
parent fd437f84d8
commit 13da0736ba
4 changed files with 29 additions and 11 deletions

View File

@ -26,6 +26,7 @@ has port => (
has _guts_device => ( is => 'rw' );
has _tempdir => ( is => 'rw', );
has _bluetooth => ( is => 'lazy' );
sub _device($self) {
if ( !defined $self->_guts_device ) {
@ -59,10 +60,14 @@ sub lf($self) {
$self->_device->lf;
}
sub _obj($self) {
sub _build__bluetooth($self) {
my $obj = Net::Bluetooth->newsocket('RFCOMM');
$self->_try_to_connect($obj);
return $obj;
return $obj;
}
sub _obj($self) {
return $self->_bluetooth;
}
sub print($self) {
@ -73,6 +78,7 @@ sub print($self) {
my $fh = $obj->perlfh;
print $fh path( $self->_tempfile )->slurp_raw;
$fh->flush;
close $fh;
}
sub _try_to_connect($self, $obj, $retries = 3) {

View File

@ -35,13 +35,13 @@ sub image( $self, $image ) {
$self->current_image($new_current);
}
sub lf {
}
sub print($self) {
path($self->output_file)->spew_raw($self->current_image->png);
}
sub lf {
}
sub serialize($self) {
my $hash = {%$self};
$hash->{type} = 'image';

View File

@ -201,7 +201,7 @@ sub _on_run_script( $self, $script, $device, $write_to_parent, $verbose = 1 ) {
eval {
my $sub =
eval
'use v5.40.0; use strict; use warnings; use utf8; use Cairo; use Pango;'
'use v5.40.0; use strict; use warnings; use utf8; no Carp::Always; use Cairo; use Pango;'
. $script;
if ($@) {
die $@;
@ -229,7 +229,15 @@ sub _monitor_run($self) {
my $buffer = $execute_log->get_buffer;
my $begin_iter = $buffer->get_iter_at_offset(0);
my $end_iter = $buffer->get_end_iter;
my $text = <$fh>;
my $text = '';
$fh->blocking(0);
while (my $line = <$fh>) {
if (!defined $line) {
next;
}
$text .= $line;
}
return if $text =~ /^\s*$/;
$buffer->insert( $end_iter, $text, -1 );
}
@ -264,6 +272,10 @@ sub _activate($self) {
$self->_win($win);
my $box_vertical = Gtk4::Box->new( 'vertical', 0 );
my $editor = Gtk4::Source::View->new;
$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');
@ -310,7 +322,7 @@ sub ($printer) {
],
30
);
$printer->print_n_lf(4);
$printer->print_n_lf(2);
$printer->print;
}
@ -345,6 +357,8 @@ EOF
$box_editor_preview->append($editor_scroll_window);
$box_editor_preview->append($preview_scroll_window);
my $execute_log_window = Gtk4::ScrolledWindow->new;
$execute_log_window->set_vexpand(0);
$execute_log_window->set_property('height-request', 300);
my $scroll = $execute_log_window->get_vadjustment;
$self->_scroll_log_upper( $scroll->get_upper );
$scroll->signal_connect(

View File

@ -362,9 +362,7 @@ sub print($self) {
}
sub print_n_lf($self, $n) {
for (my $i = 0; $i < $n; $i++) {
$self->device->lf;
}
$self->print_text("\n" x $n, 30);
}
sub _get_size_text( $self, $cr, $layout, $font, $font_size, $text ) {