Skip to content

Commit

Permalink
Merge pull request #10 from yohanyee/development
Browse files Browse the repository at this point in the history
  • Loading branch information
gdevenyi authored Oct 19, 2022
2 parents bc91e70 + d20a475 commit edd9ef4
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 11 deletions.
36 changes: 34 additions & 2 deletions PyQC.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, parent=None):

self.actionOpen_Directory.triggered.connect(self.openDir)
self.actionOpen_Files.triggered.connect(self.openFiles)
self.actionOpen_CSV.triggered.connect(self.openCSV)
self.actionSave_As.triggered.connect(self.SaveAs)
self.action_Save.triggered.connect(self.Save)

Expand Down Expand Up @@ -163,6 +164,37 @@ def openFiles(self):
)
self.tableWidget.selectRow(self.listlocation)

def openCSV(self):
self.path, _ = QFileDialog.getOpenFileName(self, "Open File", "", "CSV(*.csv)")
print("Opening CSV file: {}".format(self.path))
if self.path:
with open(self.path, "r", newline="") as f:
nrows = 0
reader = csv.reader(f)
for row in reader:
nrows += 1
f.close()
self.tableWidget.setRowCount(nrows)
self.filelist = []
self.listlocation = nrows-1
with open(self.path, "r", newline="") as f:
reader = csv.reader(f)
for row, rowdata in enumerate(reader):
self.filelist.append(rowdata[0])
for column in range(3):
item = QTableWidgetItem(rowdata[column+1])
self.tableWidget.setItem(row, column, item)
# Start at first row with no QC rating
if ((rowdata[2]=="") or (rowdata[3]=="")) and row < self.listlocation:
self.listlocation = row
f.close()
self.label.load(self.filelist[self.listlocation])
self.tableWidget.scrollToItem(
self.tableWidget.item(self.listlocation, 0),
QAbstractItemView.PositionAtCenter,
)
self.tableWidget.selectRow(self.listlocation)

def openArgumentFiles(self):
self.tableWidget.setRowCount(len(self.filelist))
for i in range(len(self.filelist)):
Expand Down Expand Up @@ -210,7 +242,7 @@ def SaveAs(self):
with open(self.path, "w", newline="") as f:
writer = csv.writer(f)
for row in range(self.tableWidget.rowCount()):
rowdata = []
rowdata = [self.filelist[row]]
for column in range(self.tableWidget.columnCount()):
item = self.tableWidget.item(row, column)
if item is not None:
Expand All @@ -225,7 +257,7 @@ def Save(self):
with open(self.path, "w", newline="") as f:
writer = csv.writer(f)
for row in range(self.tableWidget.rowCount()):
rowdata = []
rowdata = [self.filelist[row]]
for column in range(self.tableWidget.columnCount()):
item = self.tableWidget.item(row, column)
if item is not None:
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,39 @@ View Control Settings
- Menu->Full size

## Development notes
To re-generate GUI:

### To re-generate GUI:

First, use `pyuic5` to automatically generate the python code from the user interface `.ui` file:

``pyuic5 window1.ui -o window1.py``

Then, modify window1.py as follows:

- import from `image_widgets.py`:

```python
# Add the following:
from image_widget import *
```

- Switch from `QtWidgets.QLabel` to `SaneDefaultsImageLabel`:

```python
# Replace (around line 90):
self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents)

# with
self.label = SaneDefaultsImageLabel()
```

- Switch from `scrollAreaWidgetContents` to `label`:

```python
# Replace (around line 100):
self.scrollArea.setWidget(self.scrollAreaWidgetContents)

# with
self.scrollArea.setWidget(self.label)
```

14 changes: 9 additions & 5 deletions window1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

# Form implementation generated from reading ui file 'window1.ui'
#
# Created by: PyQt5 UI code generator 5.12.3
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING! All changes made in this file will be lost!

# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.

from PyQt5 import QtCore, QtGui, QtWidgets
from image_widget import *
Expand Down Expand Up @@ -77,7 +77,7 @@ def setupUi(self, MainWindow):
self.scrollArea.setAlignment(QtCore.Qt.AlignCenter)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 810, 788))
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 800, 773))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
Expand All @@ -100,7 +100,7 @@ def setupUi(self, MainWindow):
self.gridLayout_2.addWidget(self.splitter_3, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1059, 20))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1059, 27))
self.menubar.setObjectName("menubar")
self.menu_File = QtWidgets.QMenu(self.menubar)
self.menu_File.setObjectName("menu_File")
Expand All @@ -115,10 +115,13 @@ def setupUi(self, MainWindow):
self.actionOpen_Files.setObjectName("actionOpen_Files")
self.actionOpen_Directory = QtWidgets.QAction(MainWindow)
self.actionOpen_Directory.setObjectName("actionOpen_Directory")
self.actionOpen_CSV = QtWidgets.QAction(MainWindow)
self.actionOpen_CSV.setObjectName("actionOpen_CSV")
self.menu_File.addAction(self.action_Save)
self.menu_File.addAction(self.actionSave_As)
self.menu_File.addAction(self.actionOpen_Files)
self.menu_File.addAction(self.actionOpen_Directory)
self.menu_File.addAction(self.actionOpen_CSV)
self.menubar.addAction(self.menu_File.menuAction())
self.menubar.addAction(self.menu_View.menuAction())

Expand All @@ -141,3 +144,4 @@ def retranslateUi(self, MainWindow):
self.actionSave_As.setText(_translate("MainWindow", "Save &As"))
self.actionOpen_Files.setText(_translate("MainWindow", "Open &Files"))
self.actionOpen_Directory.setText(_translate("MainWindow", "Open &Directory"))
self.actionOpen_CSV.setText(_translate("MainWindow", "Open CSV"))
12 changes: 9 additions & 3 deletions window1.ui
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>810</width>
<height>788</height>
<width>800</width>
<height>773</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -188,7 +188,7 @@
<x>0</x>
<y>0</y>
<width>1059</width>
<height>20</height>
<height>27</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
Expand All @@ -199,6 +199,7 @@
<addaction name="actionSave_As"/>
<addaction name="actionOpen_Files"/>
<addaction name="actionOpen_Directory"/>
<addaction name="actionOpen_CSV"/>
</widget>
<widget class="QMenu" name="menu_View">
<property name="title">
Expand Down Expand Up @@ -228,6 +229,11 @@
<string>Open &amp;Directory</string>
</property>
</action>
<action name="actionOpen_CSV">
<property name="text">
<string>Open CSV</string>
</property>
</action>
</widget>
<resources/>
<connections/>
Expand Down

0 comments on commit edd9ef4

Please sign in to comment.