support grabbing values from inputs
Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
This commit is contained in:
parent
709d603424
commit
660205a184
|
@ -262,11 +262,10 @@ class Controller:
|
|||
disk)
|
||||
self.ui.set_body(adp_view)
|
||||
|
||||
def add_disk_partition_handler(self, partition_spec):
|
||||
if not partition_spec:
|
||||
log.debug("New partition: {}".format(partition_spec))
|
||||
else:
|
||||
log.debug("Empty partition spec, should go back one.")
|
||||
def add_disk_partition_handler(self, disk, partition_spec):
|
||||
log.debug("Adding partition spec to "
|
||||
"Filesystem model: {}".format(partition_spec))
|
||||
self.signal.emit_signal('filesystem:show-disk-partition', disk)
|
||||
|
||||
def connect_iscsi_disk(self, *args, **kwargs):
|
||||
self.ui.set_body(DummyView(self.signal))
|
||||
|
|
|
@ -34,6 +34,7 @@ from subiquity.ui.lists import SimpleList
|
|||
from subiquity.ui.buttons import done_btn, reset_btn, cancel_btn
|
||||
from subiquity.ui.widgets import Box
|
||||
from subiquity.ui.utils import Padding, Color
|
||||
from subiquity.ui.interactive import (StringEditor, IntegerEditor, Selector)
|
||||
|
||||
log = logging.getLogger('subiquity.filesystem')
|
||||
|
||||
|
@ -216,12 +217,17 @@ def _dehumanize_size(size):
|
|||
class AddPartitionView(WidgetWrap):
|
||||
|
||||
def __init__(self, model, signal, selected_disk):
|
||||
self.partition_spec = {}
|
||||
self.signal = signal
|
||||
self.model = model
|
||||
self.partnum = IntegerEditor(caption="Partition number (1-4): ",
|
||||
default=1)
|
||||
self.size = StringEditor(caption="Size (max 2Tb): ")
|
||||
self.mountpoint = StringEditor(caption="Mount: ", edit_text="/")
|
||||
self.fstype = Selector(opts=self.model.supported_filesystems)
|
||||
self.selected_disk = selected_disk
|
||||
body = [
|
||||
Padding.center_95(
|
||||
Text("Adding partition to {}".format(selected_disk))),
|
||||
Text("Adding partition to {}".format(self.selected_disk))),
|
||||
Padding.line_break(""),
|
||||
Padding.center_90(self._container()),
|
||||
Padding.line_break(""),
|
||||
|
@ -240,29 +246,16 @@ class AddPartitionView(WidgetWrap):
|
|||
]
|
||||
return Pile(buttons)
|
||||
|
||||
def _partition_edit(self):
|
||||
return IntEdit(caption="Partition number (1-4): ",
|
||||
default=1)
|
||||
|
||||
def _size_edit(self):
|
||||
return Edit(caption="Size (max 2Tb): ")
|
||||
|
||||
def _format_edit(self):
|
||||
group = []
|
||||
for fs in self.model.supported_filesystems:
|
||||
RadioButton(group, fs)
|
||||
formats_list = Pile(group)
|
||||
formats_list = Pile(self.fstype.group)
|
||||
return Columns([(10, Text("Format: ")), formats_list], 2)
|
||||
|
||||
def _mount_point_edit(self):
|
||||
return Edit(caption="Mount: ", edit_text="/")
|
||||
|
||||
def _container(self):
|
||||
total_items = [
|
||||
self._partition_edit(),
|
||||
self._size_edit(),
|
||||
self.partnum,
|
||||
self.size,
|
||||
self._format_edit(),
|
||||
self._mount_point_edit()
|
||||
self.mountpoint
|
||||
]
|
||||
|
||||
return Pile(total_items)
|
||||
|
@ -270,7 +263,7 @@ class AddPartitionView(WidgetWrap):
|
|||
def cancel(self, button):
|
||||
self.signal.emit_signal('filesystem:show')
|
||||
|
||||
def done(self):
|
||||
def done(self, result):
|
||||
""" partition spec
|
||||
|
||||
{ 'partition_number': Int,
|
||||
|
@ -279,11 +272,15 @@ class AddPartitionView(WidgetWrap):
|
|||
'mount_point': Str
|
||||
}
|
||||
"""
|
||||
if not self.partition_spec:
|
||||
# TODO: Maybe popup warning?
|
||||
return
|
||||
result = {
|
||||
"partnum": self.partnum.value,
|
||||
"size": self.size.value,
|
||||
"fstype": self.fstype.value,
|
||||
"mountpoint": self.mountpoint.value
|
||||
}
|
||||
log.debug("Add Partition Result: {}".format(result))
|
||||
self.signal.emit_signal(
|
||||
'filesystem:finish-add-disk-partition', self.partition_spec)
|
||||
'filesystem:finish-add-disk-partition', self.selected_disk, result)
|
||||
|
||||
|
||||
class DiskPartitionView(WidgetWrap):
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
# Copyright 2015 Canonical, Ltd.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# 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 Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
""" Re-usable input widgets
|
||||
"""
|
||||
|
||||
from urwid import (Edit, IntEdit, RadioButton, WidgetWrap)
|
||||
import logging
|
||||
|
||||
log = logging.getLogger("subiquity.ui.input")
|
||||
|
||||
|
||||
class StringEditor(WidgetWrap):
|
||||
""" Edit input class
|
||||
|
||||
Initializes and Edit object and attachs its result
|
||||
to the `value` accessor.
|
||||
"""
|
||||
def __init__(self, caption, **kwargs):
|
||||
self._edit = Edit(caption=caption, **kwargs)
|
||||
super().__init__(self._edit)
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._edit.get_edit_text()
|
||||
|
||||
|
||||
class IntegerEditor(WidgetWrap):
|
||||
""" IntEdit input class
|
||||
"""
|
||||
def __init__(self, caption, default=0):
|
||||
self._edit = IntEdit(caption=caption, default=default)
|
||||
super().__init__(self._edit)
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
return self._edit.get_edit_text()
|
||||
|
||||
|
||||
class Selector(WidgetWrap):
|
||||
""" Radio selection list of options
|
||||
"""
|
||||
def __init__(self, opts, group=[]):
|
||||
"""
|
||||
:param list opts: list of options to display
|
||||
"""
|
||||
self.opts = opts
|
||||
self.group = group
|
||||
self._add_options()
|
||||
|
||||
def _add_options(self):
|
||||
for item in self.opts:
|
||||
RadioButton(self.group, item)
|
||||
log.debug(self.group)
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
for item in self.group:
|
||||
log.debug(item)
|
||||
if item.get_state():
|
||||
return item.label
|
||||
return "Unknown option"
|
Loading…
Reference in New Issue