sizewizard.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. # $Id$
  2. import sys
  3. from PyQt4 import QtCore, QtGui
  4. from qt_utils import connect
  5. class Sizewizardtwo(QtGui.QDialog):
  6. def __init__(self, parent=None):
  7. QtGui.QDialog.__init__(self, parent)
  8. self.resize(
  9. QtCore.QSize(
  10. QtCore.QRect(0, 0, 192, 182).size()
  11. ).expandedTo(self.minimumSizeHint()))
  12. self.vboxlayout = QtGui.QVBoxLayout(self)
  13. self.hboxlayout = QtGui.QHBoxLayout()
  14. self.label = QtGui.QLabel(self)
  15. self.hboxlayout.addWidget(self.label)
  16. self.spinBox = QtGui.QSpinBox(self)
  17. self.spinBox.setMinimum(1)
  18. self.spinBox.setMaximum(32)
  19. self.spinBox.setProperty("value", QtCore.QVariant(3))
  20. self.nr_partitions = 3
  21. self.hboxlayout.addWidget(self.spinBox)
  22. self.vboxlayout.addLayout(self.hboxlayout)
  23. self.listWidget = QtGui.QListWidget(self)
  24. self.vboxlayout.addWidget(self.listWidget)
  25. self.buttonBox = QtGui.QDialogButtonBox(self)
  26. self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
  27. self.buttonBox.setStandardButtons(
  28. QtGui.QDialogButtonBox.Cancel | \
  29. QtGui.QDialogButtonBox.NoButton | \
  30. QtGui.QDialogButtonBox.Ok
  31. )
  32. self.vboxlayout.addWidget(self.buttonBox)
  33. connect(self.buttonBox, "accepted()", self.accept)
  34. connect(self.buttonBox, "rejected()", self.reject)
  35. connect(self.spinBox, "valueChanged(int)", self.setNrPartitions)
  36. self.label.setText(QtGui.QApplication.translate(
  37. "Dialog", "Number of partitions", None,
  38. QtGui.QApplication.UnicodeUTF8)
  39. )
  40. self.listWidget.clear()
  41. index = 0
  42. while index < 32:
  43. widgetItem = QtGui.QListWidgetItem(self.listWidget)
  44. widgetItem.setFlags(
  45. QtCore.Qt.ItemIsSelectable | \
  46. QtCore.Qt.ItemIsEditable | \
  47. QtCore.Qt.ItemIsEnabled
  48. )
  49. widgetItem.setText(
  50. QtGui.QApplication.translate(
  51. "Dialog", "32M", None,
  52. QtGui.QApplication.UnicodeUTF8
  53. )
  54. )
  55. index += 1
  56. self.hideItems()
  57. def getPartitionsList(self):
  58. partList = []
  59. index = 0
  60. while index < self.nr_partitions:
  61. widgetItem = self.listWidget.item(index)
  62. partList.append( str(widgetItem.text()) )
  63. index += 1
  64. return ' '.join(partList)
  65. def getNrPartitions(self):
  66. return str(self.nr_partitions)
  67. def setNrPartitions(self, i):
  68. self.nr_partitions = i
  69. self.hideItems()
  70. def hideItems(self):
  71. hide = 0
  72. index = 0
  73. while index < 32:
  74. widgetItem = self.listWidget.item(index)
  75. if index == self.nr_partitions:
  76. hide = 1
  77. widgetItem.setHidden(hide)
  78. index += 1
  79. class Sizewizard(QtGui.QDialog):
  80. def __init__(self, parent=None):
  81. QtGui.QDialog.__init__(self, parent)
  82. self.__dmDialog = None
  83. self.__ui = None
  84. self.__changePartitionsDialog = None
  85. self.__partitionsList = '32M 32M 32M'
  86. # Setup UI made in Qt Designer.
  87. from ui_sizewiz1 import Ui_Dialog
  88. ui = Ui_Dialog()
  89. ui.setupUi(self)
  90. self.__ui = ui
  91. connect(
  92. ui.unpartedButton,
  93. 'toggled(bool)',
  94. self.setWidgetstate
  95. )
  96. connect(
  97. ui.partedButton,
  98. 'toggled(bool)',
  99. self.setWidgetstate
  100. )
  101. connect(
  102. ui.changePartitionsButton,
  103. 'clicked()',
  104. self.changePartionSizes
  105. )
  106. connect(
  107. ui.unpartedSize,
  108. 'valueChanged(int)',
  109. self.changedDiskSize
  110. )
  111. def setWidgetstate(self):
  112. print 'def setWidgetstate():'
  113. ui = self.__ui
  114. state = ui.partedButton.isChecked()
  115. print state
  116. ui.changePartitionsButton.setEnabled(state)
  117. ui.partedLabel.setEnabled(state)
  118. state = not state
  119. ui.unpartedSize.setEnabled(state)
  120. ui.unpartedLabel.setEnabled(state)
  121. def changedDiskSize(self, size):
  122. bold = 1
  123. if size > 32767:
  124. txt = 'Maximum sized FAT12 disk fo IDE extension'
  125. elif size == 720:
  126. txt = 'Regular 720KB DD-DS disk '+ \
  127. '(double density, double sided)'
  128. elif size == 360:
  129. txt = 'Regular 360KB DD-SS disk '+ \
  130. '(double density, single sided)'
  131. elif size > 720:
  132. txt = 'big disk for IDE extension' + \
  133. 'with size ' + str(size/1024) + "MB"
  134. bold = 0
  135. else:
  136. txt = "disk with custom size of " + \
  137. str(size) + "KB"
  138. bold = 0
  139. self.__ui.unpartedLabel.setText(txt)
  140. self.__ui.unpartedLabel.font().setBold(bold)
  141. def changePartionSizes(self):
  142. cpd = self.__changePartitionsDialog
  143. if cpd is None:
  144. self.__changePartitionsDialog = cpd = Sizewizardtwo()
  145. cpd.exec_()
  146. nr = cpd.getNrPartitions()
  147. partList = cpd.getPartitionsList()
  148. self.__partitionsList = partList
  149. self.__ui.partedLabel.setText( nr + " partitions: " + partList )
  150. def getSizes(self):
  151. ui = self.__ui
  152. if ui.partedButton.isChecked():
  153. sizes = self.__partitionsList
  154. else:
  155. sizes = str( self.__ui.unpartedSize.value() ) + 'K'
  156. print sizes
  157. return sizes
  158. if __name__ == '__main__':
  159. app = QtGui.QApplication(sys.argv)
  160. item = Sizewizard()
  161. #item.exec_()
  162. item.show()
  163. sys.exit(app.exec_())