Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. <?php
  2. namespace app\forms;
  3.  
  4. use php\gui\framework\AbstractForm;
  5. use php\gui\event\UXEvent;
  6. use php\gui\event\UXWindowEvent;
  7. use php\gui\event\UXMouseEvent;
  8. use php\gui\UXLabel;
  9. use php\gui\graphic\UXColor;
  10. use php\gui\layout\UXVBox;
  11. use php\gui\layout\UXHBox;
  12. use php\gui\UXImageView;
  13. use php\gui\UXImage;
  14. use php\io\File;
  15. use php\lib\Str;
  16.  
  17.  
  18.  
  19. class MainForm extends AbstractForm
  20. {
  21.  
  22.      public $arr = [];
  23.  
  24.     /**
  25.      * @event show
  26.      **/
  27.     function doShow(UXWindowEvent $event = null)
  28.     {                
  29.              
  30.          $this->list->setCellFactory(function($cell, $item) {
  31.                 if ($item) {
  32.                 $cell->text = null;
  33.                
  34.                 $titleName = new UXLabel($item->title);
  35.                 $titleName->css('font-weight', 'bold');
  36.              
  37.                 $titleDescription = new UXLabel($item->description);
  38.                 $titleDescription->css('text-fill', 'gray');
  39.              
  40.                 $title  = new UXVBox([$titleName, $titleDescription]);
  41.                 $title->spacing = 0;
  42.                
  43.                 $line = new UXHBox([$item->graphic, $title]);
  44.                 $line->spacing = 7;
  45.                 $line->padding = 5;
  46.                 $cell->text = null;
  47.                 $cell->graphic = $line;
  48.                 }
  49.            });
  50.          
  51.      }
  52.  
  53.     /**
  54.      * @event button.action
  55.      **/
  56.     function doButtonAction(UXEvent $event = null)
  57.     {  
  58.            $this->list->items->clear();
  59.  
  60.            $this->arr = null;
  61.          
  62.          $dir = new File($this->edit->text);
  63.          
  64.            $files = $dir->find(function(File $file, $name) {
  65.                  $this->arr[] = $name;
  66.            });
  67.  
  68.            foreach ($this->arr as $v) {  
  69.  
  70.                  if (Str::endsWith($v, '.png')) {
  71.                      $img = 'png.png';
  72.                  } elseif (Str::endsWith($v, '.jpg')) {
  73.                      $img = 'jpg.png';
  74.                  } elseif (Str::endsWith($v, '.gif')) {
  75.                      $img = 'gif.png';
  76.                  }
  77.                        
  78.                  $View = new UXImageView();
  79.                  $View->image = new UXImage('res://.data/img/'. $img);    
  80.  
  81.                  $item = new \stdClass();
  82.                  $item->title = $v;
  83.                  $item->description = 'File '. Str::sub($v, Str::pos($v, '.'));
  84.                  $item->graphic = $View;
  85.                  $this->list->items->add($item);
  86.              
  87.     }
  88.  
  89.      
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement