Changeset - 2e3b9132fe02
[Not reviewed]
default
0 2 0
Silverwing - 4 years ago 2020-06-21 13:22:28

fix: properly show up to 1000 disks with proper indices
2 files changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
forms/mainwindow.py
Show inline comments
 
@@ -6,96 +6,98 @@ from mount.udisks import MountManager
 
import tempfile
 
import os
 
import shutil
 
import stat
 
import floppyemu
 
from .format_dlgs import FormatManyDialog, FormatOneDialog
 

	
 

	
 
class CustomListModel(QtCore.QStringListModel):
 
    def __init__(self, model=()):
 
        self.model = model
 
        super().__init__([m[1] for m in self.model])
 

	
 
    def setModel(self, model):
 
        self.model = model
 
        self.setStringList([m[1] for m in self.model])
 

	
 
    def getItem(self, index):
 
        return self.model[index]
 

	
 

	
 
class CustomTableModel(QtCore.QAbstractTableModel):
 
    headers = ['Label', 'Size']
 

	
 
    def __init__(self, placeholder):
 
        super().__init__()
 
        self.placeholder = placeholder
 
        self.model = []
 

	
 
    def setModel(self, model):
 
        self.beginResetModel()
 
        self.model = model
 
        self.endResetModel()
 

	
 
    def data(self, index, role=QtCore.Qt.DisplayRole):
 
        model = self.model[index.row()]
 
        if role == QtCore.Qt.DisplayRole:
 
            if QtCore.QVariant(model[index.column()]):
 
                if index.column() == 1:
 
                    return QtCore.QVariant(str(round(model[index.column()] / 1024, 2)) + 'KB')
 
                else:
 
                    return QtCore.QVariant(model[index.column()])
 
            else:
 
                return QtCore.QVariant(self.placeholder)
 

	
 
    def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
 
        if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
 
            return QtCore.QVariant(self.headers[section])
 
        elif orientation == QtCore.Qt.Vertical and role == QtCore.Qt.DisplayRole:
 
            return QtCore.QVariant(section)
 
        return super().headerData(section, orientation, role)
 

	
 
    def rowCount(self, parent=None):
 
        return len(self.model)
 

	
 
    def columnCount(self, parent=None):
 
        return 2
 

	
 

	
 
class MainWindow(Ui_MainWindow, QtWidgets.QMainWindow):
 
    def __init__(self, root=None):
 
        super().__init__()
 
        self.setupUi(self)
 

	
 
        self.root = root if root else tempfile.mktemp(prefix='kusbff_')
 
        os.makedirs(self.root, exist_ok=True)
 

	
 
        self.devices_model = CustomListModel()
 
        self.devices_combobox.setModel(self.devices_model)
 
        self.refresh_disk_drives()
 

	
 
        self.table_model = CustomTableModel('(Not set)')
 
        self.tableView.setModel(self.table_model)
 
        self.refresh_image_list()
 

	
 
        self.action_refresh_devices.triggered.connect(self.refresh_disk_drives)
 
        self.devices_combobox.currentIndexChanged.connect(self.on_device_change)
 
        self.action_open_floppy.triggered.connect(self.open_directory)
 
        self.action_write_floppy.triggered.connect(self.save_directory)
 
        self.action_read_image.triggered.connect(self.read_image)
 
        self.action_write_image.triggered.connect(self.write_image)
 
        self.action_format_disk.triggered.connect(self.format_one)
 
        self.action_format_usb.triggered.connect(self.format_many)
 
        self.action_about.triggered.connect(self.show_about_dialog)
 

	
 
    def show_about_dialog(self):
 
        AboutWidget().exec_()
 

	
 
    def format_one(self):
 
        if self.devices_combobox.currentIndex() != -1:
 
            indexes = self.tableView.selectedIndexes()
 
            device = '/dev/{}'.format(self.devices_model.getItem(self.devices_combobox.currentIndex())[0])
 
            FormatOneDialog.show_dialog(indexes[0].row(), device, os.path.join(self.root, 'temp'))
 
            self.refresh_image_list()
 

	
 
    def format_many(self):
 
        if self.devices_combobox.currentIndex() != -1:
 
            device = '/dev/{}'.format(self.devices_model.getItem(self.devices_combobox.currentIndex())[0])
ui/format_dialog.ui
Show inline comments
 
<?xml version="1.0" encoding="UTF-8"?>
 
<ui version="4.0">
 
 <class>Dialog</class>
 
 <widget class="QDialog" name="Dialog">
 
  <property name="geometry">
 
   <rect>
 
    <x>0</x>
 
    <y>0</y>
 
    <width>400</width>
 
    <height>96</height>
 
   </rect>
 
  </property>
 
  <property name="windowTitle">
 
   <string>Format</string>
 
  </property>
 
  <layout class="QVBoxLayout" name="verticalLayout">
 
   <property name="spacing">
 
    <number>0</number>
 
   </property>
 
   <property name="leftMargin">
 
    <number>0</number>
 
   </property>
 
   <property name="topMargin">
 
    <number>0</number>
 
   </property>
 
   <property name="rightMargin">
 
    <number>0</number>
 
   </property>
 
   <property name="bottomMargin">
 
    <number>0</number>
 
   </property>
 
   <item>
 
    <layout class="QGridLayout" name="gridLayout">
 
     <item row="1" column="1">
 
      <widget class="QSpinBox" name="sb_to"/>
 
      <widget class="QSpinBox" name="sb_to">
 
       <property name="maximum">
 
        <number>999</number>
 
       </property>
 
      </widget>
 
     </item>
 
     <item row="0" column="1">
 
      <widget class="QLabel" name="label_2">
 
       <property name="maximumSize">
 
        <size>
 
         <width>16777215</width>
 
         <height>16</height>
 
        </size>
 
       </property>
 
       <property name="text">
 
        <string>to</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item row="1" column="0">
 
      <widget class="QSpinBox" name="sb_from"/>
 
     </item>
 
     <item row="0" column="0">
 
      <widget class="QLabel" name="label">
 
       <property name="maximumSize">
 
        <size>
 
         <width>16777215</width>
 
         <height>16</height>
 
        </size>
 
       </property>
 
       <property name="text">
 
        <string>from</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item row="2" column="0">
 
      <widget class="QRadioButton" name="rb_size_720">
 
       <property name="text">
 
        <string>&amp;720KB</string>
 
       </property>
 
      </widget>
 
     </item>
 
     <item row="2" column="1">
 
      <widget class="QRadioButton" name="rb_size_1440">
 
       <property name="text">
 
        <string>&amp;1.44MB</string>
 
       </property>
 
       <property name="checked">
 
        <bool>true</bool>
 
       </property>
 
      </widget>
 
     </item>
 
    </layout>
0 comments (0 inline, 0 general)