Changeset 6494


Ignore:
Timestamp:
Jun 9, 2010, 8:49:00 AM (14 years ago)
Author:
ronosman
Message:

New progress dialog implementation using virtual listctrl. Fix scrolling issues with Wx::Gauge.

Location:
extensions/pLoader/trunk/src/Uploader/GUI
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/pLoader/trunk/src/Uploader/GUI/Frame.pm

    r6426 r6494  
    706706                progress_column => 2,
    707707                cancel_cbk => sub { wxTheApp->cancel_queues },
     708                column_item_data => {
     709                    0 => sub { my ( $image ) = @_; $image->{site_name} },
     710                    1 => sub { my ( $image ) = @_; 1+$image->{add_rank} },
     711                    2 => sub { my ( $image ) = @_; sprintf("%u", $image->{progress}) },
     712                    3 => sub { my ( $image ) = @_; $image->{status} },
     713                    4 => sub { my ( $image ) = @_; $image->{file} },
     714                },
    708715            }
    709716        )
  • extensions/pLoader/trunk/src/Uploader/GUI/ImageProgressDlg.pm

    r6426 r6494  
    8585    );
    8686
     87    $self->listctrl->column_item_data(
     88        $params->{column_item_data}
     89    );
     90
    8791    Wx::Event::EVT_BUTTON( $self, $main::ID_UPLOAD_CANCEL, \&on_cancel );
    8892    Wx::Event::EVT_CLOSE( $self, \&on_close );
     
    108112    my ( $self, $images ) = @_;
    109113
    110     map {
    111         my $item = $self->listctrl->InsertStringItem(
    112             $self->listctrl->GetItemCount,
    113             $_->{site_name}
    114         );
    115         $self->listctrl->SetItemProgressBar($item);
    116         $self->update_image_item($_);
    117     }@$images;
    118 
     114    $self->listctrl->add_progress_items($images);
    119115}
    120116
     
    123119    my ( $self, $image ) = @_;
    124120
    125     my $index = $image->{add_rank};
    126 
    127     $self->listctrl->SetItem(
    128         $index,
    129         1,
    130         1+$image->{add_rank}
    131     );
    132 
    133 
    134     $self->listctrl->SetItemProgressValue(
    135         $index,
    136         $image->{progress}
    137     );
    138 
    139     $self->listctrl->SetItem(
    140         $index,
    141         3,
    142         $image->{status}
    143     );
    144 
    145     $self->listctrl->SetItem(
    146         $index,
    147         4,
    148         $image->{file}
    149     );
    150 
     121    my $item = $image->{add_rank};
     122    $self->listctrl->replace_item_data($item, $image);
    151123}
    152124
     
    168140    $event->Skip;
    169141}
    170 
     142 
    171143
    172144sub on_close {
  • extensions/pLoader/trunk/src/Uploader/GUI/Layout/ImageProgress.pm

    r6426 r6494  
    88use Wx qw( wxVERTICAL wxHORIZONTAL wxALL wxLEFT wxRIGHT wxTOP wxBOTTOM wxCENTRE wxGROW );
    99use Wx qw( wxALIGN_RIGHT wxALIGN_BOTTOM wxALIGN_CENTER wxALIGN_CENTER_VERTICAL wxALIGN_CENTER_HORIZONTAL wxALIGN_LEFT);
    10 use Wx qw( wxLI_HORIZONTAL wxLC_REPORT wxSUNKEN_BORDER );
     10use Wx qw( wxLI_HORIZONTAL wxLC_REPORT wxSUNKEN_BORDER wxLC_VIRTUAL);
    1111use Wx::Locale qw/:default/;
    1212
     
    2727
    2828    $parent_wnd->listctrl(
    29         Uploader::GUI::ListCtrlProgress->new( $panel, $main::ID_LISTCTRL, wxDefaultPosition, [600, 300], wxLC_REPORT )
     29        Uploader::GUI::ListCtrlProgress->new(
     30            $panel,
     31            $main::ID_LISTCTRL,
     32            wxDefaultPosition, [600, 400],
     33            wxLC_REPORT|wxLC_VIRTUAL
     34        )
    3035    );
    3136
  • extensions/pLoader/trunk/src/Uploader/GUI/ListCtrlProgress.pm

    r6427 r6494  
    1111        progress_column
    1212        progress_bars
     13        items
     14        column_item_data
     15        item_data
    1316    /
    1417);
     
    2326
    2427    $self->progress_bars([]);
     28    $self->item_data([]);
    2529
    2630    Wx::Event::EVT_PAINT(
     
    3438    );
    3539
     40
    3641    $self;
    3742}
    3843
    39 sub SetItemProgressBar {
    40     my ( $self, $item ) = @_;
    4144
    42     return unless defined $self->progress_column;
    43    
    44     my $rect = $self->GetSubItemRect($item, $self->progress_column);
     45sub replace_item_data {
     46    my ( $self, $item, $data ) = @_;
    4547
    46     $self->progress_bars->[$item]= Wx::Gauge->new(
     48    $self->item_data->[$item] = $data;
     49    $self->progress_bars->[$item] ||= Wx::Gauge->new(
    4750        $self,
    4851        -1,
    4952        100,
    50         $rect->GetPosition,
    51         $rect->GetSize,
     53        wxDefaultPosition,
     54        wxDefaultSize,
    5255        Wx::wxGA_SMOOTH
    5356    );
     57
     58    my $progress_bar = $self->progress_bars->[$item];
     59    $self->paint_progress_bar($item, $progress_bar);
     60    $self->RefreshItem($item);
    5461}
    5562
    56 sub GetSubItemRect {
     63
     64sub add_progress_items {
     65    my ( $self, $added_items ) = @_;
     66
     67    push @{$self->item_data}, @{$added_items};
     68
     69    $self->SetItemCount(scalar @{$self->item_data});
     70}
     71
     72
     73sub OnGetItemText {
     74    my ( $self, $item, $column ) = @_;
     75
     76    my $value = $self->column_item_data->{$column}->(
     77        $self->item_data->[$item]
     78    );
     79
     80    # progress column
     81    if( $column == $self->progress_column ){
     82        $self->set_item_progress_value(
     83            $item,
     84            $value
     85        );
     86        $value = '';
     87    }
     88
     89    return $value;
     90}
     91
     92
     93
     94sub get_item_progress_rect {
    5795    my ( $self, $item, $subitem ) = @_;
    5896
    59     my $rect;
    60     eval { $rect = $self->SUPER::GetSubItemRect($item, $subitem); };
    61     if($@){
     97    my $rect = $self->GetItemRect($item);
     98    #my $pos = $self->GetItemPosition($item);
     99    # cumulate columns widths. If progress bar is column 4,
     100    # cumulate columns widths 0, 1, 2, 3
     101    my $x = $rect->GetX;
    62102
    63         # have to calculate sub item position and size
    64         $rect = $self->GetItemRect($item);
    65 
    66         my $x = $rect->GetX;
    67         map { $x += $self->GetColumnWidth($_ ) } grep { $_ < $subitem } (0..$subitem);
    68 
    69         $rect->SetX($x);
    70         $rect->SetWidth(
    71             $self->GetColumnWidth($subitem )
    72         );
    73     }
     103    map { $x += $self->GetColumnWidth($_) } grep { $_ < $subitem } (0..$subitem);
     104    $rect->SetX($x);
     105    $rect->SetWidth(
     106        $self->GetColumnWidth($subitem)
     107    );
    74108
    75109    $rect;
    76110}
    77111
    78 sub SetItemProgressValue {
     112
     113sub set_item_progress_value {
    79114    my ( $self, $indx, $value ) = @_;
    80115
     
    87122    }
    88123    else{
    89         $$item->Pulse;
     124        $item->Pulse;
    90125    }
    91126}
     
    95130    my ( $self ) = @_;
    96131
    97     my $i = 0;
    98132    # re-paint progress bars at the right position and size
    99     # hide the bars that are no longer visible after scrolling
    100     while( $i < $self->GetItemCount ) {
    101         my $progress_bar = $self->progress_bars->[$i];
    102         if($i < $self->GetTopItem or $i > $self->GetTopItem + $self->GetCountPerPage){
    103             $progress_bar->Hide;
    104         }
    105         else{
    106             $progress_bar->Show;
    107             $self->paint_progress_bar($i, $progress_bar);
    108         }
     133    my $i=0;
     134    map{
     135        $self->paint_progress_bar($i, $_);
    109136        $i++;
    110     }
     137    }@{$self->progress_bars};
    111138}
    112139
     
    115142    my ( $self, $item, $progress_bar ) = @_;
    116143
    117     my $rect = $self->GetSubItemRect($item, $self->progress_column);
     144    my $rect = $self->get_item_progress_rect($item, $self->progress_column);
     145    # top most visible item
     146    $self->{_y_top} ||= $rect->GetY;
     147
     148    # hidden
     149    my $bar_pos = Wx::Point->new(-1000, -1000);
     150
     151    if(  $rect->GetY >=  $self->{_y_top}) {
     152        $bar_pos = $rect->GetPosition;
     153    }
    118154
    119155    $progress_bar->Move(
    120        $rect->GetPosition
     156        $bar_pos
    121157    );
    122158
     
    124160        $rect->GetSize
    125161    );
    126 
    127162}
    128163
     164
     165
    1291661;
Note: See TracChangeset for help on using the changeset viewer.