Ejemplo n.º 1
0
class MainWindow(QTableView):
    def __init__(self, *args):
        QTableView.__init__(self, *args)
        today = datetime.date.today()
        self.year = today.year
        self.cal = calendar.Calendar()
        
        horiz_header = HorizHeader(self, days)
        self.setHorizontalHeader(horiz_header)
        horiz_header.setResizeMode(QHeaderView.Stretch)
        horiz_header.setMinimumSectionSize(37)

        vert_header = VertHeader(self, months)
        self.setVerticalHeader(vert_header)
        vert_header.setResizeMode(QHeaderView.Stretch)
        vert_header.setMinimumSectionSize(52)
        
        #self.ui.button_back.clicked.connect(self.year_back)
        #self.ui.button_forward.clicked.connect(self.year_forward)
        self.col1 = QBrush(QColor(100, 250, 213))
        self.col2 = QBrush(QColor(200, 150, 213))
        self.init_calendar(self.year)
        

    def year_back(self):
        self.year -= 1
        self.init_calendar(self.year)

    def year_forward(self):
        self.year += 1
        self.init_calendar(self.year)

    def init_calendar(self, year):
        year_instance = Year(self, year)
        months = year_instance.get_months()
        self.tablemodel = TableModel(months)
        self.setModel(self.tablemodel)


    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            ep = event.pos() # QPoint
            ind = self.indexAt(ep)  #QModelIndex
            year_instance = Year(self, self.year)
            months = year_instance.get_months()
            print ind.column(), ind.row()
            col = ind.column()
            row = ind.row()
            month = months[row]
            day = month[col]
            print day, row + 1, self.year   # Date in dd/mm/yr format

        if event.button() == Qt.RightButton:
            ep = event.pos() # QPoint
            ind = self.indexAt(ep)  #QModelIndex
            date_data = self.tablemodel.itemData(ind)    #Data at this index
            day = date_data[0].toString() #date_data[8].type() returns cell's QBrush
            col = ind.column()
            row = ind.row()
            self.tablemodel.colour_cell(ind, Qt.BackgroundRole, QBrush(QColor(200, 150, 213)))
Ejemplo n.º 2
0
class MainWindow(QTableView):
    def __init__(self, *args):
        QTableView.__init__(self, *args)
        today = datetime.date.today()
        self.year = today.year
        self.cal = calendar.Calendar()

        horiz_header = HorizHeader(self, days)
        self.setHorizontalHeader(horiz_header)
        horiz_header.setResizeMode(QHeaderView.Stretch)
        horiz_header.setMinimumSectionSize(37)

        vert_header = VertHeader(self, months)
        self.setVerticalHeader(vert_header)
        vert_header.setResizeMode(QHeaderView.Stretch)
        vert_header.setMinimumSectionSize(52)

        #self.ui.button_back.clicked.connect(self.year_back)
        #self.ui.button_forward.clicked.connect(self.year_forward)
        self.col1 = QBrush(QColor(100, 250, 213))
        self.col2 = QBrush(QColor(200, 150, 213))
        self.init_calendar(self.year)

    def year_back(self):
        self.year -= 1
        self.init_calendar(self.year)

    def year_forward(self):
        self.year += 1
        self.init_calendar(self.year)

    def init_calendar(self, year):
        year_instance = Year(self, year)
        months = year_instance.get_months()
        self.tablemodel = TableModel(months)
        self.setModel(self.tablemodel)

    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            ep = event.pos()  # QPoint
            ind = self.indexAt(ep)  #QModelIndex
            year_instance = Year(self, self.year)
            months = year_instance.get_months()
            print ind.column(), ind.row()
            col = ind.column()
            row = ind.row()
            month = months[row]
            day = month[col]
            print day, row + 1, self.year  # Date in dd/mm/yr format

        if event.button() == Qt.RightButton:
            ep = event.pos()  # QPoint
            ind = self.indexAt(ep)  #QModelIndex
            date_data = self.tablemodel.itemData(ind)  #Data at this index
            day = date_data[0].toString(
            )  #date_data[8].type() returns cell's QBrush
            col = ind.column()
            row = ind.row()
            self.tablemodel.colour_cell(ind, Qt.BackgroundRole,
                                        QBrush(QColor(200, 150, 213)))
Ejemplo n.º 3
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self._pyString = "initial"

        self._pyListOfInt = [1, 2, 3]
        self._qAbstractTable = TableModel()
        self._pyListOfInt2d = [
            [11, 12, 13],
            [14, 15, 16],
            [17, 18, 19],
        ]

        self._pyDict = {"a": 1, "b": 2, "c": {"x": 3, "y": 4}, "d": [5, 6, 7]}
        self._qAbstractList = ListModel()

        self._pyListOfDict = [
            {
                "a": 1,
                "b": 12.0,
                "c": True
            },
            {
                "a": 4,
                "b": 556.2,
                "c": False
            },
            {
                "a": 7,
                "b": 81.0,
                "c": True
            },
        ]
Ejemplo n.º 4
0
 def make_widgets(self, select):
     self.sqlEdit = SQLEdit.SQLEdit(select)
     self.sqlEdit.setTabChangesFocus(True)
     self.tableModel = TableModel.TableModel(self.db,
                                             Sql.uncommented(select))
     self.tableView = QTableView()
     self.tableView.setModel(self.tableModel)
     self.statusLabel = QLabel()
     self.statusLabel.setTextFormat(Qt.RichText)
     self.update_status(select)
Ejemplo n.º 5
0
class Proxy(QObject):
    def __init__(self, parent=None):
        super().__init__(parent)
        self._list = ListModel()
        self._table = TableModel()

    def _getList(self):
        return self._list

    def _getTable(self):
        return self._table

    dataChanged = Signal()

    list = Property('QVariant', _getList, notify=dataChanged)
    table = Property('QVariant', _getTable, notify=dataChanged)

    @Slot(result='QVariant')
    def randomChange(self):
        self._list.updateModelRandomly()
        self._table.updateModelRandomly()
Ejemplo n.º 6
0
    def createTable(self):
        self.my_array = [['00', '01', '02', '34'],
                         ['10', '11', '12','45'],
                         ['20', '21', '22','45']]
        # create the view
        # set the table model
        header = ['Detalle', 'Precio', 'Tiempo','']
        self.tm = TableModel.MyTableModel(self.my_array, header, self)
        self.tv.setModel(self.tm)
        self.tv.setColumnHidden(3, True)
        # set the minimum size
        #self.tv.setMinimumSize(400, 300)

        # hide grid
        self.tv.setShowGrid(False)

        # set the font
        font = QFont("Courier New", 8)
        self.tv.setFont(font)

        # hide vertical header
        vh = self.tv.verticalHeader()
        vh.setVisible(True)

        # set horizontal header properties
        hh = self.tv.horizontalHeader()
        hh.setStretchLastSection(True)
        hh.setResizeMode(QtGui.QHeaderView.Stretch)


        # set column width to fit contents
        self.tv.resizeColumnsToContents()

        # set row height
        nrows = len(self.my_array)
        for row in xrange(nrows):
            self.tv.setRowHeight(row, 25)

        # enable sorting
        self.tv.setSortingEnabled(True)

        return self.tv
Ejemplo n.º 7
0
 def init_calendar(self, year):
     year_instance = Year(self, year)
     months = year_instance.get_months()
     self.tablemodel = TableModel(months)
     self.setModel(self.tablemodel)
Ejemplo n.º 8
0
 def init_calendar(self, year):
     year_instance = Year(self, year)
     months = year_instance.get_months()
     self.tablemodel = TableModel(months)
     self.setModel(self.tablemodel)
Ejemplo n.º 9
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self._list = ListModel()
     self._table = TableModel()
Ejemplo n.º 10
0
class Proxy(QObject):
    def __init__(self, parent=None):
        super().__init__(parent)
        self._pyString = "initial"

        self._pyListOfInt = [1, 2, 3]
        self._qAbstractTable = TableModel()
        self._pyListOfInt2d = [
            [11, 12, 13],
            [14, 15, 16],
            [17, 18, 19],
        ]

        self._pyDict = {"a": 1, "b": 2, "c": {"x": 3, "y": 4}, "d": [5, 6, 7]}
        self._qAbstractList = ListModel()

        self._pyListOfDict = [
            {
                "a": 1,
                "b": 12.0,
                "c": True
            },
            {
                "a": 4,
                "b": 556.2,
                "c": False
            },
            {
                "a": 7,
                "b": 81.0,
                "c": True
            },
        ]

    # self._pyString
    pyStringChanged = Signal()

    def getPyString(self):
        return self._pyString

    def setPyString(self, value):
        self._pyString = value
        self.pyStringChanged.emit()

    pyString = Property(str,
                        fget=getPyString,
                        fset=setPyString,
                        notify=pyStringChanged)

    # self._pyDict
    pyDictChanged = Signal()

    def getPyDict(self):
        return self._pyDict

    def setPyDict(self, value):
        self._pyDict = value
        self.pyDictChanged.emit()

    pyDict = Property('QVariant', getPyDict, setPyDict, notify=pyDictChanged)

    # self._qAbstractTable
    qAbstractTableChanged = Signal()

    def getQAbstractTable(self):
        return self._qAbstractTable

    qAbstractTable = Property('QVariant',
                              getQAbstractTable,
                              notify=qAbstractTableChanged)

    # self._getAbstractList
    qAbstractListChanged = Signal()

    def getQAbstractList(self):
        return self._qAbstractList

    qAbstractList = Property('QVariant',
                             getQAbstractList,
                             notify=qAbstractListChanged)

    # self._pyListOfInt
    pyListOfIntChanged = Signal()

    def getPyListOfInt(self):
        return self._pyListOfInt

    def setPyListOfInt(self, value):
        self._pyListOfInt = value
        self.pyListOfIntChanged.emit()

    pyListOfInt = Property('QVariant',
                           getPyListOfInt,
                           setPyListOfInt,
                           notify=pyListOfIntChanged)

    # self._pyListOfInt2d
    pyListOfInt2dChanged = Signal()

    def getPyListOfInt2d(self):
        return self._pyListOfInt2d

    def setPyListOfInt2d(self, value):
        self._pyListOfInt2d = value
        self.pyListOfInt2dChanged.emit()

    pyListOfInt2d = Property('QVariant',
                             getPyListOfInt2d,
                             setPyListOfInt2d,
                             notify=pyListOfInt2dChanged)

    # self._pyListOfDict
    pyListOfDictChanged = Signal()

    def getPyListOfDict(self):
        return self._pyListOfDict

    def setPyListOfInt(self, obj):
        self._pyListOfDict = value
        self.pyListOfDictChanged.emit()

    pyListOfDict = Property('QVariant',
                            getPyListOfDict,
                            setPyListOfInt,
                            notify=pyListOfDictChanged)

    # randomChange
    @Slot(result='QVariant')
    def randomChange(self):
        self._qAbstractList.updateModelRandomly()
        self._qAbstractTable.updateModelRandomly()