Commits

Moises Henriquez  committed f73befc

Fixes crash when pressing the 'esc' key while viewing an fstab entry details. Fixes #13

  • Participants
  • Parent commits bf2f05f

Comments (0)

Files changed (4)

File modules/support/widgets.py

 vlbluecolor = gtk.gdk.color_parse("#003063")
 vllightbluecolor = gtk.gdk.color_parse("#6d87a3")
 modulesdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-print modulesdir
 horizontal = gtk.HBox
 vertical = gtk.VBox
 

File modules/tui/tui_fstab.py

 
         body = urwid.Pile(_pile_list)
         widgets.TuiModule.__init__(self,
-            parent = self,
+            parent = self.parent,
             body = body,
             header = 'foo',
             desc = [],
         if entry_device.startswith('/') and self.entry.mountpoint != '/':
             # Display a delete option button only for non  / mountpoints.
             _buttons = [
-                (_("Delete"), self.delete_entry),
-                (_("Back"), self.parent.return_to_module)]
+                (_("Back"), self.parent.return_to_module),
+                (_("Delete"), self.delete_entry),]
         else:
             _buttons = [
                 (_("Back"), self.parent.return_to_module)]
         widgets.TuiModule.__init__(self,
-            parent = parent,
+            parent = self.parent,
             buttons = _buttons,
             body = _body,
-            desc = [urwid.Text(_("Entry Details.")), widgets.blank],
+            desc = [widgets.blank, 
+                urwid.Text(_("Entry Details.")),
+                urwid.Divider(u'='), widgets.blank],
             header = _("About") + " " + self.entry.device)
 
     def delete_entry(self, widget=None):
         return self.parent._confirm_delete_entry(widget, self.entry)
+    
+    def keypress(self, size, key):
+        if key == 'esc':
+            return self.parent.return_to_module()
+        return size, key
 
 class FstabMod(dialogs.ModuleDialog):
     def __init__(self, parent):
         _body.append(_("Mount Point") + " %s"% selected.mountpoint)
         
         dia = dialogs.Info(
-            parent = self,
+            parent = self.parent,
             message = _body,
             buttons = [],
             )
-        dia.add_button("OK", self.return_to_module)
-        dia.add_button("OK", self._confirm_delete_entry)
         return self.pop_dialog(dia)
 
 

File modules/tui/tui_partitioning.py

 import subprocess as sp
 import os
 import sys
+import urwid
+import parted
 if os.getcwd() not in sys.path:
     sys.path.append(os.getcwd())
-from modules.tuisupport.tui_utils import run_external_tui
-
+from modules.tuisupport.tui_utils import run_external_tui, _
+from modules.support.vectorlinux import FSTAB
+from modules.tuisupport import widgets
+from modules.tuisupport import dialogs
 
 VASM_CATEGORY = "System"
 VASM_LABEL = "System Disk Partitions"
 
+class DrivePickerDialog(widgets.TuiModule):
+    def __init__(self, parent=None):
+        self.parent = parent
+        self._drive = None
+        msg = (_("There is more than one drive installed on your system."),"  ",
+            _("Select which one you would like to partition."))
+        _radios = []
+        drives = FSTAB.list_all_system_drives()
+        model = urwid.SimpleListWalker([])
+        # create the radio buttons
+        for drive in drives:
+            dev = parted.Device(drive)
+            label = "%s [ %s MB - %s ]"% ( dev.path, str(round(dev.getSize('MB'), 2)),
+                dev.model)
+            radio = urwid.RadioButton(group=_radios,
+                label = label, user_data = dev.path, state=False,
+                on_state_change=self.radiobutton_toggle_event)
+            wrap = urwid.AttrWrap(radio, 'button', 'button sel')
+            model.append(wrap)
+        
+        listbox = urwid.ListBox(model)
+        body = urwid.Pile([
+            ('flow', widgets.blank),
+            listbox,
+            ('flow',urwid.Divider('_')),
+            ])
+        
+        #_body = [urwid.Text("Body content")]        
+        widgets.TuiModule.__init__(
+            self,
+            header = _("Select which drive to partition"),
+            desc = [widgets.blank, ''.join(msg), urwid.Divider('_'),widgets.blank],
+            parent = self.parent,
+            body = body,
+            buttons = [("OK", self.module_ok_event),
+                ("Cancel", self.parent.return_home)])
+        
+        self.set_focus('body')
+        # set the focus to the left button on the bottom toolbar
+        bar = self._get_action_area()
+    
+    def radiobutton_toggle_event(self, radio, newstate, user_data):
+        if newstate:
+            self._drive = user_data
+        return
+    
+    def module_ok_event(self, widget=None, data=None):
+        if not self._drive:
+            dia = dialogs.Error(
+                parent = self,
+                message = _("You must select a hard disk before continuing."),
+                buttons = [("OK", self.return_to_module)],
+                )
+            return self.pop_dialog(dia)
+        
+        return self.run_cfdisk(self._drive)
+        dia = dialogs.Info(
+            parent = self,
+            message = self._drive,
+            buttons = [("OK", self.return_to_module)]
+            )
+        return self.pop_dialog(dia)
+    
+    def run_cfdisk(self, disk_drive):
+        """ Launch cfdisk on the selected drive """
+        cfpath = _get_cfdisk_path()
+        self.close_module()
+        return run_external_tui(self.parent, [cfpath, disk_drive])
+        
+
 def _get_cfdisk_path():
     """ Return the path to cfdisk """
     _paths = ('/sbin/cfdisk',
 
 def __run__(parent):
     # Execute cfdisk in the running terminal
-    run_external_tui(parent, _get_cfdisk_path())
+    # If we only find one disk, go straight to it,
+    # otherwise, intercept the call with a dialog asking which drive to partition.
+    drives = FSTAB.list_all_system_drives()
+    if len(drives) > 1:
+        dia = DrivePickerDialog(parent)
+        return parent.pop_module(dia)
+    else:
+        run_external_tui(parent, _get_cfdisk_path())

File modules/tuisupport/widgets.py

            ml.process_input(['left'])
            self.keypress((10, 2), 'left')
 
-    #def keypress(self, size, key):
-    #    if key in ('esc'):
-    #        return self._emulate_left_button(2)
-    #    
-    #    return super(ModuleRightPane, self).keypress(size, key)
-        
 class CategoryDisplay(urwid.SimpleListWalker):
     """ Custom list walker used to display settings categories.
     
 
         bar = urwid.GridFlow(buttons, 15, 0, 0, 'right')
         if buttons:
-            bar.set_focus(buttons[-1])
+            bar.set_focus(buttons[0])
         return bar
     
     def add_button(self, button, callback, data=None):