-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcode_Enlargement.py
708 lines (521 loc) · 28.8 KB
/
code_Enlargement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
import form_Enlargement
import code_Filter
import datetime
import ntpath
import os
from math import floor
import piexif
from PyQt5.QtGui import (
QPixmap,
QPainter,
QCursor,
QIcon
)
from PyQt5.QtCore import (
Qt,
pyqtSignal,
QTimer,
QSize
)
from PyQt5.QtWidgets import (
QApplication,
QMdiSubWindow,
QGraphicsView,
QGraphicsScene,
QMessageBox,
QMenu,
QLabel,
QGroupBox,
QHBoxLayout
)
from PyQt5.Qt import QFrame, QVBoxLayout, QPushButton
class Enlargement(QMdiSubWindow, form_Enlargement.Ui_frmEnlargement):
# create "resized" as a signal that the window can emit
# we respond to this signal with the form's resizeMe method below
resized = pyqtSignal()
class MyGraphicsView(QGraphicsView):
def __init__(self):
QGraphicsView.__init__(self)
self.setRenderHints(QPainter.Antialiasing|QPainter.SmoothPixmapTransform)
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
self.setDragMode(QGraphicsView.ScrollHandDrag)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.mdiParent = ""
def wheelEvent(self,event):
adj = 1 + event.angleDelta().y()/120 * 0.1
self.scale(adj, adj)
# we need a keepress event handler here in case the user clicks on the photo.
# when user clicks on the photo, the keypress handler is this GraphicsView, not the Englargement class.
def keyPressEvent(self, e):
# F key is pressed. Re-display the currentEnlargement to fit the screen
if e.key() == Qt.Key_F:
self.mdiParent.fitEnlargement()
# Backspace key is pressed, so show previous image as enlargement
if e.key() == Qt.Key_Backspace:
self.mdiParent.showPreviousPhoto()
# Space bar is pressed, so show next image as enlargement
if e.key() == Qt.Key_Space:
self.mdiParent.showNextPhoto()
# F7 is pressed, so toggle display of cursor
if e.key() == Qt.Key_F7:
self.mdiParent.toggleHideCursor()
# F9 is pressed, so toggle display of camera details
if e.key() == Qt.Key_F9:
self.mdiParent.toggleCameraDetails()
# F11 is pressed, so toggle display of camera details
if e.key() == Qt.Key_F11:
self.mdiParent.toggleFullScreen()
# Esc is pressed, so exit full screen mode, if we're in it
if e.key() == Qt.Key_Escape and self.mdiParent.mdiParent.mdiParent.statusBar.isVisible() is False:
self.mdiParent.toggleFullScreen()
# 1-5 pressed, so rate the photo
if e.key() in [Qt.Key_0, Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5]:
self.mdiParent.ratePhoto(e.key())
# Right is pressed: show next photo
if e.key() == Qt.Key_Right or e.key() == Qt.Key_PageDown:
self.mdiParent.showNextPhoto()
# Left is pressed: show previous photo
if e.key() == Qt.Key_Left or e.key() == Qt.Key_PageUp:
self.mdiParent.showPreviousPhoto()
def contextMenuEvent(self, event):
QApplication.restoreOverrideCursor()
menu = QMenu(self)
menu.setStyleSheet("color:silver; background-color: #343333;")
actionFitToWindow = menu.addAction("Fit to window (F)")
menu.addSeparator()
actionShowNextPhoto = menu.addAction("Next photo (Right arrow)")
actionShowPreviousPhoto = menu.addAction("Previous photo (Left arrow)")
menu.addSeparator()
if self.mdiParent.isMaximized() is True:
if self.mdiParent.cursorIsVisible:
actionToggleHideCursor = menu.addAction("Hide cursor (F7)")
else:
actionToggleHideCursor = menu.addAction("Show cursor (F7)")
if self.mdiParent.detailsPane.isVisible():
actionToggleCameraDetails = menu.addAction("Hide details (F9)")
else:
actionToggleCameraDetails = menu.addAction("Show details (F9)")
if self.mdiParent.isMaximized() and self.mdiParent.mdiParent.mdiParent.isFullScreen():
actionToggleFullScreen = menu.addAction("Exit full screen (F11)")
else:
actionToggleFullScreen = menu.addAction("Full screen (F11)")
menu.addSeparator()
actionDetachFile = menu.addAction("Detach photo from Yearbird")
menu.addSeparator()
actionDeleteFile = menu.addAction("Delete photo from file system")
action = menu.exec_(self.mapToGlobal(event.pos()))
if self.mdiParent.isMaximized() is True:
if action == actionToggleHideCursor:
self.parent().toggleHideCursor()
if action == actionFitToWindow:
self.parent().fitEnlargement()
if action == actionShowNextPhoto:
self.parent().showNextPhoto()
if action == actionShowPreviousPhoto:
self.parent().showPreviousPhoto()
if action == actionToggleCameraDetails:
self.parent().toggleCameraDetails()
if action == actionToggleFullScreen:
self.parent().toggleFullScreen()
if action == actionDeleteFile:
self.parent().deleteFile()
if action == actionDetachFile:
self.parent().detachFile()
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.setAttribute(Qt.WA_DeleteOnClose,True)
self.resized.connect(self.resizeMe)
self.mdiParent = ""
self.photoList = []
self.currentIndex = 0
self.pixmapEnlargement = QPixmap()
self.layout().setDirection(1)
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(0)
self.setStyleSheet("color:silver; background-color: #343333")
self.detailsPaneLayout = QVBoxLayout()
self.detailsPaneLayout.setContentsMargins(0, 0, 0, 0)
self.detailsPaneLayout.setSpacing(0)
self.detailsPaneLayout.setAlignment(Qt.AlignCenter)
self.detailsPane = QFrame()
self.detailsPane.setLayout(self.detailsPaneLayout)
self.detailsPane.setStyleSheet("color:silver; background-color: #343333")
self.layout().addWidget(self.detailsPane)
# create label for species common name
self.commonName = QLabel()
self.commonName.setStyleSheet("font:12pt; font-weight:bold; color:silver; background-color: #343333; padding: 3px")
self.detailsPaneLayout.addWidget(self.commonName)
# create label for species scientific name
self.scientificName = QLabel()
self.scientificName.setStyleSheet("font:12pt; font-style:italic; color:silver; background-color: #343333; padding: 3px")
self.detailsPaneLayout.addWidget(self.scientificName)
# create label for camera details text
self.cameraDetails = QLabel()
self.cameraDetails.setStyleSheet("color:silver; background-color: #343333; padding: 3px")
self.detailsPane.setVisible(False)
self.detailsPaneLayout.addWidget(self.cameraDetails)
# create horizontal layout to show rating stars
self.horizontalGroupBox = QGroupBox()
self.horizontalGroupBox.setContentsMargins(0, 0, 0, 0)
self.horizontalGroupBox.setStyleSheet("background-color: #343333; padding: 3px")
self.detailsPaneLayout.addWidget(self.horizontalGroupBox)
ratingLayout = QHBoxLayout()
ratingLayout.setContentsMargins(0, 0, 0, 0)
ratingLayout.setSpacing(0)
self.star1 = QPushButton()
self.star2 = QPushButton()
self.star3 = QPushButton()
self.star4 = QPushButton()
self.star5 = QPushButton()
self.star1.setIconSize(QSize(40,40))
self.star2.setIconSize(QSize(40,40))
self.star3.setIconSize(QSize(40,40))
self.star4.setIconSize(QSize(40,40))
self.star5.setIconSize(QSize(40,40))
self.star1.setStyleSheet("QPushButton:pressed{ background-color: #343333; }")
self.star1.setStyleSheet("QPushButton:hover{ background-color: #343333; }")
self.star1.setStyleSheet("QPushButton:flat{ background-color: #343333; }")
self.star1.setStyleSheet("QPushButton{ background-color: #343333; border:none }")
self.star2.setStyleSheet("QPushButton:pressed{ background-color: #343333; }")
self.star2.setStyleSheet("QPushButton:hover{ background-color: #343333; }")
self.star2.setStyleSheet("QPushButton:flat{ background-color: #343333; }")
self.star2.setStyleSheet("QPushButton{ background-color: #343333; border:none }")
self.star3.setStyleSheet("QPushButton:pressed{ background-color: #343333; }")
self.star3.setStyleSheet("QPushButton:hover{ background-color: #343333; }")
self.star3.setStyleSheet("QPushButton:flat{ background-color: #343333; }")
self.star3.setStyleSheet("QPushButton{ background-color: #343333; border:none }")
self.star4.setStyleSheet("QPushButton:pressed{ background-color: #343333; }")
self.star4.setStyleSheet("QPushButton:hover{ background-color: #343333; }")
self.star4.setStyleSheet("QPushButton:flat{ background-color: #343333; }")
self.star4.setStyleSheet("QPushButton{ background-color: #343333; border:none }")
self.star5.setStyleSheet("QPushButton:pressed{ background-color: #343333; }")
self.star5.setStyleSheet("QPushButton:hover{ background-color: #343333; }")
self.star5.setStyleSheet("QPushButton:flat{ background-color: #343333; }")
self.star5.setStyleSheet("QPushButton{ background-color: #343333; border:none }")
self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star4.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star5.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star1.clicked.connect(lambda: self.ratePhoto(Qt.Key_1, "Clicked"))
self.star2.clicked.connect(lambda: self.ratePhoto(Qt.Key_2))
self.star3.clicked.connect(lambda: self.ratePhoto(Qt.Key_3))
self.star4.clicked.connect(lambda: self.ratePhoto(Qt.Key_4))
self.star5.clicked.connect(lambda: self.ratePhoto(Qt.Key_5))
ratingLayout.addWidget(self.star1)
ratingLayout.addWidget(self.star2)
ratingLayout.addWidget(self.star3)
ratingLayout.addWidget(self.star4)
ratingLayout.addWidget(self.star5)
self.horizontalGroupBox.setLayout(ratingLayout)
self.cursorIsVisible = True
def resizeEvent(self, event):
#routine to handle window resize event
self.resized.emit()
return super(self.__class__, self).resizeEvent(event)
def resizeMe(self):
QTimer.singleShot(5, self.fitEnlargement)
def scaleMe(self):
return
def keyPressEvent(self, e):
# F key is pressed. Re-display the currentEnlargement to fit the screen
if e.key() == Qt.Key_F:
self.fitEnlargement()
# Backspace key is pressed, so show previous image as enlargement
if e.key() == Qt.Key_Backspace:
self.showPreviousPhoto()
# Space bar is pressed, so show next image as enlargement
if e.key() == Qt.Key_Space:
self.showNextPhoto()
# F7 is pressed, so toggle display of cursor
if e.key() == Qt.Key_F7:
self.toggleHideCursor()
# F9 is pressed, so toggle display of camera details
if e.key() == Qt.Key_F9:
self.toggleCameraDetails()
# F11 is pressed, so toggle display of camera details
if e.key() == Qt.Key_F11:
self.toggleFullScreen()
# Esc is pressed, so exit full screen mode, if we're in it
if e.key() == Qt.Key_Escape and self.mdiParent.mdiParent.statusBar.isVisible() is False:
self.toggleFullScreen()
# 1-5 pressed, so rate the photo
if e.key() in [Qt.Key_0, Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5]:
self.ratePhoto(e.key())
# Right is pressed: show next photo
if e.key() == Qt.Key_Right or e.key() == Qt.Key_PageDown:
self.showNextPhoto()
# Left is pressed: show previous photo
if e.key() == Qt.Key_Left or e.key() == Qt.Key_PageUp:
self.showPreviousPhoto()
def ratePhoto(self, ratingKey, actionType=""):
if ratingKey == Qt.Key_0:
self.photoList[self.currentIndex][0]["rating"] = "0"
if ratingKey == Qt.Key_1:
if self.photoList[self.currentIndex][0]["rating"] == "1" and actionType == "Clicked":
self.photoList[self.currentIndex][0]["rating"] = "0"
else:
self.photoList[self.currentIndex][0]["rating"] = "1"
if ratingKey == Qt.Key_2:
self.photoList[self.currentIndex][0]["rating"] = "2"
if ratingKey == Qt.Key_3:
self.photoList[self.currentIndex][0]["rating"] = "3"
if ratingKey == Qt.Key_4:
self.photoList[self.currentIndex][0]["rating"] = "4"
if ratingKey == Qt.Key_5:
self.photoList[self.currentIndex][0]["rating"] = "5"
self.setCameraDetails()
self.detailsPane.setVisible(True)
self.mdiParent.mdiParent.db.photosNeedSaving = True
self.viewEnlargement.setFocus()
def showPreviousPhoto(self):
if self.currentIndex > 0:
self.currentIndex = self.currentIndex - 1
if self.currentIndex >= 0:
self.changeEnlargement()
def showNextPhoto(self):
if self.currentIndex < len(self.photoList) - 1:
self.currentIndex += 1
self.changeEnlargement()
def fillEnlargement(self):
# routine uses self.currentIndex to fill the right photo
self.pixmapEnlargement = QPixmap(self.photoList[self.currentIndex][0]["fileName"])
self.sceneEnlargement= QGraphicsScene()
# save the item ID of the pixmap so we can replace the pixmap photo easily later
self.itemPixmap = self.sceneEnlargement.addPixmap(self.pixmapEnlargement)
self.viewEnlargement = self.MyGraphicsView()
self.viewEnlargement.mdiParent = self
self.viewEnlargement.setScene(self.sceneEnlargement)
self.viewEnlargement.setStyleSheet("QWidget{ background-color: #343333;}")
# add viewEnlargementto the default layout of the form
self.layout().addWidget(self.viewEnlargement)
self.setCameraDetails()
self.setPhotoTitle()
QTimer.singleShot(10, self.fitEnlargement)
def changeEnlargement(self):
self.pixmapEnlargement = QPixmap(self.photoList[self.currentIndex][0]["fileName"])
self.itemPixmap.setPixmap(self.pixmapEnlargement)
self.setCameraDetails()
self.setPhotoTitle()
QTimer.singleShot(20, self.fitEnlargement)
def fitEnlargement(self):
# scale the view to fit the photo, edge to edge
self.viewEnlargement.setSceneRect(0, 0, self.pixmapEnlargement.width(), self.pixmapEnlargement.height())
self.viewEnlargement.fitInView(self.viewEnlargement.sceneRect(), Qt.KeepAspectRatio)
def setPhotoTitle(self):
# display the file name in the window title bar
basename = os.path.basename(self.photoList[self.currentIndex][0]["fileName"])
self.setWindowTitle(basename)
def toggleCameraDetails(self):
# toggle visibility of cameraDetails
if self.detailsPane.isVisible():
self.detailsPane.setVisible(False)
else:
self.detailsPane.setVisible(True)
QTimer.singleShot(10, self.fitEnlargement)
def toggleHideCursor(self):
# toggle visibility of the cursor
# abort if we're not full screen (don't want to confuse user by hiding cursor)
if not self.isMaximized():
return()
# abort if we're not full screen (don't want to confuse user by hiding cursor)
if not self.mdiParent.mdiParent.isFullScreen():
return()
if self.cursorIsVisible is True:
QApplication.setOverrideCursor(QCursor(Qt.BlankCursor))
self.cursorIsVisible = False
else:
QApplication.restoreOverrideCursor()
self.cursorIsVisible = True
def detachFile(self):
# remove photo from database, but don't delete it from file system
msgText = "Detach \n\n" + self.photoList[self.currentIndex][0]["fileName"] + "\n\n from Yearbird?"
msgText = msgText + "\n\n(File will NOT be deleted from file system)"
msg = QMessageBox()
msg.setText(msgText)
msg.setWindowTitle("Detach photo?")
msg.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
buttonClicked = msg.exec_()
if buttonClicked == QMessageBox.Yes:
# remove photo from database
currentPhoto = self.photoList[self.currentIndex][0]["fileName"]
photoCommonName = self.photoList[self.currentIndex][1]["commonName"]
photoLocation = self.photoList[self.currentIndex][1]["location"]
self.mdiParent.mdiParent.db.removePhotoFromDatabase(photoLocation, "", "", photoCommonName, currentPhoto)
# remove photo from current window's photo list
self.photoList.remove(self.photoList[self.currentIndex])
# refresh display of parent photo list
self.mdiParent.FillPhotos(self.mdiParent.filter)
# advance display to next photo
if len(self.photoList) == 0:
self.close()
if self.currentIndex < len(self.photoList):
self.changeEnlargement()
else:
self.currentIndex -= 1
self.changeEnlargement()
# set flag for requiring photo file save
self.mdiParent.mdiParent.db.photosNeedSaving = True
def deleteFile(self):
# remove photo from database, but don't delete it from file system
msgText = "Permanently delete \n\n" + self.photoList[self.currentIndex][0]["fileName"] + "\n\n from Yearbird and the file system?"
msg = QMessageBox()
msg.setText(msgText)
msg.setWindowTitle("Permanently delete photo?")
msg.setStandardButtons(QMessageBox.No | QMessageBox.Yes)
buttonClicked = msg.exec_()
if buttonClicked == QMessageBox.Yes:
# remove photo from database
currentPhoto = self.photoList[self.currentIndex][0]["fileName"]
photoCommonName = self.photoList[self.currentIndex][1]["commonName"]
photoLocation = self.photoList[self.currentIndex][1]["location"]
self.mdiParent.mdiParent.db.removePhotoFromDatabase(photoLocation, "", "", photoCommonName, currentPhoto)
# remove photo from current window's photo list
self.photoList.remove(self.photoList[self.currentIndex])
# advance display to next photo
if len(self.photoList) == 0:
self.close()
if self.currentIndex < len(self.photoList):
self.changeEnlargement()
else:
self.currentIndex -= 1
self.changeEnlargement()
# set flag for requiring photo file save
self.mdiParent.mdiParent.db.photosNeedSaving = True
# delete file from file system
if os.path.isfile(currentPhoto):
try:
os.remove(currentPhoto)
except:
pass
# refresh display of parent photo list
self.mdiParent.FillPhotos(self.mdiParent.filter)
def toggleFullScreen(self):
# toggle visibility of filter and menu bar
if not self.mdiParent.mdiParent.isFullScreen() is True:
self.mdiParent.mdiParent.dckFilter.setVisible(False)
self.mdiParent.mdiParent.dckPhotoFilter.setVisible(False)
self.mdiParent.mdiParent.menuBar.setVisible(False)
self.mdiParent.mdiParent.toolBar.setVisible(False)
self.mdiParent.mdiParent.statusBar.setVisible(False)
self.setWindowFlags(Qt.FramelessWindowHint)
self.mdiParent.mdiParent.showFullScreen()
self.showMaximized()
else:
self.mdiParent.mdiParent.dckFilter.setVisible(True)
self.mdiParent.mdiParent.dckPhotoFilter.setVisible(True)
self.mdiParent.mdiParent.menuBar.setVisible(True)
self.mdiParent.mdiParent.toolBar.setVisible(True)
self.mdiParent.mdiParent.statusBar.setVisible(True)
self.mdiParent.mdiParent.showNormal()
self.mdiParent.mdiParent.showMaximized()
self.setWindowFlags(Qt.SubWindow)
self.showNormal()
QApplication.restoreOverrideCursor()
QTimer.singleShot(10, self.fitEnlargement)
def setCameraDetails(self):
currentPhoto = self.photoList[self.currentIndex][0]["fileName"]
photoRating = self.photoList[self.currentIndex][0]["rating"]
photoCommonName = self.photoList[self.currentIndex][1]["commonName"]
photoScientificName = self.photoList[self.currentIndex][1]["scientificName"]
photoLocation = self.photoList[self.currentIndex][1]["location"]
# get EXIF data
try:
exif_dict = piexif.load(currentPhoto)
except:
exif_dict = ""
# get photo date from EXIF
try:
photoDateTime = exif_dict["Exif"][piexif.ExifIFD.DateTimeOriginal].decode("utf-8")
#parse EXIF data for date/time components
photoExifDate = photoDateTime[0:4] + "-" + photoDateTime[5:7] + "-" + photoDateTime[8:10]
photoExifTime = photoDateTime[11:13] + ":" + photoDateTime[14:16]
photoWeekday = datetime.datetime(int(photoDateTime[0:4]), int(photoDateTime[5:7]), int(photoDateTime[8:10]))
photoWeekday = photoWeekday.strftime("%A") + ", "
except:
photoExifDate = "Date unknown"
photoExifTime = "Time unknown"
photoWeekday = ""
try:
photoExifModel = exif_dict["0th"][piexif.ImageIFD.Model].decode("utf-8")
except:
photoExifModel = ""
try:
photoExifLensModel = exif_dict["Exif"][piexif.ExifIFD.LensModel].decode("utf-8")
except:
photoExifLensModel = ""
try:
photoExifExposureTime = exif_dict["Exif"][piexif.ExifIFD.ExposureTime]
photoExifExposureTime = "1/" + str(floor(photoExifExposureTime[1] / photoExifExposureTime[0])) + " sec"
except:
photoExifExposureTime = ""
try:
photoExifAperture = exif_dict["Exif"][piexif.ExifIFD.FNumber]
photoExifAperture = round(photoExifAperture[0] / photoExifAperture[1], 1)
except:
photoExifAperture = ""
try:
photoExifISO = exif_dict["Exif"][piexif.ExifIFD.ISOSpeedRatings]
except:
photoExifISO = ""
try:
photoExifFocalLength = exif_dict["Exif"][piexif.ExifIFD.FocalLength]
photoExifFocalLength = floor(photoExifFocalLength[0] / photoExifFocalLength[1])
photoExifFocalLength = str(photoExifFocalLength) + " mm"
except:
photoExifFocalLength = ""
self.commonName.setText(photoCommonName)
self.scientificName.setText(photoScientificName)
# detailsText = photoCommonName + "\n"
# detailsText = photoScientificName + "\n"
detailsText = "\n\n" + photoLocation + "\n"
detailsText = detailsText + photoWeekday + photoExifDate + "\n"
detailsText = detailsText + photoExifTime + "\n"
detailsText = detailsText + "\n"
detailsText = detailsText + photoExifModel + "\n"
detailsText = detailsText + photoExifLensModel + "\n"
detailsText = detailsText + "Focal Length: " + str(photoExifFocalLength) + "\n"
detailsText = detailsText + str(photoExifExposureTime) + "\n"
detailsText = detailsText + "Aperture: " + str(photoExifAperture) + "\n"
detailsText = detailsText + "ISO: " + str(photoExifISO)
detailsText = detailsText + "\n\n" + ntpath.basename(currentPhoto)
detailsText = detailsText + "\n\n\n" #add space to separate rating stars from text
if photoRating == "0":
self.star1.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star2.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star3.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
if photoRating == "1":
self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star2.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star3.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
if photoRating == "2":
self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star3.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
if photoRating == "3":
self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star4.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
if photoRating == "4":
self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star4.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star5.setIcon(QIcon(QPixmap(":/icon_star_gray.png")))
if photoRating == "5":
self.star1.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star2.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star3.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star4.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.star5.setIcon(QIcon(QPixmap(":/icon_star.png")))
self.cameraDetails.setText(detailsText)