Esempio n. 1
0
    def update_calendar(self):
        """
        # Calendar の初期設定
        """

        for date_item in self.has_data_date_list:
            qdate = QtCore.QDate(*date_item)
            self.calendar.setDateTextFormat(qdate, self.has_data_chfmt)

        maximum_date_item = self.has_data_date_list[-1]
        maximum_qdate = QtCore.QDate(*maximum_date_item)
        self.calendar.setMaximumDate(maximum_qdate)

        minimum_date_item = self.has_data_date_list[0]
        minimum_qdate = QtCore.QDate(*minimum_date_item)
        self.calendar.setMinimumDate(minimum_qdate)

        # set today
        d = datetime.datetime.fromtimestamp(time.time())
        time_today_start = time.mktime(
            datetime.datetime(d.year, d.month, d.day, 0, 0, 0).timetuple())

        self.target_datetime = datetime.datetime.fromtimestamp(
            time_today_start)
        self.calendar.setSelectedDate(QtCore.QDate(d.year, d.month, d.day))

        return
Esempio n. 2
0
    def readMovieNode(self, element):
        def getText(node):
            child = node.firstChild()
            text = ""
            while not child.isNull():
                if child.nodeType() == QtXml.QDomNode.TextNode:
                    text += child.toText().data()
                child = child.nextSibling()
            return text.strip()

        year = int(element.attribute("YEAR"))
        minutes = int(element.attribute("MINUTES"))
        ymd = element.attribute("ACQUIRED").split("-")
        if len(ymd) != 3:
            raise ValueError("invalid acquired date {}".format(
                element.attribute("ACQUIRED")))
        acquired = QtCore.QDate(int(ymd[0]), int(ymd[1]), int(ymd[2]))
        title = notes = None
        node = element.firstChild()
        while title is None or notes is None:
            if node.isNull():
                raise ValueError("missing title or notes")
            if node.toElement().tagName() == "TITLE":
                title = getText(node)
            elif node.toElement().tagName() == "NOTES":
                notes = getText(node)
            node = node.nextSibling()
        if not title:
            raise ValueError("missing title")
        self.add(Movie(title, year, minutes, acquired, decodedNewlines(notes)))
    def readResponse(self):
        stream = QtCore.QDataStream(self.socket)
        stream.setVersion(QtCore.QDataStream.Qt_4_2)

        while True:
            if self.nextBlockSize == 0:
                if self.socket.bytesAvailable() < SIZEOF_UINT16:
                    break
                self.nextBlockSize = stream.readUInt16()
            if self.socket.bytesAvailable() < self.nextBlockSize:
                break
            action = stream.readQString()
            room = stream.readQString()
            date = QtCore.QDate()
            if action != "ERROR":
                stream >> date
            if action == "ERROR":
                msg = "Error: {}".format(room)
            elif action == "BOOK":
                msg = "Booked room {} for {}".format(
                    room, date.toString(QtCore.Qt.ISODate))
            elif action == "UNBOOK":
                msg = "Unbooked room {} for {}".format(
                    room, date.toString(QtCore.Qt.ISODate))
            self.responseLabel.setText(msg)
            self.updateUi()
            self.nextBlockSize = 0
Esempio n. 4
0
    def testDates(self):

        y = 2001
        m = 1
        d = 1

        self.assertEqual(Util.convert_date('DB2Qt', '2001-01-01'),
                         QtCore.QDate(y, m, d))
        self.assertEqual(Util.convert_date('DB2Disp', '2001-01-01'),
                         '1/1/2001')
        self.assertEqual(Util.convert_date('Disp2DB', '1/1/2001'),
                         '2001-01-01')
        self.assertEqual(Util.convert_date('Disp2Qt', '1/1/2001'),
                         QtCore.QDate(y, m, d))
        self.assertEqual(Util.convert_date('Qt2Disp', QtCore.QDate(y, m, d)),
                         '1/1/2001')
        self.assertEqual(Util.convert_date('Qt2DB', QtCore.QDate(y, m, d)),
                         '2001-01-01')
Esempio n. 5
0
 def __init__(self,
              minimum=QtCore.QDate(),
              maximum=QtCore.QDate.currentDate(),
              dateFormat="yyyy-MM-dd",
              parent=None):
     super(DateColumnDelegate, self).__init__(parent)
     self.minimum = minimum
     self.maximum = maximum
     self.format = dateFormat
Esempio n. 6
0
 def loadText(self):
     error = None
     fh = None
     try:
         fh = codecs.open(unicode(self.__fname), "rU", CODEC)
         self.clear(False)
         lino = 0
         while True:
             title = year = minutes = acquired = notes = None
             line = fh.readline()
             if not line:
                 break
             lino += 1
             if not line.startswith("{{MOVIE}}"):
                 raise ValueError("no movie record found")
             else:
                 title = line[len("{{MOVIE}}"):].strip()
             line = fh.readline()
             if not line:
                 raise ValueError, "premature end of file"
             lino += 1
             parts = line.split(" ")
             if len(parts) != 3:
                 raise ValueError, "invalid numeric data"
             year = int(parts[0])
             minutes = int(parts[1])
             ymd = parts[2].split("-")
             if len(ymd) != 3:
                 raise ValueError, "invalid acquired date"
             acquired = QtCore.QDate(int(ymd[0]), int(ymd[1]), int(ymd[2]))
             line = fh.readline()
             if not line:
                 raise ValueError, "premature end of file"
             lino += 1
             if line != "{NOTES}\n":
                 raise ValueError, "notes expected"
             notes = ""
             while True:
                 line = fh.readline()
                 if not line:
                     raise ValueError, "missing endmovie marker"
                 lino += 1
                 if line == "{{ENDMOVIE}}\n":
                     if (title is None or year is None or minutes is None
                             or acquired is None or notes is None):
                         raise ValueError, "incomplete record"
                     self.add(
                         Movie(title, year, minutes, acquired,
                               notes.trimmed()))
                     break
                 else:
                     notes += line
     except (IOError, OSError, ValueError), e:
         error = "Failed to load: {0} on line {1}".format(e, lino)
Esempio n. 7
0
 def __init__(self):
     app = QtGui.QApplication(sys.argv)
     form = QtGui.QWidget()
     self.setupUi(form)
     form.show()
     self.fill_tickers_combobox()
     self.comboTicker.currentIndexChanged[str].connect(
         self.quotes_params_changed)
     self.dateDay.dateChanged.connect(self.quotes_params_changed)
     self.dateDay.setDate(QtCore.QDate.currentDate())
     dt = QtCore.QDate()
     dt.getDate()
     sys.exit(app.exec_())
    def __init__(self, date, tree_item, column, parent=None, type='end'):
        QtWidgets.QDateEdit.__init__(self, parent)

        self.tree_item = tree_item
        self.column = column

        self.min_date = QtCore.QDate(2016, 1, 1)
        self.max_date = QtCore.QDate(2016, 12, 31)
        self.today = QtCore.QDate.currentDate()
        self.date_format = 'yyyy-MM-dd'
        self.date = date

        self.dateedit = TreeDateLineEdit(self)
        self.dateedit.setCalendarPopup(True)
        self.dateedit.setDisplayFormat(self.date_format)
        self.dateedit.setMinimumDate(self.min_date)
        self.dateedit.setMaximumDate(self.max_date)

        self.empty = DateLineEdit(date, self)

        self.layout = QtWidgets.QVBoxLayout(parent)
        self.layout.addWidget(self.empty)
        self.layout.addWidget(self.dateedit)

        if date != "":
            self.dateedit.setDate(
                QtCore.QDate.fromString(date, self.date_format))
            self.empty.setVisible(False)
            self.dateedit.setVisible(True)
        else:
            self.dateedit.setDate(self.today)
            self.empty.setVisible(True)
            self.dateedit.setVisible(False)

        self.setLayout(self.layout)
        self.empty.clicked.connect(self._show_date)
        self.dateedit.dateChanged.connect(self._change_date)
Esempio n. 9
0
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.setWindowModality(QtCore.Qt.NonModal)
        Dialog.resize(383, 137)
        self.verticalLayout = QtGui.QVBoxLayout(Dialog)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setObjectName("label_2")
        self.verticalLayout.addWidget(self.label_2)
        self.dateTimeEdit = QtGui.QDateTimeEdit(Dialog)
        self.dateTimeEdit.setDate(QtCore.QDate(2017, 1, 1))
        self.dateTimeEdit.setCurrentSection(QtGui.QDateTimeEdit.MonthSection)
        self.dateTimeEdit.setCalendarPopup(True)
        self.dateTimeEdit.setObjectName("dateTimeEdit")
        self.verticalLayout.addWidget(self.dateTimeEdit)
        self.label = QtGui.QLabel(Dialog)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout = QtGui.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setObjectName("lineEdit")
        self.horizontalLayout.addWidget(self.lineEdit)
        self.toolButton = QtGui.QToolButton(Dialog)
        self.toolButton.setObjectName("toolButton")
        self.horizontalLayout.addWidget(self.toolButton)
        self.verticalLayout.addLayout(self.horizontalLayout)
        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        self.buttonBox = QtGui.QDialogButtonBox(Dialog)
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel
                                          | QtGui.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.verticalLayout.addWidget(self.buttonBox)
        self.actionPath = QtGui.QAction(Dialog)
        self.actionPath.setObjectName("actionPath")

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"),
                               Dialog.accept)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"),
                               Dialog.reject)
        QtCore.QObject.connect(self.toolButton, QtCore.SIGNAL("pressed()"),
                               self.actionPath.trigger)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
Esempio n. 10
0
    def readMovieNode(self, element):
        #pull text from a node (used below)
        def getText(node):
            child = node.firstChild()
            text = ""
            while not child.isNull():
                if child.nodeType() == QtXml.QDomNode.TextNode:
                    text += child.toText().data()
                child = child.nextSibling()
            return text.strip()

        year = int(element.attribute("YEAR"))
        minutes = int(element.attribute("MINUTES"))
        ymd = element.attribute("ACQUIRED").split("-")
        if len(ymd) != 3:
            raise ValueError("invalid acquired date {}".format(
                element.attribute("ACQUIRED")))
        acquired = QtCore.QDate(int(ymd[0]), int(ymd[1]), int(ymd[2]))
        title = notes = location = None
        node = element.firstChild()

        #not sure about this way to make it backward compatible by not adding
        #the additional disjunct: `or location is None`
        while title is None or notes is None:
            if node.isNull():
                raise ValueError("missing title or location or notes")
            if node.toElement().tagName() == "TITLE":
                title = getText(node)
                #print title
            elif node.toElement().tagName() == "LOCATION":
                location = getText(node)
            elif node.toElement().tagName() == "NOTES":
                notes = getText(node)
            node = node.nextSibling()
        if not title:
            raise ValueError("missing title")
        self.add(
            Movie(title, year, minutes, acquired, decodedNewlines(notes),
                  location))