[anaconda:master 2/2] Changes around handling of size entries in custom spoke.

mulhern amulhern at redhat.com
Thu Oct 16 22:45:35 UTC 2014


* Make the max places displayed on this spoke a named constant.
* Get rid of _device_size_text attribute. It looks like that state is
unnecessary and CustomSpoke has plenty of state as it is.
* Still assume that if the entry text has not changed at all from the
text displayed, then no change was intended.
* Also, if the entry text has changed, but it represents exactly the same
size as the current device's size, consider this no change.
Assuming the size was actually 1 MiB, and that the string representation was
"1 MiB", if the user enters "1" (which is interpreted as 1 MiB), or
"1024 KiB", or "1      MiB    ", or even, "1.00 MiB", then changed_size
will be False. Previously any of these would have been interpreted as
an actual change.

This is still a bit paradoxical, because not all digits are displayed.
The value displayed represents a range of possible values, of which
the actual size value is just one. This means that, if the actual value is
1.001 MiB, and the displayed value is "1 MiB", and the user enters "1.0 MiB",
then the value will be updated (but the user won't see the change, because
the value will still be represented as "1 MiB").
This patch doesn't change that fact, though. It's hard to do much
different w/out getting a whole lot more sophisticated.
---
 pyanaconda/ui/gui/spokes/custom.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 9fdfbc2..6e7038a 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -141,6 +141,9 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
     category = SystemCategory
     title = N_("MANUAL PARTITIONING")
 
+    # The maximum number of places to show when displaying a size
+    MAX_SIZE_PLACES = 2
+
     def __init__(self, data, storage, payload, instclass):
         StorageChecker.__init__(self, min_ram=isys.MIN_GUI_RAM)
         NormalSpoke.__init__(self, data, storage, payload, instclass)
@@ -157,7 +160,6 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         self._fs_types = []             # list of supported fstypes
         self._free_space = Size(0)
 
-        self._device_size_text = None
         self._device_disks = []
         self._device_container_name = None
         self._device_container_raid_level = None
@@ -918,15 +920,16 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         # SIZE
         old_size = device.size
 
-        # we are interested in size human readable representation change because
-        # that's what the user sees
-        same_size = self._device_size_text == self._sizeEntry.get_text()
-        if same_size:
+        # If the size text hasn't changed at all from that displayed,
+        # assume no change intended.
+        if old_size.humanReadable(max_places=self.MAX_SIZE_PLACES) == self._sizeEntry.get_text():
             size = old_size
         else:
+            # Note that this size may not correspond to user's entry,
+            # as size_from_entry has a default lower limit.
             size = size_from_entry(self._sizeEntry)
         changed_size = ((use_dev.resizable or not use_dev.exists) and
-                        not same_size)
+                        size != old_size)
         old_device_info["size"] = old_size
         new_device_info["size"] = size
 
@@ -1460,8 +1463,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             self._labelEntry.set_text("")
         fancy_set_sensitive(self._labelEntry, True)
 
-        self._device_size_text = device.size.humanReadable(max_places=2)
-        self._sizeEntry.set_text(self._device_size_text)
+        self._sizeEntry.set_text(device.size.humanReadable(max_places=self.MAX_SIZE_PLACES))
 
         self._reformatCheckbox.set_active(not device.format.exists)
         fancy_set_sensitive(self._reformatCheckbox,
-- 
1.9.3



More information about the anaconda-patches mailing list