diff options
| author | Maarten Vanraes <alien@mageia.org> | 2016-05-08 00:34:35 +0200 | 
|---|---|---|
| committer | Maarten Vanraes <alien@mageia.org> | 2016-05-14 09:25:24 +0200 | 
| commit | 711d8e99e724adefa0d8cd0079e2b371c8accf2d (patch) | |
| tree | b0415bff4a644096716e913d06aa1d8db5aaad85 /lib | |
| parent | 217e666629249458fd0f3e40787aab89f074045a (diff) | |
| download | manatools-711d8e99e724adefa0d8cd0079e2b371c8accf2d.tar manatools-711d8e99e724adefa0d8cd0079e2b371c8accf2d.tar.gz manatools-711d8e99e724adefa0d8cd0079e2b371c8accf2d.tar.bz2 manatools-711d8e99e724adefa0d8cd0079e2b371c8accf2d.tar.xz manatools-711d8e99e724adefa0d8cd0079e2b371c8accf2d.zip | |
add an ExtButtonBox widget and debug logs
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ManaTools/Module/Disk.pm | 115 | ||||
| -rw-r--r-- | lib/ManaTools/Shared/GUI/ExtButtonBox.pm | 213 | ||||
| -rw-r--r-- | lib/ManaTools/Shared/GUI/ExtWidget.pm | 23 | 
3 files changed, 345 insertions, 6 deletions
| diff --git a/lib/ManaTools/Module/Disk.pm b/lib/ManaTools/Module/Disk.pm index a5228a64..396fdbec 100644 --- a/lib/ManaTools/Module/Disk.pm +++ b/lib/ManaTools/Module/Disk.pm @@ -65,6 +65,7 @@ use ManaTools::Shared::GUI::ReplacePoint;  use ManaTools::Shared::GUI::Properties;  use ManaTools::Shared::GUI::ExtList;  use ManaTools::Shared::GUI::ExtTab; +use ManaTools::Shared::GUI::ExtButtonBox;  use File::ShareDir ':ALL';  use ManaTools::Shared::Locales;  use ManaTools::Shared::disk_backend; @@ -213,6 +214,7 @@ our $VERSION = '1.0.1';  sub start {      my $self = shift; +    $self->logger()->trace(1);      $self->_adminDiskPanel();  } @@ -305,6 +307,109 @@ sub _rebuildList {      return $list;  } +sub _rebuildButtonBox { +    my $self = shift; +    my $eventHandler = shift; +    my $container = shift; +    my $parent = shift; +    my @items = sort {$a->prop('start') <=> $b->prop('start')} @_; +    my $minsize = 2;        # min DISPLAY size +    my $maxparts = 128;     # max GPT partitions +    my $boundary = 34;      # GPT sector boundaries +    my $alignment = 2048;   # current Disk partition alignment convention +    $maxparts = 8; # TODO: fix it so that the actions don't disappear when this is removed!!!!!!!! +    my $offset = $boundary; +    my $totalWeight = $maxparts * $minsize; +    # TODO: dependant upon disk types, etc... +    $offset = $alignment; +    my $totalWidth = $parent->prop('size') - $boundary - $offset; # offset at beginning, boundary at end +    my $start = $offset; +    my $buttonWidths = []; +    my $count = 0; +    my $currentWeight = 0; +    $self->D("$self: make a new ExtButtonBox inside $container with eventHandler $eventHandler"); +    my $buttonbox = ManaTools::Shared::GUI::ExtButtonBox->new(eventHandler => $eventHandler, parentWidget => $container, buttonWidths => $buttonWidths); +    for my $i (@items) { +        # handle overlaps +        $start = $i->prop('start') if ($start > $i->prop('start')); +        # fill in gaps +        if ($start < $i->prop('start')) { +            $self->D("$self: add a gap SelectorItem to $buttonbox"); +            my $item = $buttonbox->addSelectorItem('', { prop => sub { my $prop = shift; return $start if ($prop eq 'start'); return $i->prop('start') - $start if ($prop eq 'sectors'); return 0 if ($prop eq 'size'); return undef; } }, sub { +                my $self = shift; +                my $parent = shift; +                my $backendItem = shift; +                my $dialog = $self->parentDialog(); +                my $factory = $dialog->factory(); +                my $vbox = $factory->createVBox($parent); +                $dialog->D("$self: build the gap SelectorItem"); +                $factory->createHStretch($vbox); +                $factory->createVStretch($vbox); +            }); +            my $width = int(($i->prop('start') - $start) * $totalWeight / $totalWidth); +            if ($width < $minsize) { +                $width = $minsize; +            } +            $buttonWidths->[$count] = $width; +            $currentWeight = $currentWeight + $buttonWidths->[$count]; +            $count = $count + 1; +            $start = $i->prop('start'); +        } +        # get part type (path) +        my $label = ''; +        my @p = $i->findin(); +        if (scalar(@p) > 0) { +            $label = join ',', map { ($_->type() eq 'Mount') && $_->prop('path') || $_->type() } @p; +        } +        $self->D("$self: add a button SelectorItem to $buttonbox with label $label and backend $i"); +        my $item = $buttonbox->addSelectorItem($label, $i, sub { +            my $self = shift; +            my $parent = shift; +            my $backendItem = shift; +            my $dialog = $self->parentDialog(); +            $dialog->D("$self: build the button SelectorItem with backend $backendItem"); +            my $factory = $dialog->factory(); +            my $vbox = $factory->createVBox($parent); +            $self->addWidget($backendItem->label() .': button 1', $factory->createPushButton($vbox, $backendItem->label() .': button 1'), sub { my $backendItem = shift; print STDERR "backendItem: ". $backendItem->label() ."::button1\n"; }); +            $self->addWidget($backendItem->label() .': button 2', $factory->createPushButton($vbox, $backendItem->label() .': button 2'), sub { my $backendItem = shift; print STDERR "backendItem: ". $backendItem->label() ."::button2\n"; }); +            $self->addWidget($backendItem->label() .': button 3', $factory->createPushButton($vbox, $backendItem->label() .': button 3'), sub { my $backendItem = shift; print STDERR "backendItem: ". $backendItem->label() ."::button3\n"; }); +            $factory->createHStretch($vbox); +            $factory->createVStretch($vbox); +        }); +        my $backendItem = $item->backend(); +        my $width = $backendItem->prop('sectors') * $totalWeight / $totalWidth; +        if ($width < $minsize) { +            $width = $minsize; +        } +        $buttonWidths->[$count] = int($width); +        $currentWeight = $currentWeight + $buttonWidths->[$count]; +        $count = $count + 1; +        $start = $start + $backendItem->prop('sectors'); +    } +    # fill in gaps +    if ($start < ($totalWidth + $offset)) { +        my $item = $buttonbox->addSelectorItem('', { prop => sub { my $prop = shift; return $start if ($prop eq 'start'); return $totalWidth + $offset - $start if ($prop eq 'sectors'); return 0 if ($prop eq 'size'); return undef; } }, sub { +            my $self = shift; +            my $parent = shift; +            my $backendItem = shift; +            my $dialog = $self->parentDialog(); +            $dialog->D("$self: build the gap SelectorItem (at the end)"); +            my $factory = $dialog->factory(); +            my $vbox = $factory->createVBox($parent); +            $factory->createHStretch($vbox); +            $factory->createVStretch($vbox); +        }); +        my $width = $totalWeight - $currentWeight; +        if ($width < $minsize) { +            $width = $minsize; +        } +        $buttonWidths->[$count] = $width; +    } +    $buttonbox->finishedSelectorItems(); +    $self->D("$self: finished $buttonbox SelectorItems"); +    return $buttonbox; +} +  sub _rebuildTree {      my $self = shift;      my $eventHandler = shift; @@ -324,6 +429,9 @@ sub _rebuildItems {          if ($i->{type} eq 'tab') {              return $self->_rebuildTab($eventHandler, $container, $i->{io}, @{$i->{items}});          } +        if ($i->{type} eq 'buttonbox') { +            return $self->_rebuildButtonBox($eventHandler, $container, $i->{io}, @{$i->{items}}); +        }          if ($i->{type} eq 'list') {              return $self->_rebuildList($eventHandler, $container, $i->{io}, @{$i->{items}});          } @@ -352,10 +460,7 @@ sub _expandItem {      # merge all outs from these Parts      for my $p (@items) { -        if ($p->type() eq 'Disks') { -            $type = 'tab'; -        } -        push @{$infos}, {io => $io, part=> $p, type => $type, items => [sort {$a->label() cmp $b->label()} $p->out_list()]}; +        push @{$infos}, {io => $io, part => $p, type => ( $p->type() eq 'Disks' ? 'tab' : $p->type() eq 'PartitionTable' ? 'buttonbox' : $type ), items => [sort {$a->label() cmp $b->label()} $p->out_list()]};      }      return $infos;  } @@ -553,7 +658,9 @@ sub _adminDiskPanel {          },      )); +    $self->D("$self: call mainDialog");      $self->mainDialog->call(); +    $self->D("$self: done calling mainDialog");      return 1;  } diff --git a/lib/ManaTools/Shared/GUI/ExtButtonBox.pm b/lib/ManaTools/Shared/GUI/ExtButtonBox.pm new file mode 100644 index 00000000..a4b6206e --- /dev/null +++ b/lib/ManaTools/Shared/GUI/ExtButtonBox.pm @@ -0,0 +1,213 @@ +# vim: set et ts=4 sw=4: +package ManaTools::Shared::GUI::ExtButtonBox; +#============================================================= -*-perl-*- + +=head1 NAME + +ManaTools::Shared::GUI::ExtButtonBox - Class to manage a yui YSelectionBox properly + +=head1 SYNOPSIS + +use ManaTools::Shared::GUI::ExtButtonBox; + +my $extlist = ManaTools::Shared::GUI::ExtButtonBox->new(name => "ButtonBox1", eventHandler => $dialog, parentWidget => $widget, callback => { my $self = shift; my $yevent = shift; my $backenditem = $_; ... }); + +$extlist->addSelectorItem("Label 1", $backenditem1, sub { +    my ($self, $parent, $backendItem) = @_; +    my $dialog = $self->parentDialog(); +    my $factory = $dialog->factory(); +    my $vbox = $factory->createVBox($parent); +    my $button1 = $self->addWidget($backendItem->label() .'_button1', $factory->createPushButton('Button 1', $vbox), sub { +        my $self = shift; +        my $yevent = shift; +        my $backendItem = shift; +        my $list = $self->eventHandler(); +        ... +    }, $backendItem); +    my $button2 = $self->addWidget($backendItem->label() .'_button2', $factory->createPushButton('Button 2', $vbox), sub {...}, $backendItem); +    ... +}); +$extlist->addSelectorItem("Label 2", $backenditem2, sub { my ($self, $parent, $backendItem) = @_; my $factory = $self->parentDialog()->factory(); my $vbox = $factory->createVBox($parent); ... } ); +$extlist->addSelectorItem("Label 3", $backenditem3, sub { my ($self, $parent, $backendItem) = @_; my $factory = $self->parentDialog()->factory(); my $vbox = $factory->createVBox($parent); ... } ); +$extlist->addSelectorItem("Label 4", $backenditem4, sub { my ($self, $parent, $backendItem) = @_; my $factory = $self->parentDialog()->factory(); my $vbox = $factory->createVBox($parent); ... } ); +$extlist->finishedSelectorItems(); + + +=head1 DESCRIPTION + +This class wraps YSelectionBox with backend items to handle + + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command: + +perldoc ManaTools::Shared::GUI::ExtButtonBox + +=head1 SEE ALSO + +yui::YSelectionBox + +=head1 AUTHOR + +Maarten Vanraes <alien@rmail.be> + +=head1 COPYRIGHT and LICENSE + +Copyright (C) 2015-2016, Maarten Vanraes. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2, as +published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +=head1 FUNCTIONS + +=cut + + +use Moose; +use diagnostics; +use utf8; + +extends 'ManaTools::Shared::GUI::ExtWidget'; + +use ManaTools::Shared::GUI::ButtonBoxSelection; + +has '+basename' => ( +    default => 'ExtButtonBox', +); + +has '+itemEventType' => ( +    default => $yui::YEvent::WidgetEvent, +); + +has 'buttonWidths' => ( +    is => 'ro', +    isa => 'ArrayRef[Int]', +    required => 1, +); + +use yui; + +#============================================================= + +=head2 new + +=head3 INPUT + +    hash ref containing +        name:               a name for the widget to add event to the eventHandler +        eventHandler:       the parent that does eventHandlerRole +        parentWidget:       the parent widget +        callback:           optional parameter to execute a callback when an item has changed + + +=head3 DESCRIPTION + +    new is inherited from ExtWidget, to create a ExtButtonBox object + +=cut + +#============================================================= + +=head2 _selectorItem + +=head3 INPUT + +    $self: this object +    $yevent: yui::YEvent + +=head3 OUTPUT + +    YItem: the selected item + +=head3 DESCRIPTION + +    returns the items that is selected when an event fires + +=cut + +#============================================================= +sub _selectorItem { +    my $self = shift; +    my $yevent = shift; +    my $buttonbox = $self->selector(); +    return $buttonbox->selectedItem(); +} + +#============================================================= + +=head2 _buildSelectorWidget + +=head3 INPUT + +    $self: this object + +=head3 OUTPUT + +    ($selector, $parent): $selector is the YSelectionWidget; $parent is the replacepoint's parent + +=head3 DESCRIPTION + +    builds the YSelectionBox widget + +=cut + +#============================================================= +override('_buildSelectorWidget', sub { +    my $self = shift; +    my $parentWidget = shift; +    my $dialog = $self->parentDialog(); +    my $factory = $dialog->factory(); + +    # create the buttonbox +    my $vbox = $factory->createVBox($parentWidget); +    $dialog->D("$self: make buttonbox in $vbox"); +    my $bb = ManaTools::Shared::GUI::ButtonBoxSelection->new(parentWidget => $vbox, eventHandler => $self->eventHandler(), buttonWidths => $self->buttonWidths()); +    # force visualising the container first +    $dialog->D("$self: force visualization, by accessing $bb container()"); +    $bb->container(); +    return ($bb, $vbox); +}); + +#============================================================= + +=head2 _finishSelectorWidget + +=head3 INPUT + +    $self: this object + +=head3 DESCRIPTION + +    finalizes the selection widget, needs to be overridden in subclasses + +=cut + +#============================================================= +override('_finishSelectorWidget', sub { +    my $self = shift; +    my $selectorWidget = shift; +    my $dialog = $self->parentDialog(); +    $dialog->D("$self: setting Weight distribution to ". $selectorWidget->replacepoint()->container() ." & ". $self->{replacepoint}->container()); +    # set weight for both replacepoints +    $selectorWidget->replacepoint()->container()->setWeight(1, 3); +    $self->{replacepoint}->container()->setWeight(1, 15); +}); + +#============================================================= + +no Moose; +__PACKAGE__->meta->make_immutable; + + +1; diff --git a/lib/ManaTools/Shared/GUI/ExtWidget.pm b/lib/ManaTools/Shared/GUI/ExtWidget.pm index 43c00394..f00b2701 100644 --- a/lib/ManaTools/Shared/GUI/ExtWidget.pm +++ b/lib/ManaTools/Shared/GUI/ExtWidget.pm @@ -160,7 +160,7 @@ has 'replacepoint' => (  has 'selector' => (      is => 'ro', -    does => 'yui::YWidget', +#    does => 'ManaTools::Shared::GUI::SelectionWidgetRole|yui::YSelectionWidget',      init_arg => undef,      lazy => 1,      builder => 'buildSelectionWidget', @@ -247,12 +247,14 @@ sub _finishSelectorWidget {  #=============================================================  sub buildSelectionWidget {      my $self = shift; - +    my $dialog = $self->parentDialog(); +    $dialog->D("$self: first _buildSelectorWidget in ". $self->parentWidget());      # this builds the actual widget in subclasses      my ($selectorWidget, $parentWidget) = $self->_buildSelectorWidget($self->parentWidget());      # create a replacepoint on the selectionWidget      $self->{replacepoint} = ManaTools::Shared::GUI::ReplacePoint->new(parentWidget => $parentWidget); +    $dialog->D("$self: need replacepoint ". $self->{replacepoint} ." in parent $parentWidget");      # because this Event's processEvent also takes care of the replacepoints      # processEvents, it means we cannot set the replacepoint's (being an @@ -265,6 +267,7 @@ sub buildSelectionWidget {      # don't add any children right away      $self->{replacepoint}->finished(); +    $dialog->D("$self: return selectorWidget $selectorWidget");      return $selectorWidget;  } @@ -373,10 +376,13 @@ sub addSelectorItem {      my $label = shift;      my $backendItem = shift;      my $buildWidget = shift; +    my $dialog = $self->parentDialog();      my $items = $self->items();      my $item = ManaTools::Shared::GUI::ExtWidget::Item->new(backend => $backendItem, builder => $buildWidget); +    $dialog->D("$self: new item: $item");      $item->setLabel($label);      push @{$items}, $item; +    $dialog->D("$self: add item $item to collection ". $self->itemcollection());      $item->addToCollection($self->itemcollection());      if (scalar(@{$items}) == 1) {          $self->lastItem($item); @@ -431,13 +437,16 @@ sub buildSelectorItem {      my $item = shift;      my $replacepoint = $self->replacepoint();      my $container = $replacepoint->container(); +    my $dialog = $self->parentDialog();      # clear out any previous children/events      $replacepoint->clear(); +    $dialog->D("$self: call builder for item $item in $container");      # build item's widgetbuilder      my $builder = $item->builder();      $builder->($self, $container, $item->backend()) if (defined $builder); +    $dialog->D("$self: done building, now finish the replacepoint $replacepoint");      # finished with replacepoint children      $replacepoint->finished(); @@ -461,9 +470,11 @@ sub buildSelectorItem {  sub clearSelectorItems {      my $self = shift;      my $items = $self->items(); +    my $dialog = $self->parentDialog();      # remove all events before deleting all items      $self->clearEvents(); +    $dialog->D("$self: cleared events");      for (my $i = 0; $i < scalar(@{$items}); $i = $i + 1) {          delete $items->[$i]; @@ -487,22 +498,30 @@ sub clearSelectorItems {  #=============================================================  sub finishedSelectorItems {      my $self = shift; +    my $dialog = $self->parentDialog(); +    $dialog->D("$self: lazy init selector if required.");      my $selector = $self->selector(); +    $dialog->D("$self: clear selector so we can add the items."); +    $dialog->D("$self: clear selector $selector with deleteAllItems.");      # remove all Items before adding      $selector->deleteAllItems(); +    $dialog->D("$self: addItems ". $self->itemcollection ." to selector $selector.");      # add items from collection      $selector->addItems($self->itemcollection);      # set last item to know the active item      my $item = $self->lastItem(); +    $dialog->D("$self: lastItem is $item");      # show the current one if there is one +    $dialog->D("$self: start buildSelectorItem($item)");      $self->buildSelectorItem($item) if defined($item);      # create a new itemcollection for adding new items      $self->itemcollection(new yui::YItemCollection()); +    $dialog->D("$self: new collection: ". $self->itemcollection);  }  #============================================================= | 
