class DecisionMakerControls(QWidget): # DecisionMakerControls class constructor def __init__(self, parent): # Call superclass constructor super().__init__() # Save parent instance self.parent = parent # Slider box slider_box = QVBoxLayout() slider_box.addWidget( DecisionMakerSlider('How hungry are you?', parent.setHungerLevel)) slider_box.addWidget( DecisionMakerSlider('Thirsty?', parent.setThirstLevel)) slider_box.addWidget( DecisionMakerSlider('Energy level?', parent.setEnergyLevel)) slider_box.addWidget( DecisionMakerSlider('Introversion level?', parent.setIntrovertLevel)) slider_box.addWidget( DecisionMakerSlider('Stress level?', parent.setStressLevel)) # Box containing calendar control, time control, weather control, alone toggle and retrograde toggle right_box = QVBoxLayout() # Box containing all of the above minus calendar #lowerright_box = QHBoxLayout() # Box containing labels for contorl in lower right box #lowerright_label_box = QVBoxLayout() # Box containing controls in lower right box #lowerright_control_box = QVBoxLayout() # Calendar control self.calendar = QCalendarWidget() self.calendar.setHorizontalHeaderFormat( QCalendarWidget.SingleLetterDayNames) self.calendar.setVerticalHeaderFormat(QCalendarWidget.NoVerticalHeader) self.calendar.selectionChanged.connect(self.calendarChanged) self.calendar.setFixedWidth(325) right_box.addWidget(self.calendar) # Save today's date self.today = self.calendar.selectedDate() # Initialize day and year self.parent.setDay(self.today.dayOfWeek() - 1) # Limit year to +- 100 form current year = self.today.year() if (year > 100): year = 100 elif (year < -100): year = -100 self.parent.setYear(year) # Time control time_box = QHBoxLayout() time_label = QLabel('What time is it?', self) self.time_combo = QComboBox() self.time_combo.addItems( ['1:00', '2:00', '3:00', '4:00', '5:00', '6:00', \ '7:00', '8:00', '9:00', '10:00', '11:00', '12:00' ] ) hour = QTime.currentTime().hour() - 1 hour_convert = hour if (hour_convert < 0): hour_convert = 23 if (hour_convert > 12): hour_convert -= 12 self.time_combo.setCurrentIndex(hour_convert) self.time_combo.currentIndexChanged.connect(self.comboChanged) self.ampm_combo = QComboBox() self.ampm_combo.addItems(['AM', 'PM']) if (hour > 12): self.ampm_combo.setCurrentIndex(1) else: self.ampm_combo.setCurrentIndex(0) self.ampm_combo.currentIndexChanged.connect(self.comboChanged) self.parent.setTime(hour) time_box.addWidget(time_label) time_box.addWidget(self.time_combo) time_box.addWidget(self.ampm_combo) right_box.addLayout(time_box) # Weather control weather_box = QHBoxLayout() weather_label = QLabel('What\'s the weather like?', self) self.weather_combo = QComboBox() self.weather_combo.addItems( ['Sunny', 'Cloudy', 'Raining', 'Snowing', 'Natural Disaster']) self.weather_combo.currentIndexChanged.connect(self.comboChanged) weather_box.addWidget(weather_label) weather_box.addWidget(self.weather_combo) right_box.addLayout(weather_box) # Alone toggle button alone_box = QHBoxLayout() alone_label = QLabel('Are you alone, or with someone else?', self) self.button_alone = QPushButton('Alone') self.button_alone.setCheckable(True) self.button_alone.clicked.connect(self.buttonClicked) alone_box.addWidget(alone_label) alone_box.addWidget(self.button_alone) right_box.addLayout(alone_box) # Retrograde toggle button retrograde_box = QHBoxLayout() retrograde_label = QLabel('Is Mercury in retrograde?', self) self.button_retrograde = QPushButton('Nope') self.button_retrograde.setCheckable(True) self.button_retrograde.clicked.connect(self.buttonClicked) retrograde_box.addWidget(retrograde_label) retrograde_box.addWidget(self.button_retrograde) right_box.addLayout(retrograde_box) # Color palette self.setAutoFillBackground(True) palette = self.palette() palette.setColor(self.backgroundRole(), Qt.white) self.setPalette(palette) # Set up layout hbox = QHBoxLayout() hbox.addLayout(slider_box) hbox.insertSpacing(1, 25) hbox.addLayout(right_box) hbox.setSizeConstraint(QLayout.SetFixedSize) self.setLayout(hbox) # Button event handler def buttonClicked(self): sender = self.sender() if (sender == self.button_alone): if (self.button_alone.isChecked()): self.button_alone.setText('With someone else') self.parent.setAlone(1) else: self.button_alone.setText('Alone') self.parent.setAlone(0) elif (sender == self.button_retrograde): if (self.button_retrograde.isChecked()): self.button_retrograde.setText('Maybe?') self.parent.setRetrograde(1) else: self.button_retrograde.setText('Nope') self.parent.setRetrograde(0) # Cobobox event handler def comboChanged(self): sender = self.sender() if ((sender == self.time_combo) or (sender == self.ampm_combo)): hour = self.time_combo.currentIndex() + 1 if (hour == 13): hour = 0 time = (hour + 12 * self.ampm_combo.currentIndex()) self.parent.setTime(time) if (sender == self.weather_combo): self.parent.setWeather(self.weather_combo.currentIndex()) # Calendar event handler def calendarChanged(self): sender = self.sender() if (sender == self.calendar): date = self.calendar.selectedDate() self.parent.setDay(date.dayOfWeek() - 1) year = date.year() # Limit year to +- 100 form current year = year - self.today.year() if (year > 100): year = 100 elif (year < -100): year = -100 self.parent.setYear(year)
class Ui_PostX_Calendar(object): def setupUi(self, PostX_Calendar): PostX_Calendar.setObjectName(_fromUtf8("PostX_Calendar")) PostX_Calendar.resize(500, 300) palette = QPalette() brush = QBrush(QColor(245, 245, 225)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.WindowText, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Button, brush) brush = QBrush(QColor(88, 87, 82)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Light, brush) brush = QBrush(QColor(73, 72, 68)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Midlight, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Dark, brush) brush = QBrush(QColor(39, 38, 36)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Mid, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Text, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.BrightText, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.ButtonText, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Base, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Window, brush) brush = QBrush(QColor(0, 0, 74)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Shadow, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.AlternateBase, brush) brush = QBrush(QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.ToolTipBase, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.ToolTipText, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.WindowText, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Button, brush) brush = QBrush(QColor(88, 87, 82)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Light, brush) brush = QBrush(QColor(73, 72, 68)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Midlight, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Dark, brush) brush = QBrush(QColor(39, 38, 36)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Mid, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Text, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.BrightText, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.ButtonText, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Base, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Window, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Shadow, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.AlternateBase, brush) brush = QBrush(QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.ToolTipBase, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.ToolTipText, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.WindowText, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Button, brush) brush = QBrush(QColor(88, 87, 82)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Light, brush) brush = QBrush(QColor(73, 72, 68)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Midlight, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Dark, brush) brush = QBrush(QColor(39, 38, 36)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Mid, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Text, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.BrightText, brush) brush = QBrush(QColor(29, 29, 27)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.ButtonText, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Base, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Window, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Shadow, brush) brush = QBrush(QColor(59, 58, 55)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.AlternateBase, brush) brush = QBrush(QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.ToolTipBase, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.ToolTipText, brush) PostX_Calendar.setPalette(palette) PostX_Calendar.setWindowOpacity(1.0) self.horizontalLayout = QHBoxLayout(PostX_Calendar) self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.calendarWidget = QCalendarWidget(PostX_Calendar) palette = QPalette() brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.WindowText, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Button, brush) brush = QBrush(QColor(146, 146, 146)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Light, brush) brush = QBrush(QColor(121, 121, 121)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Midlight, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Dark, brush) brush = QBrush(QColor(64, 64, 64)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Mid, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Text, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.BrightText, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.ButtonText, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Base, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Window, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.Shadow, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.AlternateBase, brush) brush = QBrush(QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.ToolTipBase, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Active, QPalette.ToolTipText, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.WindowText, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Button, brush) brush = QBrush(QColor(146, 146, 146)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Light, brush) brush = QBrush(QColor(121, 121, 121)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Midlight, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Dark, brush) brush = QBrush(QColor(64, 64, 64)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Mid, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Text, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.BrightText, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.ButtonText, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Base, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Window, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.Shadow, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.AlternateBase, brush) brush = QBrush(QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.ToolTipBase, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Inactive, QPalette.ToolTipText, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.WindowText, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Button, brush) brush = QBrush(QColor(146, 146, 146)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Light, brush) brush = QBrush(QColor(121, 121, 121)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Midlight, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Dark, brush) brush = QBrush(QColor(64, 64, 64)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Mid, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Text, brush) brush = QBrush(QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.BrightText, brush) brush = QBrush(QColor(48, 48, 48)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.ButtonText, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Base, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Window, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.Shadow, brush) brush = QBrush(QColor(97, 97, 97)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.AlternateBase, brush) brush = QBrush(QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.ToolTipBase, brush) brush = QBrush(QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QPalette.Disabled, QPalette.ToolTipText, brush) self.calendarWidget.setPalette(palette) font = QFont() font.setFamily(_fromUtf8("Monospace")) font.setPointSize(12) font.setStyleStrategy(QFont.PreferAntialias) self.calendarWidget.setFont(font) self.calendarWidget.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu) self.calendarWidget.setFirstDayOfWeek(QtCore.Qt.Monday) self.calendarWidget.setGridVisible(True) self.calendarWidget.setHorizontalHeaderFormat( QCalendarWidget.ShortDayNames) self.calendarWidget.setDateEditEnabled(True) self.calendarWidget.setObjectName(_fromUtf8("calendarWidget")) self.horizontalLayout.addWidget(self.calendarWidget) self.retranslateUi(PostX_Calendar) QtCore.QMetaObject.connectSlotsByName(PostX_Calendar) def retranslateUi(self, PostX_Calendar): PostX_Calendar.setWindowTitle( _translate("PostX_Calendar", "PostX-Calendar-QT5", None)) PostX_Calendar.setToolTip( _translate("PostX_Calendar", "PostX-Calendar", None)) self.calendarWidget.setToolTip( _translate("PostX_Calendar", "PostX-Calendar", None))
class ui_excute(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(511, 475) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.envComboBox = QComboBox(self.centralwidget) self.envComboBox.setGeometry(QtCore.QRect(160, 30, 111, 21)) self.envComboBox.setObjectName("envComboBox") self.typeComboBox = QComboBox(self.centralwidget) self.typeComboBox.setGeometry(QtCore.QRect(160, 80, 111, 21)) self.typeComboBox.setObjectName("typeComboBox") self.label = QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(40, 30, 91, 16)) self.label.setObjectName("label") self.label_2 = QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(40, 80, 91, 16)) self.label_2.setObjectName("label_2") self.label_3 = QLabel(self.centralwidget) self.label_3.setGeometry(QtCore.QRect(40, 130, 91, 16)) self.label_3.setObjectName("label_3") self.pushButton = QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(410, 365, 81, 41)) self.pushButton.setObjectName("pushButton") self.pushButton_1 = QPushButton(self.centralwidget) self.pushButton_1.setGeometry(QtCore.QRect(30, 365, 81, 41)) self.pushButton_1.setObjectName("checkPushButton") self.textBrowser = QTextBrowser(self.centralwidget) self.textBrowser.setGeometry(QtCore.QRect(160, 350, 240, 90)) self.textBrowser.setObjectName("textBrowser") self.calendarWidget = QCalendarWidget(self.centralwidget) self.calendarWidget.setGeometry(QtCore.QRect(160, 130, 271, 200)) self.calendarWidget.setGridVisible(True) self.calendarWidget.setHorizontalHeaderFormat( QCalendarWidget.ShortDayNames) self.calendarWidget.setVerticalHeaderFormat( QCalendarWidget.NoVerticalHeader) self.calendarWidget.setNavigationBarVisible(True) self.calendarWidget.setDateEditEnabled(True) self.calendarWidget.setObjectName("calendarWidget") MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) for i in list_env: self.envComboBox.insertItem(list_env.index(i), i) for i in list_job_type: self.typeComboBox.insertItem(list_job_type.index(i), i) self.pushButton.clicked.connect(self.excutejob) self.pushButton_1.clicked.connect(self.checkScanJob) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "定时任务执行工具")) self.label.setText(_translate("MainWindow", "定时任务环境:")) self.label_2.setText(_translate("MainWindow", "定时任务类型:")) self.label_3.setText(_translate("MainWindow", "定时任务日期:")) self.pushButton.setText(_translate("MainWindow", "执行")) self.pushButton_1.setText(_translate("MainWindow", "服务扫描检查")) def checkScanJob(self): table = dic_env[self.envComboBox.currentText()]['tablename'] last_create_time = lastCreatTime(table) if ('beginTime' in globals()): if last_create_time > beginTime: QTextBrowser.append(self.textBrowser, "服务扫描任务已经执行完毕!") else: QTextBrowser.append(self.textBrowser, "服务扫描任务仍在执行,请稍后再检查!") else: QTextBrowser.append(self.textBrowser, "请先执行服务扫描任务") def excutejob(self): #获取参数 job_env = self.envComboBox.currentText() job_type = dic_job_type[self.typeComboBox.currentText()] job_name = self.typeComboBox.currentText() date = self.calendarWidget.selectedDate() job_date = date.toString(Qt.ISODate) ip = dic_env[job_env]['ip'] username = dic_env[job_env]['username'] password = dic_env[job_env]['password'] # 连接SSH try: ssh = paramiko.SSHClient() key = paramiko.AutoAddPolicy() ssh.set_missing_host_key_policy(key) ssh.connect(ip, 22, username, password, timeout=5) # 执行Job命令 job_command = 'export app_name="cs-expertsystem-job";app_job="cs-expertsystem-job-crontab";port=' + str( port ) + ';parameter=' + job_type + ';parameter2=' + job_date + ';PATH=/usr/java/jdk1.8.0_73/bin:$PATH;JAVA_HOME=/usr/java/jdk1.8.0_73;mkdir -p /yazuo_apps/logs/$app_name/;chmod a+x /yazuo_apps/$app_name/current/$app_name.jar;java -server -Xms512m -Xmx512m -XX:MaxPermSize=128m -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintClassHistogram -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:/yazuo_apps/logs/$app_name/gc_log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=100 -XX:GCLogFileSize=10240K -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/yazuo_apps/logs/$app_name/heap_dump.hprof -Dfile.encoding=UTF-8 -Dapp_home=/yazuo_apps/$app_name/current -jar /yazuo_apps/$app_name/current/$app_name.jar $parameter $parameter2 --server.port=$port --spring.application.name=$app_name --logging.path=/yazuo_apps/logs/$app_name/ --logging.file=/yazuo_apps/logs/$app_name/info.log --task.name=$app_job --server.tomcat.accesslog.suffix=.log >/yazuo_apps/logs/$app_name/console.log 2>&1' stdin, stdout, stderr = ssh.exec_command(job_command) ssh.close() msg = job_name + '(' + job_date + ") 定时任务发送完毕!" QTextBrowser.setText(self.textBrowser, msg) except: QTextBrowser.setText(self.textBrowser, "执行失败!") # 获取日志文件 t = paramiko.Transport((ip, 22)) t.connect(username=username, password=password) sftp = paramiko.SFTPClient.from_transport(t) beginString = job_type + '任务开始时间' cmpleteString = job_type + '执行完毕时间' time.sleep(1) try: state = 0 time.sleep(5) for i in range(1, 120): time.sleep(5) sftp.get('/yazuo_apps/logs/cs-expertsystem-job/console.log', os.getcwd() + '/\\console.log') log_content = open('console.log', 'r', encoding='UTF-8') log_string = log_content.read() log_content.close() if state == 0: if beginString in log_string: state = 1 if job_type == 'ScanBizOpportunityJob': break if state == 1: if cmpleteString in log_string: state = 2 break if state == 0: QTextBrowser.append(self.textBrowser, "未检测到任务开始执行") if state == 1 and job_type == 'ScanBizOpportunityJob': mat = re.search(beginString + r'.{21}', log_string) global beginTime beginTime = datetime.datetime.strptime( mat.group(0)[-19:], '%Y-%m-%d %H:%M:%S') print(beginTime) QTextBrowser.append(self.textBrowser, "请点击 服务扫描查询 按钮来检查是否执行完毕") if state == 1 and job_type != 'ScanBizOpportunityJob': mat = re.search(beginString + r'.{21}', log_string) QTextBrowser.append( self.textBrowser, job_type + mat.group(0)[-27:] + " 但未检测到执行结束") if state == 2: mat = re.search(beginString + r'.{21}', log_string) mat1 = re.search(cmpleteString + r'.{21}', log_string) QTextBrowser.append(self.textBrowser, job_name + mat.group(0)[-27:]) QTextBrowser.append(self.textBrowser, job_name + mat1.group(0)[-27:]) except: QTextBrowser.append(self.textBrowser, "获取日志失败,可能未执行成功")