class RangeSelection(QWidget): """ Allow to select a date, a build id, a release number or an arbitrary changeset. """ def __init__(self, parent=None): QWidget.__init__(self, parent) layout = QHBoxLayout(self) self._create_widgets() layout.addWidget(self.stacked) layout.addWidget(self.select_combo) self.setLayout(layout) def _create_widgets(self): self.stacked = QStackedWidget() self.datew = QDateEdit() self.datew.setDisplayFormat("yyyy-MM-dd") self.stacked.addWidget(self.datew) self.buildidw = QLineEdit() self.stacked.addWidget(self.buildidw) self.releasew = QComboBox() self.releasew.addItems([str(k) for k in sorted(releases())]) self.stacked.addWidget(self.releasew) self.revw = QLineEdit() self.stacked.addWidget(self.revw) self.select_combo = QComboBox() self.select_combo.addItems(['date', 'buildid', 'release', 'changeset']) self.select_combo.activated.connect(self.stacked.setCurrentIndex) def get_value(self): currentw = self.stacked.currentWidget() if currentw == self.datew: return self.datew.date().toPyDate() elif currentw == self.buildidw: buildid = unicode(self.buildidw.text()) try: return parse_date(buildid) except DateFormatError: raise DateFormatError(buildid, "Not a valid build id: `%s`") elif currentw == self.releasew: return parse_date( date_of_release(str(self.releasew.currentText()))) elif currentw == self.revw: return unicode(self.revw.text())
def create_dateedit(self, text, option, tip=None): label = QLabel(text) dateedit = QDateEdit() dateedit.setDisplayFormat('dd MMM yyyy') dateedit.setMaximumDate(QDate(2010,12,31)) dateedit.setMinimumDate(QDate(2002,01,01)) if tip is not None: dateedit.setToolTip(tip) self.dateedits[dateedit] = option layout = QHBoxLayout() for subwidget in (label, dateedit): layout.addWidget(subwidget) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.setLayout(layout) return widget
def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) self.widget = QWidget(self) self.horizontalLayout = QHBoxLayout(self.widget) self.label_1 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_1) self.lineEdit = QLineEdit(self.widget) self.horizontalLayout.addWidget(self.lineEdit) self.label_2 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_2) self.dateEdit = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit) self.label_3 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_3) self.dateEdit_2 = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit_2) self.button1 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button1) self.button2 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button2) self.lineEdit.setText(QtCore.QString('600198')) three_month = QtCore.QDate.currentDate().toJulianDay() - 40 self.dateEdit.setDate(QtCore.QDate.fromJulianDay(three_month)) self.dateEdit_2.setDate(QtCore.QDate.currentDate()) self.label_1.setText(_translate("MainWindow", "股票代码", None)) self.label_2.setText(_translate("MainWindow", "起始时间", None)) self.label_3.setText(_translate("MainWindow", "终止时间", None)) self.button1.setText(_translate("MainWindow", "提交", None)) self.button2.setText(_translate("MainWindow", "清除", None)) self.button1.clicked.connect(self.get_value) self.button2.clicked.connect(self.clear)
class DateRangeDialog(QDialog): def __init__(self): super(DateRangeDialog, self).__init__() self._fro = QDateEdit(datetime.date.today()) self._to = QDateEdit(datetime.date.today() + datetime.timedelta(4)) self._fro.dateChanged.connect(self._check_valid_range) self._to.dateChanged.connect(self._check_valid_range) self.buttons = QDialogButtonBox(QDialogButtonBox.Ok) self.buttons.accepted.connect(self.accept) layout = QVBoxLayout() layout.addWidget(QLabel('Please select a date range')) layout.addWidget(self._fro) layout.addWidget(self._to) layout.addWidget(self.buttons) self.setLayout(layout) def _check_valid_range(self): self.buttons.button(QDialogButtonBox.Ok)\ .setEnabled(self._fro.date() <= self._to.date()) @property def fro(self): return self._fro.date().toPyDate() @property def to(self): return self._to.date().toPyDate()
def createEditor(self, parent, option, index): dateedit = QDateEdit(parent) dateedit.setDateRange(self.minimum, self.maximum) dateedit.setAlignment(Qt.AlignRight | Qt.AlignVCenter) dateedit.setDisplayFormat(self.format) dateedit.setCalendarPopup(True) return dateedit
def createEditor(self, parent, option, index): dateedit = QDateEdit(parent) dateedit.setDateRange(self.minimum, self.maximum) dateedit.setAlignment(Qt.AlignRight|Qt.AlignVCenter) dateedit.setDisplayFormat(self.format) dateedit.setCalendarPopup(True) return dateedit
def __init__(self, sid, parent=None): super(EditForm, self).__init__(parent) self.sid = sid data = self.callData(self.sid) try: details = self.pullDetails(data[1]) pagetitle = str(details[2]) +' Session' except: details = [] pagetitle = 'None' self.l1 = QLabel("Name") self.le = QLineEdit() self.le.setObjectName("name") self.le.setText(str(data[1])) self.l2 = QLabel("Start Date") self.le2 = QDateEdit() self.le2.setObjectName("startdate") #self.le2.setDate(data[2]) self.l3 = QLabel("End Date") self.le3 = QDateEdit() self.le3.setObjectName("enddate") #self.le3.setDate(data[3]) self.pb = QPushButton() self.pb.setObjectName("Submit") self.pb.setText("Submit") self.pb1 = QPushButton() self.pb1.setObjectName("Cancel") self.pb1.setText("Cancel") layout = QFormLayout() layout.addRow(self.l1, self.le) layout.addRow(self.l2, self.le2) layout.addRow(self.l3, self.le3) layout.addRow(self.pb1, self.pb) groupBox = QGroupBox('Edit Session') groupBox.setLayout(layout) grid = QGridLayout() grid.addWidget(groupBox, 0, 0) self.setLayout(grid) self.connect(self.pb, SIGNAL("clicked()"), lambda: self.button_click(data[0], self)) self.connect(self.pb1, SIGNAL("clicked()"),lambda: self.button_close(self)) self.setWindowTitle(pagetitle)
class CatalogFilterDate(CatalogFilter): def __init__(self, id): super(CatalogFilterDate, self).__init__(id) self.label = QLabel(TEXT_LABEL_BETWEEN) self.datetime_begin_edit = QDateEdit(QDate.currentDate()) self.datetime_end_edit = QDateEdit(QDate.currentDate()) self.datetime_begin_edit.setCalendarPopup(True) self.datetime_end_edit.setCalendarPopup(True) self.expand_widget(self.datetime_begin_edit) self.expand_widget(self.datetime_end_edit) value_item = QGridLayout() value_item.addWidget(self.datetime_begin_edit, 0, 0) value_item.addWidget(QLabel(TEXT_LABEL_AND), 0, 1) value_item.addWidget(self.datetime_end_edit, 0, 2) self.value_item = value_item def get_query_filters(self): # date request filter values are returned by get_datetime_begin/end return [] def validate(self, errors): datetime_begin = self.datetime_begin_edit.dateTime() datetime_end = self.datetime_end_edit.dateTime() if datetime_begin.daysTo(datetime_end) < 0: errors.append("First value must be less than or equal to second for %s filter." % self.column_name) def get_datetime_begin(self): return self.datetime_begin_edit.dateTime().toString(DATETIME_FORMAT) def get_datetime_end(self): return self.datetime_end_edit.dateTime().toString(DATETIME_FORMAT)
def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) # 初始化变量,以控制图表的显示 self.control = {"basic":True, "extreme":True, "slope":True, "star":True} self.widget = QWidget(self) self.horizontalLayout = QHBoxLayout(self.widget) self.label_1 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_1) self.lineEdit = QLineEdit(self.widget) self.horizontalLayout.addWidget(self.lineEdit) self.label_2 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_2) self.dateEdit = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit) self.label_3 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_3) self.dateEdit_2 = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit_2) self.button1 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button1) self.button2 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button2) self.button3 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button3) self.button4 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button4) self.button5 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button5) self.lineEdit.setText(QtCore.QString('002594')) three_month = QtCore.QDate.currentDate().toJulianDay() - 150 self.dateEdit.setDate(QtCore.QDate.fromJulianDay(three_month)) self.dateEdit_2.setDate(QtCore.QDate.currentDate()) self.label_1.setText(_translate("MainWindow", "股票代码", None)) self.label_2.setText(_translate("MainWindow", "起始时间", None)) self.label_3.setText(_translate("MainWindow", "终止时间", None)) self.button1.setText(_translate("MainWindow", "所有", None)) self.button2.setText(_translate("MainWindow", "极端", None)) self.button3.setText(_translate("MainWindow", "斜率", None)) self.button4.setText(_translate("MainWindow", "趋势", None)) self.button5.setText(_translate("MainWindow", "清除", None)) self.button1.clicked.connect(self.draw_all) self.button2.clicked.connect(self.draw_extreme) self.button3.clicked.connect(self.draw_slope) self.button4.clicked.connect(self.draw_trend) self.button5.clicked.connect(self.clear)
def _create_widgets(self): self.stacked = QStackedWidget() self.datew = QDateEdit() self.datew.setDisplayFormat("yyyy-MM-dd") self.stacked.addWidget(self.datew) self.buildidw = QLineEdit() self.stacked.addWidget(self.buildidw) self.releasew = QComboBox() self.releasew.addItems([str(k) for k in sorted(releases())]) self.stacked.addWidget(self.releasew) self.revw = QLineEdit() self.stacked.addWidget(self.revw) self.select_combo = QComboBox() self.select_combo.addItems(['date', 'buildid', 'release', 'changeset']) self.select_combo.activated.connect(self.stacked.setCurrentIndex)
def setup(self): for label, value in self.data: if DEBUG: print "value:", value if label is None and value is None: # Separator: (None, None) self.formlayout.addRow(QLabel(" "), QLabel(" ")) self.widgets.append(None) continue elif label is None: # Comment self.formlayout.addRow(QLabel(value)) self.widgets.append(None) continue elif tuple_to_qfont(value) is not None: field = FontLayout(value, self) elif text_to_qcolor(value).isValid(): field = ColorLayout(QColor(value), self) elif isinstance(value, (str, unicode)): field = QLineEdit(value, self) elif isinstance(value, (list, tuple)): selindex = value.pop(0) field = QComboBox(self) if isinstance(value[0], (list, tuple)): keys = [key for key, _val in value] value = [val for _key, val in value] else: keys = value field.addItems(value) if selindex in value: selindex = value.index(selindex) elif selindex in keys: selindex = keys.index(selindex) elif not isinstance(selindex, int): print >>STDERR, "Warning: '%s' index is invalid (label: " \ "%s, value: %s)" % (selindex, label, value) selindex = 0 field.setCurrentIndex(selindex) elif isinstance(value, bool): field = QCheckBox(self) if value: field.setCheckState(Qt.Checked) else: field.setCheckState(Qt.Unchecked) elif isinstance(value, float): field = QLineEdit(repr(value), self) elif isinstance(value, int): field = QSpinBox(self) field.setRange(-1e9, 1e9) field.setValue(value) elif isinstance(value, datetime.datetime): field = QDateTimeEdit(self) field.setDateTime(value) elif isinstance(value, datetime.date): field = QDateEdit(self) field.setDate(value) else: field = QLineEdit(repr(value), self) self.formlayout.addRow(label, field) self.widgets.append(field)
def __init__(self, id): super(CatalogFilterDate, self).__init__(id) self.label = QLabel(TEXT_LABEL_BETWEEN) self.datetime_begin_edit = QDateEdit(QDate.currentDate()) self.datetime_end_edit = QDateEdit(QDate.currentDate()) self.datetime_begin_edit.setCalendarPopup(True) self.datetime_end_edit.setCalendarPopup(True) self.expand_widget(self.datetime_begin_edit) self.expand_widget(self.datetime_end_edit) value_item = QGridLayout() value_item.addWidget(self.datetime_begin_edit, 0, 0) value_item.addWidget(QLabel(TEXT_LABEL_AND), 0, 1) value_item.addWidget(self.datetime_end_edit, 0, 2) self.value_item = value_item
def createEditor(self, parent, option, index): """Overriding method createEditor""" if index.column() < 3: return None value = self.get_value(index) key = index.model().get_key(index) readonly = isinstance(value, tuple) or self.parent().readonly #---editor = DictEditor if isinstance(value, (list, tuple, dict)) and not self.inplace: editor = DictEditor(value, key, icon=self.parent().windowIcon(), readonly=readonly) if editor.exec_() and not readonly: self.set_value(index, editor.get_copy()) return None #---editor = ArrayEditor elif isinstance(value, ndarray) and ndarray is not FakeObject \ and not self.inplace: if value.size == 0: return None editor = ArrayEditor(parent) if editor.setup_and_check(value, title=key, readonly=readonly): if editor.exec_(): # Only necessary for child class RemoteDictDelegate: # (ArrayEditor does not make a copy of value) self.set_value(index, value) return None #---editor = QDateTimeEdit elif isinstance(value, datetime.datetime) and not self.inplace: editor = QDateTimeEdit(value, parent) editor.setCalendarPopup(True) editor.setFont(get_font('dicteditor')) self.connect(editor, SIGNAL("returnPressed()"), self.commitAndCloseEditor) return editor #---editor = QDateEdit elif isinstance(value, datetime.date) and not self.inplace: editor = QDateEdit(value, parent) editor.setCalendarPopup(True) editor.setFont(get_font('dicteditor')) self.connect(editor, SIGNAL("returnPressed()"), self.commitAndCloseEditor) return editor #---editor = QTextEdit elif isinstance(value, (str, unicode)) and len(value) > 40: editor = TextEditor(value, key) if editor.exec_() and not readonly: conv = str if isinstance(value, str) else unicode self.set_value(index, conv(editor.get_copy())) return None #---editor = QLineEdit else: editor = QLineEdit(parent) editor.setFont(get_font('dicteditor')) editor.setAlignment(Qt.AlignLeft) self.connect(editor, SIGNAL("returnPressed()"), self.commitAndCloseEditor) return editor
def __init__(self): box = gui.widgetBox(self.controlArea, 'Yahoo Finance Stock Data', orientation='horizontal') lbox = gui.widgetBox(box, orientation='vertical') hbox = gui.widgetBox(lbox, orientation='horizontal') gui.label(hbox, self, 'Ticker:') self.combo = combo = QComboBox(editable=True, insertPolicy=QComboBox.InsertAtTop) combo.addItems(self.symbols) hbox.layout().addWidget(combo) # combo = gui.comboBox( # lbox, self, 'symbol',#, items=self.symbols, # label='Ticker:', orientation='horizontal', # editable=True, maximumContentsLength=-1) gui.rubber(combo.parentWidget()) minDate = QDate.fromString(self.MIN_DATE.strftime(self.PY_DATE_FORMAT), self.QT_DATE_FORMAT) date_from = QDateEdit( QDate.fromString(self.date_from, self.QT_DATE_FORMAT), displayFormat=self.QT_DATE_FORMAT, minimumDate=minDate, calendarPopup=True) date_to = QDateEdit( QDate.fromString(self.date_to, self.QT_DATE_FORMAT), displayFormat=self.QT_DATE_FORMAT, minimumDate=minDate, calendarPopup=True) date_from.dateChanged.connect( lambda date: setattr(self, 'date_from', date.toString(self.QT_DATE_FORMAT))) date_to.dateChanged.connect( lambda date: setattr(self, 'date_to', date.toString(self.QT_DATE_FORMAT))) hbox = gui.hBox(lbox) gui.label(hbox, self, "From:") hbox.layout().addWidget(date_from) hbox = gui.hBox(lbox) gui.label(hbox, self, "To:") hbox.layout().addWidget(date_to) gui.radioButtons(box, self, 'data_granularity', btnLabels=[i.name.capitalize().replace('_', ' ') for i in DataGranularity], box='Resolution') self.button = gui.button(self.controlArea, self, 'Download', callback=self.download)
def __init__(self, parent=None): super(NewTaskDialog, self).__init__(parent) # task name nameLabel = QLabel(self.tr("Name:")) self.name = QLineEdit() nameLabel.setBuddy(self.name) # priority priorityLabel = QLabel(self.tr("Priority:")) self.priority = QComboBox() priorityLabel.setBuddy(self.priority) dateLabel = QLabel(self.tr("Deadline:")) self.deadline = QDateEdit() dateLabel.setBuddy(self.deadline) self.deadline.setCalendarPopup(True) self.deadline.calendarWidget().setFirstDayOfWeek(Qt.Monday) self.deadline.setDate(QDate(date.today())) createButton = QPushButton(self.tr("Save")) cancelButton = QPushButton(self.tr("Cancel")) buttonLayout = QHBoxLayout() buttonLayout.addStretch() buttonLayout.addWidget(createButton) buttonLayout.addWidget(cancelButton) layout = QGridLayout() layout.addWidget(nameLabel, 0, 0) layout.addWidget(self.name, 0, 1) layout.addWidget(priorityLabel, 1, 0) layout.addWidget(self.priority, 1, 1) layout.addWidget(dateLabel, 2, 0) layout.addWidget(self.deadline, 2, 1) layout.addLayout(buttonLayout, 3, 0, 3, 2) self.setLayout(layout) self.connect(self.deadline, SIGNAL("dateChanged(const QDate&)"), self, SLOT("changed()")) self.connect(createButton, SIGNAL("clicked()"), self, SLOT("accept()")) self.connect(cancelButton, SIGNAL("clicked()"), self, SLOT("reject()")) self.setWindowTitle(self.tr("Task")) self.resize(350, 120) self.setMinimumSize(QSize(250, 120)) self.setMaximumSize(QSize(450, 120))
def __init__(self): super(DateRangeDialog, self).__init__() self._fro = QDateEdit(datetime.date.today()) self._to = QDateEdit(datetime.date.today() + datetime.timedelta(4)) self._fro.dateChanged.connect(self._check_valid_range) self._to.dateChanged.connect(self._check_valid_range) self.buttons = QDialogButtonBox(QDialogButtonBox.Ok) self.buttons.accepted.connect(self.accept) layout = QVBoxLayout() layout.addWidget(QLabel('Please select a date range')) layout.addWidget(self._fro) layout.addWidget(self._to) layout.addWidget(self.buttons) self.setLayout(layout)
def __init__(self, parent=None): super(AddForm, self).__init__(parent) self.l1 = QLabel("Name") self.le = QLineEdit() self.le.setObjectName("name") self.le.setText("") self.l2 = QLabel("Start Date") self.le2 = QDateEdit() self.le2.setObjectName("startdate") self.le2.setCalendarPopup(True) self.l3 = QLabel("End Date") self.le3 = QDateEdit() self.le3.setObjectName("enddate") self.le3.setCalendarPopup(True) self.pb = QPushButton() self.pb.setObjectName("Submit") self.pb.setText("Submit") self.pb1 = QPushButton() self.pb1.setObjectName("Cancel") self.pb1.setText("Cancel") layout = QFormLayout() layout.addRow(self.l1, self.le) layout.addRow(self.l2, self.le2) layout.addRow(self.l3, self.le3) layout.addRow(self.pb1, self.pb) groupBox = QGroupBox('Add Session') groupBox.setLayout(layout) grid = QGridLayout() grid.addWidget(groupBox, 0, 0) self.setLayout(grid) self.connect(self.pb, SIGNAL("clicked()"), lambda: self.button_click(self)) self.connect(self.pb1, SIGNAL("clicked()"), lambda: self.button_close(self)) self.setWindowTitle("Session Manager")
def create_dateedit(self, text, option, tip=None, min_date=None, max_date=None): label = QLabel(text) dateedit = QDateEdit() dateedit.setDisplayFormat('dd MMM yyyy') if min_date: dateedit.setMinimumDate(min_date) if max_date: dateedit.setMaximumDate(max_date) if tip: dateedit.setToolTip(tip) self.dateedits[dateedit] = option layout = QHBoxLayout() for subwidget in (label, dateedit): layout.addWidget(subwidget) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.setLayout(layout) return widget
class DlgCredito( QDialog ): def __init__( self, parent = None ): super( DlgCredito, self ).__init__( parent ) self.dtFechaTope = QDateEdit( QDate.currentDate().addDays( 1 ) ) self.dtFechaTope.setMinimumDate( QDate.currentDate().addDays( 1 ) ) """ @ivar: Este widget tiene la fecha tope en la que puede pagarse el credito @type: QDateEdit """ self.sbTaxRate = QDoubleSpinBox() """ @ivar: Este widget contiene la tasa de multa que se le aplicara a este credito @typ: QDoubleSpinBox """ self.setupUi() def setupUi( self ): vertical_layout = QVBoxLayout( self ) form_layout = QFormLayout() self.dtFechaTope.setCalendarPopup( True ) self.sbTaxRate.setSuffix( '%' ) form_layout.addRow( u"<b>Fecha Tope</b>", self.dtFechaTope ) form_layout.addRow( u"<b>Tasa de multa</b>", self.sbTaxRate ) buttonbox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) vertical_layout.addLayout( form_layout ) vertical_layout.addWidget( buttonbox ) buttonbox.accepted.connect( self.accept ) buttonbox.rejected.connect( self.reject )
def keyPressEvent(self, event): """ Returns key press event. Sets date to minimum if backspace or delete button is an event key. :param event: An Event. :type event: QEvent """ if event.key() == Qt.Key_Delete or event.key() == Qt.Key_Backspace: self.setDate(self.minimumDateTime().date()) return QDateEdit.keyPressEvent(self, event)
def mousePressEvent(self, event): """ Returns mouse press event. Sets date to current date if text in line edit is an empty string. :param event: An Event. :type event: QEvent """ if self.findChild(QLineEdit).text() == u'': self.setDate(QDate.currentDate()) return QDateEdit.mousePressEvent(self, event)
class NewTaskDialog(QDialog): def __init__(self, parent=None): super(NewTaskDialog, self).__init__(parent) # task name nameLabel = QLabel(self.tr("Name:")) self.name = QLineEdit() nameLabel.setBuddy(self.name) # priority priorityLabel = QLabel(self.tr("Priority:")) self.priority = QComboBox() priorityLabel.setBuddy(self.priority) dateLabel = QLabel(self.tr("Deadline:")) self.deadline = QDateEdit() dateLabel.setBuddy(self.deadline) self.deadline.setCalendarPopup(True) self.deadline.calendarWidget().setFirstDayOfWeek(Qt.Monday) self.deadline.setDate(QDate(date.today())) createButton = QPushButton(self.tr("Save")) cancelButton = QPushButton(self.tr("Cancel")) buttonLayout = QHBoxLayout() buttonLayout.addStretch() buttonLayout.addWidget(createButton) buttonLayout.addWidget(cancelButton) layout = QGridLayout() layout.addWidget(nameLabel, 0, 0) layout.addWidget(self.name, 0, 1) layout.addWidget(priorityLabel, 1, 0) layout.addWidget(self.priority, 1, 1) layout.addWidget(dateLabel, 2, 0) layout.addWidget(self.deadline, 2, 1) layout.addLayout(buttonLayout, 3, 0, 3, 2) self.setLayout(layout) self.connect(self.deadline, SIGNAL("dateChanged(const QDate&)"), self, SLOT("changed()")) self.connect(createButton, SIGNAL("clicked()"), self, SLOT("accept()")) self.connect(cancelButton, SIGNAL("clicked()"), self, SLOT("reject()")) self.setWindowTitle(self.tr("Task")) self.resize(350, 120) self.setMinimumSize(QSize(250, 120)) self.setMaximumSize(QSize(450, 120)) @pyqtSlot() def changed(self): print(self.deadline.text())
def _create_widgets(self): self.stacked = QStackedWidget() self.datew = QDateEdit() self.datew.setDisplayFormat("yyyy-MM-dd") self.stacked.addWidget(self.datew) self.buildidw = QLineEdit() self.stacked.addWidget(self.buildidw) self.releasew = QComboBox() self.releasew.addItems([str(k) for k in sorted(releases())]) self.stacked.addWidget(self.releasew) self.select_combo = QComboBox() self.select_combo.addItems(['date', 'buildid', 'release']) self.select_combo.activated.connect(self.stacked.setCurrentIndex)
def __init__( self, parent = None ): super( DlgCredito, self ).__init__( parent ) self.dtFechaTope = QDateEdit( QDate.currentDate().addDays( 1 ) ) self.dtFechaTope.setMinimumDate( QDate.currentDate().addDays( 1 ) ) """ @ivar: Este widget tiene la fecha tope en la que puede pagarse el credito @type: QDateEdit """ self.sbTaxRate = QDoubleSpinBox() """ @ivar: Este widget contiene la tasa de multa que se le aplicara a este credito @typ: QDoubleSpinBox """ self.setupUi()
def addPref(self): noi = 0 self._listPerson.append([ QLabel('%d' % (noi + 1), self), QDateEdit(self), QComboBox(self), QComboBox(self), QPushButton(self), QComboBox(self), QComboBox(self) ]) temp = self._listPerson[0] temp[S.birth].setDisplayFormat( QApplication.translate("Page01", "dd MMM yyyy", None, QApplication.UnicodeUTF8)) temp[S.birth].setObjectName('Bir%d' % noi) temp[S.birth].setCurrentSection(QDateEdit.YearSection) temp[S.decpos].setObjectName('Dec%d' % noi) temp[S.decpos].addItems(['vous']) temp[S.decpos].setEnabled(False) temp[S.decnum].setObjectName('Foy%d' % noi) temp[S.decnum].setEnabled(False) temp[S.fampos].addItems(['parent 1']) temp[S.fampos].setObjectName('Fam%d' % noi) temp[S.fampos].setEnabled(False) temp[S.famnum].setObjectName('Fam%d' % noi) temp[S.famnum].setEnabled(False) temp[S.decbtn].setObjectName('But%d' % noi) for i in xrange(7): self.gridLayout.addWidget(temp[i], noi + 2, i) self.gridLayout.setAlignment(temp[i], Qt.AlignCenter) self.emit(SIGNAL('compoChanged()'))
def addRow(self): noi = len(self._listPerson) self._listPerson.append([ QLabel('%d' % (noi + 1), self), QDateEdit(self), QComboBox(self), QComboBox(self), QPushButton(self), QComboBox(self), QComboBox(self) ]) temp = self._listPerson[-1] temp[S.birth].setDisplayFormat( QApplication.translate("Page01", "dd MMM yyyy", None, QApplication.UnicodeUTF8)) temp[S.birth].setObjectName('Bir%d' % noi) temp[S.birth].setCurrentSection(QDateEdit.YearSection) temp[S.decpos].setObjectName('Dec%d' % noi) temp[S.decpos].addItems(['vous', 'conj', 'pac']) temp[S.decnum].setObjectName('Foy%d' % noi) temp[S.fampos].setObjectName('Fam%d' % noi) temp[S.fampos].addItems(['parent 1', 'parent 2', 'enfant']) temp[S.famnum].setObjectName('Fam%d' % noi) temp[S.decbtn].setObjectName('But%d' % noi) for i in xrange(7): self.gridLayout.addWidget(temp[i], noi + 2, i) self.gridLayout.setAlignment(temp[i], Qt.AlignCenter) self.rmv_btn.setEnabled(True) if len(self.scenario.indiv) == 9: self.add_btn.setEnabled(False)
def __init__(self, parent = None): QDialog.__init__(self, parent) self.resize(290, 136); self.setWindowTitle("Reference Positions") sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()); self.setSizePolicy(sizePolicy); verticalLayoutDlg = QVBoxLayout(self) verticalLayoutDlg.setObjectName(("verticalLayoutDlg")); frameDate = QFrame(self); frameDate.setObjectName(("frameDate")); frameDate.setFrameShape(QFrame.StyledPanel); frameDate.setFrameShadow(QFrame.Raised); horizontalLayoutDate = QHBoxLayout(frameDate); horizontalLayoutDate.setObjectName(("horizontalLayoutDate")); labelDate = QLabel(frameDate); labelDate.setObjectName(("labelDate")); labelDate.setMinimumSize(QSize(70, 0)); labelDate.setMaximumSize(QSize(70, 16777215)); labelDate.setText("Date:") horizontalLayoutDate.addWidget(labelDate); self.dtpDate = QDateEdit(frameDate); self.dtpDate.setObjectName(("dtpDate")); horizontalLayoutDate.addWidget(self.dtpDate); self.btnDtpDate = QToolButton(frameDate); self.btnDtpDate.setObjectName(("btnDtpDate")); sizePolicy.setHeightForWidth(self.btnDtpDate.sizePolicy().hasHeightForWidth()); self.btnDtpDate.setSizePolicy(sizePolicy); self.btnDtpDate.setMinimumSize(QSize(25, 0)); self.btnDtpDate.setMaximumSize(QSize(25, 16777215)); icon = QIcon() icon.addPixmap(QPixmap(("Resource/calender.png")), QIcon.Normal, QIcon.Off) self.btnDtpDate.setIcon(icon) horizontalLayoutDate.addWidget(self.btnDtpDate); verticalLayoutDlg.addWidget(frameDate); frameModel = QFrame(self); frameModel.setObjectName(("frameModel")); frameModel.setFrameShape(QFrame.StyledPanel); frameModel.setFrameShadow(QFrame.Raised); horizontalLayoutModel = QHBoxLayout(frameModel); horizontalLayoutModel.setObjectName(("horizontalLayoutModel")); labelModel = QLabel(frameModel); labelModel.setObjectName(("labelModel")); labelModel.setMinimumSize(QSize(70, 0)); labelModel.setMaximumSize(QSize(70, 16777215)); labelModel.setText("Model:") horizontalLayoutModel.addWidget(labelModel); self.cmbModel = QComboBox(frameModel); self.cmbModel.setObjectName(("cmbModel")); horizontalLayoutModel.addWidget(self.cmbModel); verticalLayoutDlg.addWidget(frameModel); self.buttonBox = QDialogButtonBox(self); self.buttonBox.setObjectName(("buttonBox")); self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok); self.connect(self.buttonBox, SIGNAL("accepted()"), self.accept) self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject) verticalLayoutDlg.addWidget(self.buttonBox); self.calendar = QCalendarWidget() self.calendar.clicked.connect(self.calendar_clicked) self.menu = QMenu() layout = QVBoxLayout(self.menu) layout.addWidget(self.calendar) self.btnDtpDate.clicked.connect(self.btnDtpDate_clicked) self.cmbModel.addItems(["WMM2015", "WMM2010" , "WMM2005", "WMM2000", "WMM95", "WMM90", "WMM85", "IGRF2000", "IGRF95", "IGRF90"])
def create_widget(self): """ Create the QDateEdit widget. """ self.widget = QDateEdit(self.parent_widget())
def createEditor(self, parent, option, index): if index.column() == DATAINS: editor = QDateEdit(parent) editor.setCalendarPopup(True) editor.setAlignment(Qt.AlignRight|Qt.AlignVCenter) return editor elif index.column() == QT: editor = QLineEdit(parent) validator = QIntValidator(self) editor.setValidator(validator) editor.setAlignment(Qt.AlignRight|Qt.AlignVCenter) return editor elif index.column() == IMP: editor = QLineEdit(parent) validator = QDoubleValidator(self) validator.setDecimals(3) editor.setValidator(validator) editor.setAlignment(Qt.AlignRight|Qt.AlignVCenter) return editor else: return QSqlRelationalDelegate.createEditor(self, parent, option, index)
def __init__(self, parent=None): super(TalkDetailsWidget, self).__init__(parent) self.layout = QGridLayout() self.setLayout(self.layout) self.buttonLayout = QHBoxLayout() saveIcon = QIcon.fromTheme("document-save") self.saveButton = QPushButton('Save Talk') self.saveButton.setIcon(saveIcon) self.buttonLayout.addWidget(self.saveButton) self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1) self.titleLabel = QLabel('Title') self.titleLineEdit = QLineEdit() self.presenterLabel = QLabel('Presenter') self.presenterLineEdit = QLineEdit() self.layout.addWidget(self.titleLabel, 1, 0, 1, 1) self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 1) self.layout.addWidget(self.presenterLabel, 1, 2, 1, 1) self.layout.addWidget(self.presenterLineEdit, 1, 3, 1, 1) self.eventLabel = QLabel('Event') self.eventLineEdit = QLineEdit() self.categoryLabel = QLabel('Category') self.categoryLineEdit = QLineEdit() self.layout.addWidget(self.eventLabel, 2, 0, 1, 1) self.layout.addWidget(self.eventLineEdit, 2, 1, 1, 1) self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1) self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1) self.roomLabel = QLabel('Room') self.roomLineEdit = QLineEdit() self.dateLayout = QHBoxLayout() self.dateLabel = QLabel('Date') self.dateEdit = QDateEdit() currentDate = QDate() self.dateEdit.setDate(currentDate.currentDate()) self.dateEdit.setCalendarPopup(True) self.layout.addWidget(self.roomLabel, 3, 0, 1, 1) self.layout.addWidget(self.roomLineEdit, 3, 1, 1, 1) self.dateLayout.addWidget(self.dateEdit) self.layout.addWidget(self.dateLabel, 3, 2, 1, 1) self.layout.addLayout(self.dateLayout, 3, 3, 1, 1) self.startTimeLayout = QHBoxLayout() self.startTimeLabel = QLabel('Start Time') self.startTimeEdit = QTimeEdit() self.startTimeLayout.addWidget(self.startTimeEdit) self.endTimeLayout = QHBoxLayout() self.endTimeLabel = QLabel('End Time') self.endTimeEdit = QTimeEdit() self.endTimeLayout.addWidget(self.endTimeEdit) self.layout.addWidget(self.startTimeLabel, 4, 0, 1, 1) self.layout.addLayout(self.startTimeLayout, 4, 1, 1, 1) self.layout.addWidget(self.endTimeLabel, 4, 2, 1, 1) self.layout.addLayout(self.endTimeLayout, 4, 3, 1, 1) self.descriptionLabel = QLabel('Description') self.descriptionLabel.setAlignment(Qt.AlignTop) self.descriptionTextEdit = QPlainTextEdit() self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1) self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3)
def __init__(self, parent=None): super(TalkDetailsWidget, self).__init__(parent) self.layout = QGridLayout() self.setLayout(self.layout) self.buttonLayout = QHBoxLayout() addIcon = QIcon.fromTheme("list-add") self.addButton = QPushButton("Add New Talk") self.addButton.setIcon(addIcon) self.buttonLayout.addWidget(self.addButton) saveIcon = QIcon.fromTheme("document-save") self.saveButton = QPushButton("Save New Talk") self.saveButton.setIcon(saveIcon) self.buttonLayout.addWidget(self.saveButton) self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1) self.titleLabel = QLabel("Title") self.titleLineEdit = QLineEdit() self.layout.addWidget(self.titleLabel, 1, 0, 1, 1) self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 3) self.presenterLabel = QLabel("Presenter") self.presenterLineEdit = QLineEdit() self.categoryLabel = QLabel("Category") self.categoryLineEdit = QLineEdit() self.layout.addWidget(self.presenterLabel, 2, 0, 1, 1) self.layout.addWidget(self.presenterLineEdit, 2, 1, 1, 1) self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1) self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1) self.eventLabel = QLabel("Event") self.eventLineEdit = QLineEdit() self.roomLabel = QLabel("Room") self.roomLineEdit = QLineEdit() self.layout.addWidget(self.eventLabel, 3, 0, 1, 1) self.layout.addWidget(self.eventLineEdit, 3, 1, 1, 1) self.layout.addWidget(self.roomLabel, 3, 2, 1, 1) self.layout.addWidget(self.roomLineEdit, 3, 3, 1, 1) self.dateLayout = QHBoxLayout() self.timeLayout = QHBoxLayout() self.dateLabel = QLabel("Date") self.dateEdit = QDateEdit() currentDate = QDate() self.dateEdit.setDate(currentDate.currentDate()) self.dateEdit.setCalendarPopup(True) self.timeLabel = QLabel("Time") self.timeEdit = QTimeEdit() self.dateLayout.addWidget(self.dateEdit) self.timeLayout.addWidget(self.timeEdit) self.layout.addWidget(self.dateLabel, 4, 0, 1, 1) self.layout.addLayout(self.dateLayout, 4, 1, 1, 1) self.layout.addWidget(self.timeLabel, 4, 2, 1, 1) self.layout.addLayout(self.timeLayout, 4, 3, 1, 1) self.descriptionLabel = QLabel("Description") self.descriptionLabel.setAlignment(Qt.AlignTop) self.descriptionTextEdit = QPlainTextEdit() self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1) self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3)
def initUI(self): # 0 1 2 3 4 5 6 7 8 #'destname','lgselect','layer','uconf','group','epsg','fd','td','int' #self.rdest,rlgselect,self.rlayer,ruconf,self.rgroup,repsg,rfd,rtd,rint = readlist QToolTip.setFont(QFont('SansSerif', 10)) #labels destLabel = QLabel('Destination') lgLabel = QLabel('Group/Layer') epsgLabel = QLabel('EPSG') fromDateLabel = QLabel('From Date') toDateLabel = QLabel('To Date') confLabel = QLabel('User Config') self.view = QLabel() self.view.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.view.setAlignment(Qt.AlignCenter) self.confcombo = QComboBox(self) self.confcombo.setToolTip('Enter your user config name (file) here') self.confcombo.addItems(self.cflist) self.confcombo.setEditable(False) #self.confcombo.currentIndexChanged.connect(self.doLGEditUpdate) #combos self.lgcombo = QComboBox(self) self.lgcombo.setMaximumWidth(self.MAX_WD) self.lgcombo.setDuplicatesEnabled(False) #self.lgcombo.setInsertPolicy(QComboBox.InsertAlphabetically)#?doesnt seem to work self.lgcombo.setToolTip('Select either Layer or Group entry') self.lgcombo.setEditable(False) self.sepindex = None #self.updateLGValues() self.epsgcombo = QComboBox(self) self.epsgcombo.setMaximumWidth(self.MAX_WD) self.epsgcombo.setToolTip('Setting an EPSG number here determines the output SR of the layer') self.epsgcombo.addItems([i[1] for i in self.nzlsr]) self.epsgcombo.insertSeparator(len(self.nzlsr)) self.epsgcombo.addItems([i[1] for i in self.rowsr]) self.epsgcombo.setEditable(True) self.epsgcombo.setEnabled(False) self.destlist = self.getConfiguredDestinations() self.destcombo = QComboBox(self) self.destcombo.setToolTip('Choose the desired output type') self.destcombo.setEditable(False) self.destcombo.addItems(self.destlist) #date selection self.fromdateedit = QDateEdit() self.fromdateedit.setCalendarPopup(True) self.fromdateedit.setEnabled(False) self.todateedit = QDateEdit() self.todateedit.setCalendarPopup(True) self.todateedit.setEnabled(False) #check boxes self.epsgenable = QCheckBox() self.epsgenable.setCheckState(False) self.epsgenable.clicked.connect(self.doEPSGEnable) self.fromdateenable = QCheckBox() self.fromdateenable.setCheckState(False) self.fromdateenable.clicked.connect(self.doFromDateEnable) self.todateenable = QCheckBox() self.todateenable.setCheckState(False) self.todateenable.clicked.connect(self.doToDateEnable) self.progressbar = QProgressBar() self.progressbar.setRange(0,100) self.progressbar.setVisible(True) self.progressbar.setMinimumWidth(self.MAX_WD) #buttons self.initbutton = QPushButton("waiting") self.initbutton.setToolTip('Initialise the Layer Configuration') self.initbutton.clicked.connect(self.doInitClickAction) self.cleanbutton = QPushButton("Clean") self.cleanbutton.setToolTip('Clean the selected layer/group from local storage') self.cleanbutton.clicked.connect(self.doCleanClickAction) self.replicatebutton = QPushButton("Replicate") self.replicatebutton.setToolTip('Execute selected replication') self.replicatebutton.clicked.connect(self.doReplicateClickAction) self.cancelbutton = QPushButton("Close") self.cancelbutton.setToolTip('Close the LDS Replicate application') self.cancelbutton.clicked.connect(self.parent.close) #set dialog values using GPR self.updateGUIValues(self.parent.gvs) #set onchange here otherwise we get circular initialisation self.destcombo.currentIndexChanged.connect(self.doDestChanged) self.confcombo.currentIndexChanged.connect(self.doConfChanged) self.lgcombo.currentIndexChanged.connect(self.doLGComboChanged) self.setStatus(self.STATUS.IDLE) #grid grid = QGridLayout() grid.setSpacing(10) #placement section ------------------------------------ #---------+---------+--------+---------+-------- # dest LB | | dest DD # grp LB | | grp DD # conf LB | | conf DD # epsg L | epsg CB | epsg DD # f dt L | f dt CB | f dt DD # t td L | t td CB | t td DD # icon | <- progress -> # layer B | <- . -> |repl B | clean B | close B #---------+---------+--------+---------+-------- grid.addWidget(destLabel, 1, 0) grid.addWidget(self.destcombo, 1, 2) #grid.addWidget(layerLabel, 2, 0) grid.addWidget(lgLabel, 2, 0) grid.addWidget(self.lgcombo, 2, 2) grid.addWidget(confLabel, 3, 0) grid.addWidget(self.confcombo, 3, 2) #grid.addWidget(groupLabel, 4, 0) #grid.addWidget(self.groupEdit, 4, 2) grid.addWidget(epsgLabel, 5, 0) grid.addWidget(self.epsgenable, 5, 1) grid.addWidget(self.epsgcombo, 5, 2) grid.addWidget(fromDateLabel, 6, 0) grid.addWidget(self.fromdateenable, 6, 1) grid.addWidget(self.fromdateedit, 6, 2) grid.addWidget(toDateLabel, 7, 0) grid.addWidget(self.todateenable, 7, 1) grid.addWidget(self.todateedit, 7, 2) hbox3 = QHBoxLayout() hbox3.addWidget(self.view) hbox3.addStretch(1) hbox3.addWidget(self.progressbar) #hbox3.addLayout(vbox2) #hbox3.addLayout(vbox3) hbox4 = QHBoxLayout() hbox4.addWidget(self.initbutton) hbox4.addStretch(1) hbox4.addWidget(self.replicatebutton) hbox4.addWidget(self.cleanbutton) hbox4.addWidget(self.cancelbutton) vbox = QVBoxLayout() #vbox.addStretch(1) vbox.addLayout(grid) vbox.addLayout(hbox3) vbox.addLayout(hbox4) self.setLayout(vbox)
class LDSControls(QFrame): STATIC_IMG = ('error_static.png','linz_static.png','busy_static.png','clean_static.png') ANIM_IMG = ('error.gif','linz.gif','layer.gif','clean.gif') IMG_SPEED = 100 IMG_WIDTH = 64 IMG_HEIGHT = 64 MAX_WD = 450 GD_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../../bin/gdal/gdal-data')) STATUS = LU.enum('ERROR','IDLE','BUSY','CLEAN') def __init__(self,parent): super(LDSControls, self).__init__() self.parent = parent self.initConf() self.initEPSG() self.initUI() def initConf(self): '''Read files in conf dir ending in conf''' self.cflist = ConfigInitialiser.getConfFiles() #self.imgset = self.STATIC_IMG if ConfigWrapper().readDSProperty('Misc','indicator')=='static' else self.ANIM_IMG #self.imgset = self.STATIC_IMG if self.parent.confconn.tp.src.confwrap.readDSProperty('Misc','indicator')=='static' else self.ANIM_IMG sep = self.parent.confconn.reg.openEndPoint(self.parent.confconn.SRCNAME,self.parent.confconn.uconf) self.imgset = self.STATIC_IMG if sep.confwrap.readDSProperty('Misc','indicator')=='static' else self.ANIM_IMG self.parent.confconn.reg.closeEndPoint(self.parent.confconn.SRCNAME) def initEPSG(self): '''Read GDAL EPSG files, splitting by NZ(RSR) and RestOfTheWorld''' gcsf = gdal.FindFile('gdal','gcs.csv') if not gcsf: gcsf = os.path.join(self.GD_PATH,'gcs.csv') pcsf = gdal.FindFile('gdal','pcs.csv') if not pcsf: pcsf = os.path.join(self.GD_PATH,'pcs.csv') gcs = ConfigInitialiser.readCSV(gcsf) pcs = ConfigInitialiser.readCSV(pcsf) self.nzlsr = [(e[0],e[0]+' - '+e[3]) for e in gcs if 'NZGD' in e[1] or 'RSRGD' in e[1]] \ + [(e[0],e[0]+' - '+e[1]) for e in pcs if 'NZGD' in e[1] or 'RSRGD' in e[1]] self.rowsr = [(e[0],e[0]+' - '+e[3]) for e in gcs if 'NZGD' not in e[1] and 'RSRGD' not in e[1]] \ + [(e[0],e[0]+' - '+e[1]) for e in pcs if 'NZGD' not in e[1] and 'RSRGD' not in e[1]] def initUI(self): # 0 1 2 3 4 5 6 7 8 #'destname','lgselect','layer','uconf','group','epsg','fd','td','int' #self.rdest,rlgselect,self.rlayer,ruconf,self.rgroup,repsg,rfd,rtd,rint = readlist QToolTip.setFont(QFont('SansSerif', 10)) #labels destLabel = QLabel('Destination') lgLabel = QLabel('Group/Layer') epsgLabel = QLabel('EPSG') fromDateLabel = QLabel('From Date') toDateLabel = QLabel('To Date') confLabel = QLabel('User Config') self.view = QLabel() self.view.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) self.view.setAlignment(Qt.AlignCenter) self.confcombo = QComboBox(self) self.confcombo.setToolTip('Enter your user config name (file) here') self.confcombo.addItems(self.cflist) self.confcombo.setEditable(False) #self.confcombo.currentIndexChanged.connect(self.doLGEditUpdate) #combos self.lgcombo = QComboBox(self) self.lgcombo.setMaximumWidth(self.MAX_WD) self.lgcombo.setDuplicatesEnabled(False) #self.lgcombo.setInsertPolicy(QComboBox.InsertAlphabetically)#?doesnt seem to work self.lgcombo.setToolTip('Select either Layer or Group entry') self.lgcombo.setEditable(False) self.sepindex = None #self.updateLGValues() self.epsgcombo = QComboBox(self) self.epsgcombo.setMaximumWidth(self.MAX_WD) self.epsgcombo.setToolTip('Setting an EPSG number here determines the output SR of the layer') self.epsgcombo.addItems([i[1] for i in self.nzlsr]) self.epsgcombo.insertSeparator(len(self.nzlsr)) self.epsgcombo.addItems([i[1] for i in self.rowsr]) self.epsgcombo.setEditable(True) self.epsgcombo.setEnabled(False) self.destlist = self.getConfiguredDestinations() self.destcombo = QComboBox(self) self.destcombo.setToolTip('Choose the desired output type') self.destcombo.setEditable(False) self.destcombo.addItems(self.destlist) #date selection self.fromdateedit = QDateEdit() self.fromdateedit.setCalendarPopup(True) self.fromdateedit.setEnabled(False) self.todateedit = QDateEdit() self.todateedit.setCalendarPopup(True) self.todateedit.setEnabled(False) #check boxes self.epsgenable = QCheckBox() self.epsgenable.setCheckState(False) self.epsgenable.clicked.connect(self.doEPSGEnable) self.fromdateenable = QCheckBox() self.fromdateenable.setCheckState(False) self.fromdateenable.clicked.connect(self.doFromDateEnable) self.todateenable = QCheckBox() self.todateenable.setCheckState(False) self.todateenable.clicked.connect(self.doToDateEnable) self.progressbar = QProgressBar() self.progressbar.setRange(0,100) self.progressbar.setVisible(True) self.progressbar.setMinimumWidth(self.MAX_WD) #buttons self.initbutton = QPushButton("waiting") self.initbutton.setToolTip('Initialise the Layer Configuration') self.initbutton.clicked.connect(self.doInitClickAction) self.cleanbutton = QPushButton("Clean") self.cleanbutton.setToolTip('Clean the selected layer/group from local storage') self.cleanbutton.clicked.connect(self.doCleanClickAction) self.replicatebutton = QPushButton("Replicate") self.replicatebutton.setToolTip('Execute selected replication') self.replicatebutton.clicked.connect(self.doReplicateClickAction) self.cancelbutton = QPushButton("Close") self.cancelbutton.setToolTip('Close the LDS Replicate application') self.cancelbutton.clicked.connect(self.parent.close) #set dialog values using GPR self.updateGUIValues(self.parent.gvs) #set onchange here otherwise we get circular initialisation self.destcombo.currentIndexChanged.connect(self.doDestChanged) self.confcombo.currentIndexChanged.connect(self.doConfChanged) self.lgcombo.currentIndexChanged.connect(self.doLGComboChanged) self.setStatus(self.STATUS.IDLE) #grid grid = QGridLayout() grid.setSpacing(10) #placement section ------------------------------------ #---------+---------+--------+---------+-------- # dest LB | | dest DD # grp LB | | grp DD # conf LB | | conf DD # epsg L | epsg CB | epsg DD # f dt L | f dt CB | f dt DD # t td L | t td CB | t td DD # icon | <- progress -> # layer B | <- . -> |repl B | clean B | close B #---------+---------+--------+---------+-------- grid.addWidget(destLabel, 1, 0) grid.addWidget(self.destcombo, 1, 2) #grid.addWidget(layerLabel, 2, 0) grid.addWidget(lgLabel, 2, 0) grid.addWidget(self.lgcombo, 2, 2) grid.addWidget(confLabel, 3, 0) grid.addWidget(self.confcombo, 3, 2) #grid.addWidget(groupLabel, 4, 0) #grid.addWidget(self.groupEdit, 4, 2) grid.addWidget(epsgLabel, 5, 0) grid.addWidget(self.epsgenable, 5, 1) grid.addWidget(self.epsgcombo, 5, 2) grid.addWidget(fromDateLabel, 6, 0) grid.addWidget(self.fromdateenable, 6, 1) grid.addWidget(self.fromdateedit, 6, 2) grid.addWidget(toDateLabel, 7, 0) grid.addWidget(self.todateenable, 7, 1) grid.addWidget(self.todateedit, 7, 2) hbox3 = QHBoxLayout() hbox3.addWidget(self.view) hbox3.addStretch(1) hbox3.addWidget(self.progressbar) #hbox3.addLayout(vbox2) #hbox3.addLayout(vbox3) hbox4 = QHBoxLayout() hbox4.addWidget(self.initbutton) hbox4.addStretch(1) hbox4.addWidget(self.replicatebutton) hbox4.addWidget(self.cleanbutton) hbox4.addWidget(self.cancelbutton) vbox = QVBoxLayout() #vbox.addStretch(1) vbox.addLayout(grid) vbox.addLayout(hbox3) vbox.addLayout(hbox4) self.setLayout(vbox) #def setProgress(self,pct): # self.progressbar.setValue(pct) def setStatus(self,status,message='',tooltip=None): '''Sets indicator icon and statusbar message''' self.parent.statusbar.showMessage(message) self.parent.statusbar.setToolTip(tooltip if tooltip else '') #progress loc = os.path.abspath(os.path.join(IMG_LOC,self.imgset[status])) #loc = os.path.abspath(os.path.join(os.path.dirname(__file__),self.parent.IMG_LOC,self.imgset[status])) self.progressbar.setVisible(status in (self.STATUS.BUSY, self.STATUS.CLEAN)) #icon anim = QMovie(loc, QByteArray(), self) anim.setScaledSize(QSize(self.IMG_WIDTH,self.IMG_HEIGHT)) anim.setCacheMode(QMovie.CacheAll) anim.setSpeed(self.IMG_SPEED) self.view.clear() self.view.setMovie(anim) anim.start() self.view.repaint() QApplication.processEvents(QEventLoop.AllEvents) def mainWindowEnable(self,enable=True): cons = (self.lgcombo, self.confcombo, self.destcombo, self.initbutton, self.replicatebutton, self.cleanbutton, self.cancelbutton, self.epsgenable,self.fromdateenable,self.todateenable, self.parent.menubar) for c in cons: c.setEnabled(enable) if enable: self.epsgcombo.setEnabled(self.epsgenable.checkState()) self.fromdateedit.setEnabled(self.fromdateenable.checkState()) self.todateedit.setEnabled(self.todateenable.checkState()) else: self.epsgcombo.setEnabled(False) self.fromdateedit.setEnabled(False) self.todateedit.setEnabled(False) QApplication.restoreOverrideCursor() if enable else QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) def refreshLGCombo(self): '''Re index LG combobox since a refreshLG call (new dest?) will usually mean new groups''' self.lgcombo.clear() self.lgcombo.addItems([i[2] for i in self.parent.confconn.lglist]) #NOTE the separator consumes an index, if not clearing the combobox selectively remove the old sepindex (assumes g preceeds l) #if self.sepindex: # self.lgcombo.removeItem(self.sepindex) self.sepindex = [i[0] for i in self.parent.confconn.lglist].count(LORG.GROUP) self.lgcombo.insertSeparator(self.sepindex) def updateLGValues(self,uconf,lgval,dest): '''Sets the values displayed in the Layer/Group combo''' #because we cant seem to sort combobox entries and want groups at the top, clear and re-add #TRACE# #pdb.set_trace() sf = None try: self.parent.confconn.initConnections(uconf,lgval,dest) except Exception as e: sf=1 ldslog.error('Error Updating UC Values. '+str(e)) if sf: self.setStatus(self.STATUS.ERROR,'Error Updating UC Values', str(e)) else: self.setStatus(self.STATUS.IDLE) self.refreshLGCombo() def centre(self): qr = self.frameGeometry() cp = QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) def gprParameters(self,rdest): '''Zip default and GPR values''' return [x if LU.assessNone(x) else y for x,y in zip(self.parent.gpr.readsec(rdest),self.parent.DEF_RVALS[1:])] def getLCE(self,ln): '''Read layer parameters''' dep = self.parent.confconn.reg.openEndPoint(self.parent.confconn.destname,self.parent.confconn.uconf) #sep = self.parent.confconn.reg.openEndPoint('WFS',self.parent.confconn.uconf) self.parent.confconn.reg.setupLayerConfig(self.parent.confconn.tp,None,dep,initlc=False) lce = dep.getLayerConf().readLayerParameters(ln) #self.parent.confconn.reg.closeEndPoint('WFS') self.parent.confconn.reg.closeEndPoint(self.parent.confconn.destname) sep,dep = None,None return lce def doDestChanged(self): '''Read the destname parameter and fill dialog with matching GPR values''' rdest = str(self.destlist[self.destcombo.currentIndex()]) rvals = self.gprParameters(rdest) self.updateGUIValues([rdest]+rvals) def doConfChanged(self): '''Read the user conf parameter and fill dialog with matching GPR values''' rdest = str(self.destlist[self.destcombo.currentIndex()]) rlg,_,rep,rfd,rtd = self.gprParameters(rdest) ruc = str(self.cflist[self.confcombo.currentIndex()]) self.updateGUIValues((rdest,rlg,ruc,rep,rfd,rtd)) def doLGComboChanged(self): '''Read the layer/group value and change epsg to layer or gpr match''' #get a matching LG entry and test whether its a layer or group #lgi = self.parent.confconn.getLayerGroupIndex(self.lgcombo.currentText().toUtf8().data()) lgi = self.parent.confconn.getLayerGroupIndex(LQ.readWidgetText(self.lgcombo.currentText())) #lgi can be none if we init a new group, in which case we use the GPR value if lgi: lge = self.parent.confconn.lglist[lgi] lce = self.getLCE(lge[1]) if lge[0]==LORG.LAYER else None else: lce = None #look for filled layer conf epsg OR use prefs stored in gpr if lce and LU.assessNone(lce.epsg): epsgval = lce.epsg else: rdest = str(self.destlist[self.destcombo.currentIndex()]) _,_,epsgval,_,_ = self.gprParameters(rdest) epsgindex = [i[0] for i in self.nzlsr+[(0,0)]+self.rowsr].index(epsgval) if self.epsgcombo.currentIndex() != epsgindex: self.epsgcombo.setCurrentIndex(int(epsgindex)) def updateGUIValues(self,readlist): '''Fill dialog values from provided list''' #TODO. Remove circular references when setCurrentIndex() triggers do###Changed() #Read user input rdest,self.rlgval,ruconf,repsg,rfd,rtd = readlist #-------------------------------------------------------------------- #Destination Menu selecteddest = LU.standardiseDriverNames(rdest) if selecteddest not in self.destlist: self.destlist = self.getConfiguredDestinations() self.destcombo.addItem(selecteddest) destindex = self.destlist.index(selecteddest) if selecteddest else 0 if self.destcombo.currentIndex() != destindex: self.destcombo.setCurrentIndex(destindex) #InitButton self.initbutton.setText('Layer Select') #Config File confindex = 0 if LU.assessNone(ruconf): ruconf = ruconf.split('.')[0] if ruconf not in self.cflist: self.cflist += [ruconf,] self.confcombo.addItem(ruconf) confindex = self.cflist.index(ruconf) if self.confcombo.currentIndex() != confindex: self.confcombo.setCurrentIndex(confindex) #self.confEdit.setText(ruconf if LU.assessNone(ruconf) else '') #Layer/Group Selection self.updateLGValues(ruconf,self.rlgval,rdest) lgindex = None if LU.assessNone(self.rlgval): #index of list value lgindex = self.parent.confconn.getLayerGroupIndex(self.rlgval,col=1) if LU.assessNone(lgindex): #advance by 1 for sep lgindex += 1 if lgindex>self.sepindex else 0 else: #using the separator index sets the combo to blank lgindex = self.sepindex if self.lgcombo.currentIndex() != lgindex: self.lgcombo.setCurrentIndex(lgindex) #self.doLGEditUpdate() #EPSG # user > layerconf #useepsg = LU.precedence(repsg, lce.epsg if lce else None, None) epsgindex = [i[0] for i in self.nzlsr+[(None,None)]+self.rowsr].index(repsg) if self.epsgcombo.currentIndex() != epsgindex: self.epsgcombo.setCurrentIndex(epsgindex) #epsgedit = self.epsgcombo.lineEdit() #epsgedit.setText([e[1] for e in self.nzlsr+self.rowsr if e[0]==repsg][0]) #epsgedit.setText([e for e in self.nzlsr+self.rowsr if re.match('^\s*(\d+).*',e).group(1)==repsg][0]) #To/From Dates if LU.assessNone(rfd): self.fromdateedit.setDate(QDate(int(rfd[0:4]),int(rfd[5:7]),int(rfd[8:10]))) else: early = DataStore.EARLIEST_INIT_DATE self.fromdateedit.setDate(QDate(int(early[0:4]),int(early[5:7]),int(early[8:10]))) if LU.assessNone(rtd): self.todateedit.setDate(QDate(int(rtd[0:4]),int(rtd[5:7]),int(rtd[8:10]))) else: today = DataStore.getCurrent() self.todateedit.setDate(QDate(int(today[0:4]),int(today[5:7]),int(today[8:10]))) #Internal/External CheckBox # if LU.assessNone(rint): # self.internalTrigger.setChecked(rint.lower()==DataStore.CONF_INT) # else: # self.internalTrigger.setChecked(DataStore.DEFAULT_CONF==DataStore.CONF_INT) def getConfiguredDestinations(self): defml = ['',]+DataStore.DRIVER_NAMES.values() return [d for d in self.parent.gpr.getDestinations() if d in defml] def doEPSGEnable(self): self.epsgcombo.setEnabled(self.epsgenable.isChecked()) def doFromDateEnable(self): self.fromdateedit.setEnabled(self.fromdateenable.isChecked()) def doToDateEnable(self): self.todateedit.setEnabled(self.todateenable.isChecked()) def readParameters(self): '''Read values out of dialogs''' destination = LU.assessNone(str(self.destlist[self.destcombo.currentIndex()])) #lgindex = self.parent.confconn.getLayerGroupIndex(self.lgcombo.currentText().toUtf8().data()) lgindex = self.parent.confconn.getLayerGroupIndex(LQ.readWidgetText(self.lgcombo.currentText())) #NB need to test for None explicitly since zero is a valid index lgval = self.parent.confconn.lglist[lgindex][1] if LU.assessNone(lgindex) else None #uconf = LU.standardiseUserConfigName(str(self.confcombo.lineEdit().text())) #uconf = str(self.confcombo.lineEdit().text()) uconf = str(self.cflist[self.confcombo.currentIndex()]) ee = self.epsgenable.isChecked() epsg = None if ee is False else re.match('^\s*(\d+).*',str(self.epsgcombo.lineEdit().text())).group(1) fe = self.fromdateenable.isChecked() te = self.todateenable.isChecked() fd = None if fe is False else str(self.fromdateedit.date().toString('yyyy-MM-dd')) td = None if te is False else str(self.todateedit.date().toString('yyyy-MM-dd')) return destination,lgval,uconf,epsg,fe,te,fd,td def doInitClickAction(self): '''Initialise the LC on LC-button-click, action''' try: try: self.setStatus(self.STATUS.BUSY,'Opening Layer-Config Editor') self.progressbar.setValue(0) self.parent.runLayerConfigAction() finally: self.setStatus(self.STATUS.IDLE,'Ready') except Exception as e: self.setStatus(self.STATUS.ERROR,'Error in Layer-Config',str(sys.exc_info()))#e)) def doCleanClickAction(self): '''Set clean anim and run clean''' #lgo = self.lgcombo.currentText().toUtf8().data() lgo = LQ.readWidgetText(self.lgcombo.currentText()) try: self.setStatus(self.STATUS.CLEAN,'Running Clean '+lgo) self.progressbar.setValue(0) self.runReplicationScript(True) except Exception as e: self.setStatus(self.STATUS.ERROR,'Failed Clean of '+lgo,str(sys.exc_info()))#e)) def doReplicateClickAction(self): '''Set busy anim and run repl''' lgo = self.lgcombo.currentText()#.toUtf8().data()#only used for error messages try: self.setStatus(self.STATUS.BUSY,'Running Replicate '+lgo) self.progressbar.setValue(0) self.runReplicationScript(False) except Exception as e: self.setStatus(self.STATUS.ERROR,'Failed Replication of '+lgo,str(sys.exc_info()))#e)) def runReplicationScript(self,clean=False): '''Run the layer/group repliction script''' destination,lgval,uconf,epsg,fe,te,fd,td = self.readParameters() uconf_path = LU.standardiseUserConfigName(uconf) destination_path = LU.standardiseLayerConfigName(destination) destination_driver = LU.standardiseDriverNames(destination) if not os.path.exists(uconf_path): self.userConfMessage(uconf_path) return elif not MainFileReader(uconf_path).hasSection(destination_driver): self.userConfMessage(uconf_path,destination_driver) return #----------------------------------------------------- #'destname','layer','uconf','group','epsg','fd','td','int' self.parent.gpr.write((destination_driver,lgval,uconf,epsg,fd,td)) ldslog.info(u'dest={0}, lg={1}, conf={2}, epsg={3}'.format(destination_driver,lgval,uconf,epsg)) ldslog.info('fd={0}, td={1}, fe={2}, te={3}'.format(fd,td,fe,te)) lgindex = self.parent.confconn.getLayerGroupIndex(lgval,col=1) #lorg = self.parent.confconn.lglist[lgindex][0] #----------don't need lorg in TP anymore but it is useful for sorting/counting groups #self.parent.confconn.tp.setLayerOrGroup(lorg) self.parent.confconn.tp.setLayerGroupValue(lgval) if self.fromdateenable.isChecked(): self.parent.confconn.tp.setFromDate(fd) if self.todateenable.isChecked(): self.parent.confconn.tp.setToDate(td) self.parent.confconn.tp.setUserConf(uconf) if self.epsgenable: self.parent.confconn.tp.setEPSG(epsg) #because clean state persists in TP if clean: self.parent.confconn.tp.setCleanConfig() else: self.parent.confconn.tp.clearCleanConfig() #(re)initialise the data source since uconf may have changed #>>#self.parent.confconn.tp.src = self.parent.confconn.initSourceWrapper() #-------------------------- ###ep = self.parent.confconn.reg.openEndPoint(self.parent.confconn.destname,self.parent.confconn.uconf) ###self.parent.confconn.reg.closeEndPoint(self.parent.confconn.destname) ###ep = None #Open ProcessRunner and run with TP(proc)/self(gui) instances #HACK temp add of dest_drv to PR call try: #TODO. Test for valid LC first self.tpr = ProcessRunner(self,destination_driver) except Exception as e: ldslog.error('Cannot create ProcessRunner {}. NB Possible missing Layer Config {}'.format(str(e),destination_path)) self.layerConfMessage(destination_path) return #If PR has been successfully created we must vave a valid dst self.tpr.start() def quitProcessRunner(self): self.tpr.join() self.tpr.quit() self.trp = None def userConfMessage(self,uconf,secname=None): ucans = QMessageBox.warning(self, 'User Config Missing/Incomplete', 'Specified User-Config file, '+str(uconf)+' does not exist' if secname is None else 'User-Config file does not contain '+str(secname)+' section', 'Back','Initialise User Config') if not ucans: #Retry ldslog.warn('Retry specifying UC') #self.confcombo.setCurrentIndex(0) return #Init ldslog.warn('Reset User Config Wizard') self.parent.runWizardAction() def layerConfMessage(self,dest): lcans = QMessageBox.warning(self, 'Layer Config Missing', 'Required Layer-Config file, '+str(dest)+' does not exist', 'Back','Run Layer Select') if not lcans: #Retry ldslog.warn('Retry specifying LC') #self.destcombo.setCurrentIndex(0) return #Init ldslog.warn('Reset Layer Config') self.doInitClickAction()
def initGui(): def setData(): buttonPath.setText(self.data["path"]) radioVisual.setChecked(self.data["isVisual"]) radioAnalytic.setChecked(not self.data["isVisual"]) chkBoxSquare.setChecked(self.data["isSquare"]) d1 = self.data["date1"] d2 = self.data["date2"] date1.setDate(d1) date2.setDate(d2) date1.setMaximumDate(d2.addDays(-1)) date2.setMinimumDate(d1.addDays(+1)) spinDay.setValue(d1.daysTo(d2)) def connect(): buttonOK.clicked.connect(self.onOK) buttonPath.clicked.connect(self.onPath) date1.dateChanged.connect(self.onDateChanged1) date2.dateChanged.connect(self.onDateChanged2) spinDay.valueChanged.connect(self.onValueChanged) windowTitle = "Setting download images Planet Labs" self.setWindowTitle(windowTitle) self.setWindowIcon(icon) grpImage = QGroupBox("Images", self) radioVisual = QRadioButton("Visual", grpImage) radioVisual.setObjectName("rbVisual") radioAnalytic = QRadioButton("Analytic", grpImage) chkBoxSquare = QCheckBox("Square thumbnail", grpImage) chkBoxSquare.setObjectName("cbBoxSquare") buttonPath = QPushButton(self.titleSelectDirectory, grpImage) buttonPath.setObjectName("pbPath") layoutRadioButtons = QHBoxLayout() for item in (radioVisual, radioAnalytic): layoutRadioButtons.addWidget(item) layoutImage = QVBoxLayout(grpImage) layoutImage.addLayout(layoutRadioButtons) layoutImage.addWidget(chkBoxSquare) layoutImage.addWidget(buttonPath) grpDateSearch = QGroupBox("Dates for search", self) date1 = QDateEdit(grpDateSearch) date1.setObjectName("deDate1") date2 = QDateEdit(grpDateSearch) date2.setObjectName("deDate2") for item in [date1, date2]: item.setCalendarPopup(True) format = item.displayFormat().replace("yy", "yyyy") item.setDisplayFormat(format) spinDay = QSpinBox(grpDateSearch) spinDay.setObjectName("sbDay") spinDay.setSingleStep(1) spinDay.setSuffix(" Days") spinDay.setRange(1, 1000 * 360) layoutDate = QHBoxLayout(grpDateSearch) layoutDate.addWidget(QLabel("From", grpDateSearch)) layoutDate.addWidget(date1) layoutDate.addWidget(QLabel("To", grpDateSearch)) layoutDate.addWidget(date2) layoutDate.addWidget(spinDay) buttonOK = QPushButton("OK", self) layout = QVBoxLayout(self) layout.addWidget(grpImage) layout.addWidget(grpDateSearch) layout.addWidget(buttonOK) self.resize(5 * len(windowTitle) + 200, 30) if not self.data is None: setData() else: radioVisual.setChecked(True) radioAnalytic.setChecked(False) chkBoxSquare.setChecked(False) d2 = QDate.currentDate() d1 = d2.addMonths(-1) date1.setDate(d1) date2.setDate(d2) date1.setMaximumDate(d2.addDays(-1)) date2.setMinimumDate(d1.addDays(+1)) spinDay.setValue(d1.daysTo(d2)) connect()
def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) self.widget = QWidget(self) self.horizontalLayout = QHBoxLayout(self.widget) self.treeWidget = QTreeWidget(self.widget) self.horizontalLayout.addWidget(self.treeWidget) self.label_1 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_1) self.label_2 = QLabel(self.widget ) self.lineEdit = QLineEdit(self.widget) self.horizontalLayout.addWidget(self.lineEdit) self.horizontalLayout.addWidget(self.label_2) self.dateEdit = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit) self.label_3 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_3) self.dateEdit_2 = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit_2) self.button1 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button1) self.button2 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button2) self.lineEdit.setText(QtCore.QString('M')) three_month = QtCore.QDate.currentDate().toJulianDay() - 60 self.dateEdit.setDate(QtCore.QDate.fromJulianDay(three_month)) self.dateEdit_2.setDate(QtCore.QDate.currentDate()) self.button1.clicked.connect(self.get_value) self.button2.clicked.connect(self.clear) self.treeWidget.headerItem().setText(0, _translate("MainWindow", "期货品种", None)) self.root1 = QTreeWidgetItem(self.treeWidget) self.root1.setText(0, _translate("MainWindow", "中金所", None)) self.root2 = QTreeWidgetItem(self.treeWidget) self.root2.setText(0, _translate("MainWindow", "上海期货", None)) self.root3 = QTreeWidgetItem(self.treeWidget) self.root3.setText(0, _translate("MainWindow", "大连商品", None)) self.root4 = QTreeWidgetItem(self.treeWidget) self.root4.setText(0, _translate("MainWindow", "郑州商品", None)) self.child11 = QTreeWidgetItem(self.root1) self.child12 = QTreeWidgetItem(self.root1) self.child13 = QTreeWidgetItem(self.root1) self.child14 = QTreeWidgetItem(self.root1) self.child15 = QTreeWidgetItem(self.root1) self.child16 = QTreeWidgetItem(self.root1) self.child17 = QTreeWidgetItem(self.root1) self.child18 = QTreeWidgetItem(self.root1) self.child11.setText(0, _translate("MainWindow", "CFFEX 沪深300指数期货(IF)", None)) self.child12.setText(0, _translate("MainWindow", "CFFEX 上证50指数期货(IH)", None)) self.child13.setText(0, _translate("MainWindow", "CFFEX 中证500指数期货(IC)", None)) self.child14.setText(0, _translate("MainWindow", "CFFEX 5年期国债期货(TF)", None)) self.child15.setText(0, _translate("MainWindow", "CFFEX 10年期国债期货(T)", None)) self.child16.setText(0, _translate("MainWindow", "CFFEX 3年期国债期货(仿真)(TT)", None)) self.child17.setText(0, _translate("MainWindow", "CFFEX 澳元兑美元(AUDUSD)期货(仿真)(AF)", None)) self.child18.setText(0, _translate("MainWindow", "CFFEX 欧元兑美元(EURUSD)期货(仿真)(EF)", None)) self.child21 = QTreeWidgetItem(self.root2) self.child22 = QTreeWidgetItem(self.root2) self.child23 = QTreeWidgetItem(self.root2) self.child24 = QTreeWidgetItem(self.root2) self.child25 = QTreeWidgetItem(self.root2) self.child26 = QTreeWidgetItem(self.root2) self.child27 = QTreeWidgetItem(self.root2) self.child28 = QTreeWidgetItem(self.root2) self.child29 = QTreeWidgetItem(self.root2) self.child210 = QTreeWidgetItem(self.root2) self.child211 = QTreeWidgetItem(self.root2) self.child212 = QTreeWidgetItem(self.root2) self.child213 = QTreeWidgetItem(self.root2) self.child214 = QTreeWidgetItem(self.root2) self.child21.setText(0, _translate("MainWindow", "SHFE 铜(CU)", None)) self.child22.setText(0, _translate("MainWindow", "SHFE 铝(AL)", None)) self.child23.setText(0, _translate("MainWindow", "SHFE 铅(ZN)", None)) self.child24.setText(0, _translate("MainWindow", "SHFE 黄金(AU)", None)) self.child25.setText(0, _translate("MainWindow", "SHFE 白银(AG)", None)) self.child26.setText(0, _translate("MainWindow", "SHFE 螺纹钢(RB)", None)) self.child27.setText(0, _translate("MainWindow", "SHFE 橡胶(RU)", None)) self.child28.setText(0, _translate("MainWindow", "SHFE 燃油(FU)", None)) self.child29.setText(0, _translate("MainWindow", "SHFE 线材(WR)", None)) self.child210.setText(0, _translate("MainWindow", "SHFE 石油沥青(BU)", None)) self.child211.setText(0, _translate("MainWindow", "SHFE 热轧卷板(HC)", None)) self.child212.setText(0, _translate("MainWindow", "SHFE 镍(NI)", None)) self.child213.setText(0, _translate("MainWindow", "SHFE 锡(SN)", None)) self.child214.setText(0, _translate("MainWindow", "SHFE 上期有色金属指数期货(仿真)(IM)", None)) self.child31 = QTreeWidgetItem(self.root3) self.child32 = QTreeWidgetItem(self.root3) self.child33 = QTreeWidgetItem(self.root3) self.child34 = QTreeWidgetItem(self.root3) self.child35 = QTreeWidgetItem(self.root3) self.child36 = QTreeWidgetItem(self.root3) self.child37 = QTreeWidgetItem(self.root3) self.child38 = QTreeWidgetItem(self.root3) self.child39 = QTreeWidgetItem(self.root3) self.child310 = QTreeWidgetItem(self.root3) self.child311 = QTreeWidgetItem(self.root3) self.child312 = QTreeWidgetItem(self.root3) self.child313 = QTreeWidgetItem(self.root3) self.child314 = QTreeWidgetItem(self.root3) self.child31.setText(0, _translate("MainWindow", "DCE 豆一(A)", None)) self.child32.setText(0, _translate("MainWindow", "DCE 豆粕(M)", None)) self.child33.setText(0, _translate("MainWindow", "DCE 豆油(Y)", None)) self.child34.setText(0, _translate("MainWindow", "DCE 棕榈油(P)", None)) self.child35.setText(0, _translate("MainWindow", "DCE 玉米(C)", None)) self.child36.setText(0, _translate("MainWindow", "DCE 铁矿石(I)", None)) self.child37.setText(0, _translate("MainWindow", "DCE 焦炭(JM)", None)) self.child38.setText(0, _translate("MainWindow", "DCE PVC(V)", None)) self.child39.setText(0, _translate("MainWindow", "DCE 豆二(B)", None)) self.child310.setText(0, _translate("MainWindow", "DCE 鸡蛋(JD)", None)) self.child311.setText(0, _translate("MainWindow", "DCE 纤维板(FB)", None)) self.child312.setText(0, _translate("MainWindow", "DCE 胶合板(BB)", None)) self.child313.setText(0, _translate("MainWindow", "DCE 聚丙烯(PP)", None)) self.child314.setText(0, _translate("MainWindow", "DCE 玉米淀粉(CS)", None)) self.child41 = QTreeWidgetItem(self.root4) self.child42 = QTreeWidgetItem(self.root4) self.child43 = QTreeWidgetItem(self.root4) self.child44 = QTreeWidgetItem(self.root4) self.child45 = QTreeWidgetItem(self.root4) self.child46 = QTreeWidgetItem(self.root4) self.child47 = QTreeWidgetItem(self.root4) self.child48 = QTreeWidgetItem(self.root4) self.child49 = QTreeWidgetItem(self.root4) self.child410 = QTreeWidgetItem(self.root4) self.child411 = QTreeWidgetItem(self.root4) self.child412 = QTreeWidgetItem(self.root4) self.child413 = QTreeWidgetItem(self.root4) self.child414 = QTreeWidgetItem(self.root4) self.child415 = QTreeWidgetItem(self.root4) self.child416 = QTreeWidgetItem(self.root4) self.child41.setText(0, _translate("MainWindow", "CZCE 强麦(WH)", None)) self.child42.setText(0, _translate("MainWindow", "CZCE 菜油(OI)", None)) self.child43.setText(0, _translate("MainWindow", "CZCE 棉花(CF)", None)) self.child44.setText(0, _translate("MainWindow", "CZCE 白糖(SR)", None)) self.child45.setText(0, _translate("MainWindow", "CZCE 早籼稻(RI)", None)) self.child46.setText(0, _translate("MainWindow", "CZCE 动力煤(ZC)", None)) self.child47.setText(0, _translate("MainWindow", "CZCE PTA(TA)", None)) self.child48.setText(0, _translate("MainWindow", "CZCE 玻璃(FG)", None)) self.child49.setText(0, _translate("MainWindow", "CZCE 甲醇(MA)", None)) self.child410.setText(0, _translate("MainWindow", "CZCE 菜籽油(RM)", None)) self.child411.setText(0, _translate("MainWindow", "CZCE 油菜籽(RS)", None)) self.child412.setText(0, _translate("MainWindow", "CZCE 普麦(PM)", None)) self.child413.setText(0, _translate("MainWindow", "CZCE 粳稻(JR)", None)) self.child414.setText(0, _translate("MainWindow", "CZCE 晚籼稻(LR)", None)) self.child415.setText(0, _translate("MainWindow", "CZCE 锰硅(SM)", None)) self.child416.setText(0, _translate("MainWindow", "CZCE 硅铁(LR)", None)) # self.treeWidget.addTopLevelItem(self.root) # self.treeWidget.addTopLevelItem(self.root) self.label_1.setText(_translate("MainWindow", "期货品种", None)) self.label_2.setText(_translate("MainWindow", "起始时间", None)) self.label_3.setText(_translate("MainWindow", "终止时间", None)) self.button1.setText(_translate("MainWindow", "提交", None)) self.button2.setText(_translate("MainWindow", "清除", None))
def createEditor(self, parent, option, index): """Create the Date edit widget to set the payment date""" qde = QDateEdit(parent) qde.setDisplayFormat(self.format) qde.setCalendarPopup(True) return qde
def _create_widget(cls, c, parent, host=None): dt = QDateEdit(parent) dt.setObjectName(u'{0}_{1}'.format(cls._TYPE_PREFIX, c.name)) dt.setCalendarPopup(True) # Set ranges if c.min_use_current_date: dt.setMinimumDate(date.today()) else: dt.setMinimumDate(c.minimum) if c.max_use_current_date: dt.setMaximumDate(date.today()) else: dt.setMaximumDate(c.maximum) # Set maximum date as current date dt.setDate(date.today()) return dt
class TalkDetailsWidget(QWidget): def __init__(self, parent=None): super(TalkDetailsWidget, self).__init__(parent) self.layout = QGridLayout() self.setLayout(self.layout) self.buttonLayout = QHBoxLayout() saveIcon = QIcon.fromTheme("document-save") self.saveButton = QPushButton('Save Talk') self.saveButton.setIcon(saveIcon) self.buttonLayout.addWidget(self.saveButton) self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1) self.titleLabel = QLabel('Title') self.titleLineEdit = QLineEdit() self.presenterLabel = QLabel('Presenter') self.presenterLineEdit = QLineEdit() self.layout.addWidget(self.titleLabel, 1, 0, 1, 1) self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 1) self.layout.addWidget(self.presenterLabel, 1, 2, 1, 1) self.layout.addWidget(self.presenterLineEdit, 1, 3, 1, 1) self.eventLabel = QLabel('Event') self.eventLineEdit = QLineEdit() self.categoryLabel = QLabel('Category') self.categoryLineEdit = QLineEdit() self.layout.addWidget(self.eventLabel, 2, 0, 1, 1) self.layout.addWidget(self.eventLineEdit, 2, 1, 1, 1) self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1) self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1) self.roomLabel = QLabel('Room') self.roomLineEdit = QLineEdit() self.dateLayout = QHBoxLayout() self.dateLabel = QLabel('Date') self.dateEdit = QDateEdit() currentDate = QDate() self.dateEdit.setDate(currentDate.currentDate()) self.dateEdit.setCalendarPopup(True) self.layout.addWidget(self.roomLabel, 3, 0, 1, 1) self.layout.addWidget(self.roomLineEdit, 3, 1, 1, 1) self.dateLayout.addWidget(self.dateEdit) self.layout.addWidget(self.dateLabel, 3, 2, 1, 1) self.layout.addLayout(self.dateLayout, 3, 3, 1, 1) self.startTimeLayout = QHBoxLayout() self.startTimeLabel = QLabel('Start Time') self.startTimeEdit = QTimeEdit() self.startTimeLayout.addWidget(self.startTimeEdit) self.endTimeLayout = QHBoxLayout() self.endTimeLabel = QLabel('End Time') self.endTimeEdit = QTimeEdit() self.endTimeLayout.addWidget(self.endTimeEdit) self.layout.addWidget(self.startTimeLabel, 4, 0, 1, 1) self.layout.addLayout(self.startTimeLayout, 4, 1, 1, 1) self.layout.addWidget(self.endTimeLabel, 4, 2, 1, 1) self.layout.addLayout(self.endTimeLayout, 4, 3, 1, 1) self.descriptionLabel = QLabel('Description') self.descriptionLabel.setAlignment(Qt.AlignTop) self.descriptionTextEdit = QPlainTextEdit() self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1) self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3) def enable_input_fields(self): self.titleLineEdit.setPlaceholderText("Enter Talk Title") self.presenterLineEdit.setPlaceholderText("Enter Presenter Name") self.categoryLineEdit.setPlaceholderText("Enter Category Type") self.eventLineEdit.setPlaceholderText("Enter Event Name") self.roomLineEdit.setPlaceholderText("Enter Room Location") self.titleLineEdit.setEnabled(True) self.presenterLineEdit.setEnabled(True) self.categoryLineEdit.setEnabled(True) self.eventLineEdit.setEnabled(True) self.roomLineEdit.setEnabled(True) self.dateEdit.setEnabled(True) self.startTimeEdit.setEnabled(True) self.endTimeEdit.setEnabled(True) self.descriptionTextEdit.setEnabled(True) def disable_input_fields(self): self.titleLineEdit.setPlaceholderText("") self.presenterLineEdit.setPlaceholderText("") self.categoryLineEdit.setPlaceholderText("") self.eventLineEdit.setPlaceholderText("") self.roomLineEdit.setPlaceholderText("") self.titleLineEdit.setEnabled(False) self.presenterLineEdit.setEnabled(False) self.categoryLineEdit.setEnabled(False) self.eventLineEdit.setEnabled(False) self.roomLineEdit.setEnabled(False) self.dateEdit.setEnabled(False) self.startTimeEdit.setEnabled(False) self.endTimeEdit.setEnabled(False) self.descriptionTextEdit.setEnabled(False) def clear_input_fields(self): self.titleLineEdit.clear() self.presenterLineEdit.clear() self.categoryLineEdit.clear() self.eventLineEdit.clear() self.roomLineEdit.clear() self.descriptionTextEdit.clear()
def __init__(self, parent=None): ''' Constructor ''' QWidget.__init__(self, parent) self.mainLayout = QVBoxLayout() self.setLayout(self.mainLayout) self.addTalkGroupBox = QGroupBox("Add Talk") self.mainLayout.addWidget(self.addTalkGroupBox) self.addTalkLayout = QFormLayout() self.addTalkGroupBox.setLayout(self.addTalkLayout) # Title self.titleLabel = QLabel("Title") self.titleLineEdit = QLineEdit() if hasattr(QLineEdit(), 'setPlaceholderText'): self.titleLineEdit.setPlaceholderText("Title of the presentation") self.titleLabel.setBuddy(self.titleLineEdit) self.addTalkLayout.addRow(self.titleLabel, self.titleLineEdit) # Presenter self.presenterLabel = QLabel("Presenter") self.presenterLineEdit = QLineEdit() if hasattr(QLineEdit(), 'setPlaceholderText'): self.presenterLineEdit.setPlaceholderText("Name person or people presenting (comma separated)") self.presenterLabel.setBuddy(self.presenterLineEdit) self.addTalkLayout.addRow(self.presenterLabel, self.presenterLineEdit) # Event self.eventLabel = QLabel("Event") self.eventLineEdit = QLineEdit() if hasattr(QLineEdit(), 'setPlaceholderText'): self.eventLineEdit.setPlaceholderText("The name of the Event this talk is being presented at") self.eventLabel.setBuddy(self.eventLineEdit) self.addTalkLayout.addRow(self.eventLabel, self.eventLineEdit) # Room self.roomLabel = QLabel("Room") self.roomLineEdit = QLineEdit() if hasattr(QLineEdit(), 'setPlaceholderText'): self.roomLineEdit.setPlaceholderText("The Room in which the presentation is taking place") self.roomLabel.setBuddy(self.roomLineEdit) self.addTalkLayout.addRow(self.roomLabel, self.roomLineEdit) # Date current_date = QDate() self.dateLabel = QLabel("Date") self.dateEdit = QDateEdit() self.dateEdit.setDate(current_date.currentDate()) self.dateLabel.setBuddy(self.dateEdit) self.addTalkLayout.addRow(self.dateLabel, self.dateEdit) self.dateEdit.setCalendarPopup(True) # Time current_time = QTime() self.timeLabel = QLabel("Time") self.timeEdit = QTimeEdit() self.timeEdit.setTime(current_time.currentTime()) self.timeLabel.setBuddy(self.dateEdit) self.addTalkLayout.addRow(self.timeLabel, self.timeEdit) # Buttons addIcon = QIcon.fromTheme("list-add") cancelIcon = QIcon.fromTheme("edit-clear") self.buttonsWidget = QHBoxLayout() self.addButton = QPushButton("Add") self.addButton.setIcon(addIcon) self.cancelButton = QPushButton("Cancel") self.cancelButton.setIcon(cancelIcon) self.buttonsWidget.addWidget(self.addButton) self.buttonsWidget.addWidget(self.cancelButton) self.addTalkLayout.addRow(None, self.buttonsWidget)
class sub_canvas(MyMplCanvas): def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) # 初始化变量,以控制图表的显示 self.control = {"basic":True, "extreme":True, "slope":True, "star":True} self.widget = QWidget(self) self.horizontalLayout = QHBoxLayout(self.widget) self.label_1 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_1) self.lineEdit = QLineEdit(self.widget) self.horizontalLayout.addWidget(self.lineEdit) self.label_2 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_2) self.dateEdit = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit) self.label_3 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_3) self.dateEdit_2 = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit_2) self.button1 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button1) self.button2 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button2) self.button3 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button3) self.button4 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button4) self.button5 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button5) self.lineEdit.setText(QtCore.QString('002594')) three_month = QtCore.QDate.currentDate().toJulianDay() - 150 self.dateEdit.setDate(QtCore.QDate.fromJulianDay(three_month)) self.dateEdit_2.setDate(QtCore.QDate.currentDate()) self.label_1.setText(_translate("MainWindow", "股票代码", None)) self.label_2.setText(_translate("MainWindow", "起始时间", None)) self.label_3.setText(_translate("MainWindow", "终止时间", None)) self.button1.setText(_translate("MainWindow", "所有", None)) self.button2.setText(_translate("MainWindow", "极端", None)) self.button3.setText(_translate("MainWindow", "斜率", None)) self.button4.setText(_translate("MainWindow", "趋势", None)) self.button5.setText(_translate("MainWindow", "清除", None)) self.button1.clicked.connect(self.draw_all) self.button2.clicked.connect(self.draw_extreme) self.button3.clicked.connect(self.draw_slope) self.button4.clicked.connect(self.draw_trend) self.button5.clicked.connect(self.clear) def keyPressEvent(self, event): keyEvent = QKeyEvent(event) if keyEvent.key() == QtCore.Qt.Key_Enter or keyEvent.key() == QtCore.Qt.Key_Return: self.draw_all() if keyEvent.key() == QtCore.Qt.Key_0: self.draw_all() # 定义横坐标格式的回调函数 def my_major_formatter(self, x, pos): for i in range(self.num): if (x == i): return self.str_date[i] # 控制图表的显示信息 # basic 为基本图标,extreme为极端情景,slope为斜率,star为选股星数,trend为趋势线 def set_control_all(self): self.control = {"basic": True, "extreme": True, "slope": True,"star":True,"trend":False} def set_control_extreme(self): self.control = {"basic": True, "extreme": True, "slope": False, "star": True,"trend":False} def set_control_slope(self): self.control = {"basic": True, "extreme": False, "slope": True, "star": True,"trend":False} def set_control_star(self): self.control = {"basic": True, "extreme": False, "slope": False, "star": True,"trend":False} def set_control_trend(self): self.control = {"basic": True, "extreme": False, "slope": False, "star": False, "trend": True} def draw_all(self): self.get_value() self.set_control_all() self.update_figure() def draw_extreme(self): self.get_value() self.set_control_extreme() self.update_figure() def draw_slope(self): self.get_value() self.set_control_slope() self.update_figure() def draw_star(self): self.get_value() self.set_control_star() self.update_figure() def draw_trend(self): self.get_value() self.set_control_trend() self.update_figure() def get_value(self): # 从qt中读取数据并进行格式转化,然后将这个读入到已有的软件中 code = QtCore.QString(self.lineEdit.text()) start = QtCore.QString(self.dateEdit.text()) end = QtCore.QString(self.dateEdit_2.text()) code = unicode(code) start = datetime.date(int(start.split("/")[0]), int(start.split("/")[1]), int(start.split("/")[2])).isoformat() end = datetime.date(int(end.split("/")[0]), int(end.split("/")[1]), int(end.split("/")[2])).isoformat() # K线图和EMA等 self.num, self.kbar, self.str_date, self.ema, self.name= source(code, start, end) # 星图 self.star_date, self.star_value = star(col, code, start, end) def update_figure(self): self.fig.clf() self.ax1 = self.fig.add_subplot(111) self.ax2 = self.ax1.twinx() # 创建第二个坐标轴,为同图 # 万得的接口 WindPy.w.start() self.ax1.set_xticks(range(self.num)) xmajorLocator = MultipleLocator(5) # 将x主刻度标签设置为5的倍数 xminorLocator = MultipleLocator(1) # 将x副刻度标签设置为1的倍数 self.ax1.xaxis.set_major_locator(xmajorLocator) self.ax1.xaxis.set_minor_locator(xminorLocator) self.ax1.xaxis.set_major_formatter(FuncFormatter(self.my_major_formatter)) # 设置网格 self.ax1.grid() self.ax1.plot(range(self.num),self.ema,linewidth = 0.5,color = "blue") if self.control["star"]: self.ax2.bar(range(len(self.star_date)), self.star_value, picker=True, color='#FFFF00', width = 0.5,edgecolor = 'black') from matplotlib.font_manager import FontProperties font = FontProperties(size=14) # 设置字体 self.ax1.set_title(self.name) self.ax1.set_ylabel(u'价格') self.ax2.set_ylabel(u'星数') # 极端情况 high_1 = self.kbar[0][2] low_1 = self.kbar[0][3] ema_1 = self.ema[0] deviate_1 = max(abs(high_1 - ema_1),abs(low_1 - ema_1)) high_2 = self.kbar[1][2] low_2 = self.kbar[1][3] ema_2 = self.ema[1] deviate_2 = max(abs(high_2 - ema_2),abs(low_2 - ema_2)) high_3 = self.kbar[2][2] low_3 = self.kbar[2][3] ema_3 = self.ema[2] deviate_3 = max(abs(high_3 - ema_3),abs(low_3 - ema_3)) high_4 = self.kbar[3][2] low_4 = self.kbar[3][3] ema_4 = self.ema[3] deviate_4 = max(abs(high_4 - ema_4), abs(low_4 - ema_4)) high_5 = self.kbar[3][2] low_5 = self.kbar[3][3] ema_5 = self.ema[3] deviate_5 = max(abs(high_5 - ema_5), abs(low_5 - ema_5)) lim = self.ax1.get_ylim() distance = (lim[1] - lim[0])/9 mark_1 = {'Buy':False,'Sell':False} mark_2 = {'Buy':False,'Sell':False} mark_3 = {'Buy':False,'Sell':False} mark_4 = {'Buy':False,'Sell':False} mark_5 = {'Buy':False,'Sell':False} mark_6 = {'Buy':False,'Sell':False} for i in range(5,self.num): alpha = 1.11 beta = 0.88 high_6 = self.kbar[i][2] low_6 = self.kbar[i][3] ema_6 = self.ema[i] deviate_6 = max(abs(high_6 - ema_6),abs(low_6 - ema_6)) condition1 = deviate_4 > deviate_3 > deviate_2 or deviate_4 > deviate_3 > deviate_1 or deviate_4 > deviate_2 > deviate_1 condition2 = ema_4 > ema_3 > ema_2 or ema_2 > ema_3 > ema_4 condition3 = deviate_4 > deviate_5 * beta and deviate_4 > deviate_6 top = high_4 - ema_4 bottom = ema_4 - low_4 condition4 = (low_4 < low_5 * alpha and low_4 < low_6 and top < bottom) or (high_4 > high_5 * beta and high_4 > high_6 and top > bottom) condition5 = top < bottom condition6 = top > bottom condition7 = high_3 < ema_3 and high_4 < ema_4 and high_5 < ema_5 and high_6 > ema_6 * alpha condition8 = low_3 > ema_3 and low_4 > ema_4 and low_5 > ema_5 and low_6 < ema_6 * beta max_ema = max(ema_3,ema_4,ema_5) min_ema = min(ema_3,ema_4,ema_5) condition9 = (ema_3 > ema_4 > ema_5) and ema_6 > ema_5 condition10 = (ema_3 < ema_4 < ema_5) and ema_6 < ema_5 condition11 = max_ema < (min_ema * 1.1) condition12 = (mark_5['Buy'] == False) condition13 = (mark_5['Sell'] == False) matplotlib.rcParams.update({'font.size': 9}) highest = max(high_1, high_2, high_3, high_4, high_5, high_6) lowest = max(low_1, low_2, low_3, low_4, low_5, low_6) if self.control["extreme"]: if condition1 and condition2 and condition3 and condition4 and condition5 and condition12 or condition7 : # self.ax1.annotate(u'多', xy=(i, low_6), xytext=(i-0.5, low_6 - distance), arrowprops=dict(arrowstyle="-")) self.ax1.text(i-0.7, low_6 - distance * 1, u'多',size=5) mark_6['Buy'] = True if condition1 and condition2 and condition3 and condition4 and condition6 and condition13 or condition8 : # self.ax1.annotate(u'空', xy=(i, high_6), xytext=(i-0.5, high_6 + distance), arrowprops=dict(arrowstyle="-")) self.ax1.text(i-0.7, high_6 + distance * 1, u'空', size=5) mark_6['Sell'] = True if self.control["slope"]: if condition9 and condition11: # self.ax1.annotate(u'B', xy=(i - 0.5, low_6 - distance * 3), xytext=(i - 0.5, low_6 - distance * 3),arrowprops=dict(arrowstyle="-")) self.ax1.text(i - 0.5, low_6 - distance * 1.8, u'B', size=8) if condition10 and condition11: # self.ax1.annotate(u'S', xy=(i - 0.5, high_6 + distance * 3), xytext=(i - 0.5, high_6 + distance * 3),arrowprops=dict(arrowstyle="-")) self.ax1.text(i - 0.5, high_6 + distance * 1.8, u'S', size=8) if self.control["trend"]: if i%6 == 0: self.trend_x = [i-6,i] self.trend_y = [high_1,highest] self.ax1.plot(self.trend_x,self.trend_y) deviate_1 = deviate_2 deviate_2 = deviate_3 deviate_3 = deviate_4 deviate_4 = deviate_5 deviate_5 = deviate_6 ema_1 = ema_2 ema_2 = ema_3 ema_3 = ema_4 ema_4 = ema_5 ema_5 = ema_6 low_1 = low_2 low_2 = low_3 low_3 = low_4 low_4 = low_5 low_5 = low_6 high_1 = high_2 high_2 = high_3 high_3 = high_4 high_4 = high_5 high_5 = high_6 mark_1 = mark_2 mark_2 = mark_3 mark_3 = mark_4 mark_4 = mark_5 mark_5 = mark_6 mark_6 = {'Buy':False,'Sell':False} # self.ax1.annotate('extreme', xy=(18, 16.8), xytext=(20, 16), arrowprops=dict(arrowstyle="->")) self.ax2.set_ylim(0, 80) candlestick_ohlc(self.ax1, self.kbar, width=0.5, colorup='r', colordown='g') # self.ax1.hold(False) # self.ax2.hold(False) lim = self.ax1.get_ylim() self.ax1.set_ylim(lim[0] * 0.9, lim[1]*0.98) for tick in self.ax1.xaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(75) for tick in self.ax1.yaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(30) for tick in self.ax2.xaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(75) for tick in self.ax2.yaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(30) # 子图二 # self.ax2.set_xticks(range(self.num)) # self.ax2.xaxis.set_major_locator(xmajorLocator) # self.ax2.xaxis.set_minor_locator(xminorLocator) # self.ax2.grid() # self.ax2.set_xticklabels(self.str_date, rotation=25, horizontalalignment='right') # self.ax2.bar(range(len(self.star_date)), self.star_value, picker=True, color='#FFFF00') # #self.ax2.xaxis.set_major_locator(xmajorLocator) # self.ax2.xaxis.set_major_formatter(FuncFormatter(self.my_major_formatter)) # for label in self.ax2.get_xticklabels(): # label.set_picker(True) # for tick in self.ax2.xaxis.get_major_ticks(): # tick.label1.set_fontsize(5) # tick.label1.set_rotation(90) # for tick in self.ax2.yaxis.get_major_ticks(): # tick.label1.set_fontsize(5) # tick.label1.set_rotation(30) # self.draw() # self.fig.clf() def clear(self): self.fig.clf() self.ax1 = self.fig.add_subplot(111) # self.ax1 = self.fig.add_axes([0.1, 0.35, 0.8, 0.58]) # self.ax2 = self.fig.add_axes([0.1, 0.07, 0.8, 0.2]) self.draw()
def __init__(self, session, parent=None): super(ExpensesDialog, self).__init__(parent) self.session = session session = self.pullOnes('session', session) self.sessionname = str(session['name']) + ' Session' self.pagetitle = self.sessionname self.tableFont = QFont('Century Gothic', 8) #self.tableFont.setFamily('Century Gothic') self.tableHeaderStyle = "::section {" "background-color: teal; color:white}" #pull all CA self.editID = 0 self.hold_account = {} self.hold_expenses = {} self.hold_expensesGroup = {} from_label = QLabel('From:') to_label = QLabel('To:') self.fromData = QDateEdit() self.toData = QDateEdit() currentDate = QDate() self.fromData.setDate(currentDate.currentDate()) self.fromData.setCalendarPopup(True) self.toData.setDate(currentDate.currentDate()) self.toData.setCalendarPopup(True) self.pull_btn = QPushButton() self.pull_btn.setText("Load") h_pull_box = QHBoxLayout() h_pull_box.addWidget(from_label) h_pull_box.addWidget(self.fromData) h_pull_box.addWidget(to_label) h_pull_box.addWidget(self.toData) h_pull_box.addWidget(self.pull_btn) expensesGroup = self.pullGroupExpenses() account = self.pullAccount() self.expenseGroupText = QLabel('Category') self.expenseGroupData = QComboBox() self.expenseGroupData.currentIndexChanged.connect(self.reloadExpenses) self.expenseText = QLabel('Expenses') self.expenseData = QComboBox() self.amountText = QLabel('Amount') self.amountData = QLineEdit() self.amountData.setPlaceholderText('0000.00') self.tellerText = QLabel('Teller/Reciept No.') self.tellerData = QLineEdit() self.tellerData.setPlaceholderText('xxxxxxxxx') self.accountText = QLabel('Account') self.accountData = QComboBox() self.dateText = QLabel('Date') self.dateData = QDateEdit() self.dateData.setDate(currentDate.currentDate()) self.dateData.setCalendarPopup(True) self.descriptionText = QLabel('Brief Description') self.descriptionData = QPlainTextEdit() self.descriptionData.move(200, 100) hboz = QHBoxLayout() self.gender = QLabel('State') self.r1 = QRadioButton('Expenses') self.r1.setChecked(True) self.r2 = QRadioButton('Refund') hboz.addWidget(self.r1) hboz.addWidget(self.r2) i = 0 for a in expensesGroup: self.hold_expensesGroup[i] = a['id'] tex = str(a['name']).upper() self.expenseGroupData.addItem(tex) i += 1 i = 0 exp_key = self.hold_expensesGroup[self.expenseGroupData.currentIndex()] expenses = self.pullExpenses(exp_key) for a in expenses: self.hold_expenses[i] = a['id'] tex = str(a['name']).upper() self.expenseData.addItem(tex) i += 1 i = 0 for a in account: self.hold_account[i] = a['id'] tex = str(a['name']).upper() self.accountData.addItem(tex) i += 1 self.FormLayout = QFormLayout() self.FormLayout.addRow(self.expenseGroupText, self.expenseGroupData) self.FormLayout.addRow(self.expenseText, self.expenseData) self.FormLayout.addRow(self.accountText, self.accountData) self.FormLayout.addRow(self.tellerText, self.tellerData) self.FormLayout.addRow(self.amountText, self.amountData) self.FormLayout.addRow(self.gender, hboz) self.FormLayout.addRow(self.dateText, self.dateData) self.FormLayout.addRow(self.descriptionText, self.descriptionData) groupBox1 = QGroupBox('Add Expenses') groupBox1.setLayout(self.FormLayout) self.pb = QPushButton() self.pb.setObjectName("Add") self.pb.setText("Add Expenses") self.pb1 = QPushButton() self.pb1.setObjectName("Edit") self.pb1.setText("Edit Row") self.pb1.setEnabled(False) self.pb2 = QPushButton() self.pb2.setObjectName("Close") self.pb2.setText("Close") self.pb3 = QPushButton() self.pb3.setObjectName("Delete") self.pb3.setText("Delete Row") self.pb3.setEnabled(False) self.pb4 = QPushButton() self.pb4.setObjectName("Reset") self.pb4.setText("Reset") self.pb4.hide() self.pb5 = QPushButton() self.pb5.setObjectName("Change") self.pb5.setText("Change Expenses") self.pb5.hide() self.pb6 = QPushButton() self.pb6.setObjectName("Clear") self.pb6.setText("Clear Selection") self.pb6.setEnabled(False) hbo = QHBoxLayout() hbo.addWidget(self.pb) hbo.addWidget(self.pb5) hbo.addWidget(self.pb4) hbo.addWidget(self.pb2) groupBox2 = QGroupBox('Expenses Data') groupBox2.setLayout(hbo) self.cols = ['SN', 'EXPENSES', 'ACCOUNT', 'AMOUNT', 'DATE'] al = self.pullExpensesData() if len(al) > 0: al = al else: al = {} self.table = QTableWidget() header = self.table.horizontalHeader() header.setResizeMode(QHeaderView.ResizeToContents) header.setStretchLastSection(True) header.setStyleSheet(self.tableHeaderStyle) vheader = self.table.verticalHeader() vheader.setStyleSheet(self.tableHeaderStyle) # Body self.table.setWindowTitle("Expenses") self.table.resize(300, 250) self.table.setFont(self.tableFont) self.table.setSortingEnabled(2) #self.table.resizeColumnsToContents() self.table.setRowCount(len(al)) self.table.setColumnCount(len(self.cols)) self.table.setHorizontalHeaderLabels(self.cols) self.table.setContextMenuPolicy(Qt.CustomContextMenu) self.table.customContextMenuRequested.connect(self.handleHeaderMenu) self.table.hideColumn(0) self.table.setSelectionMode(QAbstractItemView.MultiSelection) self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.table.setEditTriggers(QAbstractItemView.NoEditTriggers) i = 0 for q in al: #row id self.table.setItem(i, 0, QTableWidgetItem(str(q['id']))) self.table.setItem(i, 1, QTableWidgetItem(str(q['expensename']).upper())) self.table.setItem(i, 2, QTableWidgetItem(str(q['accountname']).upper())) zamt = str("{:,}".format(float(q['amount']))) self.table.setItem(i, 3, QTableWidgetItem(zamt)) damz = float(q['datepaid']) damt = datetime.utcfromtimestamp(damz).strftime('%d-%m-%Y') self.table.setItem(i, 4, QTableWidgetItem(str(damt))) i += 1 self.table.itemSelectionChanged.connect(self.confirmSelection) self.table.resizeRowsToContents() v_pull_box = QVBoxLayout() self.h1_pull_box = QVBoxLayout() self.h1_pull_box.addWidget(self.table) v_pull_box.addLayout(h_pull_box) v_pull_box.addLayout(self.h1_pull_box) h2_pull_box = QHBoxLayout() h2_pull_box.addWidget(self.pb1) h2_pull_box.addWidget(self.pb3) h2_pull_box.addWidget(self.pb6) v_pull_box.addLayout(h2_pull_box) groupBox3 = QGroupBox() groupBox3.setLayout(hbo) groupBox2.setLayout(v_pull_box) grid = QGridLayout() grid.addWidget(groupBox1, 0, 0) grid.addWidget(groupBox2, 0, 1, 2, 1) grid.addWidget(groupBox3, 1, 0) self.setLayout(grid) self.connect(self.pb, SIGNAL("clicked()"), lambda: self.button_click()) self.connect(self.pb1, SIGNAL("clicked()"), lambda: self.button_editshow()) self.connect(self.pb2, SIGNAL("clicked()"), lambda: self.button_close(self)) self.connect(self.pb3, SIGNAL("clicked()"), lambda: self.button_delete()) self.connect(self.pb4, SIGNAL("clicked()"), lambda: self.button_reset()) self.connect(self.pb5, SIGNAL("clicked()"), lambda: self.button_edit()) self.connect(self.pb6, SIGNAL("clicked()"), lambda: self.button_clear()) self.connect(self.pull_btn, SIGNAL("clicked()"), lambda x=1: self.reloadTable(x)) self.setWindowTitle(self.pagetitle)
class DlgMagneticVariationParameters(QDialog): def __init__(self, parent = None): QDialog.__init__(self, parent) self.resize(290, 136); self.setWindowTitle("Reference Positions") sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed); sizePolicy.setHorizontalStretch(0); sizePolicy.setVerticalStretch(0); sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()); self.setSizePolicy(sizePolicy); verticalLayoutDlg = QVBoxLayout(self) verticalLayoutDlg.setObjectName(("verticalLayoutDlg")); frameDate = QFrame(self); frameDate.setObjectName(("frameDate")); frameDate.setFrameShape(QFrame.StyledPanel); frameDate.setFrameShadow(QFrame.Raised); horizontalLayoutDate = QHBoxLayout(frameDate); horizontalLayoutDate.setObjectName(("horizontalLayoutDate")); labelDate = QLabel(frameDate); labelDate.setObjectName(("labelDate")); labelDate.setMinimumSize(QSize(70, 0)); labelDate.setMaximumSize(QSize(70, 16777215)); labelDate.setText("Date:") horizontalLayoutDate.addWidget(labelDate); self.dtpDate = QDateEdit(frameDate); self.dtpDate.setObjectName(("dtpDate")); horizontalLayoutDate.addWidget(self.dtpDate); self.btnDtpDate = QToolButton(frameDate); self.btnDtpDate.setObjectName(("btnDtpDate")); sizePolicy.setHeightForWidth(self.btnDtpDate.sizePolicy().hasHeightForWidth()); self.btnDtpDate.setSizePolicy(sizePolicy); self.btnDtpDate.setMinimumSize(QSize(25, 0)); self.btnDtpDate.setMaximumSize(QSize(25, 16777215)); icon = QIcon() icon.addPixmap(QPixmap(("Resource/calender.png")), QIcon.Normal, QIcon.Off) self.btnDtpDate.setIcon(icon) horizontalLayoutDate.addWidget(self.btnDtpDate); verticalLayoutDlg.addWidget(frameDate); frameModel = QFrame(self); frameModel.setObjectName(("frameModel")); frameModel.setFrameShape(QFrame.StyledPanel); frameModel.setFrameShadow(QFrame.Raised); horizontalLayoutModel = QHBoxLayout(frameModel); horizontalLayoutModel.setObjectName(("horizontalLayoutModel")); labelModel = QLabel(frameModel); labelModel.setObjectName(("labelModel")); labelModel.setMinimumSize(QSize(70, 0)); labelModel.setMaximumSize(QSize(70, 16777215)); labelModel.setText("Model:") horizontalLayoutModel.addWidget(labelModel); self.cmbModel = QComboBox(frameModel); self.cmbModel.setObjectName(("cmbModel")); horizontalLayoutModel.addWidget(self.cmbModel); verticalLayoutDlg.addWidget(frameModel); self.buttonBox = QDialogButtonBox(self); self.buttonBox.setObjectName(("buttonBox")); self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok); self.connect(self.buttonBox, SIGNAL("accepted()"), self.accept) self.connect(self.buttonBox, SIGNAL("rejected()"), self.reject) verticalLayoutDlg.addWidget(self.buttonBox); self.calendar = QCalendarWidget() self.calendar.clicked.connect(self.calendar_clicked) self.menu = QMenu() layout = QVBoxLayout(self.menu) layout.addWidget(self.calendar) self.btnDtpDate.clicked.connect(self.btnDtpDate_clicked) self.cmbModel.addItems(["WMM2015", "WMM2010" , "WMM2005", "WMM2000", "WMM95", "WMM90", "WMM85", "IGRF2000", "IGRF95", "IGRF90"]) def btnDtpDate_clicked(self): rcRect = self.btnDtpDate.geometry() ptPoint = rcRect.bottomLeft() self.menu.exec_( self.mapToGlobal(ptPoint) ) def calendar_clicked(self, date): self.dtpDate.setDate(date) def get_Date(self): return self.dtpDate.date() def setDate(self, date): if date != None: self.dtpDate.setDate(date) Date = property(get_Date, setDate, None, None) def get_Model(self): return self.cmbModel.currentIndex() def set_Model(self, index): if index == None: self.cmbModel.setCurrentIndex(1) return self.cmbModel.setCurrentIndex(index) Model = property(get_Model, set_Model, None, None) @staticmethod def smethod_0(date_0, magneticModelIndex_0): dlgMagneticVariationParameters = DlgMagneticVariationParameters() dlgMagneticVariationParameters.Date = date_0 dlgMagneticVariationParameters.Model = magneticModelIndex_0 dialogResult = dlgMagneticVariationParameters.exec_() if dialogResult != QDialog.Accepted: return (False, None, None) else: date = dlgMagneticVariationParameters.Date; magneticIndex = dlgMagneticVariationParameters.Model; return (True, date, magneticIndex)
class sub_canvas(MyMplCanvas): def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) self.widget = QWidget(self) self.horizontalLayout = QHBoxLayout(self.widget) self.treeWidget = QTreeWidget(self.widget) self.horizontalLayout.addWidget(self.treeWidget) self.label_1 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_1) self.label_2 = QLabel(self.widget ) self.lineEdit = QLineEdit(self.widget) self.horizontalLayout.addWidget(self.lineEdit) self.horizontalLayout.addWidget(self.label_2) self.dateEdit = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit) self.label_3 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_3) self.dateEdit_2 = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit_2) self.button1 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button1) self.button2 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button2) self.lineEdit.setText(QtCore.QString('M')) three_month = QtCore.QDate.currentDate().toJulianDay() - 60 self.dateEdit.setDate(QtCore.QDate.fromJulianDay(three_month)) self.dateEdit_2.setDate(QtCore.QDate.currentDate()) self.button1.clicked.connect(self.get_value) self.button2.clicked.connect(self.clear) self.treeWidget.headerItem().setText(0, _translate("MainWindow", "期货品种", None)) self.root1 = QTreeWidgetItem(self.treeWidget) self.root1.setText(0, _translate("MainWindow", "中金所", None)) self.root2 = QTreeWidgetItem(self.treeWidget) self.root2.setText(0, _translate("MainWindow", "上海期货", None)) self.root3 = QTreeWidgetItem(self.treeWidget) self.root3.setText(0, _translate("MainWindow", "大连商品", None)) self.root4 = QTreeWidgetItem(self.treeWidget) self.root4.setText(0, _translate("MainWindow", "郑州商品", None)) self.child11 = QTreeWidgetItem(self.root1) self.child12 = QTreeWidgetItem(self.root1) self.child13 = QTreeWidgetItem(self.root1) self.child14 = QTreeWidgetItem(self.root1) self.child15 = QTreeWidgetItem(self.root1) self.child16 = QTreeWidgetItem(self.root1) self.child17 = QTreeWidgetItem(self.root1) self.child18 = QTreeWidgetItem(self.root1) self.child11.setText(0, _translate("MainWindow", "CFFEX 沪深300指数期货(IF)", None)) self.child12.setText(0, _translate("MainWindow", "CFFEX 上证50指数期货(IH)", None)) self.child13.setText(0, _translate("MainWindow", "CFFEX 中证500指数期货(IC)", None)) self.child14.setText(0, _translate("MainWindow", "CFFEX 5年期国债期货(TF)", None)) self.child15.setText(0, _translate("MainWindow", "CFFEX 10年期国债期货(T)", None)) self.child16.setText(0, _translate("MainWindow", "CFFEX 3年期国债期货(仿真)(TT)", None)) self.child17.setText(0, _translate("MainWindow", "CFFEX 澳元兑美元(AUDUSD)期货(仿真)(AF)", None)) self.child18.setText(0, _translate("MainWindow", "CFFEX 欧元兑美元(EURUSD)期货(仿真)(EF)", None)) self.child21 = QTreeWidgetItem(self.root2) self.child22 = QTreeWidgetItem(self.root2) self.child23 = QTreeWidgetItem(self.root2) self.child24 = QTreeWidgetItem(self.root2) self.child25 = QTreeWidgetItem(self.root2) self.child26 = QTreeWidgetItem(self.root2) self.child27 = QTreeWidgetItem(self.root2) self.child28 = QTreeWidgetItem(self.root2) self.child29 = QTreeWidgetItem(self.root2) self.child210 = QTreeWidgetItem(self.root2) self.child211 = QTreeWidgetItem(self.root2) self.child212 = QTreeWidgetItem(self.root2) self.child213 = QTreeWidgetItem(self.root2) self.child214 = QTreeWidgetItem(self.root2) self.child21.setText(0, _translate("MainWindow", "SHFE 铜(CU)", None)) self.child22.setText(0, _translate("MainWindow", "SHFE 铝(AL)", None)) self.child23.setText(0, _translate("MainWindow", "SHFE 铅(ZN)", None)) self.child24.setText(0, _translate("MainWindow", "SHFE 黄金(AU)", None)) self.child25.setText(0, _translate("MainWindow", "SHFE 白银(AG)", None)) self.child26.setText(0, _translate("MainWindow", "SHFE 螺纹钢(RB)", None)) self.child27.setText(0, _translate("MainWindow", "SHFE 橡胶(RU)", None)) self.child28.setText(0, _translate("MainWindow", "SHFE 燃油(FU)", None)) self.child29.setText(0, _translate("MainWindow", "SHFE 线材(WR)", None)) self.child210.setText(0, _translate("MainWindow", "SHFE 石油沥青(BU)", None)) self.child211.setText(0, _translate("MainWindow", "SHFE 热轧卷板(HC)", None)) self.child212.setText(0, _translate("MainWindow", "SHFE 镍(NI)", None)) self.child213.setText(0, _translate("MainWindow", "SHFE 锡(SN)", None)) self.child214.setText(0, _translate("MainWindow", "SHFE 上期有色金属指数期货(仿真)(IM)", None)) self.child31 = QTreeWidgetItem(self.root3) self.child32 = QTreeWidgetItem(self.root3) self.child33 = QTreeWidgetItem(self.root3) self.child34 = QTreeWidgetItem(self.root3) self.child35 = QTreeWidgetItem(self.root3) self.child36 = QTreeWidgetItem(self.root3) self.child37 = QTreeWidgetItem(self.root3) self.child38 = QTreeWidgetItem(self.root3) self.child39 = QTreeWidgetItem(self.root3) self.child310 = QTreeWidgetItem(self.root3) self.child311 = QTreeWidgetItem(self.root3) self.child312 = QTreeWidgetItem(self.root3) self.child313 = QTreeWidgetItem(self.root3) self.child314 = QTreeWidgetItem(self.root3) self.child31.setText(0, _translate("MainWindow", "DCE 豆一(A)", None)) self.child32.setText(0, _translate("MainWindow", "DCE 豆粕(M)", None)) self.child33.setText(0, _translate("MainWindow", "DCE 豆油(Y)", None)) self.child34.setText(0, _translate("MainWindow", "DCE 棕榈油(P)", None)) self.child35.setText(0, _translate("MainWindow", "DCE 玉米(C)", None)) self.child36.setText(0, _translate("MainWindow", "DCE 铁矿石(I)", None)) self.child37.setText(0, _translate("MainWindow", "DCE 焦炭(JM)", None)) self.child38.setText(0, _translate("MainWindow", "DCE PVC(V)", None)) self.child39.setText(0, _translate("MainWindow", "DCE 豆二(B)", None)) self.child310.setText(0, _translate("MainWindow", "DCE 鸡蛋(JD)", None)) self.child311.setText(0, _translate("MainWindow", "DCE 纤维板(FB)", None)) self.child312.setText(0, _translate("MainWindow", "DCE 胶合板(BB)", None)) self.child313.setText(0, _translate("MainWindow", "DCE 聚丙烯(PP)", None)) self.child314.setText(0, _translate("MainWindow", "DCE 玉米淀粉(CS)", None)) self.child41 = QTreeWidgetItem(self.root4) self.child42 = QTreeWidgetItem(self.root4) self.child43 = QTreeWidgetItem(self.root4) self.child44 = QTreeWidgetItem(self.root4) self.child45 = QTreeWidgetItem(self.root4) self.child46 = QTreeWidgetItem(self.root4) self.child47 = QTreeWidgetItem(self.root4) self.child48 = QTreeWidgetItem(self.root4) self.child49 = QTreeWidgetItem(self.root4) self.child410 = QTreeWidgetItem(self.root4) self.child411 = QTreeWidgetItem(self.root4) self.child412 = QTreeWidgetItem(self.root4) self.child413 = QTreeWidgetItem(self.root4) self.child414 = QTreeWidgetItem(self.root4) self.child415 = QTreeWidgetItem(self.root4) self.child416 = QTreeWidgetItem(self.root4) self.child41.setText(0, _translate("MainWindow", "CZCE 强麦(WH)", None)) self.child42.setText(0, _translate("MainWindow", "CZCE 菜油(OI)", None)) self.child43.setText(0, _translate("MainWindow", "CZCE 棉花(CF)", None)) self.child44.setText(0, _translate("MainWindow", "CZCE 白糖(SR)", None)) self.child45.setText(0, _translate("MainWindow", "CZCE 早籼稻(RI)", None)) self.child46.setText(0, _translate("MainWindow", "CZCE 动力煤(ZC)", None)) self.child47.setText(0, _translate("MainWindow", "CZCE PTA(TA)", None)) self.child48.setText(0, _translate("MainWindow", "CZCE 玻璃(FG)", None)) self.child49.setText(0, _translate("MainWindow", "CZCE 甲醇(MA)", None)) self.child410.setText(0, _translate("MainWindow", "CZCE 菜籽油(RM)", None)) self.child411.setText(0, _translate("MainWindow", "CZCE 油菜籽(RS)", None)) self.child412.setText(0, _translate("MainWindow", "CZCE 普麦(PM)", None)) self.child413.setText(0, _translate("MainWindow", "CZCE 粳稻(JR)", None)) self.child414.setText(0, _translate("MainWindow", "CZCE 晚籼稻(LR)", None)) self.child415.setText(0, _translate("MainWindow", "CZCE 锰硅(SM)", None)) self.child416.setText(0, _translate("MainWindow", "CZCE 硅铁(LR)", None)) # self.treeWidget.addTopLevelItem(self.root) # self.treeWidget.addTopLevelItem(self.root) self.label_1.setText(_translate("MainWindow", "期货品种", None)) self.label_2.setText(_translate("MainWindow", "起始时间", None)) self.label_3.setText(_translate("MainWindow", "终止时间", None)) self.button1.setText(_translate("MainWindow", "提交", None)) self.button2.setText(_translate("MainWindow", "清除", None)) def keyPressEvent(self, event): keyEvent = QKeyEvent(event) if keyEvent.key() == QtCore.Qt.Key_Enter or keyEvent.key() == QtCore.Qt.Key_Return: self.get_value() if keyEvent.key() == QtCore.Qt.Key_0: self.get_value() # 定义横坐标格式的回调函数 def my_major_formatter(self, x, pos): for i in range(self.num): if (x == i): return self.str_date[i] def get_value(self): code = QtCore.QString(self.lineEdit.text()) start = QtCore.QString(self.dateEdit.text()) end = QtCore.QString(self.dateEdit_2.text()) code = unicode(code) start = datetime.date(int(start.split("/")[0]), int(start.split("/")[1]), int(start.split("/")[2])).isoformat() end = datetime.date(int(end.split("/")[0]), int(end.split("/")[1]), int(end.split("/")[2])).isoformat() self.num, self.kbar, self.str_date, self.ema, self.name= source(code, start, end) self.star_date, self.star_value = star(col, code, start, end) self.update_figure() def update_figure(self): self.fig.clf() self.ax1 = self.fig.add_axes([0.22, 0.1, 0.7, 0.7]) # self.ax2 = self.ax1.twinx() # 创建第二个坐标轴,为同图 # 子图一 WindPy.w.start() self.ax1.set_xticks(range(self.num)) xmajorLocator = MultipleLocator(5) # 将x主刻度标签设置为3的倍数 xminorLocator = MultipleLocator(1) # 将x副刻度标签设置为1的倍数 self.ax1.xaxis.set_major_locator(xmajorLocator) self.ax1.xaxis.set_minor_locator(xminorLocator) self.ax1.xaxis.set_major_formatter(FuncFormatter(self.my_major_formatter)) self.ax1.grid() # self.ax2.bar(range(len(self.star_date)), self.star_value, picker=True, color='#FFFF00', width = 0.5,edgecolor = 'black') self.ax1.plot(range(self.num),self.ema,linewidth = 0.5,color = "blue") from matplotlib.font_manager import FontProperties font = FontProperties(size=14) # 设置字体 self.ax1.set_title(self.name) self.ax1.set_ylabel(u'价格') # self.ax2.set_ylabel(u'星数') #极端情况1 # high_1 = self.kbar[0][2] # low_1 = self.kbar[0][3] # ema_1 = self.ema[0] # deviate_1 = max(abs(high_1 - ema_1),abs(low_1 - ema_1)) # high_2 = self.kbar[1][2] # low_2 = self.kbar[1][3] # ema_2 = self.ema[1] # deviate_2 = max(abs(high_2 - ema_2),abs(low_2 - ema_2)) # high_3 = self.kbar[2][2] # low_3 = self.kbar[2][3] # ema_3 = self.ema[2] # deviate_3 = max(abs(high_3 - ema_3),abs(low_3 - ema_3)) # high_4 = self.kbar[3][2] # low_4 = self.kbar[3][3] # ema_4 = self.ema[3] # deviate_4 = max(abs(high_4 - ema_4),abs(low_4 - ema_4)) # high_5 = self.kbar[4][2] # low_5 = self.kbar[4][3] # ema_5 = self.ema[4] # deviate_5 = max(abs(high_5 - ema_5),abs(low_5 - ema_5)) # high_6 = self.kbar[5][2] # low_6 = self.kbar[5][3] # ema_6 = self.ema[5] # deviate_6 = max(abs(high_6 - ema_6),abs(low_6 - ema_6)) # for i in range(6,self.num): # high_7 = self.kbar[i][2] # low_7 = self.kbar[i][3] # ema_7 = self.ema[i] # deviate_7 = max(abs(high_7 - ema_7),abs(low_7 - ema_7)) # condition1 = deviate_5 > deviate_3 > deviate_2 > deviate_1 or deviate_4 > deviate_3 > deviate_2 > deviate_1 # condition2 = ema_5 > ema_4 > ema_3 > ema_2 > ema_1 or ema_1 > ema_2 > ema_3 > ema_4 > ema_5 # condition3 = deviate_5 > deviate_6 > deviate_7 # if condition1 and condition2 and condition3 : # self.ax1.annotate('E', xy=(i, low_7), xytext=(i+ 1, low_7+0.5), arrowprops=dict(arrowstyle="->")) # deviate_1 = deviate_2 # deviate_2 = deviate_3 # deviate_3 = deviate_4 # deviate_4 = deviate_5 # deviate_5 = deviate_6 # deviate_6 = deviate_7 # ema_1 = ema_2 # ema_2 = ema_3 # ema_3 = ema_4 # ema_4 = ema_5 # ema_5 = ema_6 # ema_6 = ema_7 # 极端情况2 high_1 = self.kbar[0][2] low_1 = self.kbar[0][3] ema_1 = self.ema[0] deviate_1 = max(abs(high_1 - ema_1),abs(low_1 - ema_1)) high_2 = self.kbar[1][2] low_2 = self.kbar[1][3] ema_2 = self.ema[1] deviate_2 = max(abs(high_2 - ema_2),abs(low_2 - ema_2)) high_3 = self.kbar[2][2] low_3 = self.kbar[2][3] ema_3 = self.ema[2] deviate_3 = max(abs(high_3 - ema_3),abs(low_3 - ema_3)) high_4 = self.kbar[3][2] low_4 = self.kbar[3][3] ema_4 = self.ema[3] deviate_4 = max(abs(high_4 - ema_4), abs(low_4 - ema_4)) high_5 = self.kbar[3][2] low_5 = self.kbar[3][3] ema_5 = self.ema[3] deviate_5 = max(abs(high_5 - ema_5), abs(low_5 - ema_5)) lim = self.ax1.get_ylim() # distance = 0.3 distance = (lim[1] - lim[0])/9 for i in range(5,self.num): alpha = 1.10 beta = 0.90 high_6 = self.kbar[i][2] low_6 = self.kbar[i][3] ema_6 = self.ema[i] deviate_6 = max(abs(high_6 - ema_6),abs(low_6 - ema_6)) condition1 = deviate_4 > deviate_3 > deviate_2 or deviate_4 > deviate_3 > deviate_1 or deviate_4 > deviate_2 > deviate_1 condition2 = ema_4 > ema_3 > ema_2 or ema_2 > ema_3 > ema_4 condition3 = deviate_4 > deviate_5 * beta and deviate_4 > deviate_6 top = high_4 - ema_4 bottom = ema_4 - low_4 condition4 = (low_4 < low_5 * alpha and low_4 < low_6 and top < bottom) or (high_4 > high_5 * beta and high_4 > high_6 and top > bottom) condition5 = top < bottom condition6 = top > bottom condition7 = high_3 < ema_3 and high_4 < ema_4 and high_5 < ema_5 and high_6 > ema_6 * alpha condition8 = low_3 > ema_3 and low_4 > ema_4 and low_5 > ema_5 and low_6 < ema_6 * beta matplotlib.rcParams.update({'font.size': 9}) if condition1 and condition2 and condition3 and condition4 and condition5 or condition7: self.ax1.annotate(u'多', xy=(i, low_6), xytext=(i-0.5, low_6 - distance), arrowprops=dict(arrowstyle="-")) if condition1 and condition2 and condition3 and condition4 and condition6 or condition8: self.ax1.annotate(u'空', xy=(i, high_6), xytext=(i-0.5, high_6 + distance), arrowprops=dict(arrowstyle="-")) deviate_1 = deviate_2 deviate_2 = deviate_3 deviate_3 = deviate_4 deviate_4 = deviate_5 deviate_5 = deviate_6 ema_1 = ema_2 ema_2 = ema_3 ema_3 = ema_4 ema_4 = ema_5 ema_5 = ema_6 low_1 = low_2 low_2 = low_3 low_3 = low_4 low_4 = low_5 low_5 = low_6 high_1 = high_2 high_2 = high_3 high_3 = high_4 high_4 = high_5 high_5 = high_6 # self.ax1.annotate('extreme', xy=(18, 16.8), xytext=(20, 16), arrowprops=dict(arrowstyle="->")) # self.ax2.set_ylim(0, 80) candlestick_ohlc(self.ax1, self.kbar, width=0.5, colorup='r', colordown='g') # self.ax1.hold(False) # self.ax2.hold(False) lim = self.ax1.get_ylim() self.ax1.set_ylim(lim[0] * 0.95, lim[1]) for tick in self.ax1.xaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(75) for tick in self.ax1.yaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(30) # for tick in self.ax2.xaxis.get_major_ticks(): # tick.label1.set_fontsize(8) # tick.label1.set_rotation(75) # for tick in self.ax2.yaxis.get_major_ticks(): # tick.label1.set_fontsize(8) # tick.label1.set_rotation(30) # 子图二 # self.ax2.set_xticks(range(self.num)) # self.ax2.xaxis.set_major_locator(xmajorLocator) # self.ax2.xaxis.set_minor_locator(xminorLocator) # self.ax2.grid() # self.ax2.set_xticklabels(self.str_date, rotation=25, horizontalalignment='right') # self.ax2.bar(range(len(self.star_date)), self.star_value, picker=True, color='#FFFF00') # #self.ax2.xaxis.set_major_locator(xmajorLocator) # self.ax2.xaxis.set_major_formatter(FuncFormatter(self.my_major_formatter)) # for label in self.ax2.get_xticklabels(): # label.set_picker(True) # for tick in self.ax2.xaxis.get_major_ticks(): # tick.label1.set_fontsize(5) # tick.label1.set_rotation(90) # for tick in self.ax2.yaxis.get_major_ticks(): # tick.label1.set_fontsize(5) # tick.label1.set_rotation(30) # self.draw() # self.fig.clf() def clear(self): self.fig.clf() self.ax1 = self.fig.add_axes([0.22, 0.1, 0.7, 0.7]) # self.ax1 = self.fig.add_axes([0.1, 0.35, 0.8, 0.58]) # self.ax2 = self.fig.add_axes([0.1, 0.07, 0.8, 0.2]) self.draw()
class TalkDetailsWidget(QWidget): def __init__(self, parent=None): super(TalkDetailsWidget, self).__init__(parent) self.layout = QGridLayout() self.setLayout(self.layout) self.buttonLayout = QHBoxLayout() addIcon = QIcon.fromTheme("list-add") self.addButton = QPushButton('Add New Talk') self.addButton.setIcon(addIcon) self.buttonLayout.addWidget(self.addButton) saveIcon = QIcon.fromTheme("document-save") self.saveButton = QPushButton('Save New Talk') self.saveButton.setIcon(saveIcon) self.buttonLayout.addWidget(self.saveButton) self.layout.addLayout(self.buttonLayout, 0, 1, 1, 1) self.titleLabel = QLabel('Title') self.titleLineEdit = QLineEdit() self.layout.addWidget(self.titleLabel, 1, 0, 1, 1) self.layout.addWidget(self.titleLineEdit, 1, 1, 1, 3) self.presenterLabel = QLabel('Presenter') self.presenterLineEdit = QLineEdit() self.categoryLabel = QLabel('Category') self.categoryLineEdit = QLineEdit() self.layout.addWidget(self.presenterLabel, 2, 0, 1, 1) self.layout.addWidget(self.presenterLineEdit, 2, 1, 1, 1) self.layout.addWidget(self.categoryLabel, 2, 2, 1, 1) self.layout.addWidget(self.categoryLineEdit, 2, 3, 1, 1) self.eventLabel = QLabel('Event') self.eventLineEdit = QLineEdit() self.roomLabel = QLabel('Room') self.roomLineEdit = QLineEdit() self.layout.addWidget(self.eventLabel, 3, 0, 1, 1) self.layout.addWidget(self.eventLineEdit, 3, 1, 1, 1) self.layout.addWidget(self.roomLabel, 3, 2, 1, 1) self.layout.addWidget(self.roomLineEdit, 3, 3, 1, 1) self.dateLayout = QHBoxLayout() self.timeLayout = QHBoxLayout() self.dateLabel = QLabel('Date') self.dateEdit = QDateEdit() currentDate = QDate() self.dateEdit.setDate(currentDate.currentDate()) self.dateEdit.setCalendarPopup(True) self.timeLabel = QLabel('Time') self.timeEdit = QTimeEdit() self.dateLayout.addWidget(self.dateEdit) self.timeLayout.addWidget(self.timeEdit) self.layout.addWidget(self.dateLabel, 4, 0, 1, 1) self.layout.addLayout(self.dateLayout, 4, 1, 1, 1) self.layout.addWidget(self.timeLabel, 4, 2, 1, 1) self.layout.addLayout(self.timeLayout, 4, 3, 1, 1) self.descriptionLabel = QLabel('Description') self.descriptionLabel.setAlignment(Qt.AlignTop) self.descriptionTextEdit = QPlainTextEdit() self.layout.addWidget(self.descriptionLabel, 5, 0, 1, 1) self.layout.addWidget(self.descriptionTextEdit, 5, 1, 1, 3) def enable_input_fields(self): self.titleLineEdit.setPlaceholderText("Enter Talk Title") self.presenterLineEdit.setPlaceholderText("Enter Presenter Name") self.categoryLineEdit.setPlaceholderText("Enter Category Type") self.eventLineEdit.setPlaceholderText("Enter Event Name") self.roomLineEdit.setPlaceholderText("Enter Room Location") self.titleLineEdit.setEnabled(True) self.presenterLineEdit.setEnabled(True) self.categoryLineEdit.setEnabled(True) self.eventLineEdit.setEnabled(True) self.roomLineEdit.setEnabled(True) self.dateEdit.setEnabled(True) self.timeEdit.setEnabled(True) self.descriptionTextEdit.setEnabled(True) def disable_input_fields(self): self.titleLineEdit.setPlaceholderText("") self.presenterLineEdit.setPlaceholderText("") self.categoryLineEdit.setPlaceholderText("") self.eventLineEdit.setPlaceholderText("") self.roomLineEdit.setPlaceholderText("") self.titleLineEdit.setEnabled(False) self.presenterLineEdit.setEnabled(False) self.categoryLineEdit.setEnabled(False) self.eventLineEdit.setEnabled(False) self.roomLineEdit.setEnabled(False) self.dateEdit.setEnabled(False) self.timeEdit.setEnabled(False) self.descriptionTextEdit.setEnabled(False)
class QtDateSelector(QtBoundedDate, ProxyDateSelector): """ A Qt implementation of an Enaml ProxyDateSelector. """ #: A reference to the widget created by the proxy. widget = Typed(QDateEdit) # -------------------------------------------------------------------------- # Initialization API # -------------------------------------------------------------------------- def create_widget(self): """ Create the QDateEdit widget. """ self.widget = QDateEdit(self.parent_widget()) def init_widget(self): """ Initialize the widget. """ super(QtDateSelector, self).init_widget() d = self.declaration self.set_date_format(d.date_format) self.set_calendar_popup(d.calendar_popup) self.widget.dateChanged.connect(self.on_date_changed) # -------------------------------------------------------------------------- # Abstract API Implementation # -------------------------------------------------------------------------- def get_date(self): """ Return the current date in the control. Returns ------- result : date The current control date as a date object. """ return self.widget.date().toPyDate() def set_minimum(self, date): """ Set the widget's minimum date. Parameters ---------- date : date The date object to use for setting the minimum date. """ self.widget.setMinimumDate(date) def set_maximum(self, date): """ Set the widget's maximum date. Parameters ---------- date : date The date object to use for setting the maximum date. """ self.widget.setMaximumDate(date) def set_date(self, date): """ Set the widget's current date. Parameters ---------- date : date The date object to use for setting the date. """ self._guard |= CHANGED_GUARD try: self.widget.setDate(date) finally: self._guard &= ~CHANGED_GUARD def set_date_format(self, format): """ Set the widget's date format. Parameters ---------- format : str A Python time formatting string. """ # XXX make sure Python's and Qt's format strings are the # same, or convert between the two. self.widget.setDisplayFormat(format) def set_calendar_popup(self, popup): """ Set whether a calendar popup is available on the widget. Parameters ---------- popup : bool Whether the calendar popup is enabled. """ self.widget.setCalendarPopup(popup)
class AddForm(QDialog): def __init__(self, parent=None): super(AddForm, self).__init__(parent) self.l1 = QLabel("Name") self.le = QLineEdit() self.le.setObjectName("name") self.le.setText("") self.l2 = QLabel("Start Date") self.le2 = QDateEdit() self.le2.setObjectName("startdate") self.le2.setCalendarPopup(True) self.l3 = QLabel("End Date") self.le3 = QDateEdit() self.le3.setObjectName("enddate") self.le3.setCalendarPopup(True) self.pb = QPushButton() self.pb.setObjectName("Submit") self.pb.setText("Submit") self.pb1 = QPushButton() self.pb1.setObjectName("Cancel") self.pb1.setText("Cancel") layout = QFormLayout() layout.addRow(self.l1, self.le) layout.addRow(self.l2, self.le2) layout.addRow(self.l3, self.le3) layout.addRow(self.pb1, self.pb) groupBox = QGroupBox('Add Session') groupBox.setLayout(layout) grid = QGridLayout() grid.addWidget(groupBox, 0, 0) self.setLayout(grid) self.connect(self.pb, SIGNAL("clicked()"), lambda: self.button_click(self)) self.connect(self.pb1, SIGNAL("clicked()"), lambda: self.button_close(self)) self.setWindowTitle("Session Manager") def button_click(self, a): # shost is a QString object a.close() s1 = self.le.text() s2 = self.le2.date().toPyDate() s3 = self.le3.date().toPyDate() g = Db() try: if (len(s1) > 0): y = {'name': s1, 'start_date': s2, 'end_date': s3, 'active': 0} z = g.insert('session', y) if z and z > 0: g.createExpenses(z) g.createStores(z) g.createAwards(z) g.createConducts(z) g.createMails(z) g.createMedicals(z) else: pass except: pass try: self.button_close() except: pass try: self.close() except: pass def lunchForm(self): self.form = SessionForm() self.form.show() def button_close(self, a): a.close()
def createEditor(self, parent, option, index): editor = QDateEdit(parent) editor.setCalendarPopup(True) return editor
class EditForm(QDialog): def __init__(self, sid, parent=None): super(EditForm, self).__init__(parent) self.sid = sid data = self.callData(self.sid) self.l1 = QLabel("Name") self.le = QLineEdit() self.le.setObjectName("name") self.le.setText(str(data[1])) self.l2 = QLabel("Start Date") self.le2 = QDateEdit() self.le2.setObjectName("startdate") #self.le2.setDate(data[2]) self.l3 = QLabel("End Date") self.le3 = QDateEdit() self.le3.setObjectName("enddate") #self.le3.setDate(data[3]) self.pb = QPushButton() self.pb.setObjectName("Submit") self.pb.setText("Submit") self.pb1 = QPushButton() self.pb1.setObjectName("Cancel") self.pb1.setText("Cancel") layout = QFormLayout() layout.addRow(self.l1, self.le) layout.addRow(self.l2, self.le2) layout.addRow(self.l3, self.le3) layout.addRow(self.pb1, self.pb) groupBox = QGroupBox('Edit Session') groupBox.setLayout(layout) grid = QGridLayout() grid.addWidget(groupBox, 0, 0) self.setLayout(grid) self.connect(self.pb, SIGNAL("clicked()"), lambda: self.button_click(data[0], self)) self.connect(self.pb1, SIGNAL("clicked()"), lambda: self.button_close(self)) self.setWindowTitle("Session Manager") def button_click(self, a, b): # shost is a QString object b.close() s1 = self.le.text() s2 = self.le2.date().toPyDate() s3 = self.le3.date().toPyDate() self.a = a g = Db() if (len(s1) > 0): y = {'name': s1, 'start_date': s2, 'end_date': s3} z = {'id': self.a} g.update('session', y, z) if z and z > 0: g.createExpenses(self.a) g.createStores(self.a) g.createAwards(self.a) g.createConducts(self.a) g.createMails(self.a) g.createMedicals(self.a) self.form = SessionForm() self.form.show() self.close() #self.lunchForm() def lunchForm(self): self.form = SessionForm() self.form.show() def button_close(self, a): a.close() self.lunchForm() def callData(self, a): # select a file self.a = a g = Db() return g.select('session', '', 1, {'id': self.a})
def setup(self): for label, value in self.data: if DEBUG_FORMLAYOUT: print("value:", value) if label is None and value is None: # Separator: (None, None) self.formlayout.addRow(QLabel(" "), QLabel(" ")) self.widgets.append(None) continue elif label is None: # Comment self.formlayout.addRow(QLabel(value)) self.widgets.append(None) continue elif tuple_to_qfont(value) is not None: field = FontLayout(value, self) elif text_to_qcolor(value).isValid(): field = ColorLayout(QColor(value), self) elif is_text_string(value): if '\n' in value: for linesep in (os.linesep, '\n'): if linesep in value: value = value.replace(linesep, u("\u2029")) field = QTextEdit(value, self) else: field = QLineEdit(value, self) elif isinstance(value, (list, tuple)): value = list(value) # in case this is a tuple selindex = value.pop(0) field = QComboBox(self) if isinstance(value[0], (list, tuple)): keys = [key for key, _val in value] value = [val for _key, val in value] else: keys = value field.addItems(value) if selindex in value: selindex = value.index(selindex) elif selindex in keys: selindex = keys.index(selindex) elif not isinstance(selindex, int): print("Warning: '%s' index is invalid (label: "\ "%s, value: %s)" % (selindex, label, value), file=STDERR) selindex = 0 field.setCurrentIndex(selindex) elif isinstance(value, bool): field = QCheckBox(self) field.setCheckState(Qt.Checked if value else Qt.Unchecked) elif isinstance(value, float): field = QLineEdit(repr(value), self) field.setValidator(QDoubleValidator(field)) dialog = self.get_dialog() dialog.register_float_field(field) self.connect(field, SIGNAL('textChanged(QString)'), lambda text: dialog.update_buttons()) elif isinstance(value, int): field = QSpinBox(self) field.setRange(-1e9, 1e9) field.setValue(value) elif isinstance(value, datetime.datetime): field = QDateTimeEdit(self) field.setDateTime(value) elif isinstance(value, datetime.date): field = QDateEdit(self) field.setDate(value) else: field = QLineEdit(repr(value), self) self.formlayout.addRow(label, field) self.widgets.append(field)
class sub_canvas(MyMplCanvas): def __init__(self, *args, **kwargs): MyMplCanvas.__init__(self, *args, **kwargs) self.widget = QWidget(self) self.horizontalLayout = QHBoxLayout(self.widget) self.label_1 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_1) self.lineEdit = QLineEdit(self.widget) self.horizontalLayout.addWidget(self.lineEdit) self.label_2 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_2) self.dateEdit = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit) self.label_3 = QLabel(self.widget) self.horizontalLayout.addWidget(self.label_3) self.dateEdit_2 = QDateEdit(self.widget) self.horizontalLayout.addWidget(self.dateEdit_2) self.button1 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button1) self.button2 = QPushButton(self.widget) self.horizontalLayout.addWidget(self.button2) self.lineEdit.setText(QtCore.QString('600198')) three_month = QtCore.QDate.currentDate().toJulianDay() - 40 self.dateEdit.setDate(QtCore.QDate.fromJulianDay(three_month)) self.dateEdit_2.setDate(QtCore.QDate.currentDate()) self.label_1.setText(_translate("MainWindow", "股票代码", None)) self.label_2.setText(_translate("MainWindow", "起始时间", None)) self.label_3.setText(_translate("MainWindow", "终止时间", None)) self.button1.setText(_translate("MainWindow", "提交", None)) self.button2.setText(_translate("MainWindow", "清除", None)) self.button1.clicked.connect(self.get_value) self.button2.clicked.connect(self.clear) # 定义横坐标格式的回调函数 def my_major_formatter(self, x, pos): for i in range(self.num): if (x == i): return self.str_date[i] def get_value(self): code = QtCore.QString(self.lineEdit.text()) start = QtCore.QString(self.dateEdit.text()) end = QtCore.QString(self.dateEdit_2.text()) code = unicode(code) start = datetime.date(int(start.split("/")[0]), int(start.split("/")[1]), int(start.split("/")[2])).isoformat() end = datetime.date(int(end.split("/")[0]), int(end.split("/")[1]), int(end.split("/")[2])).isoformat() self.num, self.kbar, self.str_date, self.ema, = source(code, start, end) self.star_date, self.star_value = star(col, code, start, end) self.update_figure() def update_figure(self): self.fig.clf() self.ax1 = self.fig.add_subplot(111) self.ax2 = self.ax1.twinx() # 创建第二个坐标轴,为同图 # 子图一 self.ax1.set_xticks(range(self.num)) xmajorLocator = MultipleLocator(5) # 将x主刻度标签设置为3的倍数 xminorLocator = MultipleLocator(1) # 将x副刻度标签设置为1的倍数 self.ax1.xaxis.set_major_locator(xmajorLocator) self.ax1.xaxis.set_minor_locator(xminorLocator) self.ax1.xaxis.set_major_formatter(FuncFormatter(self.my_major_formatter)) self.ax1.grid() self.ax2.bar(range(len(self.star_date)), self.star_value, picker=True, color='#FFFF00', width = 0.5,edgecolor = 'black') self.ax1.plot(range(self.num),self.ema,linewidth = 0.5,color = "blue") #极端情况 high_1 = self.kbar[0][2] low_1 = self.kbar[0][3] ema_1 = self.ema[0] deviate_1 = max(abs(high_1 - ema_1),abs(low_1 - ema_1)) high_2 = self.kbar[1][2] low_2 = self.kbar[1][3] ema_2 = self.ema[1] deviate_2 = max(abs(high_2 - ema_2),abs(low_2 - ema_2)) high_3 = self.kbar[2][2] low_3 = self.kbar[2][3] ema_3 = self.ema[2] deviate_3 = max(abs(high_3 - ema_3),abs(low_3 - ema_3)) high_4 = self.kbar[3][2] low_4 = self.kbar[3][3] ema_4 = self.ema[3] deviate_4 = max(abs(high_4 - ema_4),abs(low_4 - ema_4)) high_5 = self.kbar[4][2] low_5 = self.kbar[4][3] ema_5 = self.ema[4] deviate_5 = max(abs(high_5 - ema_5),abs(low_5 - ema_5)) high_6 = self.kbar[5][2] low_6 = self.kbar[5][3] ema_6 = self.ema[5] deviate_6 = max(abs(high_6 - ema_6),abs(low_6 - ema_6)) for i in range(6,self.num): high_7 = self.kbar[i][2] low_7 = self.kbar[i][3] ema_7 = self.ema[i] deviate_7 = max(abs(high_7 - ema_7),abs(low_7 - ema_7)) condition1 = deviate_5 > deviate_3 > deviate_2 > deviate_1 or deviate_4 > deviate_3 > deviate_2 > deviate_1 condition2 = ema_5 > ema_4 > ema_3 > ema_2 > ema_1 or ema_1 > ema_2 > ema_3 > ema_4 > ema_5 condition3 = deviate_5 > deviate_6 > deviate_7 if condition1 and condition2 and condition3 : self.ax1.annotate('E', xy=(i, low_7), xytext=(i+ 1, low_7+0.5), arrowprops=dict(arrowstyle="->")) deviate_1 = deviate_2 deviate_2 = deviate_3 deviate_3 = deviate_4 deviate_4 = deviate_5 deviate_5 = deviate_6 deviate_6 = deviate_7 ema_1 = ema_2 ema_2 = ema_3 ema_3 = ema_4 ema_4 = ema_5 ema_5 = ema_6 ema_6 = ema_7 # self.ax1.annotate('extreme', xy=(18, 16.8), xytext=(20, 16), arrowprops=dict(arrowstyle="->")) self.ax2.set_ylim(0, 80) candlestick_ohlc(self.ax1, self.kbar, width=0.5, colorup='r', colordown='g') lim = self.ax1.get_ylim() # self.ax1.hold(False) # self.ax2.hold(False) self.ax1.set_ylim(lim[0] * 0.95, lim[1]) for tick in self.ax1.xaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(75) for tick in self.ax1.yaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(30) for tick in self.ax2.xaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(75) for tick in self.ax2.yaxis.get_major_ticks(): tick.label1.set_fontsize(8) tick.label1.set_rotation(30) # 子图二 # self.ax2.set_xticks(range(self.num)) # self.ax2.xaxis.set_major_locator(xmajorLocator) # self.ax2.xaxis.set_minor_locator(xminorLocator) # self.ax2.grid() # self.ax2.set_xticklabels(self.str_date, rotation=25, horizontalalignment='right') # self.ax2.bar(range(len(self.star_date)), self.star_value, picker=True, color='#FFFF00') # #self.ax2.xaxis.set_major_locator(xmajorLocator) # self.ax2.xaxis.set_major_formatter(FuncFormatter(self.my_major_formatter)) # for label in self.ax2.get_xticklabels(): # label.set_picker(True) # for tick in self.ax2.xaxis.get_major_ticks(): # tick.label1.set_fontsize(5) # tick.label1.set_rotation(90) # for tick in self.ax2.yaxis.get_major_ticks(): # tick.label1.set_fontsize(5) # tick.label1.set_rotation(30) # self.draw() # self.fig.clf() def clear(self): self.fig.clf() self.ax1 = self.fig.add_subplot(111) # self.ax1 = self.fig.add_axes([0.1, 0.35, 0.8, 0.58]) # self.ax2 = self.fig.add_axes([0.1, 0.07, 0.8, 0.2]) self.draw()