def setTracks(self, tracks): if not self._first_display: self._removeOldWidgets() self._first_display = False self._widgets = {} parent = QWidget(self) l = QVBoxLayout(parent) for track in tracks: w = self._createTrackProgress(parent, track) l.addWidget(w) self._widgets[track['id']] = w l.addStretch(1) parent.setLayout(l) scroll = QScrollArea(self) scroll.setWidgetResizable(True) scroll.setWidget(parent) scroll.setAlignment(Qt.AlignCenter) scroll.setFrameShape(QFrame.NoFrame); l = QVBoxLayout(self) l.addWidget(scroll) l.addWidget(self.close_button) self.setLayout(l) self.close_button.setEnabled(False)
class PDFWidget(QWidget): scaleFactors = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 2.0] scalePercents = ["25%", "50%", "75%", "100%", "125%", "150%", "200%"] def __init__(self): QWidget.__init__(self) self.hboxLayout = QVBoxLayout() self.setLayout(self.hboxLayout) self.setMenu() self.setPDFLabelScrollArea() self.connect(self.pageLineEdit, SIGNAL("valueChanged(int)"), self.pdfLabel.setPage) self.connect(self.pdfLabel, SIGNAL("pageChanged"), self.pageLineEdit.setPageNumberValue) self.connect(self.pdfLabel, SIGNAL("pageChanged"), self.scrollToTop) self.connect(self.scaleComboBox, SIGNAL("currentIndexChanged(int)"), self.scaleDocument) self.connect(self.searchLineEdit, SIGNAL("returnPressed()"), self.searchDocument) self.connect(self.findButton, SIGNAL("clicked()"), self.searchDocument) self.connect(self.clearButton, SIGNAL("clicked()"), self.pdfLabel.setPage) self.connect(self.searchLineEdit, SIGNAL("textChanged(QString)"), self.checkSearchText) self.connect(self, SIGNAL("setDocument"), self.setDocument) def setMenu(self): self.menuLayout = QHBoxLayout() self.hboxLayout.addLayout(self.menuLayout) self.pageLineEdit = PageLineEdit() self.pageLineEdit.setEnabled(False) self.menuLayout.addLayout(self.pageLineEdit) spacer = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.menuLayout.addItem(spacer) self.searchLayout = QHBoxLayout() self.menuLayout.addLayout(self.searchLayout) self.searchLabel = QLabel(self.tr("Search:")) self.searchLabel.setTextFormat(Qt.AutoText) self.searchLayout.addWidget(self.searchLabel) self.searchLineEdit = QLineEdit() self.searchLineEdit.setEnabled(False) self.searchLabel.setBuddy(self.searchLineEdit) self.searchLayout.addWidget(self.searchLineEdit) self.searchComboBox = QComboBox() self.searchComboBox.setEnabled(False) self.searchComboBox.insertItems(0, ["Forwards", "Backwards"]) self.searchLayout.addWidget(self.searchComboBox) self.findButton = QPushButton("Find") self.findButton.setEnabled(False) self.searchLayout.addWidget(self.findButton) self.clearButton = QPushButton("Clear") self.clearButton.setEnabled(False) self.searchLayout.addWidget(self.clearButton) spacer = QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.menuLayout.addItem(spacer) self.scaleLabel = QLabel("Scale:") self.menuLayout.addWidget(self.scaleLabel) self.scaleComboBox = QComboBox() self.scaleComboBox.setEnabled(False) self.scaleComboBox.insertItems(0, self.scalePercents) self.scaleComboBox.setCurrentIndex(3) self.scaleLabel.setBuddy(self.scaleComboBox) self.menuLayout.addWidget(self.scaleComboBox) def setPDFLabelScrollArea(self): self.pdfLabel = PDFLabel(self) self.scrollArea = QScrollArea() self.scrollArea.setWidgetResizable(True) self.scrollArea.setAlignment(Qt.AlignCenter) self.scrollArea.setWidget(self.pdfLabel) self.hboxLayout.addWidget(self.scrollArea) def scrollToTop(self, value): self.scrollArea.verticalScrollBar().setValue(0) def setDocument(self, data): if self.pdfLabel.setDocument(data): self.searchLineEdit.setEnabled(True) self.searchComboBox.setEnabled(True) self.findButton.setEnabled(True) self.clearButton.setEnabled(True) self.scaleComboBox.setEnabled(True) self.pageLineEdit.setEnabled(True) self.pageLineEdit.setPageNumberValue(1) self.pageLineEdit.setMaximumPageNumber( self.pdfLabel.document().numPages()) def setError(self, errorMessage): self.pdfLabel.setError(errorMessage) def setMessage(self, message): self.pdfLabel.setText(message) def checkSearchText(self, text): if text == "": self.pdfLabel.setPage() def scaleDocument(self, index): self.pdfLabel.setScale(self.scaleFactors[index]) def searchDocument(self): if self.searchComboBox.currentIndex() == 0: location = self.pdfLabel.searchForwards(self.searchLineEdit.text()) else: location = self.pdfLabel.searchBackwards( self.searchLineEdit.text()) target = self.pdfLabel.matrix().mapRect(location).center().toPoint() self.scrollArea.ensureVisible(target.x(), target.y())
class ImageView(QWidget, Script): def __init__(self): Script.__init__(self, "viewerimage") self.type = "imageview" self.icon = None self.vfs = vfs.vfs() self.reg_viewer = re.compile(".*(JPEG|JPG|jpg|jpeg|GIF|gif|bmp|png|PNG|pbm|PBM|pgm|PGM|ppm|PPM|xpm|XPM|xbm|XBM|TIFF|tiff).*", re.IGNORECASE) self.sceneWidth = 0 def start(self, args): try : self.preview = args["preview"].value() except IndexError: self.preview = False try: self.node = args["file"].value() self.curIdx = self.node.at() except KeyError: pass def isImage(self, node): if node.size() != 0: try: type = node.dataType() except (IndexError, AttributeError, IOError): return False if self.reg_viewer.search(str(type)): return True return False def next(self): listNodes = self.node.parent().children() newIdx = self.curIdx + 1 if newIdx >= len(listNodes): newIdx = 0 while newIdx != self.curIdx: if self.isImage(listNodes[newIdx]): break newIdx += 1 if newIdx >= len(listNodes): newIdx = 0 self.curIdx = newIdx self.setImage(listNodes[self.curIdx]) def previous(self): listNodes = self.node.parent().children() newIdx = self.curIdx - 1 if newIdx < 0: newIdx = len(listNodes) - 1 while newIdx != self.curIdx: if self.isImage(listNodes[newIdx]): break newIdx -= 1 if newIdx < 0: newIdx = len(listNodes) - 1 self.curIdx = newIdx self.setImage(listNodes[self.curIdx]) def createActions(self): self.actions = QToolBar() self.actions.setObjectName("Image viewer actions") self.nextButton = QAction(QIcon(":next.png"), "Display next image", self.actions) self.previousButton = QAction(QIcon(":previous.png"), "Display previous image", self.actions) self.rotlButton = QAction(QIcon(":rotate-left.png"), "Rotate the image 90 degrees to the left", self.actions) self.rotrButton = QAction(QIcon(":rotate-right.png"), "Rotate the image 90 degrees to the right", self.actions) self.enlargeButton = QAction(QIcon(":viewmag+"), "Enlarge the image", self.actions) self.shrinkButton = QAction(QIcon(":viewmag-"), "Shrink the image", self.actions) self.fitButton = QAction(QIcon(":viewmagfit"), "Fit the image to the window", self.actions) self.normalButton = QAction(QIcon(":viewmag1"), "Show the image at its normal size", self.actions) self.actions.addAction(self.previousButton) self.actions.addAction(self.nextButton) self.actions.addAction(self.rotlButton) self.actions.addAction(self.rotrButton) self.actions.addAction(self.enlargeButton) self.actions.addAction(self.shrinkButton) self.actions.addAction(self.fitButton) self.actions.addAction(self.normalButton) self.connect(self.loadedImage, SIGNAL("available(bool)"), self.enableActions) self.connect(self.previousButton, SIGNAL("triggered()"), self.previous) self.connect(self.nextButton, SIGNAL("triggered()"), self.next) self.connect(self.rotlButton, SIGNAL("triggered()"), self.loadedImage.rotateLeft) self.connect(self.rotrButton, SIGNAL("triggered()"), self.loadedImage.rotateRight) self.connect(self.enlargeButton, SIGNAL("triggered()"), self.loadedImage.enlarge) self.connect(self.shrinkButton, SIGNAL("triggered()"), self.loadedImage.shrink) self.connect(self.fitButton, SIGNAL("triggered()"), self.loadedImage.fit) self.connect(self.normalButton, SIGNAL("triggered()"), self.loadedImage.normal) def enableActions(self, cond): self.rotlButton.setEnabled(cond) self.rotrButton.setEnabled(cond) self.enlargeButton.setEnabled(cond) self.shrinkButton.setEnabled(cond) self.fitButton.setEnabled(cond) self.normalButton.setEnabled(cond) def setImage(self, node): if not self.preview: self.imagelabel.clear() self.imagelabel.insert(QString.fromUtf8(node.absolute())) self.metadata.process(node) self.loadedImage.load(node) def g_display(self): QWidget.__init__(self, None) self.factor = 1 self.box = QHBoxLayout() self.setLayout(self.box) self.imagebox = QVBoxLayout() self.scrollArea = QScrollArea() self.loadedImage = LoadedImage(self.scrollArea) self.scrollArea.setWidget(self.loadedImage) self.scrollArea.setAlignment(Qt.AlignCenter) if not self.preview: self.createActions() self.imagelabelbox = QVBoxLayout() self.imagelabelbox.setSpacing(0) self.imagelabel = QLineEdit() self.imagelabelbox.addWidget(self.imagelabel) self.imagelabel.setReadOnly(True) self.imagebox.addWidget(self.actions) self.imagebox.addWidget(self.scrollArea) if not self.preview: self.imagebox.setAlignment(self.actions, Qt.AlignCenter) self.imagebox.addLayout(self.imagelabelbox) self.databox = QVBoxLayout() self.metadata = Metadata() self.databox.addWidget(self.metadata) if len(self.node.parent().children()) < 2: self.nextButton.setEnabled(False) self.previousButton.setEnabled(False) self.box.addLayout(self.imagebox) if not self.preview: self.box.addLayout(self.databox) self.setImage(self.node.parent().children()[self.curIdx]) def updateWidget(self): if not self.preview: self.metadata.setMaximumSize(self.width() / 4, self.height()) self.loadedImage.adjust() def resizeEvent(self, e): if not self.preview: self.metadata.setMaximumSize(self.width() / 4, self.height()) self.loadedImage.adjust()
class ImageView(QWidget, Script): def __init__(self): Script.__init__(self, "viewerimage") self.type = "imageview" self.icon = None self.vfs = vfs.vfs() self.ft = FILETYPE() self.reg_viewer = re.compile(".*(JPEG|JPG|jpg|jpeg|GIF|gif|bmp|BMP|png|PNG|pbm|PBM|pgm|PGM|ppm|PPM|xpm|XPM|xbm|XBM).*", re.IGNORECASE) self.loadedImage = LoadedImage() self.sceneWidth = 0 #self.sorter = SortImages() def start(self, args): self.node = args.get_node("file") self.curnode = self.node #self.parent = self.node.parent #self.sorter.setFolder(self.parent) #self.sorter.start() #self.getImage() def createMenuItems(self): self.l90button = QRotateButton(-90, ":rotate-left.png") self.r90button = QRotateButton(90, ":rotate-right.png") self.rotate180button = QRotateButton(180, ":rotate-180.png") self.zoomin = QZoomButton(float(1.25), ":zoom-in.png") self.zoomout = QZoomButton(float(0.8), ":zoom-out.png") self.fitbest = QPushButton("fitbest") #self.previous = QPushButton("previous") #self.next = QPushButton("next") self.connect(self.l90button, SIGNAL("clicked"), self.rotate) self.connect(self.r90button, SIGNAL("clicked"), self.rotate) self.connect(self.rotate180button, SIGNAL("clicked"), self.rotate) self.connect(self.zoomin, SIGNAL("zoomed"), self.zoom) self.connect(self.zoomout, SIGNAL("zoomed"), self.zoom) self.connect(self.fitbest, SIGNAL("clicked()"), self.fitbestgeom) #self.connect(self.previous, SIGNAL("clicked()"), self.setPreviousImage) #self.connect(self.next, SIGNAL("clicked()"), self.setNextImage) def drawMenu(self): self.hbox = QHBoxLayout() self.setLayout(self.vbox) self.hbox.addWidget(self.l90button) self.hbox.addWidget(self.r90button) self.hbox.addWidget(self.rotate180button) self.hbox.addWidget(self.zoomin) self.hbox.addWidget(self.zoomout) #self.hbox.addWidget(self.previous) #self.hbox.addWidget(self.next) self.hbox.addWidget(self.fitbest) self.vbox.addLayout(self.hbox) #def getIdx(self): # idx = 0 # res = -1 # for node in self.parent.next: # if node.name == self.node.name: # res = idx # idx += 1 # return res #type: 0 = forward, 1 = backward #def getImage(self, type=1): # pass #idx = self.parent.next.(self.curnode) #print nodes #for node in self.parent.next[self.idx:]: # type = getImageType(node) # if type != None: #self.setImage() #def setPreviousImage(self): # if self.idx == 0: # self.idx = len(self.parent.next) # self.node = self.parent.next[self.idx] # else: # self.idx -= 1 # self.node = self.parent.next[self.idx] # self.setImage() #def setNextImage(self): # pass def setImage(self): if self.node.attr.size != 0: map = self.node.attr.smap try: #XXX temporary patch for windows magic f = self.node.attr.smap["type"] except IndexError: #XXX temporary patch for windows magic self.ft.filetype(node) f = self.node.attr.smap["type"] res = self.reg_viewer.match(f) if res != None: type = f[:f.find(" ")] self.loadedImage.load(self.node, type) else: self.loadedImage.notSupported() #not supported format #self.loadedImage.notSupported() def g_display(self): QWidget.__init__(self, None) self.factor = 1 self.vbox = QVBoxLayout() self.setLayout(self.vbox) self.scrollArea = QScrollArea() self.scrollArea.setWidget(self.loadedImage) self.scrollArea.setAlignment(Qt.AlignCenter) self.vbox.addWidget(self.scrollArea) self.createMenuItems() self.drawMenu() self.setImage() def zoom(self, zoomer): self.factor *= zoomer self.loadedImage.resize(zoomer) if self.factor > 3.33: self.zoomin.setEnabled(False) elif self.factor < 0.33: self.zoomout.setEnabled(False) else: self.zoomin.setEnabled(True) self.zoomout.setEnabled(True) def fitbestgeom(self): self.factor = 1 self.loadedImage.adjust(self.sceneWidth) self.zoomin.setEnabled(True) self.zoomout.setEnabled(True) def rotate(self, angle): self.loadedImage.rotate(angle) def updateWidget(self): self.sceneWidth = self.scrollArea.geometry().width() self.loadedImage.adjust(self.sceneWidth) def resizeEvent(self, e): self.sceneWidth = self.scrollArea.geometry().width() self.loadedImage.adjust(self.sceneWidth)
class XNavigationEdit(XLineEdit): """ """ navigationChanged = Signal() __designer_icon__ = projexui.resources.find('img/ui/navigate.png') def __init__( self, parent = None ): super(XNavigationEdit, self).__init__( parent ) # define custom properties self._separator = '/' self._partsEditingEnabled = True self._originalText = '' self._scrollWidget = QScrollArea(self) self._partsWidget = QWidget(self._scrollWidget) self._buttonGroup = QButtonGroup(self) self._scrollAmount = 0 self._navigationModel = None # create the completer tree palette = self.palette() palette.setColor(palette.Base, palette.color(palette.Window)) palette.setColor(palette.Text, palette.color(palette.WindowText)) bg = palette.color(palette.Highlight) abg = bg.darker(115) fg = palette.color(palette.HighlightedText) sbg = 'rgb(%s, %s, %s)' % (bg.red(), bg.green(), bg.blue()) sabg = 'rgb(%s, %s, %s)' % (abg.red(), abg.green(), abg.blue()) sfg = 'rgb(%s, %s, %s)' % (fg.red(), fg.green(), fg.blue()) style = 'QTreeView::item:hover { '\ ' color: %s;'\ ' background: qlineargradient(x1:0,'\ ' y1:0,'\ ' x2:0,'\ ' y2:1,'\ ' stop: 0 %s,'\ ' stop: 1 %s);'\ '}' % (sfg, sbg, sabg) self._completerTree = QTreeView(self) self._completerTree.setStyleSheet(style) self._completerTree.header().hide() self._completerTree.setFrameShape(QTreeView.Box) self._completerTree.setFrameShadow(QTreeView.Plain) self._completerTree.setPalette(palette) self._completerTree.setEditTriggers(QTreeView.NoEditTriggers) self._completerTree.setWindowFlags(Qt.Popup) self._completerTree.installEventFilter(self) self._completerTree.setRootIsDecorated(False) self._completerTree.setItemsExpandable(False) # create the editing widget layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addStretch() self._scrollWidget.setFrameShape( QScrollArea.NoFrame ) self._scrollWidget.setFocusPolicy(Qt.NoFocus) self._scrollWidget.setWidget(self._partsWidget) self._scrollWidget.setWidgetResizable(True) self._scrollWidget.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self._scrollWidget.setAlignment(Qt.AlignTop | Qt.AlignRight) self._scrollWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self._scrollWidget.setContentsMargins(0, 0, 0, 0) self._scrollWidget.setViewportMargins(0, 0, 0, 0) self._scrollWidget.move(2, 2) self._partsWidget.setLayout(layout) self._partsWidget.setCursor(Qt.ArrowCursor) self._partsWidget.setAutoFillBackground(True) self._partsWidget.setFixedHeight(self.height() - 12) palette = self._partsWidget.palette() palette.setColor(palette.Background, palette.color(palette.Base)) self._partsWidget.setPalette(palette) # create connections self._completerTree.clicked.connect( self.navigateToIndex ) self._buttonGroup.buttonClicked.connect( self.handleButtonClick ) self._scrollWidget.horizontalScrollBar().valueChanged.connect( self.scrollParts ) def acceptEdit( self ): """ Accepts the current text and rebuilds the parts widget. """ if ( self._partsWidget.isVisible() ): return False use_completion = self.completer().popup().isVisible() completion = self.completer().currentCompletion() self._completerTree.hide() self.completer().popup().hide() if ( use_completion ): self.setText(completion) else: self.rebuild() return True def cancelEdit( self ): """ Rejects the current edit and shows the parts widget. """ if ( self._partsWidget.isVisible() ): return False self._completerTree.hide() self.completer().popup().hide() self.setText(self._originalText) return True def currentItem( self ): """ Returns the current navigation item from the current path. :return <XNavigationItem> || None """ model = self.navigationModel() if ( not model ): return None return model.itemByPath(self.text()) def eventFilter( self, object, event ): """ Filters the events for the inputed object through this edit. :param object | <QObject> event | <QEvent> :return <bool> | consumed """ if ( event.type() == event.KeyPress ): if ( event.key() == Qt.Key_Escape ): self._completerTree.hide() self.completer().popup().hide() self.cancelEdit() elif ( event.key() in (Qt.Key_Return, Qt.Key_Enter) ): self.acceptEdit() return True elif ( event.key() == Qt.Key_Tab ): if ( self.completer().popup().isVisible() ): text = str(self.completer().currentCompletion()) super(XNavigationEdit, self).setText(text) return True else: self.acceptEdit() return False elif ( event.type() == event.MouseButtonPress ): if ( not self._completerTree.rect().contains(event.pos()) ): self._completerTree.hide() self.completer().popup().hide() self.cancelEdit() return False def focusOutEvent( self, event ): """ Overloads the focus out event to cancel editing when the widget loses focus. :param event | <QFocusEvent> """ super(XNavigationEdit, self).focusOutEvent(event) self.cancelEdit() def handleButtonClick( self, button ): """ Handle the event when a user clicks on one of the part buttons. :param button | <QToolButton> """ path = button.property('path') is_completer = button.property('is_completer') # popup a completion menu if ( unwrapVariant(is_completer) ): model = self.navigationModel() if ( not model ): return sep = self.separator() path = str(unwrapVariant(path)) item = model.itemByPath(path, includeRoot = True) if ( not item ): return curr_path = str(self.text()).strip(self.separator()) curr_path = curr_path.replace(path, '').strip(self.separator()) child_name = '' if ( curr_path ): child_name = curr_path.split(self.separator())[0] index = model.indexFromItem(item) self._completerTree.move(QCursor.pos()) self._completerTree.setRootIndex(index) self._completerTree.verticalScrollBar().setValue(0) if ( child_name ): child_item = None for i in range(item.rowCount()): child = item.child(i) if ( child.text() == child_name ): child_item = child break if ( child_item ): child_index = model.indexFromItem(child_item) self._completerTree.setCurrentIndex(child_index) self._completerTree.scrollTo(child_index) self._completerTree.show() self._completerTree.setUpdatesEnabled(True) else: self.setText(unwrapVariant(path)) def keyPressEvent( self, event ): """ Overloads the key press event to listen for escape calls to cancel the parts editing. :param event | <QKeyPressEvent> """ if ( self.scrollWidget().isHidden() ): if ( event.key() == Qt.Key_Escape ): self.cancelEdit() return elif ( event.key() in (Qt.Key_Return, Qt.Key_Enter) ): self.acceptEdit() return elif ( event.key() == Qt.Key_A and event.modifiers() == Qt.ControlModifier ): self.startEdit() super(XNavigationEdit, self).keyPressEvent(event) def mouseDoubleClickEvent( self, event ): """ Overloads the system to enable editing when a user double clicks. :param event | <QMouseEvent> """ super(XNavigationEdit, self).mouseDoubleClickEvent(event) self.startEdit() def navigationModel( self ): """ Returns the navigation model linked with this edit. :return <XNavigationModel> || None """ return self._navigationModel def navigateToIndex( self, index ): """ Navigates to the inputed action's path. :param action | <QAction> """ self._completerTree.hide() item = self._navigationModel.itemFromIndex(index) self.setText(self._navigationModel.itemPath(item)) def parts( self ): """ Returns the parts that are used for this system. :return [<str>, ..] """ path = str(self.text()).strip(self.separator()) if ( not path ): return [] return path.split(self.separator()) def partsWidget( self ): """ Returns the widget that contains the parts system. :return <QScrollArea> """ return self._partsWidget def startEdit( self ): """ Rebuilds the pathing based on the parts. """ self._originalText = self.text() self.scrollWidget().hide() self.setFocus() self.selectAll() def rebuild( self ): """ Rebuilds the parts widget with the latest text. """ navitem = self.currentItem() if ( navitem ): navitem.initialize() self.setUpdatesEnabled(False) self.scrollWidget().show() self._originalText = '' partsw = self.partsWidget() for button in self._buttonGroup.buttons(): self._buttonGroup.removeButton(button) button.close() button.setParent(None) button.deleteLater() # create the root button layout = partsw.layout() parts = self.parts() button = QToolButton(partsw) button.setAutoRaise(True) button.setMaximumWidth(12) button.setArrowType(Qt.RightArrow) button.setProperty('path', wrapVariant('')) button.setProperty('is_completer', wrapVariant(True)) last_button = button self._buttonGroup.addButton(button) layout.insertWidget(0, button) # check to see if we have a navigation model setup if ( self._navigationModel ): last_item = self._navigationModel.itemByPath(self.text()) show_last = last_item and last_item.rowCount() > 0 else: show_last = False # load the navigation system count = len(parts) for i, part in enumerate(parts): path = self.separator().join(parts[:i+1]) button = QToolButton(partsw) button.setAutoRaise(True) button.setText(part) if ( self._navigationModel ): item = self._navigationModel.itemByPath(path) if ( item ): button.setIcon(item.icon()) button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) button.setProperty('path', wrapVariant(path)) button.setProperty('is_completer', wrapVariant(False)) self._buttonGroup.addButton(button) layout.insertWidget((i * 2) + 1, button) # determine if we should show the final button if ( show_last or i < (count - 1) ): button = QToolButton(partsw) button.setAutoRaise(True) button.setMaximumWidth(12) button.setArrowType(Qt.RightArrow) button.setProperty('path', wrapVariant(path)) button.setProperty('is_completer', wrapVariant(True)) self._buttonGroup.addButton(button) layout.insertWidget((i * 2) + 2, button) last_button = button if ( self.scrollWidget().width() < partsw.width() ): self.scrollParts(partsw.width() - self.scrollWidget().width()) self.setUpdatesEnabled(True) self.navigationChanged.emit() def resizeEvent( self, event ): """ Resizes the current widget and its parts widget. :param event | <QResizeEvent> """ super(XNavigationEdit, self).resizeEvent(event) w = self.width() h = self.height() self._scrollWidget.resize(w - 4, h - 4) if ( self._scrollWidget.width() < self._partsWidget.width() ): self.scrollParts( self._partsWidget.width() - self._scrollWidget.width() ) def scrollParts( self, amount ): """ Scrolls the parts to offset the scrolling amount. :param amount | <int> """ change = self._scrollAmount - amount self._partsWidget.scroll(change, 0) self._scrollAmount = amount def scrollWidget( self ): """ Returns the scrolling widget. :return <QScrollArea> """ return self._scrollWidget def separator( self ): """ Returns the separation character that is used for this edit. :return <str> """ return self._separator def setTopLevelItems( self, items ): """ Initializes the navigation system to start with the inputed root \ item. :param item | <XNavigationItem> """ if ( not self._navigationModel ): self.setNavigationModel(XNavigationModel(self)) self._navigationModel.setTopLevelItems(items) def setNavigationModel( self, model ): """ Sets the navigation model for this edit. :param model | <XNavigationModel> """ self._navigationModel = model self._completerTree.setModel(model) if ( model ): model.setSeparator(self.separator()) completer = XNavigationCompleter(model, self) self.setCompleter(completer) completer.popup().installEventFilter(self) else: self.setCompleter(None) self.rebuild() def setParts( self, parts ): """ Sets the path for this edit widget by providing the parts to the path. :param parts | [<str>, ..] """ self.setText(self.separator().join(map(str, parts))) def setSeparator( self, separator ): """ Sets the separator to the inputed character. :param separator | <str> """ self._separator = separator if ( self._navigationModel ): self._navigationModel.setSeparator(separator) self.rebuild() def setText( self, text ): """ Sets the text for this edit to the inputed text. :param text | <str> """ super(XNavigationEdit, self).setText(text) self.scrollWidget().show() if ( text == '' or self._originalText != text ): self.rebuild()
class ImageView(QWidget, Script): def __init__(self): Script.__init__(self, "viewerimage") self.type = "imageview" self.icon = None self.vfs = vfs.vfs() self.reg_viewer = re.compile( ".*(JPEG|JPG|jpg|jpeg|GIF|gif|bmp|png|PNG|pbm|PBM|pgm|PGM|ppm|PPM|xpm|XPM|xbm|XBM|TIFF|tiff).*", re.IGNORECASE) self.sceneWidth = 0 def start(self, args): try: self.preview = args["preview"].value() except IndexError: self.preview = False try: self.node = args["file"].value() self.curIdx = self.node.at() except KeyError: pass def isImage(self, node): if node.size() != 0: try: _type = node.dataType() except (IndexError, AttributeError, IOError): return False if self.reg_viewer.search(_type): return True return False def next(self): listNodes = self.node.parent().children() newIdx = self.curIdx + 1 if newIdx >= len(listNodes): newIdx = 0 while newIdx != self.curIdx: if self.isImage(listNodes[newIdx]): break newIdx += 1 if newIdx >= len(listNodes): newIdx = 0 self.curIdx = newIdx self.setImage(listNodes[self.curIdx]) def previous(self): listNodes = self.node.parent().children() newIdx = self.curIdx - 1 if newIdx < 0: newIdx = len(listNodes) - 1 while newIdx != self.curIdx: if self.isImage(listNodes[newIdx]): break newIdx -= 1 if newIdx < 0: newIdx = len(listNodes) - 1 self.curIdx = newIdx self.setImage(listNodes[self.curIdx]) def createActions(self): self.actions = QToolBar() self.actions.setObjectName("Image viewer actions") self.nextButton = QAction(QIcon(":next.png"), "Display next image", self.actions) self.previousButton = QAction(QIcon(":previous.png"), "Display previous image", self.actions) self.rotlButton = QAction(QIcon(":rotate-left.png"), "Rotate the image 90 degrees to the left", self.actions) self.rotrButton = QAction(QIcon(":rotate-right.png"), "Rotate the image 90 degrees to the right", self.actions) self.enlargeButton = QAction(QIcon(":viewmag+"), "Enlarge the image", self.actions) self.shrinkButton = QAction(QIcon(":viewmag-"), "Shrink the image", self.actions) self.fitButton = QAction(QIcon(":viewmagfit"), "Fit the image to the window", self.actions) self.normalButton = QAction(QIcon(":viewmag1"), "Show the image at its normal size", self.actions) self.actions.addAction(self.previousButton) self.actions.addAction(self.nextButton) self.actions.addAction(self.rotlButton) self.actions.addAction(self.rotrButton) self.actions.addAction(self.enlargeButton) self.actions.addAction(self.shrinkButton) self.actions.addAction(self.fitButton) self.actions.addAction(self.normalButton) self.connect(self.loadedImage, SIGNAL("available(bool)"), self.enableActions) self.connect(self.previousButton, SIGNAL("triggered()"), self.previous) self.connect(self.nextButton, SIGNAL("triggered()"), self.next) self.connect(self.rotlButton, SIGNAL("triggered()"), self.loadedImage.rotateLeft) self.connect(self.rotrButton, SIGNAL("triggered()"), self.loadedImage.rotateRight) self.connect(self.enlargeButton, SIGNAL("triggered()"), self.loadedImage.enlarge) self.connect(self.shrinkButton, SIGNAL("triggered()"), self.loadedImage.shrink) self.connect(self.fitButton, SIGNAL("triggered()"), self.loadedImage.fit) self.connect(self.normalButton, SIGNAL("triggered()"), self.loadedImage.normal) def enableActions(self, cond): self.rotlButton.setEnabled(cond) self.rotrButton.setEnabled(cond) self.enlargeButton.setEnabled(cond) self.shrinkButton.setEnabled(cond) self.fitButton.setEnabled(cond) self.normalButton.setEnabled(cond) def setImage(self, node): if not self.preview: self.imagelabel.clear() self.imagelabel.insert(QString.fromUtf8(node.absolute())) self.metadata.process(node) self.loadedImage.load(node) def g_display(self): QWidget.__init__(self, None) self.factor = 1 self.box = QHBoxLayout() self.setLayout(self.box) self.imagebox = QVBoxLayout() self.scrollArea = QScrollArea() self.loadedImage = LoadedImage(self.scrollArea) self.scrollArea.setWidget(self.loadedImage) self.scrollArea.setAlignment(Qt.AlignCenter) if not self.preview: self.createActions() self.imagelabelbox = QVBoxLayout() self.imagelabelbox.setSpacing(0) self.imagelabel = QLineEdit() self.imagelabelbox.addWidget(self.imagelabel) self.imagelabel.setReadOnly(True) self.imagebox.addWidget(self.actions) self.imagebox.addWidget(self.scrollArea) if not self.preview: self.imagebox.setAlignment(self.actions, Qt.AlignCenter) self.imagebox.addLayout(self.imagelabelbox) self.databox = QVBoxLayout() self.metadata = Metadata() self.databox.addWidget(self.metadata) if len(self.node.parent().children()) < 2: self.nextButton.setEnabled(False) self.previousButton.setEnabled(False) self.box.addLayout(self.imagebox) if not self.preview: self.box.addLayout(self.databox) self.setImage(self.node.parent().children()[self.curIdx]) def updateWidget(self): if not self.preview: self.metadata.setMaximumSize(self.width() / 4, self.height()) self.loadedImage.adjust() def resizeEvent(self, e): if not self.preview: self.metadata.setMaximumSize(self.width() / 4, self.height()) self.loadedImage.adjust()