def adjust_size_scale(self, selected_size, unit="MiB"): self.scale.set_range(self.min_size.convertTo(size.parseUnits(unit, False)), self.max_size.convertTo(size.parseUnits(unit, False))) self.scale.clear_marks() increment, digits = self.get_size_precision(self.min_size.convertTo(size.parseUnits(unit, False)), self.max_size.convertTo(size.parseUnits(unit, False)), unit) self.scale.set_increments(increment, increment*10) self.scale.set_digits(digits) self.scale.add_mark(0, Gtk.PositionType.BOTTOM, format(self.min_size.convertTo(size.parseUnits(unit, False)), "." + str(digits) + "f")) self.scale.add_mark(float(self.max_size.convertTo(size.parseUnits(unit, False))), Gtk.PositionType.BOTTOM, format(self.max_size.convertTo(size.parseUnits(unit, False)), "." + str(digits) + "f")) self.spin_size.set_range(self.min_size.convertTo(size.parseUnits(unit, False)), self.max_size.convertTo(size.parseUnits(unit, False))) self.spin_size.set_increments(increment, increment*10) self.spin_size.set_digits(digits) self.scale.set_value(selected_size.convertTo(size.parseUnits(unit, False)))
def set_selected_size(self, size): self.scale.set_value(size.convertTo(size.parseUnits(self.selected_unit, False)))
def add_size_widgets(self, unit="MiB"): scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=Gtk.Adjustment(0, self.min_size.convertTo(size.parseUnits(unit, False)), self.max_size.convertTo(size.parseUnits(unit, False)), 1, 10, 0)) scale.set_margin_left(10) scale.set_margin_bottom(5) scale.set_hexpand(True) scale.set_valign(Gtk.Align.START) scale.set_digits(0) scale.add_mark(self.min_size.convertTo(size.parseUnits(unit, False)), Gtk.PositionType.BOTTOM, str(self.min_size)) if self.dialog_type == "add": scale.set_value(self.max_size.convertTo(size.parseUnits(unit, False))) if self.max_size < self.free_device.size: scale.add_mark(self.max_size.convertTo(size.parseUnits(unit, False)), Gtk.PositionType.BOTTOM, str(self.max_size) + " of " + str(self.free_device.size)) else: scale.add_mark(self.max_size.convertTo(size.parseUnits(unit, False)), Gtk.PositionType.BOTTOM, str(self.max_size)) if self.dialog_type == "edit": scale.set_value(self.edited_device.size.convertTo(size.parseUnits(unit, False))) scale.add_mark(self.max_size.convertTo(size.parseUnits(unit, False)), Gtk.PositionType.BOTTOM, str(self.max_size)) self.frame_grid.attach(scale, 0, 0, 4, 3) label_size = Gtk.Label(label=_("Volume size:"), xalign=1) label_size.get_style_context().add_class("dim-label") self.frame_grid.attach(label_size, 4, 1, 1, 1) spin_size = Gtk.SpinButton(adjustment=Gtk.Adjustment(0, self.min_size.convertTo(size.parseUnits(unit, False)), self.max_size.convertTo(size.parseUnits(unit, False)), 1, 10, 0)) spin_size.set_numeric(True) if self.dialog_type == "add": spin_size.set_value(self.max_size.convertTo(size.parseUnits(unit, False))) elif self.dialog_type == "edit": spin_size.set_value(self.edited_device.size.convertTo(size.parseUnits(unit, False))) self.frame_grid.attach(spin_size, 5, 1, 1, 1) unit_chooser = self.add_unit_chooser(unit) self.frame_grid.attach(unit_chooser, 6, 1, 1, 1) scale.connect("value-changed", self.scale_moved, spin_size) spin_size.connect("value-changed", self.spin_size_moved, scale) scale.set_size_request(250, -1) scale.set_margin_right(18) self.widgets.extend([scale, label_size, spin_size, unit_chooser]) return scale, spin_size