def update(self, disk_cache, partition_cache, cache_order): self.partition_tree_model.clear() for child in self.part_advanced_bar_frame.children(): if isinstance(child, QtGui.QWidget): child.setParent(None) del child self.active_bar = None partition_bar = None indexCount = -1 for item in cache_order: if item in disk_cache: # the item is a disk indexCount += 1 partition_bar = PartitionsBar( self.part_advanced_bar_frame, controller=self.ctrlr) self.part_advanced_bar_frame.layout().addWidget(partition_bar) #hide all the other bars at first if self.active_bar: partition_bar.setVisible(False) else: self.active_bar = partition_bar self.partition_tree_model.append( [item, disk_cache[item], partition_bar], self.ctrlr) else: # the item is a partition, add it to the current bar partition = partition_cache[item] # add the new partition to our tree display self.partition_tree_model.append( [item, partition, partition_bar], self.ctrlr) indexCount += 1 # data for bar display size = int(partition['parted']['size']) fs = partition['parted']['fs'] path = partition['parted']['path'] partition_bar.addPartition(path, size, fs) self.partition_list_treeview.reset()
def update(self, disk_cache, partition_cache, cache_order): self.partition_tree_model.clear() for child in self.part_advanced_bar_frame.children(): if isinstance(child, QtGui.QWidget): child.setParent(None) del child self.active_bar = None partition_bar = None indexCount = -1 for item in cache_order: if item in disk_cache: # the item is a disk indexCount += 1 partition_bar = PartitionsBar(self.part_advanced_bar_frame, controller=self.ctrlr) self.part_advanced_bar_frame.layout().addWidget(partition_bar) # hide all the other bars at first if self.active_bar: partition_bar.setVisible(False) else: self.active_bar = partition_bar self.partition_tree_model.append( [item, disk_cache[item], partition_bar], self.ctrlr) else: # the item is a partition, add it to the current bar partition = partition_cache[item] # add the new partition to our tree display self.partition_tree_model.append( [item, partition, partition_bar], self.ctrlr) indexCount += 1 # data for bar display size = int(partition['parted']['size']) fs = partition['parted']['fs'] path = partition['parted']['path'] partition_bar.addPartition(path, size, fs) self.partition_list_treeview.reset()
# -*- coding: utf-8 -*- import sys from PyQt4 import QtGui from ubiquity.frontend.kde_components.PartitionBar import PartitionsBar if __name__ == "__main__": app = QtGui.QApplication(sys.argv) QtGui.QApplication.setStyle("Oxygen") wid = QtGui.QWidget() layout = QtGui.QVBoxLayout(wid) pb1 = PartitionsBar(wid) layout.addWidget(pb1) pb1.addPartition('/dev/sdb1', 57511125504, 'ext4') pb1.addPartition('/dev/sdb5', 2500452864, 'linux-swap') pb1.setResizePartition('/dev/sdb1', 230989824, 55143440896, 52143440896, 'distro') pb2 = PartitionsBar(wid) layout.addWidget(pb2) pb2.addPartition("/dev/sdb1", 5000, "linux-swap") pb2.addPartition("/dev/sdb2", 20000, "ext3") pb2.addPartition("/dev/sdb3", 30000, "fat32") pb2.addPartition("/dev/sdb4", 50000, "ntfs") pb2.setResizePartition('/dev/sdb2', 5000, 15000, 20000, 'Xenta OS')
def setupChoices(self, choices, extra_options, resize_choice, manual_choice, biggest_free_choice, use_device_choice, lvm_choice, crypto_choice): self._clearInfo() self.resizeChoice = resize_choice self.manualChoice = manual_choice self.useDeviceChoice = use_device_choice self.extra_options = extra_options self.lvm_choice = lvm_choice self.crypto_choice = crypto_choice # remove any previous autopartition selections for child in self.autopart_selection_frame.children(): if isinstance(child, QtGui.QWidget): child.setParent(None) del child for child in self.barsFrame.children(): if isinstance(child, QtGui.QWidget): self.barsFrame.layout().removeWidget(child) child.setParent(None) del child release_name = misc.get_release().name bId = 0 if 'resize' in extra_options: button = QtGui.QRadioButton( self.resizeChoice, self.autopart_selection_frame) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) self.autopartitionTexts.append(resize_choice) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for disk_id in extra_options['resize']: # information about what can be resized unused, min_size, max_size, pref_size, \ resize_path, unused, unused = \ extra_options['resize'][disk_id] for text, path in extra_options['use_device'][1].items(): path = path[0] if path.rsplit('/', 1)[1] == disk_id: bar_frame = QtGui.QFrame() bar_frame.setLayout(QtGui.QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) self.resizeSize = pref_size dev = self.diskLayout[disk_id] before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.setResizePartition( resize_path, min_size, max_size, pref_size, release_name) after_bar.partitionResized.connect( self.on_partitionResized) addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) # TODO biggest_free_choice # Use entire disk. button = QtGui.QRadioButton( self.useDeviceChoice, self.autopart_selection_frame) self.autopartitionTexts.append(self.useDeviceChoice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for text, path in extra_options['use_device'][1].items(): path = path[0] bar_frame = QtGui.QFrame() bar_frame.setLayout(QtGui.QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) dev = self.diskLayout[path.rsplit('/', 1)[1]] before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p.device, int(p.size), p.filesystem) if before_bar.diskSize > 0: after_bar.addPartition( release_name, before_bar.diskSize, 'auto') else: after_bar.addPartition(release_name, 1, 'auto') addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) #LVM button = QtGui.QRadioButton( self.lvm_choice, self.autopart_selection_frame) self.autopartitionTexts.append(self.lvm_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 #add use entire disk options to combobox again self.disks.append(disks) #Crypto button = QtGui.QRadioButton( self.crypto_choice, self.autopart_selection_frame) self.autopartitionTexts.append(self.crypto_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) self.crypto_button_id = bId bId += 1 #add use entire disk options to combobox again self.disks.append(disks) box = QtGui.QHBoxLayout() box.addStretch() self.autopart_selection_frame.layout().addLayout(box) self.passwordIcon = QtGui.QLabel() self.passwordIcon.setPixmap(QtGui.QPixmap( "/usr/share/icons/oxygen/16x16/status/dialog-password.png")) box.addWidget(self.passwordIcon) self.password = QtGui.QLineEdit() self.password.setEchoMode(QtGui.QLineEdit.Password) self.password.textChanged.connect(self.verify_password) box.addWidget(self.password) self.verified_password = QtGui.QLineEdit() self.verified_password.setEchoMode(QtGui.QLineEdit.Password) self.verified_password.textChanged.connect(self.verify_password) box.addWidget(self.verified_password) self.badPassword = QtGui.QLabel() self.badPassword.setPixmap(QtGui.QPixmap( "/usr/share/icons/oxygen/16x16/status/dialog-warning.png")) self.badPassword.hide() box.addWidget(self.badPassword) # Manual partitioning. button = QtGui.QRadioButton( manual_choice, self.autopart_selection_frame) self.autopartitionTexts.append(manual_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextNext) self.disks.append([]) #select the first button b = self.autopartition_buttongroup.button(0) b and b.click()
def setupChoices(self, choices, extra_options, resize_choice, manual_choice, biggest_free_choice, use_device_choice, lvm_choice, crypto_choice): self._clearInfo() self.resizeChoice = resize_choice self.manualChoice = manual_choice self.useDeviceChoice = use_device_choice self.extra_options = extra_options self.lvm_choice = lvm_choice self.crypto_choice = crypto_choice # remove any previous autopartition selections for child in self.autopart_selection_frame.children(): if isinstance(child, QtWidgets.QWidget): child.setParent(None) del child for child in self.barsFrame.children(): if isinstance(child, QtWidgets.QWidget): self.barsFrame.layout().removeWidget(child) child.setParent(None) del child release_name = misc.get_release().name bId = 0 if 'resize' in extra_options: button = QtWidgets.QRadioButton(self.resizeChoice, self.autopart_selection_frame) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) self.autopartitionTexts.append(resize_choice) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for disk_id in extra_options['resize']: # information about what can be resized _, min_size, max_size, pref_size, resize_path, _, _ = ( extra_options['resize'][disk_id]) for text, path in extra_options['use_device'][1].items(): path = path[0] if path.rsplit('/', 1)[1] == disk_id: bar_frame = QtWidgets.QFrame() bar_frame.setLayout(QtWidgets.QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) self.resizeSize = pref_size dev = self.diskLayout[disk_id] before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.setResizePartition(resize_path, min_size, max_size, pref_size, release_name) after_bar.partitionResized.connect( self.on_partitionResized) addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) # TODO biggest_free_choice # Use entire disk. button = QtWidgets.QRadioButton(self.useDeviceChoice, self.autopart_selection_frame) self.autopartitionTexts.append(self.useDeviceChoice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for text, path in extra_options['use_device'][1].items(): path = path[0] bar_frame = QtWidgets.QFrame() bar_frame.setLayout(QtWidgets.QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) dev = self.diskLayout[path.rsplit('/', 1)[1]] before_bar = PartitionsBar(controller=self.controller) after_bar = PartitionsBar(controller=self.controller) for p in dev: before_bar.addPartition(p.device, int(p.size), p.filesystem) if before_bar.diskSize > 0: after_bar.addPartition('', before_bar.diskSize, 'auto', name=release_name) else: after_bar.addPartition('', 1, 'auto', name=release_name) addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) # LVM button = QtWidgets.QRadioButton(self.lvm_choice, self.autopart_selection_frame) self.autopartitionTexts.append(self.lvm_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 # add use entire disk options to combobox again self.disks.append(disks) # Crypto button = QtWidgets.QRadioButton(self.crypto_choice, self.autopart_selection_frame) self.autopartitionTexts.append(self.crypto_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) self.crypto_button_id = bId bId += 1 # add use entire disk options to combobox again self.disks.append(disks) box = QtWidgets.QHBoxLayout() box.addStretch() self.autopart_selection_frame.layout().addLayout(box) self.passwordIcon = QtWidgets.QLabel() self.passwordIcon.setPixmap( QtGui.QPixmap( "/usr/share/icons/oxygen/16x16/status/dialog-password.png")) box.addWidget(self.passwordIcon) self.password = QtWidgets.QLineEdit() self.password.setEchoMode(QtWidgets.QLineEdit.Password) self.password.textChanged.connect(self.verify_password) box.addWidget(self.password) self.verified_password = QtWidgets.QLineEdit() self.verified_password.setEchoMode(QtWidgets.QLineEdit.Password) self.verified_password.textChanged.connect(self.verify_password) box.addWidget(self.verified_password) self.badPassword = QtWidgets.QLabel() self.badPassword.setPixmap( QtGui.QPixmap( "/usr/share/icons/oxygen/16x16/status/dialog-warning.png")) self.badPassword.hide() box.addWidget(self.badPassword) # Manual partitioning. button = QtWidgets.QRadioButton(manual_choice, self.autopart_selection_frame) self.autopartitionTexts.append(manual_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextNext) self.disks.append([]) # select the first button b = self.autopartition_buttongroup.button(0) b and b.click()
def setupChoices (self, choices, extra_options, resize_choice, manual_choice, biggest_free_choice, use_device_choice): self._clearInfo() self.resizeChoice = resize_choice self.manualChoice = manual_choice self.useDeviceChoice = use_device_choice self.extra_options = extra_options # remove any previous autopartition selections for child in self.autopart_selection_frame.children(): if isinstance(child, QWidget): child.setParent(None) del child for child in self.barsFrame.children(): if isinstance(child, QWidget): self.barsFrame.layout().removeWidget(child) child.setParent(None) del child release_name = get_release().name bId = 0 if resize_choice in extra_options: button = QRadioButton(resize_choice, self.autopart_selection_frame) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) self.autopartitionTexts.append(resize_choice) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for disk_id in extra_options[resize_choice]: # information about what can be resized unused, min_size, max_size, pref_size, resize_path = \ extra_options[resize_choice][disk_id] for text, path in extra_options[use_device_choice].items(): path = path[0] if path.rsplit('/', 1)[1] == disk_id: bar_frame = QFrame() bar_frame.setLayout(QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) self.resizeSize = pref_size dev = self.diskLayout[disk_id] before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.setResizePartition(resize_path, min_size, max_size, pref_size, release_name) after_bar.partitionResized.connect(self.on_partitionResized) addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) # TODO biggest_free_choice # Use entire disk. button = QRadioButton(use_device_choice, self.autopart_selection_frame) self.autopartitionTexts.append(use_device_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for text, path in extra_options[use_device_choice].items(): path = path[0] bar_frame = QFrame() bar_frame.setLayout(QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) dev = self.diskLayout[path.rsplit('/', 1)[1]] before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) if before_bar.diskSize > 0: after_bar.addPartition(release_name, before_bar.diskSize, 'auto') else: after_bar.addPartition(release_name, 1, 'auto') addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) # Manual partitioning. button = QRadioButton(manual_choice, self.autopart_selection_frame) self.autopartitionTexts.append(manual_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextNext) self.disks.append([]) #select the first button b = self.autopartition_buttongroup.button(0) b and b.click()
import sys from PyQt4 import uic from PyQt4.QtGui import * from ubiquity.frontend.kde_components.PartitionBar import PartitionsBar if __name__ == "__main__": app = QApplication(sys.argv) QApplication.setStyle("Oxygen") wid = QWidget() layout = QVBoxLayout(wid) pb1 = PartitionsBar(wid) layout.addWidget(pb1) pb1.addPartition('/dev/sdb1', 57511125504, 'ext4') pb1.addPartition('/dev/sdb5', 2500452864, 'linux-swap') pb1.setResizePartition('/dev/sdb1', 230989824, 55143440896, 52143440896, 'distro') pb2 = PartitionsBar(wid) layout.addWidget(pb2) pb2.addPartition("/dev/sdb1", 5000, "linux-swap") pb2.addPartition("/dev/sdb2", 20000, "ext3") pb2.addPartition("/dev/sdb3", 30000, "fat32") pb2.addPartition("/dev/sdb4", 50000, "ntfs") pb2.setResizePartition('/dev/sdb2', 5000, 15000, 20000, 'Kubuntu')
def setupChoices (self, choices, extra_options, resize_choice, manual_choice, biggest_free_choice): self._clearInfo() self.resizeChoice = resize_choice self.manualChoice = manual_choice # remove any previous autopartition selections for child in self.autopart_selection_frame.children(): if isinstance(child, QWidget): child.setParent(None) del child for child in self.barsFrame.children(): if isinstance(child, QWidget): self.barsFrame.layout().removeWidget(child) child.setParent(None) del child release_name = get_release_name() bId = 0 for choice in choices: button = QRadioButton(choice, self.autopart_selection_frame) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) bId += 1 #Qt changes the string by adding accelerators, #so keep pristine string here as is returned later to partman self.autopartitionTexts.append(choice) ## these three things are toggled by each option # extra options frame for the option #frame = None bar_frame = QFrame() bar_frame.setLayout(QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) button.toggled[bool].connect(bar_frame.setVisible) # if we have more information about the choice # i.e. various hard drives to install onto if choice in extra_options: # label for the before device dev = None if choice == biggest_free_choice: biggest_free_id = extra_options[choice] dev = None try: resize_path = biggest_free_id[3] dev = self.diskLayout[resize_path.replace("/", "=").rstrip("1234567890")] except Exception: pass if dev: #create partition bars for graphical before/after display before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) if p[1] == biggest_free_id: after_bar.addPartition(release_name, int(p[1]), 'auto') else: after_bar.addPartition(p[0], int(p[1]), p[3]) addBars(bar_frame, before_bar, after_bar) # install side by side/resize elif choice == resize_choice: # information about what can be resized extraInfo = extra_options[choice] min_size, max_size, pref_size, resize_path = extraInfo self.resizeSize = pref_size try: dev = self.diskLayout[resize_path.replace("/", "=").rstrip("1234567890")] except Exception: pass if dev: before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: #addPartition(name, size, fs): before_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.setResizePartition(resize_path, min_size, max_size, pref_size, release_name) after_bar.partitionResized.connect(self.on_partitionResized) addBars(bar_frame, before_bar, after_bar) #full disk install elif choice != manual_choice: # setup new frame to hold combo box # this allows us to make the combo box indented over # as well as not stretch to full width as it would do in the # vertical layout frame = QFrame() self.autopart_selection_frame.layout().addWidget(frame) frame_layout = QHBoxLayout(frame) self.extra_combo = QComboBox() self.extra_combo.setEnabled(False) self.autopart_selection_frame.layout().addWidget(self.extra_combo) frame_layout.addSpacing(20) frame_layout.addWidget(self.extra_combo) frame_layout.addStretch(1) self.extra_bar_frames = [] comboTexts = [] button.toggled[bool].connect(self.extra_combo.setEnabled) for extra in extra_options[choice]: #each extra choice needs to toggle a change in the before bar #extra is just a string with a general description #each extra choice needs to be a before/after bar option if extra == '': continue extra_bar_frame = None # add the extra disk to the combo box self.extra_combo.addItem(extra) self.extra_combo.currentIndexChanged[int].connect(self.on_extra_combo_changed) #find the device to make a partition bar out of it dev = None for d in self.diskLayout: disk = d if disk.startswith('=dev='): disk = disk[5:] if "(%s)" % disk in extra: dev = self.diskLayout[d] break #add the bars if we found the device if dev: before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) if before_bar.diskSize > 0: after_bar.addPartition(release_name, before_bar.diskSize, 'auto') else: after_bar.addPartition(release_name, 1, 'auto') extra_bar_frame = addBars(bar_frame, before_bar, after_bar) if len(self.extra_bar_frames) > 0: extra_bar_frame.setVisible(False) if extra_bar_frame is not None: self.extra_bar_frames.append(extra_bar_frame) # Qt changes the string by adding accelerators, # so keep the pristine string here to be # returned to partman later. comboTexts.append(extra) self.extraChoicesText[choice] = comboTexts #select the first button b = self.autopartition_buttongroup.button(0) if b: b.setChecked(True)
import sys import os from PyQt4 import uic from PyQt4.QtGui import * from ubiquity.frontend.kde_components.PartitionBar import PartitionsBar if __name__ == "__main__": app = QApplication(sys.argv) QApplication.setStyle("Oxygen") wid = QWidget() layout = QVBoxLayout(wid) pb1 = PartitionsBar(wid) layout.addWidget(pb1) pb1.addPartition("/dev/sdb1", 57511125504, "ext4") pb1.addPartition("/dev/sdb5", 2500452864, "linux-swap") pb1.setResizePartition("/dev/sdb1", 230989824, 55143440896, 52143440896, "distro") pb2 = PartitionsBar(wid) layout.addWidget(pb2) pb2.addPartition("/dev/sdb1", 5000, "linux-swap") pb2.addPartition("/dev/sdb2", 20000, "ext3") pb2.addPartition("/dev/sdb3", 30000, "fat32") pb2.addPartition("/dev/sdb4", 50000, "ntfs") pb2.setResizePartition("/dev/sdb2", 5000, 15000, 20000, "Kubuntu")
def setupChoices(self, choices, extra_options, resize_choice, manual_choice, biggest_free_choice, use_device_choice): self._clearInfo() self.resizeChoice = resize_choice self.manualChoice = manual_choice self.useDeviceChoice = use_device_choice self.extra_options = extra_options # remove any previous autopartition selections for child in self.autopart_selection_frame.children(): if isinstance(child, QtGui.QWidget): child.setParent(None) del child for child in self.barsFrame.children(): if isinstance(child, QtGui.QWidget): self.barsFrame.layout().removeWidget(child) child.setParent(None) del child release_name = misc.get_release().name bId = 0 if 'resize' in extra_options: button = QtGui.QRadioButton(self.resizeChoice, self.autopart_selection_frame) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) self.autopartitionTexts.append(resize_choice) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for disk_id in extra_options['resize']: # information about what can be resized unused, min_size, max_size, pref_size, \ resize_path, unused, unused = \ extra_options['resize'][disk_id] for text, path in extra_options['use_device'][1].items(): path = path[0] if path.rsplit('/', 1)[1] == disk_id: bar_frame = QtGui.QFrame() bar_frame.setLayout(QtGui.QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) self.resizeSize = pref_size dev = self.diskLayout[disk_id] before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.setResizePartition(resize_path, min_size, max_size, pref_size, release_name) after_bar.partitionResized.connect( self.on_partitionResized) addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) # TODO biggest_free_choice # Use entire disk. button = QtGui.QRadioButton(self.useDeviceChoice, self.autopart_selection_frame) self.autopartitionTexts.append(self.useDeviceChoice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextInstallNow) bId += 1 disks = [] for text, path in extra_options['use_device'][1].items(): path = path[0] bar_frame = QtGui.QFrame() bar_frame.setLayout(QtGui.QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) self.bar_frames.append(bar_frame) disks.append((text, bar_frame)) dev = self.diskLayout[path.rsplit('/', 1)[1]] before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p.device, int(p.size), p.filesystem) if before_bar.diskSize > 0: after_bar.addPartition(release_name, before_bar.diskSize, 'auto') else: after_bar.addPartition(release_name, 1, 'auto') addBars(bar_frame, before_bar, after_bar) self.disks.append(disks) # Manual partitioning. button = QtGui.QRadioButton(manual_choice, self.autopart_selection_frame) self.autopartitionTexts.append(manual_choice) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) button.clicked.connect(self.controller.setNextButtonTextNext) self.disks.append([]) #select the first button b = self.autopartition_buttongroup.button(0) b and b.click()
def setupChoices(self, choices, extra_options, resize_choice, manual_choice, biggest_free_choice): self._clearInfo() self.resizeChoice = resize_choice self.manualChoice = manual_choice # remove any previous autopartition selections for child in self.autopart_selection_frame.children(): if isinstance(child, QWidget): child.setParent(None) del child for child in self.barsFrame.children(): if isinstance(child, QWidget): self.barsFrame.layout().removeWidget(child) child.setParent(None) del child release_name = get_release_name() bId = 0 for choice in choices: button = QRadioButton(choice, self.autopart_selection_frame) self.autopart_selection_frame.layout().addWidget(button) self.autopartition_buttongroup.addButton(button, bId) bId += 1 #Qt changes the string by adding accelerators, #so keep pristine string here as is returned later to partman self.autopartitionTexts.append(choice) ## these three things are toggled by each option # extra options frame for the option #frame = None bar_frame = QFrame() bar_frame.setLayout(QVBoxLayout()) bar_frame.setVisible(False) bar_frame.layout().setSpacing(0) self.barsFrame.layout().addWidget(bar_frame) button.toggled[bool].connect(bar_frame.setVisible) # if we have more information about the choice # i.e. various hard drives to install onto if choice in extra_options: # label for the before device dev = None if choice == biggest_free_choice: biggest_free_id = extra_options[choice] dev = None try: resize_path = biggest_free_id[3] dev = self.diskLayout[resize_path.replace( "/", "=").rstrip("1234567890")] except Exception: pass if dev: #create partition bars for graphical before/after display before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) if p[1] == biggest_free_id: after_bar.addPartition(release_name, int(p[1]), 'auto') else: after_bar.addPartition(p[0], int(p[1]), p[3]) addBars(bar_frame, before_bar, after_bar) # install side by side/resize elif choice == resize_choice: # information about what can be resized extraInfo = extra_options[choice] min_size, max_size, pref_size, resize_path = extraInfo self.resizeSize = pref_size try: dev = self.diskLayout[resize_path.replace( "/", "=").rstrip("1234567890")] except Exception: pass if dev: before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: #addPartition(name, size, fs): before_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.addPartition(p[0], int(p[1]), p[3]) after_bar.setResizePartition(resize_path, min_size, max_size, pref_size, release_name) after_bar.partitionResized.connect( self.on_partitionResized) addBars(bar_frame, before_bar, after_bar) #full disk install elif choice != manual_choice: # setup new frame to hold combo box # this allows us to make the combo box indented over # as well as not stretch to full width as it would do in the # vertical layout frame = QFrame() self.autopart_selection_frame.layout().addWidget(frame) frame_layout = QHBoxLayout(frame) self.extra_combo = QComboBox() self.extra_combo.setEnabled(False) self.autopart_selection_frame.layout().addWidget( self.extra_combo) frame_layout.addSpacing(20) frame_layout.addWidget(self.extra_combo) frame_layout.addStretch(1) self.extra_bar_frames = [] comboTexts = [] button.toggled[bool].connect(self.extra_combo.setEnabled) for extra in extra_options[choice]: #each extra choice needs to toggle a change in the before bar #extra is just a string with a general description #each extra choice needs to be a before/after bar option if extra == '': continue extra_bar_frame = None # add the extra disk to the combo box self.extra_combo.addItem(extra) self.extra_combo.currentIndexChanged[int].connect( self.on_extra_combo_changed) #find the device to make a partition bar out of it dev = None for d in self.diskLayout: disk = d if disk.startswith('=dev='): disk = disk[5:] if "(%s)" % disk in extra: dev = self.diskLayout[d] break #add the bars if we found the device if dev: before_bar = PartitionsBar() after_bar = PartitionsBar() for p in dev: before_bar.addPartition(p[0], int(p[1]), p[3]) if before_bar.diskSize > 0: after_bar.addPartition(release_name, before_bar.diskSize, 'auto') else: after_bar.addPartition(release_name, 1, 'auto') extra_bar_frame = addBars(bar_frame, before_bar, after_bar) if len(self.extra_bar_frames) > 0: extra_bar_frame.setVisible(False) if extra_bar_frame is not None: self.extra_bar_frames.append(extra_bar_frame) # Qt changes the string by adding accelerators, # so keep the pristine string here to be # returned to partman later. comboTexts.append(extra) self.extraChoicesText[choice] = comboTexts #select the first button b = self.autopartition_buttongroup.button(0) if b: b.setChecked(True)