Package plugins :: Package vfs :: Package vfsutils :: Module box_copy |
[hide private]
[frames] | no frames]

# Source Code for Module plugins.vfs.vfsutils.box_copy

      1  #-*- coding: utf8 -*
      2  #
      3  # Max E. Kuznecov ~syhpoon <mek@mek.uz.ua> 2008-2009
      4  #
      5  # This file is part of XYZCommander.
      6  # XYZCommander is free software: you can redistribute it and/or modify
      7  # it under the terms of the GNU Lesser Public License as published by
      8  # the Free Software Foundation, either version 3 of the License, or
      9  # (at your option) any later version.
     10  # XYZCommander is distributed in the hope that it will be useful,
     11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13  # GNU Lesser Public License for more details.
     14  # You should have received a copy of the GNU Lesser Public License
     15  # along with XYZCommander. If not, see <http://www.gnu.org/licenses/>.
     16
     17  import libxyz.ui as uilib
     18
     19  from libxyz.ui import lowui
     20  from libxyz.core.utils import bstring
     21
     22 -class CopyBox(lowui.WidgetWrap):
     23      """
     24      Copy dialog
     25      """
     26
     27      resolution = (u"box", u"widget")
     28
     29 -    def __init__(self, xyz, srctxt, dst, caption):
     30          self.xyz = xyz
     31          self._attr = lambda name: self.xyz.skin.attr(self.resolution, name)
     32          self._keys = uilib.Keys()
     33
     34          srclabel = lowui.Text(bstring(_(u"Source:")))
     35          srctxt = lowui.Text(srctxt)
     36          dstlabel = lowui.Text(bstring(_(u"Destination:")))
     37
     38          self.dstw = lowui.AttrWrap(lowui.Edit(edit_text=dst, wrap='clip'),
     39                                     self._attr("input"))
     40
     41          self.save_attrw = lowui.CheckBox(bstring(_(u"Save attributes")),
     42                                           state=True)
     43          self.follow_linksw = lowui.CheckBox(bstring(_(u"Follow links")))
     44          self.buttonsw = lowui.Columns([self.save_attrw, self.follow_linksw])
     45
     46          spacer = lowui.Text(" ")
     47          msg = lowui.Text(
     48              bstring(_(u"TAB to cycle. ENTER to submit. ESCAPE to cancel")),
     49              align=uilib.align.CENTER)
     50
     51          w = [
     52              srclabel,
     53              srctxt,
     54              spacer,
     55              dstlabel,
     56              self.dstw,
     57              spacer,
     58              self.buttonsw,
     59              uilib.Separator(),
     60              msg
     61              ]
     62
     63          self.widgets = lowui.Pile(w)
     64          box = lowui.AttrWrap(lowui.Filler(self.widgets), self._attr("box"))
     65
     66          self.widget = uilib.Border(box, caption, self._attr("title"),
     67                                self._attr("border"))
     68
     69          super(CopyBox, self).__init__(self.widget)
     70
     71      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     72
     73 -    def show(self):
     74          def _setup(dim):
     75              width = int((dim[0] / 100.0) * 80)
     76              height = int((dim[1] / 100.0) * 40)
     77
     78              mount = lowui.AttrWrap(lowui.Filler(lowui.Text(u"")),
     79                                 self._attr(u"mount"))
     80              mount = lowui.Overlay(mount, self.xyz.top, uilib.align.CENTER,
     81                                 width, uilib.align.MIDDLE, height)
     82
     83              return lowui.Overlay(self.widget, mount, uilib.align.CENTER,
     84                                   width - 2, uilib.align.MIDDLE, height - 2)
     85
     86          #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     87
     88          def _focus_button(b):
     89              self.widgets.set_focus(self.buttonsw)
     90              self.buttonsw.set_focus(b)
     91
     92              return b
     93
     94          #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     95
     96          def _focus_edit():
     97              self.widgets.set_focus(self.dstw)
     98
     99              return self.dstw
    100
    101          #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    102
    103          focus_data = {1: lambda: _focus_edit(),
    104                        2: lambda: _focus_button(self.save_attrw),
    105                        3: lambda: _focus_button(self.follow_linksw)
    106                        }
    107          focus = 1
    108          focusw = self.dstw
    109
    110          dim = self.xyz.screen.get_cols_rows()
    111          box = _setup(dim)
    112
    113          result = None
    114
    115          while True:
    116              self.xyz.screen.draw_screen(dim, box.render(dim, True))
    117
    118              _input = self.xyz.input.get()
    119
    120              if self.xyz.input.WIN_RESIZE in _input:
    121                  dim = self.xyz.screen.get_cols_rows()
    122                  box = _setup(dim)
    123                  continue
    124
    125              if self._keys.TAB in _input:
    126                  if focus >= len(focus_data):
    127                      focus = 1
    128                  else:
    129                      focus +=1
    130
    131                  focusw = focus_data[focus]()
    132              elif self._keys.ESCAPE in _input:
    133                  break
    134              elif self._keys.ENTER in _input:
    135                  result = {
    136                      'dst': bstring(self.dstw.get_edit_text()),
    137                      'save_attributes': self.save_attrw.get_state(),
    138                      'follow_links': self.follow_linksw.get_state()
    139                      }
    140                  break
    141              else:
    142                  for k in _input:
    143                      focusw.keypress((dim[0],), k)
    144
    145          return result
    146