def initWins(self): # viewer main form newWin = QMainWindow(self.mainWin) newWin.setAttribute(Qt.WA_DeleteOnClose) newWin.setContextMenuPolicy(Qt.CustomContextMenu) self.newWin = newWin # image list listWdg = dragQListWidget() listWdg.setWrapping(False) listWdg.setSelectionMode(QAbstractItemView.ExtendedSelection) listWdg.setContextMenuPolicy(Qt.CustomContextMenu) listWdg.label = None listWdg.setViewMode(QListWidget.IconMode) # set icon and listWdg sizes listWdg.setIconSize(QSize(self.iconSize, self.iconSize)) listWdg.setMaximumSize(160000, self.iconSize + 20) listWdg.setDragDropMode(QAbstractItemView.DragDrop) listWdg.customContextMenuRequested.connect(self.contextMenu) # dock the form dock = stateAwareQDockWidget(window) dock.setWidget(newWin) dock.setWindowFlags(newWin.windowFlags()) dock.setWindowTitle(newWin.windowTitle()) dock.setAttribute(Qt.WA_DeleteOnClose) self.dock = dock window.addDockWidget(Qt.BottomDockWidgetArea, dock) newWin.setCentralWidget(listWdg) self.listWdg = listWdg self.newWin.setWhatsThis("""<b>Library Viewer</b><br> To <b>open context menu</b> right click on an icon or a selection.<br> To <b>open an image</b> drag it onto the main window.<br> <b>Rating</b> is shown as 0 to 5 stars below each icon.<br> """) # end setWhatsThis
def application_window(qtbot): """This is only a stand-in for the main application window.""" widget = QMainWindow() widget.setAttribute(Qt.WA_DeleteOnClose) widget.show() qtbot.wait_for_window_shown(widget) yield widget def is_dead(): try: widget.objectName() except RuntimeError as exception_instance: return True else: return False widget.close() qtbot.waitUntil(is_dead, timeout=500)
def viewImage(self): """ display full size image in a new window Unused yet """ parent = window newWin = QMainWindow(parent) newWin.setAttribute(Qt.WA_DeleteOnClose) newWin.setContextMenuPolicy(Qt.CustomContextMenu) label = imageLabel(parent=newWin) label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) label.img = None newWin.setCentralWidget(label) sel = self.listWdg.selectedItems() item = sel[0] filename = item.data(Qt.UserRole)[0] newWin.setWindowTitle(filename) imImg = imImage.loadImageFromFile(filename, createsidecar=False, window=window) label.img = imImg newWin.showMaximized()
def playDiaporama(diaporamaGenerator, parent=None): """ Open a new window and play a slide show. @param diaporamaGenerator: generator for file names @type diaporamaGenerator: iterator object @param parent: @type parent: """ global isSuspended isSuspended = False # init diaporama window newWin = QMainWindow(parent) newWin.setAttribute(Qt.WA_DeleteOnClose) newWin.setContextMenuPolicy(Qt.CustomContextMenu) newWin.setWindowTitle(parent.tr('Slide show')) label = imageLabel(mainForm=parent) label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) label.img = None newWin.setCentralWidget(label) newWin.showFullScreen() # Pause key shortcut actionEsc = QAction('Pause', None) actionEsc.setShortcut(QKeySequence(Qt.Key_Escape)) newWin.addAction(actionEsc) # context menu event handler def contextMenuHandler(action): global isSuspended if action.text() == 'Pause': isSuspended = True # quit full screen mode newWin.showMaximized() elif action.text() == 'Full Screen': if action.isChecked(): newWin.showFullScreen() else: newWin.showMaximized() elif action.text() == 'Resume': newWin.close() isSuspended = False playDiaporama(diaporamaGenerator, parent=window) # rating : the tag is written into the .mie file; the file is # created if needed. elif action.text() in ['0', '1', '2', '3', '4', '5']: with exiftool.ExifTool() as e: e.writeXMPTag(name, 'XMP:rating', int(action.text())) # connect shortkey action actionEsc.triggered.connect( lambda checked=False, name=actionEsc: contextMenuHandler( name)) # named arg checked is sent # context menu def contextMenu(position): menu = QMenu() actionEsc.setEnabled(not isSuspended) action2 = QAction('Full Screen', None) action2.setCheckable(True) action2.setChecked(newWin.windowState() & Qt.WindowFullScreen) action3 = QAction('Resume', None) action3.setEnabled(isSuspended) for action in [actionEsc, action2, action3]: menu.addAction(action) action.triggered.connect( lambda checked=False, name=action: contextMenuHandler( name)) # named arg checked is sent subMenuRating = menu.addMenu('Rating') for i in range(6): action = QAction(str(i), None) subMenuRating.addAction(action) action.triggered.connect( lambda checked=False, name=action: contextMenuHandler( name)) # named arg checked is sent menu.exec_(position) # connect contextMenuRequested newWin.customContextMenuRequested.connect(contextMenu) newWin.setToolTip("Esc to exit full screen mode") newWin.setWhatsThis(""" <b>Slide Show</b><br> The slide show cycles through the starting directory and its subfolders to display images. Photos rated 0 or 1 star are not shown (by default, all photos are rated 5 stars).<br> Hit the Esc key to <b>exit full screen mode and pause.</b><br> Use the Context Menu for <b>rating and resuming.</b> The rating is saved in the .mie sidecar and the image file is not modified. """) # end of setWhatsThis # play diaporama window.modeDiaporama = True while True: if isSuspended: newWin.setWindowTitle(newWin.windowTitle() + ' Paused') break try: if not newWin.isVisible(): break name = next(diaporamaGenerator) # search rating in metadata rating = 5 # default with exiftool.ExifTool() as e: try: rt = e.readXMPTag( name, 'XMP:rating') # raise ValueError if sidecar not found r = search("\d", rt) if r is not None: rating = int(r.group(0)) except ValueError: rating = 5 # don't display image with low rating if rating < 2: app.processEvents() imImg = imImage.loadImageFromFile(name, createsidecar=False, cmsConfigure=True, window=window) # zoom might be modified by the mouse wheel : remember if label.img is not None: imImg.Zoom_coeff = label.img.Zoom_coeff coeff = imImg.resize_coeff(label) imImg.yOffset -= (imImg.height() * coeff - label.height()) / 2.0 imImg.xOffset -= (imImg.width() * coeff - label.width()) / 2.0 app.processEvents() if isSuspended: newWin.setWindowTitle(newWin.windowTitle() + ' Paused') break newWin.setWindowTitle( parent.tr('Slide show') + ' ' + name + ' ' + ' '.join(['*'] * imImg.meta.rating)) gc.collect() label.img = imImg label.repaint() app.processEvents() gc.collect() sleep(2) app.processEvents() except StopIteration: newWin.close() window.diaporamaGenerator = None break except ValueError: continue except RuntimeError: window.diaporamaGenerator = None break except: window.diaporamaGenerator = None window.modeDiaporama = False raise app.processEvents() window.modeDiaporama = False
def __init__(self, MainWindow: QMainWindow): # Set main window parameters MainWindow.setWindowTitle("ASL Tools") MainWindow.setAttribute(Qt.WA_TranslucentBackground) MainWindow.setWindowFlag(Qt.FramelessWindowHint) MainWindow.setWindowFlag(Qt.WindowStaysOnTopHint) MainWindow.setAttribute(Qt.WA_QuitOnClose) icon_size = QSize(48, 48) # Main frame frame = QWidget() frame.setObjectName("mainwindow") self.v_layout = QVBoxLayout(frame) self.v_layout.setMargin(0) self.v_layout.setSpacing(0) # Top frame self.frame_top = QFrame() self.frame_top.setObjectName("topframe") self.frame_top.setMaximumHeight(20) self.frame_top.setCursor(Qt.OpenHandCursor) self.v_layout.addWidget(self.frame_top) # Ellements in top frame self.h_layout = QHBoxLayout(self.frame_top) self.h_layout.setMargin(0) self.btn_quit = QToolButton() self.btn_quit.setIcon(QIcon(":/images/quit.svg")) self.btn_quit.setIconSize(QSize(16, 16)) self.btn_quit.setCursor(Qt.CursorShape.PointingHandCursor) self.btn_quit.setAutoRaise(True) self.h_layout.addWidget(self.btn_quit, alignment=Qt.AlignRight) # Misc self.h_layout_misc = QHBoxLayout() self.h_layout_misc.setSpacing(0) self.h_layout_misc.setMargin(0) self.v_layout.addLayout(self.h_layout_misc) # Help self.btn_help = QToolButton() self.btn_help.setIcon(QIcon(":/images/help.svg")) self.btn_help.setObjectName("toolsmall") self.btn_help.setIconSize(QSize(20, 20)) self.btn_help.setCursor(Qt.CursorShape.PointingHandCursor) self.h_layout_misc.addWidget(self.btn_help) # Settings self.btn_settings = QToolButton() self.btn_settings.setIcon(QIcon(":/images/settings.svg")) self.btn_settings.setObjectName("toolsmall") self.btn_settings.setIconSize(QSize(20, 20)) self.btn_settings.setCursor(Qt.CursorShape.PointingHandCursor) self.h_layout_misc.addWidget(self.btn_settings) # Button create vr3 model self.btn_model_vr3 = QToolButton() self.btn_model_vr3.setIcon(QIcon(":/images/model-vr3.svg")) self.btn_model_vr3.setObjectName("tool") self.btn_model_vr3.setIconSize(icon_size) self.btn_model_vr3.setCursor(Qt.CursorShape.PointingHandCursor) self.v_layout.addWidget(self.btn_model_vr3) # Create script self.btn_script = QToolButton() self.btn_script.setIcon(QIcon(":/images/script.svg")) self.btn_script.setObjectName("tool") self.btn_script.setIconSize(icon_size) self.btn_script.setCursor(Qt.CursorShape.PointingHandCursor) self.v_layout.addWidget(self.btn_script) # Create dashboard self.btn_dashboard = QToolButton() self.btn_dashboard.setIcon(QIcon(":/images/dashboard.svg")) self.btn_dashboard.setObjectName("tool") self.btn_dashboard.setIconSize(icon_size) self.btn_dashboard.setCursor(Qt.CursorShape.PointingHandCursor) self.v_layout.addWidget(self.btn_dashboard) # Create big script self.btn_bigscript = QToolButton() self.btn_bigscript.setIcon(QIcon(":/images/big-script.svg")) self.btn_bigscript.setObjectName("tool") self.btn_bigscript.setIconSize(icon_size) self.btn_bigscript.setCursor(Qt.CursorShape.PointingHandCursor) self.v_layout.addWidget(self.btn_bigscript) # # Window fit the layout MainWindow.setCentralWidget(frame) MainWindow.setFixedSize(frame.sizeHint())