Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zmughal committed May 7, 2018
1 parent 15d56ea commit 2306565
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 4 deletions.
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Test::PodSpelling.stopwords[23] = subwidgets
Test::PodSpelling.stopwords[24] = subview
Test::PodSpelling.stopwords[25] = PDF
Test::PodSpelling.stopwords[26] = viewport
Test::PodSpelling.stopwords[27] = TTS

;=======================================================================

Expand Down
9 changes: 8 additions & 1 deletion lib/Renard/Curie/Component/PageDrawingArea.pm
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ method on_draw_page_cb( (InstanceOf['Cairo::Context']) $cr ) {
->set_text($page_number);
}

method on_draw_page_cb_highlight( $cr ) {
=method on_draw_page_cb_highlight
method on_draw_page_cb_highlight( (InstanceOf['Cairo::Context']) $cr )
Highlights the current sentence on the page.
=cut
method on_draw_page_cb_highlight( (InstanceOf['Cairo::Context']) $cr ) {
my @top_left = (0,0);
if( @{ $self->view_manager->current_text_page } ) {
my $sentence = $self->view_manager->current_text_page->[
Expand Down
74 changes: 72 additions & 2 deletions lib/Renard/Curie/Component/TTSWindow.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package Renard::Curie::Component::TTSWindow;
use Moo;
use Speech::Synthesis;
use Renard::Incunabula::Language::EN;
use Renard::Incunabula::Common::Types qw(InstanceOf);
use Renard::Incunabula::Common::Types qw(InstanceOf Bool Str);
use List::AllUtils qw(first);
use IO::Async::Function;

Expand All @@ -23,8 +23,14 @@ has view_manager => (
},
);

=attr playing
A C<Bool> that indicates if the TTS is playing or not.
=cut
has playing => (
is => 'rw',
isa => Bool,
default => sub { 0 },
);

Expand All @@ -36,6 +42,11 @@ has synth_function => (
is => 'lazy',
);

=method BUILD
Constructor that sets up the TTS window and its buttons.
=cut
method BUILD(@) {
$self->builder->get_object('tts-window')
->signal_connect(
Expand All @@ -58,10 +69,24 @@ method BUILD(@) {
$self->builder->get_object('tts-window')->show_all;
}

method speak( $text ) {
=method speak
method speak( (Str) $text )
Say the contents of C<$str>.
=cut
method speak( (Str) $text ) {
$self->synth->speak($text);
}

=callback on_clicked_button_play_cb
callback on_clicked_button_play_cb( $button, $self )
Callback that toggles between play and pause states.
=cut
callback on_clicked_button_play_cb( $button, $self ) {
$self->playing( ! $self->playing );
$self->builder->get_object('button-play')
Expand All @@ -73,6 +98,15 @@ callback on_clicked_button_play_cb( $button, $self ) {
$self->update;
}

=method update
method update()
Updates the TTS window.
This sets the sentence label, sentence text, and plays the text if L<playing> is true.
=cut
method update() {
return unless defined $self->view_manager->current_document;
my $text = $self->view_manager->current_text_page;
Expand Down Expand Up @@ -107,19 +141,47 @@ method update() {
}
}

=method num_of_sentences_on_page
method num_of_sentences_on_page()
Retrieves the number of sentences on the page.
=cut
method num_of_sentences_on_page() {
my $text = $self->view_manager->current_text_page;
return @{ $text };
}

=callback on_clicked_button_previous_cb
callback on_clicked_button_previous_cb( $button, $self )
Calls L<choose_previous_sentence>.
=cut
callback on_clicked_button_previous_cb( $button, $self ) {
$self->choose_previous_sentence;
}

=callback on_clicked_button_next_cb
callback on_clicked_button_next_cb( $button, $self )
Calls L<choose_next_sentence>.
=cut
callback on_clicked_button_next_cb( $button, $self ) {
$self->choose_next_sentence;
}

=method choose_previous_sentence
method choose_previous_sentence()
Move to the previous sentence or the last sentence on the previous page.
=cut
method choose_previous_sentence() {
my $v = $self->view;
my $vm = $self->view_manager;
Expand All @@ -135,6 +197,14 @@ method choose_previous_sentence() {
$self->update;
}

=method choose_next_sentence
method choose_next_sentence()
Move to the next sentence on this page or to the first sentence on the next
page.
=cut
method choose_next_sentence() {
my $v = $self->view;
my $vm = $self->view_manager;
Expand Down
2 changes: 1 addition & 1 deletion lib/Renard/Curie/ViewModel/ViewManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ has current_view => (

=attr current_sentence_number
TODO
Stores the current sentence number index (0-based): C<PositiveOrZeroInt>.
=cut
has current_sentence_number => (
Expand Down
18 changes: 18 additions & 0 deletions lib/Renard/Curie/ViewModel/ViewManager/Role/TextPage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ use Moo::Role;
use Renard::Incunabula::Language::EN;
use Scalar::Util qw(refaddr);

=method current_text_page
method current_text_page()
Returns a C<HashRef> of sentences on the page.
Keys:
=for :list
* C<sentence>: C<String::Tagged> of the sentence substring
* C<bbox>: C<ArrayRef> of bounding boxes
* C<extent>: extent
* C<spans>: C<ArrayRef> of font spans
* C<first_char>: first character information
* C<last_char>: last character information
=cut
method current_text_page() {
return [] unless $self->current_document->can('get_textual_page');

Expand Down

0 comments on commit 2306565

Please sign in to comment.