示例#1
0
class ConfSettingsWidget ( QWidget ):

    def __init__ ( self, conf, parent=None ):
        QWidget.__init__( self, parent )
        self._rowHeight = 20

        self._view = QTableView()
        self._view.setShowGrid            ( False )
        self._view.setAlternatingRowColors( True )
        self._view.setSelectionBehavior   ( QAbstractItemView.SelectRows )
       #self._view.setSortingEnabled      ( True )
       #self._view.installEventFilter     ( self )

        horizontalHeader = self._view.horizontalHeader ()
        horizontalHeader.setStretchLastSection ( True )
        horizontalHeader.setMinimumSectionSize ( 150 )
        horizontalHeader.setResizeMode         ( QHeaderView.ResizeToContents )
        horizontalHeader.setDefaultSectionSize ( 150 )

        verticalHeader = self._view.verticalHeader ();
        verticalHeader.setVisible ( False );
        verticalHeader.setDefaultSectionSize ( self._rowHeight );

        self._baseModel = ConfSettingsModel( conf )
        self._view.setModel( self._baseModel );
        self._view.horizontalHeader().setStretchLastSection( True );
        self._view.resizeColumnToContents( 0 );

        peanoDataLayout = QGridLayout();
        peanoDataLayout.addWidget( self._view, 0, 0, 1, 1 );

        self.setLayout ( peanoDataLayout );
        return
示例#2
0
class Window(QWidget):

    def __init__(self, parent = None):
    
        QWidget.__init__(self, parent)
        
        self.table = QTableView()
        self.imageTable = QTableView()
        delegate = PixelDelegate(self)
        self.imageTable.setItemDelegate(delegate)
        self.imageTable.horizontalHeader().hide()
        self.imageTable.verticalHeader().hide()
        self.imageTable.setShowGrid(False)
        
        self.imageCombo = QComboBox()
        self.imageCombo.addItem("Dream", QVariant(":/Pictures/dream.png"))
        self.imageCombo.addItem("Teapot", QVariant(":/Pictures/teapot.png"))
        
        gridCheckBox = QCheckBox(self.tr("Show grid:"))
        gridCheckBox.setCheckState(Qt.Unchecked)
        
        self.connect(self.imageCombo, SIGNAL("currentIndexChanged(int)"),
                     self.setModel)
        self.connect(gridCheckBox, SIGNAL("toggled(bool)"),
                     self.imageTable, SLOT("setShowGrid(bool)"))
        
        self.imageCombo.setCurrentIndex(1)
        
        layout = QGridLayout()
        layout.addWidget(self.imageTable, 0, 0, 1, 2)
        layout.addWidget(self.table, 0, 2, 1, 2)
        layout.addWidget(gridCheckBox, 1, 0)
        layout.addWidget(self.imageCombo, 1, 1)
        self.setLayout(layout)
    
    def setModel(self, row):
    
        image = QImage(self.imageCombo.itemData(row).toString())
        model = ImageModel(image, self)
        self.table.setModel(model)
        self.imageTable.setModel(model)
        
        for row in range(model.rowCount(QModelIndex())):
            self.imageTable.resizeRowToContents(row)
        for column in range(model.columnCount(QModelIndex())):
            self.imageTable.resizeColumnToContents(column)
示例#3
0
文件: 2669.py 项目: jlg234bob/PPQT
class pagesPanel(QWidget):
    def __init__(self, parent=None):
        super(pagesPanel, self).__init__(parent)
        # The layout is very basic, the table with an Update button.
        mainLayout = QVBoxLayout()
        self.setLayout(mainLayout)
        hlayout = QHBoxLayout()
        self.updateButton = QPushButton("Update")
        self.insertText = QLineEdit()
        self.insertText.setFont(pqMsgs.getMonoFont())
        self.insertButton = QPushButton("Insert")
        hlayout.addWidget(self.updateButton, 0)
        hlayout.addWidget(self.insertText, 1)  # text gets all available room
        hlayout.addWidget(self.insertButton, 0)
        mainLayout.addLayout(hlayout)
        self.view = QTableView()
        self.view.setCornerButtonEnabled(False)
        self.view.setWordWrap(False)
        self.view.setAlternatingRowColors(True)
        self.view.setSortingEnabled(False)
        self.c1Delegate = formatDelegate()
        self.view.setItemDelegateForColumn(1, self.c1Delegate)
        self.c2Delegate = actionDelegate()
        self.view.setItemDelegateForColumn(2, self.c2Delegate)
        self.c3Delegate = folioDelegate()
        self.view.setItemDelegateForColumn(3, self.c3Delegate)
        mainLayout.addWidget(self.view, 1)
        # Set up the table model/view.
        self.model = myTableModel()
        self.view.setModel(self.model)
        # Connect the double-clicked signal of the view
        self.connect(self.view, SIGNAL("doubleClicked(QModelIndex)"),
                     self.goToRow)
        # Connect the update button to the model's update method
        self.connect(self.updateButton, SIGNAL("clicked()"),
                     self.model.updateFolios)
        # Connect the insert button to our insert method
        self.connect(self.insertButton, SIGNAL("clicked()"),
                     self.insertMarkers)

    # This slot receives a double-click from the table view,
    # passing an index. If the click is in column 0, the scan number,
    # get the row; use it to get a text cursor from the page table
    # and make that the editor's cursor, thus moving to the top of that page.
    # Double-click on cols 1-3 initiates editing and maybe someday a
    # doubleclick on column 5 will do something with the proofer info.
    def goToRow(self, index):
        if index.column() == 0:
            tc = IMC.pageTable.getCursor(index.row())
            IMC.editWidget.setTextCursor(tc)
            IMC.editWidget.setFocus(Qt.TabFocusReason)

    # This slot receives the main window's docWillChange signal.
    # It comes with a file path but we can ignore that.
    def docWillChange(self):
        self.model.beginResetModel()

    # Subroutine to reset the visual appearance of the table view,
    # invoked on table reset because on instantiation we have no table.
    def setUpTableView(self):
        # Header text is supplied by the table model headerData method
        # Here we are going to set the column widths of the first 4
        # columns to a uniform 7 ens each based on the current font.
        # However, at least on Mac OS, the headers are rendered with a
        # much smaller font than the data, so we up it by 50%.
        hdr = self.view.horizontalHeader()
        pix = hdr.fontMetrics().width(QString("9999999"))
        hdr.resizeSection(0, pix)
        hdr.resizeSection(3, pix)
        pix += pix / 2
        hdr.resizeSection(1, pix)
        hdr.resizeSection(2, pix)
        self.view.resizeColumnToContents(4)

    # This slot receives the main window's docHasChanged signal.
    # Let the table view populate with all-new metadata (or empty
    # data if the command was File>New).
    def docHasChanged(self):
        self.model.endResetModel()
        self.setUpTableView()

    # On the Insert button being pressed, make some basic sanity checks
    # and get user go-ahead then insert the given text at the head of
    # every page.
    def insertMarkers(self):
        # Copy the text and if it is empty, complain and exit.
        qi = QString(self.insertText.text())
        if qi.isEmpty():
            pqMsgs.warningMsg("No insert text specified")
            return
        # See how many pages are involved: all the ones that aren't marked skip
        n = 0
        for i in range(IMC.pageTable.size()):
            if IMC.pageTable.getAction(i) != IMC.FolioRuleSkip:
                n += 1
        if n == 0:  # page table empty or all rows marked skip
            pqMsgs.warningMsg("No pages to give folios to")
            return
        m = "Insert this string at the top of {0} pages?".format(n)
        b = pqMsgs.okCancelMsg(QString(m), pqMsgs.trunc(qi, 35))
        if b:
            # Convert any '\n' in the text to the QT line delimiter char
            # we do this in the copy so the lineEdit text doesn't change
            qi.replace(QString(u'\\n'), QString(IMC.QtLineDelim))
            # get a cursor on the edit document
            tc = QTextCursor(IMC.editWidget.textCursor())
            tc.beginEditBlock()  # start single undoable operation
            # Working from the end of the document backward, go to the
            # top of each page and insert the string
            for i in reversed(range(IMC.pageTable.size())):
                if IMC.pageTable.getAction(i) != IMC.FolioRuleSkip:
                    # Note the page's start position and set our work cursor to it
                    pos = IMC.pageTable.getCursor(i).position()
                    tc.setPosition(pos)
                    # Make a copy of the insert string replacing %f with this folio
                    f = IMC.pageTable.getDisplay(i)
                    qf = QString(qi)
                    qf.replace(QString(u'%f'), f, Qt.CaseInsensitive)
                    tc.insertText(qf)
                    # The insertion goes in ahead of the saved cursor position so now
                    # it points after the inserted string. Put it back where it was.
                    IMC.pageTable.setPosition(i, pos)
            tc.endEditBlock()  # wrap up the undo op
示例#4
0
class pagesPanel(QWidget):
    def __init__(self, parent=None):
        super(pagesPanel, self).__init__(parent)
        # The layout is very basic, the table with an Update button.
        mainLayout = QVBoxLayout()
        self.setLayout(mainLayout)
        hlayout = QHBoxLayout()
        self.updateButton = QPushButton("Update")
        self.insertText = QLineEdit()
        self.insertText.setFont(pqMsgs.getMonoFont())
        self.insertButton = QPushButton("Insert")
        hlayout.addWidget(self.updateButton,0)
        hlayout.addWidget(self.insertText,1) # text gets all available room
        hlayout.addWidget(self.insertButton,0)
        mainLayout.addLayout(hlayout)
        self.view = QTableView()
        self.view.setCornerButtonEnabled(False)
        self.view.setWordWrap(False)
        self.view.setAlternatingRowColors(True)
        self.view.setSortingEnabled(False)
        self.c1Delegate = formatDelegate()
        self.view.setItemDelegateForColumn(1,self.c1Delegate)
        self.c2Delegate = actionDelegate()
        self.view.setItemDelegateForColumn(2,self.c2Delegate)
        self.c3Delegate = folioDelegate()
        self.view.setItemDelegateForColumn(3,self.c3Delegate)
        mainLayout.addWidget(self.view,1)
        # Set up the table model/view.
        self.model = myTableModel()
        self.view.setModel(self.model)
        # Connect the double-clicked signal of the view
        self.connect(self.view, SIGNAL("doubleClicked(QModelIndex)"),
                    self.goToRow)
        # Connect the update button to the model's update method
        self.connect(self.updateButton, SIGNAL("clicked()"),self.model.updateFolios)
        # Connect the insert button to our insert method
        self.connect(self.insertButton, SIGNAL("clicked()"),self.insertMarkers)

    # This slot receives a double-click from the table view,
    # passing an index. If the click is in column 0, the scan number,
    # get the row; use it to get a text cursor from the page table
    # and make that the editor's cursor, thus moving to the top of that page.
    # Double-click on cols 1-3 initiates editing and maybe someday a
    # doubleclick on column 5 will do something with the proofer info.
    def goToRow(self,index):
        if index.column() == 0:
            tc = IMC.pageTable.getCursor(index.row())
            IMC.editWidget.setTextCursor(tc)
            IMC.editWidget.setFocus(Qt.TabFocusReason)

    # This slot receives the main window's docWillChange signal.
    # It comes with a file path but we can ignore that.
    def docWillChange(self):
        self.model.beginResetModel()

    # Subroutine to reset the visual appearance of the table view,
    # invoked on table reset because on instantiation we have no table.
    def setUpTableView(self):
        # Header text is supplied by the table model headerData method
        # Here we are going to set the column widths of the first 4
        # columns to a uniform 7 ens each based on the current font.
        # However, at least on Mac OS, the headers are rendered with a
        # much smaller font than the data, so we up it by 50%.
        hdr = self.view.horizontalHeader()
        pix = hdr.fontMetrics().width(QString("9999999"))
        hdr.resizeSection(0,pix)
        hdr.resizeSection(3,pix)
        pix += pix/2
        hdr.resizeSection(1,pix)
        hdr.resizeSection(2,pix)
        self.view.resizeColumnToContents(4)

    # This slot receives the main window's docHasChanged signal.
    # Let the table view populate with all-new metadata (or empty
    # data if the command was File>New).
    def docHasChanged(self):
        self.model.endResetModel()
        self.setUpTableView()

    # On the Insert button being pressed, make some basic sanity checks
    # and get user go-ahead then insert the given text at the head of
    # every page.
    def insertMarkers(self):
        # Copy the text and if it is empty, complain and exit.
        qi = QString(self.insertText.text())
        if qi.isEmpty() :
            pqMsgs.warningMsg("No insert text specified")
            return
        # See how many pages are involved: all the ones that aren't marked skip
        n = 0
        for i in range(IMC.pageTable.size()):
            if IMC.pageTable.getAction(i) != IMC.FolioRuleSkip :
                n += 1
        if n == 0 : # page table empty or all rows marked skip
            pqMsgs.warningMsg("No pages to give folios to")
            return
        m = "Insert this string at the top of {0} pages?".format(n)
        b = pqMsgs.okCancelMsg(QString(m),pqMsgs.trunc(qi,35))
        if b :
            # Convert any '\n' in the text to the QT line delimiter char
            # we do this in the copy so the lineEdit text doesn't change
            qi.replace(QString(u'\\n'),QString(IMC.QtLineDelim))
            # get a cursor on the edit document
            tc = QTextCursor(IMC.editWidget.textCursor())
            tc.beginEditBlock() # start single undoable operation
            # Working from the end of the document backward, go to the
            # top of each page and insert the string
            for i in reversed( range( IMC.pageTable.size() ) ) :
                if IMC.pageTable.getAction(i) != IMC.FolioRuleSkip :
                    # Note the page's start position and set our work cursor to it
                    pos = IMC.pageTable.getCursor(i).position()
                    tc.setPosition(pos)
                    # Make a copy of the insert string replacing %f with this folio
                    f = IMC.pageTable.getDisplay(i)
                    qf = QString(qi)
                    qf.replace(QString(u'%f'),f,Qt.CaseInsensitive)
                    tc.insertText(qf)
                    # The insertion goes in ahead of the saved cursor position so now
                    # it points after the inserted string. Put it back where it was.
                    IMC.pageTable.setPosition(i, pos)
            tc.endEditBlock() # wrap up the undo op