示例#1
0
    def __init__(self):
        QtCore.QObject.__init__(self)

        self.myDM = QicsDataModelDefault()

        self.connect(self.myDM, QtCore.SIGNAL("modelChanged(QicsRegion)"),
                     self.dataValuesChanged)

        self.loadDT()
示例#2
0
    def createModel(self, nrows, ncols):
        dm = QicsDataModelDefault(nrows, ncols)

        # We need to access QicsDataModel.setItem().
        d = sip.cast(dm, QicsDataModel)

        for i in range(nrows):
            for j in range(ncols):
                d.setItem(i, j, i + j)

        return dm
示例#3
0
## program may be used, distributed and modified without limitation.

import sys

from PyQt4 import QtCore, QtGui, QtXml, Qt

from qicstable import QicsTable, QicsDataModelDefault, QicsDataInt

app = QtGui.QApplication(sys.argv)

# Dimensions of the data model.
numRows = 10
numCols = 5

# Create the data model.
dm = QicsDataModelDefault(numRows, numCols)

# Populate the data model with some data.
for i in range(numRows):
    for j in range(numCols):
        dm.setItem(i, j, QicsDataInt(i * j))

# Create the table, using the data model we created above.
table = QicsTable(dm)

# Make sure the table is only as large as necessary.
table.setVisibleRows(numRows)
table.setVisibleColumns(numCols)

# Add a title label
label = QtGui.QLabel("Hello world, table", table)
示例#4
0
    def __init__(self, parent, name):
        QtGui.QMainWindow.__init__(self, parent)

        # create the data model
        self.dataModel = QicsDataModelDefault(0, NUM_COLUMNS)

        # create the table, using the data model we created above
        self.table = QicsTable(self.dataModel, self)
        self.setCentralWidget(self.table)

        # customize the column header to make things look pretty
        self.table.columnHeaderRef().setAlignment(QtCore.Qt.AlignCenter)

        self.table.columnHeaderRef().cellRef(0,0).setLabel("First Name")
        self.table.columnHeaderRef().cellRef(0,1).setLabel("Last Name")
        self.table.columnHeaderRef().cellRef(0,2).setLabel("S.S. Number")
        self.table.columnHeaderRef().cellRef(0,3).setLabel("Date of Birth")
        self.table.columnHeaderRef().cellRef(0,4).setLabel("Office")
        self.table.columnHeaderRef().cellRef(0,5).setLabel("Sec. Clearance")
        self.table.columnHeaderRef().cellRef(0,6).setLabel("Billable Rate")

        # Add a validator to the SSN to insure a consistant display behaviour
        # and error checking.
        self.ssnValidator = SSNValidator()
        self.table.columnRef(2).setValidator(self.ssnValidator)

        # Format the combo box for the office column
        self.officeComboDisplay = QicsComboCellDisplay()
        self.officeComboDisplay.addItem("Boston")
        self.officeComboDisplay.addItem("Cambridge")
        self.officeComboDisplay.addItem("Helsinki")
        self.officeComboDisplay.setAddValueToList(False)
        self.table.columnRef(4).setDisplayer(self.officeComboDisplay)

        # Security clearance check box
        self.columnHeaderCheckDisp = SecCheckBox()
        self.table.columnRef(5).setDisplayer(self.columnHeaderCheckDisp)

        # Format the billable rate column with a dollar sign, decimal point,
        # and the appropriate cents digits.
        self.brFormatter = QicsDataItemSprintfFormatter()
        self.brFormatter.addFormatString(QicsDataItem_Float, "$%.2f")
        self.brFormatter.addFormatString(QicsDataItem_Int, "$%d.00")
        self.table.columnRef(6).setFormatter(self.brFormatter)
	self.table.columnRef(6).setValidator(QtGui.QDoubleValidator(self.table))

        # Add a title widget to the top of the table
        label = QtGui.QLabel("Consultants", self.table)
        label.setAlignment(QtCore.Qt.AlignCenter)
        self.table.setTopTitleWidget(label)

        # Set column widths
        for i in range(NUM_COLUMNS):
            self.table.columnRef(i).setWidthInChars(7)

        self.table.setVisibleColumns(NUM_COLUMNS)

        # Menu Bar
	menubar = self.menuBar()

	self.filemenu = QtGui.QMenu("File", self)

	self._Open = QtGui.QAction("Open...", self)
	self.filemenu.addAction(self._Open)
	self.connect(self._Open, QtCore.SIGNAL("triggered()"), self.fileOpen)

	self._Save = QtGui.QAction("Save...", self)
	self.filemenu.addAction(self._Save)
	self.connect(self._Save, QtCore.SIGNAL("triggered()"), self.fileSave)

	self._Exit = QtGui.QAction("Quit", self)
	self.filemenu.addAction(self._Exit)
	self.connect(self._Exit, QtCore.SIGNAL("triggered()"), QtGui.qApp, QtCore.SLOT("quit()"))

	menubar.addMenu(self.filemenu)

	self.toolsmenu = QtGui.QMenu("Tools", self)

	self._AddCs = QtGui.QAction("Add consultant", self)
	self._DelCs = QtGui.QAction("Delete consultant", self)
	self._SortA = QtGui.QAction("Sort Ascending", self)
	self._SortD = QtGui.QAction("Sort Descending", self)

	self.connect(self._AddCs, QtCore.SIGNAL("triggered()"), self.addRow)
	self.connect(self._DelCs, QtCore.SIGNAL("triggered()"), self.deleteRow)
	self.connect(self._SortA, QtCore.SIGNAL("triggered()"), self.sortAscending)
	self.connect(self._SortD, QtCore.SIGNAL("triggered()"), self.sortDescending)

	self.toolsmenu.addAction(self._AddCs)
	self.toolsmenu.addAction(self._DelCs)
	self.toolsmenu.addAction(self._SortA)
	self.toolsmenu.addAction(self._SortD)

	menubar.addMenu(self.toolsmenu)





        # Connection for autosort
        QtCore.QObject.connect(self.table.columnHeaderRef(),
                        QtCore.SIGNAL("doubleClicked(int, int, int, const QPoint &)"),
                        self.autoSort)

        # Reset autoSort sanity vars
        self._autoSortCol = -1
        self._autoSortOrder = Qics.Descending
示例#5
0
    def __init__(self, p=None, name=None):
        """
        Construct the Spreadsheet object.  Creates a QMainWindow with a menu
        and toolbar, a QicsTable, and connects the appropriate slots to load
        and manipulate data.
        """
        QtGui.QMainWindow.__init__(self)

        self._currency = QicsDataItemCurrencyFormatter()

        #self.setCaption("Excellent Spreadsheet Demo")

        # Pulldown Menu

        # File
        file = QtGui.QMenu("&File", self)
	# Formating menu File with connect to Python function
	## New

	self._New = QtGui.QAction("&New", self)
    #self._New.setShortcut(QtGui.QKeySequence("Ctrl+N"))

	## Shortcut keys

	self._New.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_N
	file.addAction(self._New)

	## Connect to self.fileNew Python func

	self.connect(self._New, QtCore.SIGNAL("triggered()"), self.fileNew)

	## Open
	self._Open = QtGui.QAction("&Open", self)
	## Shortcut keys
	self._Open.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_O
	file.addAction(self._Open)
	## Connect to self.openFile Python func
	self.connect(self._Open, QtCore.SIGNAL("triggered()"), self.openFile)

	## Save
	self._Save = QtGui.QAction("&Save", self)
	## Shortcut keys
	self._Save.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_S
	file.addAction(self._Save)
	## Connect to self.saveFile Python func
	self.connect(self._Save, QtCore.SIGNAL("triggered()"), self.saveFile)

	## Save As
	self._SaveAs = QtGui.QAction("S&ave As", self)
    ## Shortcut keys
    #self._Save.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_S
	file.addAction(self._SaveAs)
	## Connect to self.saveFile Python func
	self.connect(self._SaveAs, QtCore.SIGNAL("triggered()"), self.saveFileAs)

	## Exit
	self._Exit = QtGui.QAction("E&xit", self)
	## Shortcut keys
	self._Save.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_X
	file.addAction(self._Exit)
	## Connect to self.saveFile Python func
	self.connect(self._Exit,QtCore.SIGNAL("triggered()"), Qt.qApp, QtCore.SLOT("closeAllWindows()"))
	# Show File menu in menubar

	self.menuBar().addMenu(file)

    # Edit
	edit = QtGui.QMenu("&Edit", self)
	self._Copy = QtGui.QAction("&Copy", self)
	## Shortcut keys
	self._Copy.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_C
	edit.addAction(self._Copy)
	## Connect to self.fileNew Python func
	self.connect(self._Copy, QtCore.SIGNAL("triggered()"), self.copy)

	# Paste
	self._Paste = QtGui.QAction("&Paste", self)
	## Shortcut keys
	self._Paste.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_C
	edit.addAction(self._Paste)
    ## Connect to self.fileNew Python func
	self.connect(self._Paste, QtCore.SIGNAL("triggered()"), self.paste)
	self.menuBar().addMenu(edit)

	## View
	view = QtGui.QMenu("View", self)
	self._View = QtGui.QAction("&View", self)
	## Shortcut keys
	self._View.shortcut = QtCore.Qt.CTRL+QtCore.Qt.Key_V
	view.addAction(self._View)
    #self.connect(self._View, QtCore.SIGNAL("triggered()"), self.view)
	self.menuBar().addMenu(view)

	## Insert
	insert = QtGui.QMenu("Insert", self)
	self._InsertRow = QtGui.QAction("&Row", self)
	## Shortcut keys
	insert.addAction(self._InsertRow)
	self.connect(self._InsertRow, QtCore.SIGNAL("triggered()"), self.insertRow)
	self._InsertCol = QtGui.QAction("Co&lumn", self)
	## Shortcut keys
	insert.addAction(self._InsertCol)
	self.connect(self._InsertCol, QtCore.SIGNAL("triggered()"), self.insertColumn)
	self.menuBar().addMenu(insert)

	## Format

        format = QtGui.QMenu("Format", self)
        self.menuBar().addMenu(format)

        rowFormat = QtGui.QMenu("Row", self)
        format.addMenu(rowFormat)
        format.addSeparator()

        self._Foreground = QtGui.QAction("Fore&ground...", self)
        format.addAction(self._Foreground)
        self.connect(self._Foreground, QtCore.SIGNAL("triggered()"), self.formatForegroundColor)

        self._Background = QtGui.QAction("&Background...", self)
        format.addAction(self._Background)
        self.connect(self._Background, QtCore.SIGNAL("triggered()"), self.formatBackgroundColor)

        self._Font = QtGui.QAction("&Font...", self)
        format.addAction(self._Font)
        self.connect(self._Font, QtCore.SIGNAL("triggered()"), self.formatFont)


        # Tools
        tools = QtGui.QMenu("&Tools", self)
        self.menuBar().addMenu(tools)

        self.showQSAAction = QtGui.QAction(self.tr("Script Editor"), self)
        self.connect(self.showQSAAction, QtCore.SIGNAL("triggered()"), self.showQSAWorkbench)
        tools.addAction(self.showQSAAction)

        self.scriptTestAction = QtGui.QAction(self.tr("Script Test"), self)
        self.connect(self.scriptTestAction, QtCore.SIGNAL("triggered()"), self.testScripts)
        tools.addAction(self.scriptTestAction)

        self.saveScriptAction = QtGui.QAction(self.tr("Save Script"), self)
        self.connect(self.saveScriptAction, QtCore.SIGNAL("triggered()"), self.saveScripts)
        tools.addAction(self.saveScriptAction)

        # Data
        data = QtGui.QMenu("&Data", self)
        self.menuBar().addMenu(data)

        self.sortAscAction = QtGui.QAction(self.tr("&Ascendingt"), self)
        self.connect(self.sortAscAction, QtCore.SIGNAL("triggered()"), self.sortAscending)
        data.addAction(self.sortAscAction)

        self.sortDescAction = QtGui.QAction(self.tr("&Descendingt"), self)
        self.connect(self.sortDescAction, QtCore.SIGNAL("triggered()"), self.sortDescending)
        data.addAction(self.sortDescAction)

        # Spans
        spans = QtGui.QMenu("Spans", self)
        self.menuBar().addMenu(spans)

        self.addSpanAction = QtGui.QAction(self.tr("Add Span"), self)
        self.connect(self.addSpanAction, QtCore.SIGNAL("triggered()"), self.addSpan)
        spans.addAction(self.addSpanAction)

        self.removeSpanAction = QtGui.QAction(self.tr("Remove Span"), self)
        self.connect(self.removeSpanAction, QtCore.SIGNAL("triggered()"), self.removeSpan)
        spans.addAction(self.removeSpanAction)        

        # Toolbars

        # File operation toolbar

        fileTools = QtGui.QToolBar("File tools", self)

        #QtGui.QToolButton(_getIconSet("filenew.xpm"), "New", QtCore.QString, self.fileNew, fileTools)
        self.fileNewButton = QtGui.QToolButton()

        self.fileNewAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/filenew.xpm")), self.tr("&New"), self)
        self.connect(self.fileNewAct, QtCore.SIGNAL("triggered()"), self.fileNew)
        fileTools.addAction(self.fileNewAct)

        self.fileOpenAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/fileopen.xpm")), self.tr("&Open"), self)
        self.connect(self.fileOpenAct, QtCore.SIGNAL("triggered()"), self.openFile)
        fileTools.addAction(self.fileOpenAct)

        self.fileSaveAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/filesave.xpm")), self.tr("&Save"), self)
        self.connect(self.fileSaveAct, QtCore.SIGNAL("triggered()"), self.saveFile)
        fileTools.addAction(self.fileSaveAct)

        fileTools.addSeparator()

        # Edit operations
        self.cutAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/editcut.xpm")), self.tr("&Cut"), self)
        self.connect(self.cutAct, QtCore.SIGNAL("triggered()"), self.cut)
        fileTools.addAction(self.cutAct)

        self.copyAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/editcopy.xpm")), self.tr("&Copy"), self)
        self.connect(self.copyAct, QtCore.SIGNAL("triggered()"), self.copy)
        fileTools.addAction(self.copyAct)

        self.pasteAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/editpaste.xpm")), self.tr("&Paste"), self)
        self.connect(self.pasteAct, QtCore.SIGNAL("triggered()"), self.paste)
        fileTools.addAction(self.pasteAct)

        fileTools.addSeparator()

        # Sort

        self.sortAscendingAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/sortasc.xpm")), self.tr("Sort Ascending"), self)
        self.connect(self.sortAscendingAct, QtCore.SIGNAL("triggered()"), self.sortAscending)
        fileTools.addAction(self.sortAscendingAct)

        self.sortDescendingAct = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/sortdesc.xpm")), self.tr("Sort Descending"), self)
        self.connect(self.sortDescendingAct, QtCore.SIGNAL("triggered()"), self.sortDescending)
        fileTools.addAction(self.sortDescendingAct)

        fileTools.addSeparator()

        self.addToolBar(fileTools)

        # Font name and point size

        fontTools = QtGui.QToolBar("Font tools", self)

        self.fontFamilyCombo = QtGui.QComboBox(fontTools)
        self.fontSizeCombo = QtGui.QComboBox(fontTools)

        fontTools.addWidget(self.fontFamilyCombo)
        fontTools.addWidget(self.fontSizeCombo)

        self.connect(self.fontFamilyCombo, QtCore.SIGNAL("activated(int)"), self.selectFont)
        self.connect(self.fontSizeCombo, QtCore.SIGNAL("activated(int)"), self.selectFont)

        fdb = QtGui.QFontDatabase()
        families = fdb.families()
        self.fontFamilyCombo.insertItems(0, families)

        # Font format operations

        self.boldAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textbold.xpm")), self.tr("Bold"), self)
        self.connect(self.boldAction, QtCore.SIGNAL("triggered()"), self.textBold)
        fontTools.addAction(self.boldAction)
        self.boldAction.setCheckable(True)

        self.italicAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textitalic.xpm")), self.tr("Italic"), self)
        self.connect(self.italicAction, QtCore.SIGNAL("triggered()"), self.textItalic)
        fontTools.addAction(self.italicAction)
        self.italicAction.setCheckable(True)

        self.underlineAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textunder.xpm")), self.tr("Underline"), self)
        self.connect(self.underlineAction, QtCore.SIGNAL("triggered()"), self.textUnderline)
        fontTools.addAction(self.underlineAction)
        self.underlineAction.setCheckable(True)

        fontTools.addSeparator()

        # Text Alignment

        self.textLeftAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textleft.xpm")), self.tr("Align Left"), self)
        self.connect(self.textLeftAction, QtCore.SIGNAL("triggered()"), self.textAlignLeft)
        fontTools.addAction(self.textLeftAction)
        self.textLeftAction.setCheckable(True)

        self.textCenterAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textcenter.xpm")), self.tr("Align Center"), self)
        self.connect(self.textCenterAction, QtCore.SIGNAL("triggered()"), self.textAlignCenter)
        fontTools.addAction(self.textCenterAction)
        self.textCenterAction.setCheckable(True)

        self.textRightAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/textright.xpm")),"Align Right", self)
        self.connect(self.textRightAction, QtCore.SIGNAL("triggered()"), self.textAlignRight)
        fontTools.addAction(self.textRightAction)
        self.textRightAction.setCheckable(True)

        fontTools.addSeparator()

        # Formatters

        currencyTB = QtGui.QToolButton(fontTools)
        currencyTB.setText("$")
        self.connect(currencyTB, QtCore.SIGNAL("clicked()"), self.setCurrencyFormatter)

        fontTools.addWidget(currencyTB)

        fontTools.addSeparator()

        # Colors

        self.formatForegroundColorAction = QtGui.QAction(QtGui.QIcon(QtGui.QPixmap("images/fontcolor.xpm")), self.tr("Font Color"), self)
        self.connect(self.formatForegroundColorAction, QtCore.SIGNAL("triggered()"), self.formatForegroundColor)
        fontTools.addAction(self.formatForegroundColorAction)

        self.addToolBar(fontTools)

        # Table

        vbox = QtGui.QWidget(self)
        vboxLayout = QtGui.QVBoxLayout();
        cellrow = QtGui.QWidget(vbox)
        cellrowLayout = QtGui.QHBoxLayout()
        cellrowLayout.setMargin(2)
        cellrowLayout.addWidget(QtGui.QLabel("Cell value = "))

        self.cellLineEdit = QtGui.QLineEdit()
        cellrowLayout.addWidget(self.cellLineEdit)
        cellrow.setLayout(cellrowLayout)

        self.connect(self.cellLineEdit, QtCore.SIGNAL("returnPressed()"), self.cellLineUpdate)

        lastRow = 10
        lastCol = 50

        # Create the data model
        self.dm = QicsDataModelDefault(lastRow, lastCol)

        # Create the table, using the data model we created above
        self.table = QicsTable(self.dm)
        # self.table.setViewport(Qics.QicsRegion(0, 0, 50, 50))
        vboxLayout.addWidget(cellrow)
        vboxLayout.addWidget(self.table)
        vbox.setLayout(vboxLayout)

        self.connect(self.table, QtCore.SIGNAL("selectionListChanged(bool)"), self.updateSelection)

        # Set some visual resources on the table
        self.table.rowHeader().setAlignment(QtCore.Qt.AlignHCenter)
        self.table.columnHeader().setAlignment(QtCore.Qt.AlignHCenter)
        self.table.rowHeader().column(0).setWidthInChars(3)
        self.table.mainGridRef().setBackgroundColor(QtCore.Qt.white)
        
        # Set row sorting mode to non-distractive sord

        self.table.show()

        self.setFontCombos(self.table.font())

        self.setCentralWidget(vbox)

        self.statusBar().showMessage("Ready", -1)

        self.fileName = QtCore.QString("")
示例#6
0
        val = QtCore.QPoint()

        ds >> val
        return QicsDataQPoint(val)


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)

    QicsDataItem.registerType(QicsDataQPoint.typeName(),
                              QicsDataQPoint.fromString, QicsDataQPoint.decode)

    nrows = 10
    ncols = 10

    # Create the data model.
    dm = QicsDataModelDefault(nrows, ncols)

    # Fill the data mode with some QPoints.
    for i in range(nrows):
        for j in range(ncols):
            dm.setItem(i, j, QicsDataQPoint(QtCore.QPoint(i, j)))

    # Create the table, using the data model we created above.
    table = QicsTable(dm)

    #    app.setMainWidget(table)
    table.show()

    sys.exit(app.exec_())