def setupUi(self, Form): Form.setObjectName("Form") Form.resize(800, 600) self.verticalLayout = QtWidgets.QVBoxLayout(Form) self.verticalLayout.setObjectName("verticalLayout") self.groupBox = QtWidgets.QGroupBox(Form) self.groupBox.setObjectName("groupBox") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox) self.verticalLayout_2.setObjectName("verticalLayout_2") self.title = QtWidgets.QLabel(self.groupBox) self.title.setStyleSheet("background-color: rgb(218, 218, 218);") self.title.setAlignment(QtCore.Qt.AlignCenter) self.title.setObjectName("title") self.verticalLayout_2.addWidget(self.title) self.tableWidget = TableWidget(self.groupBox) self.tableWidget.setFocusPolicy(QtCore.Qt.NoFocus) self.tableWidget.setGridStyle(QtCore.Qt.DashDotLine) self.tableWidget.setCornerButtonEnabled(False) self.tableWidget.setRowCount(5) self.tableWidget.setColumnCount(5) self.tableWidget.setObjectName("tableWidget") self.verticalLayout_2.addWidget(self.tableWidget) # cur_page_num, page_total = self.tableWidget.getPageNum() # self.tableWidget.pageBlockDisplay() # self.form_page_bar = FormPageBar(cur_page_num, page_total) # self.verticalLayout_2.addWidget(self.form_page_bar) self.verticalLayout.addWidget(self.groupBox) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form)
def __init__(self, info : tuple, conn): super().__init__() self.conn = conn self.cursor = conn.cursor() self.fun_name = info[0] self.param = info[1] self.labels = [] self.values = [] self.gen_layout = QVBoxLayout() self.table = TableWidget() self.input = None if self.param : self.label = QLabel(self.param[0]) self.input = self.param[1]() if self.param[1] == QDateEdit : self.input.setDisplayFormat("MM/dd/yyyy") self.input.setCalendarPopup(True) if self.param[1] == QSpinBox : self.input.setMaximum(999999999) self.button = QPushButton('Esegui') self.button.clicked.connect(self._run_query) self.row = QHBoxLayout() self.row.addWidget(self.label) self.row.addWidget(self.input) self.row.addWidget(self.button) self.gen_layout.addLayout(self.row) self.gen_layout.addWidget(self.table) self.setLayout(self.gen_layout) if not self.param : self._run_query()
def main(): import sys app = QApplication(sys.argv) w = TableWidget() w.show() sys.exit(app.exec_())
def __init__(self, connection): ''' Main window for the program, handles the basic table/view queries ''' super().__init__() # Param refs self.connection = connection self.cursor = self.connection.cursor() # Get db meta self.cursor.execute(GET_TABLES_QUERY) self.table_list = [item[0] for item in self.cursor.fetchall()] self.cursor.execute(GET_VIEWS_QUERY) self.view_list = [item[0] for item in self.cursor.fetchall()] # Menu init self.menu = self.menuBar() self.table_menu = self.menu.addMenu('Tabelle') for table in self.table_list: action = QAction(' '.join([t.capitalize() for t in table.replace('_', ' ').split()]), self) callback = self._make_show_table(table) action.triggered.connect(callback) self.table_menu.addAction(action) self.view_menu = self.menu.addMenu('Viste') for view in self.view_list: action = QAction(' '.join([v.capitalize() for v in view.replace('_', ' ').split()]), self) callback = self._make_show_table(view) action.triggered.connect(callback) self.view_menu.addAction(action) self.query_menu = self.menu.addMenu('Interrogazioni') for label, info in QUERIES.items(): action = QAction(label, self) callback = self._make_show_query(info) action.triggered.connect(callback) self.query_menu.addAction(action) self.insert_menu = self.menu.addMenu('Inserimenti') for label, dialogclass in INSERTIONS.items(): action = QAction(label, self) callback = self._make_show_dialog(dialogclass) action.triggered.connect(callback) self.insert_menu.addAction(action) self.connection.commit() # GUI init self.setWindowTitle('DbApp') self.table_widget = TableWidget() self.setCentralWidget(self.table_widget)
class QueryWidget(QWidget): def __init__(self, info : tuple, conn): super().__init__() self.conn = conn self.cursor = conn.cursor() self.fun_name = info[0] self.param = info[1] self.labels = [] self.values = [] self.gen_layout = QVBoxLayout() self.table = TableWidget() self.input = None if self.param : self.label = QLabel(self.param[0]) self.input = self.param[1]() if self.param[1] == QDateEdit : self.input.setDisplayFormat("MM/dd/yyyy") self.input.setCalendarPopup(True) if self.param[1] == QSpinBox : self.input.setMaximum(999999999) self.button = QPushButton('Esegui') self.button.clicked.connect(self._run_query) self.row = QHBoxLayout() self.row.addWidget(self.label) self.row.addWidget(self.input) self.row.addWidget(self.button) self.gen_layout.addLayout(self.row) self.gen_layout.addWidget(self.table) self.setLayout(self.gen_layout) if not self.param : self._run_query() def _get_param(self): if not self.input : return None if type(self.input) == QDateEdit : return self.input.date().toString('MM/dd/yyyy') if type(self.input) == QLineEdit : return self.input.text() if type(self.input) == QSpinBox : return self.input.value() return None def _run_query(self): param = self._get_param() if param : self.cursor.callproc(self.fun_name, (self._get_param(),)) else : self.cursor.callproc(self.fun_name) labels = [item[0] for item in self.cursor.description] self.table.populate(labels, self.cursor.fetchall()) self.conn.commit()
def show_table(): ''' Display the content of a table in the main table view Parameters: table : str -- The table name to show, will be directly inserted in the query ''' self.cursor.execute(GET_ALL_FROM_X.format(table)) labels = [item[0] for item in self.cursor.description] self.table_widget = TableWidget() self.setCentralWidget(self.table_widget) self.table_widget.populate(labels, self.cursor.fetchall()) self.connection.commit()
def setupTaskTable(self): headers = [ u"账号", u"进度", u"代理", u"零售店", u"服务类型" ] self.taskTableWidget = TableWidget(headers=headers)
def initUI(self): ################## FILEMENU AREA ######################################## self.fileMenuArea = folder_widget.FolderWidget(self) self.fileMenuArea.signal_update_images.connect(self.refreshImages) self.fileMenuArea.signal_update_image.connect(self.refreshImage) ################## IMAGE AREA ######################################## self.imagePreviewArea = QtGui.QScrollArea(self) self.imagePreviewLayout = QtGui.QGridLayout(self.imagePreviewArea) self.connect(self.imagePreviewArea, QtCore.SIGNAL("resizeEvent()"), self.updateImages) self.lbl1 = CusLabel(self,0) self.imagePreviewLayout.addWidget(self.lbl1, 0,0) self.lbl2 = CusLabel(self,1) self.imagePreviewLayout.addWidget(self.lbl2, 0,1) self.lbl3 = CusLabel(self,2) self.imagePreviewLayout.addWidget(self.lbl3, 1,0) self.lbl4 = CusLabel(self,3) self.imagePreviewLayout.addWidget(self.lbl4, 1,1) self.lbl5 = CusLabel(self,4) self.imagePreviewLayout.addWidget(self.lbl5, 2,0) self.lbl6 = CusLabel(self,5) self.imagePreviewLayout.addWidget(self.lbl6, 2,1) ################## SETTINGS AREA ######################################## buttonArea = QtGui.QWidget(self) buttonLayout = QtGui.QVBoxLayout(buttonArea) self.openSettingsButton = QtGui.QPushButton("Settings") self.openSettingsButton.clicked.connect(self.openSettings) buttonLayout.addWidget(self.openSettingsButton) self.pbar = QtGui.QProgressBar(self) nuclNameFieldLabel = QtGui.QLabel(self) nuclNameFieldLabel.setText("Files with nuclei:") self.nuclNameComboBox = QtGui.QComboBox(self) self.nuclNameComboBox.activated[str].connect(self.setNuclei_name) buttonLayout.addWidget(nuclNameFieldLabel) buttonLayout.addWidget(self.nuclNameComboBox) fociNameFieldLabel = QtGui.QLabel(self) fociNameFieldLabel.setText("Files with foci:") self.fociNameComboBox = QtGui.QComboBox(self) self.fociNameComboBox.addItem('--None--') self.fociNameComboBox.activated[str].connect(self.setFoci_name) buttonLayout.addWidget(fociNameFieldLabel) buttonLayout.addWidget(self.fociNameComboBox) self.rescaleButton = QtGui.QPushButton("Get scale from selection") self.rescaleButton.clicked.connect(self.fileMenuArea.getScaleFromSelected) buttonLayout.addWidget(self.rescaleButton) runCalcButton = QtGui.QPushButton("Calculate") runCalcButton.clicked.connect(self.fileMenuArea.calculateSelected) runCalcButton.setMinimumHeight(40) buttonLayout.addWidget(runCalcButton) self.pbar.hide() buttonLayout.addWidget(self.pbar) #spacer=QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) #buttonLayout.addSpacerItem(spacer) self.tableWidget=TableWidget(self) tabs = QtGui.QTabWidget(self) #_______________________________________ #buttonLayout.addWidget(self.tableWidget) tab1=QtGui.QWidget() tab1Layout=QtGui.QVBoxLayout(tab1) tabs.addTab(tab1,"Results") tab1Layout.addWidget(self.tableWidget) self.outfileButton = QtGui.QPushButton("Save results") self.outfileButton.clicked.connect(self.saveParams) self.outfileButton.setEnabled(False) tab1Layout.addWidget(self.outfileButton) self.singleCellOutputBox = QtGui.QCheckBox('Single cell output', self) self.singleCellOutputBox.setEnabled(False) self.singleCellOutputBox.stateChanged.connect(self.fileMenuArea.updateParamsTable) tab1Layout.addWidget(self.singleCellOutputBox) nuclLogLabel = QtGui.QLabel(self) self.logText = QtGui.QTextEdit() #self.logText.setMaximumHeight(130) self.logText.setReadOnly(True) self.logText.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) self.logText.append("Welcome to DARFI! ") self.logger = Logger(self.logText) #self.errors = Logger(self.logText) sys.stdout = self.logger #sys.stderr = self.errors #________________________________ #buttonLayout.addWidget(self.logText) tabs.addTab(self.logText,"Log") buttonLayout.addWidget(tabs) buttonLayout.setAlignment(QtCore.Qt.AlignTop) ################## COMPOSITING ######################################## windowInitWidth = 1300 windowInitHeight = 768 icon = QtGui.QIcon() homepath = os.path.abspath(os.path.dirname(os.getcwd())) iconpath = os.path.join(homepath, 'misc', 'darfi.ico') if os.path.isfile(iconpath): icon.addPixmap(QtGui.QPixmap(_fromUtf8(iconpath)), QtGui.QIcon.Normal, QtGui.QIcon.Off) else: icon.addPixmap(QtGui.QPixmap(_fromUtf8(os.path.join(os.getcwd(), 'misc', 'darfi.ico'))), QtGui.QIcon.Normal, QtGui.QIcon.Off) hbox = QtGui.QHBoxLayout() splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal) splitter1.addWidget(self.imagePreviewArea) splitter1.addWidget(buttonArea) splitter1.setSizes([windowInitWidth-480,240]) splitter1.splitterMoved.connect(self.updateImages) ''' splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical) splitter2.addWidget(splitter1) splitter2.addWidget(self.statusArea) splitter2.setSizes([windowInitHeight-200,windowInitHeight/200]) splitter2.splitterMoved.connect(self.updateImages) ''' splitter3 = QtGui.QSplitter(QtCore.Qt.Horizontal) splitter3.addWidget(self.fileMenuArea) splitter3.addWidget(splitter1) splitter3.setSizes([240,windowInitWidth-240]) splitter3.splitterMoved.connect(self.updateImages) hbox.addWidget(splitter3) hboxWidget=QtGui.QWidget(self) hboxWidget.setLayout(hbox) self.setCentralWidget(hboxWidget) self.setGeometry(0, 0,windowInitWidth, windowInitHeight) self.setWindowTitle('DARFI') self.setWindowIcon(icon) self.createActions() self.createMenus() self.show()
def __init__(self, settings): super(SettingsWindow, self).__init__() tabs = QtGui.QTabWidget(self) tab1 = QtGui.QWidget() tab2 = QtGui.QWidget() tab3 = QtGui.QWidget() tab4 = QtGui.QWidget() self.settings = settings tab1layout = QtGui.QGridLayout() sensitivityLabel = QtGui.QLabel(self) sensitivityLabel.setText("Sensitivity:") self.sensitivityField = QtGui.QDoubleSpinBox() self.sensitivityField.setRange(0, 10) self.sensitivityField.setDecimals(0) self.sensitivityField.setValue(self.settings.sensitivity) sensitivityLabel.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.sensitivityField.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) tab1layout.addWidget(sensitivityLabel, 0, 0) tab1layout.addWidget(self.sensitivityField, 0, 1) min_cell_sizeLabel = QtGui.QLabel(self) min_cell_sizeLabel.setText("Minimal cell size:") self.min_cell_sizeField = QtGui.QDoubleSpinBox() self.min_cell_sizeField.setRange(0, 4294967296) self.min_cell_sizeField.setDecimals(0) self.min_cell_sizeField.setValue(self.settings.min_cell_size) min_cell_sizeLabel.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) self.min_cell_sizeField.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) tab1layout.addWidget(min_cell_sizeLabel, 1, 0) tab1layout.addWidget(self.min_cell_sizeField, 1, 1) spacer1 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) tab1layout.addItem(spacer1, 2, 0) tab2layout = QtGui.QGridLayout() foci_lookup_sensivityLabel = QtGui.QLabel(self) foci_lookup_sensivityLabel.setText("Foci lookup sensitivity") self.foci_lookup_sensivityField = QtGui.QDoubleSpinBox() self.foci_lookup_sensivityField.setRange(0, 100) self.foci_lookup_sensivityField.setDecimals(0) self.foci_lookup_sensivityField.setValue( self.settings.foci_lookup_sensivity) tab2layout.addWidget(foci_lookup_sensivityLabel, 0, 0) tab2layout.addWidget(self.foci_lookup_sensivityField, 0, 1) foci_min_val_percLabel = QtGui.QLabel(self) foci_min_val_percLabel.setText("Foci area fill percent") self.foci_area_fill_percentField = QtGui.QDoubleSpinBox() self.foci_area_fill_percentField.setRange(0, 100) self.foci_area_fill_percentField.setDecimals(0) self.foci_area_fill_percentField.setValue( self.settings.foci_area_fill_percent) tab2layout.addWidget(foci_min_val_percLabel, 1, 0) tab2layout.addWidget(self.foci_area_fill_percentField, 1, 1) min_foci_radiusLabel = QtGui.QLabel(self) min_foci_radiusLabel.setText("Min foci radius") self.min_foci_radiusField = QtGui.QDoubleSpinBox() self.min_foci_radiusField.setRange(0, 4294967296) self.min_foci_radiusField.setDecimals(0) self.min_foci_radiusField.setValue(self.settings.min_foci_radius) tab2layout.addWidget(min_foci_radiusLabel, 2, 0) tab2layout.addWidget(self.min_foci_radiusField, 2, 1) max_foci_radiusLabel = QtGui.QLabel(self) max_foci_radiusLabel.setText("Max foci radius") self.max_foci_radiusField = QtGui.QDoubleSpinBox() self.max_foci_radiusField.setRange(0, 4294967296) self.max_foci_radiusField.setDecimals(0) self.max_foci_radiusField.setValue(self.settings.max_foci_radius) tab2layout.addWidget(max_foci_radiusLabel, 3, 0) tab2layout.addWidget(self.max_foci_radiusField, 3, 1) allowed_foci_overlapLabel = QtGui.QLabel(self) allowed_foci_overlapLabel.setText("Allowed foci overlap") self.allowed_foci_overlapField = QtGui.QDoubleSpinBox() self.allowed_foci_overlapField.setRange(0, 100) self.allowed_foci_overlapField.setDecimals(0) self.allowed_foci_overlapField.setValue( self.settings.allowed_foci_overlap) tab2layout.addWidget(allowed_foci_overlapLabel, 4, 0) tab2layout.addWidget(self.allowed_foci_overlapField, 4, 1) self.set_auto_rescale_box = QtGui.QCheckBox('Auto rescale Foci', self) self.set_auto_rescale_box.setChecked(self.settings.normalize_intensity) tab2layout.addWidget(self.set_auto_rescale_box, 5, 1) if (self.settings.foci_rescale_min == None) & (self.settings.foci_rescale_max == None): self.set_auto_rescale_box.setChecked(True) else: self.set_auto_rescale_box.setChecked(False) self.set_auto_rescale_box.clicked.connect(self.checkEvent) foci_rescale_minLabel = QtGui.QLabel(self) foci_rescale_minLabel.setText("Foci rescale min:") self.foci_rescale_minField = QtGui.QDoubleSpinBox() self.foci_rescale_minField.setRange(0, 255) self.foci_rescale_minField.setSingleStep(0.1) try: self.foci_rescale_minField.setValue(self.settings.foci_rescale_min) except TypeError: self.foci_rescale_minField.setValue(0) tab2layout.addWidget(foci_rescale_minLabel, 6, 0) tab2layout.addWidget(self.foci_rescale_minField, 6, 1) foci_rescale_maxLabel = QtGui.QLabel(self) foci_rescale_maxLabel.setText("Foci rescale max:") self.foci_rescale_maxField = QtGui.QDoubleSpinBox() self.foci_rescale_maxField.setRange(0, 255) self.foci_rescale_maxField.setSingleStep(0.1) try: self.foci_rescale_maxField.setValue(self.settings.foci_rescale_max) except TypeError: self.foci_rescale_maxField.setValue(0) tab2layout.addWidget(foci_rescale_maxLabel, 7, 0) tab2layout.addWidget(self.foci_rescale_maxField, 7, 1) self.checkEvent() self.normalize_intensity_box = QtGui.QCheckBox('Normalize intensity', self) self.normalize_intensity_box.setChecked( self.settings.normalize_intensity) tab2layout.addWidget(self.normalize_intensity_box, 8, 0) spacer2 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) tab2layout.addItem(spacer2, 9, 0) tab3layout = QtGui.QGridLayout() self.nucleiColorSlider = hsv_qslider.slider() self.nucleiColorSlider.setPos(self.settings.nuclei_color) nuclei_colorLabel = QtGui.QLabel(self) nuclei_colorLabel.setText("Nuclei color:") nuclei_colorLabel.setFixedHeight(20) tab3layout.addWidget(nuclei_colorLabel, 0, 0) tab3layout.addWidget(self.nucleiColorSlider, 0, 1) self.fociColorSlider = hsv_qslider.slider() self.fociColorSlider.setPos(self.settings.foci_color) self.fociColorSlider.setFixedHeight(20) foci_colorLabel = QtGui.QLabel(self) foci_colorLabel.setText("Foci color:") foci_colorLabel.setFixedHeight(20) tab3layout.addWidget(foci_colorLabel, 1, 0) tab3layout.addWidget(self.fociColorSlider, 1, 1) self.return_circles_box = QtGui.QCheckBox('Draw foci with circles', self) self.return_circles_box.setChecked(self.settings.return_circles) tab3layout.addWidget(self.return_circles_box, 2, 0) spacer3 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) tab3layout.addItem(spacer3, 3, 0) tab4layout = QtGui.QVBoxLayout() self.tableWidget = TableWidget(self) tab4layout.addWidget(self.tableWidget) spacer4 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) tab4layout.addSpacerItem(spacer4) self.setFixedSize(400, 400) tabs.resize(400, 400) tabs.addTab(tab1, "Cell detection") tabs.addTab(tab2, "Foci detection") tabs.addTab(tab3, "Images") tabs.addTab(tab4, "Table") tab1.setLayout(tab1layout) tab2.setLayout(tab2layout) tab3.setLayout(tab3layout) tab4.setLayout(tab4layout)
class DbMainWindow(QMainWindow): def __init__(self, connection): ''' Main window for the program, handles the basic table/view queries ''' super().__init__() # Param refs self.connection = connection self.cursor = self.connection.cursor() # Get db meta self.cursor.execute(GET_TABLES_QUERY) self.table_list = [item[0] for item in self.cursor.fetchall()] self.cursor.execute(GET_VIEWS_QUERY) self.view_list = [item[0] for item in self.cursor.fetchall()] # Menu init self.menu = self.menuBar() self.table_menu = self.menu.addMenu('Tabelle') for table in self.table_list: action = QAction(' '.join([t.capitalize() for t in table.replace('_', ' ').split()]), self) callback = self._make_show_table(table) action.triggered.connect(callback) self.table_menu.addAction(action) self.view_menu = self.menu.addMenu('Viste') for view in self.view_list: action = QAction(' '.join([v.capitalize() for v in view.replace('_', ' ').split()]), self) callback = self._make_show_table(view) action.triggered.connect(callback) self.view_menu.addAction(action) self.query_menu = self.menu.addMenu('Interrogazioni') for label, info in QUERIES.items(): action = QAction(label, self) callback = self._make_show_query(info) action.triggered.connect(callback) self.query_menu.addAction(action) self.insert_menu = self.menu.addMenu('Inserimenti') for label, dialogclass in INSERTIONS.items(): action = QAction(label, self) callback = self._make_show_dialog(dialogclass) action.triggered.connect(callback) self.insert_menu.addAction(action) self.connection.commit() # GUI init self.setWindowTitle('DbApp') self.table_widget = TableWidget() self.setCentralWidget(self.table_widget) def _make_show_table(self, table): def show_table(): ''' Display the content of a table in the main table view Parameters: table : str -- The table name to show, will be directly inserted in the query ''' self.cursor.execute(GET_ALL_FROM_X.format(table)) labels = [item[0] for item in self.cursor.description] self.table_widget = TableWidget() self.setCentralWidget(self.table_widget) self.table_widget.populate(labels, self.cursor.fetchall()) self.connection.commit() return show_table def _make_show_query(self, info): def show_query(): self.query_widget = QueryWidget(info, self.connection) self.setCentralWidget(self.query_widget) return show_query def _make_show_dialog(self, dialogclass): def show_dialog(): self.last_dialog = dialogclass(self.connection) self.last_dialog.show() return show_dialog def _show_error(self, msg=''): dialog = QMessageBox() dialog.setWindowTitle('ERRORE') dialog.setText(msg) dialog.exec_()
class MainWindow(QtGui.QMainWindow): signalViewTask = pyqtSignal(int) signalUpdateProgress = pyqtSignal(str, str) signalStoreResult = pyqtSignal(str) # sigUpdateCurrentId = pyqtSignal() sigUpdateProgressBar = pyqtSignal(str) def setupTaskTable(self): headers = [ u"账号", u"进度", u"代理", u"零售店", u"服务类型" ] self.taskTableWidget = TableWidget(headers=headers) def setupResultTable(self): headers = [ u'账号', u'预约信息' ] self.reservResultTable = TableWidget(headers=headers) def setupViews(self): splitter = QSplitter() self.setupTaskTable() splitter.addWidget(self.taskTableWidget) self.taskViewWidget = taskviewwidget.TaskViewWidget() splitter.addWidget(self.taskViewWidget) splitter.setStretchFactor(0, 0) splitter.setStretchFactor(1, 1) self.setCentralWidget(splitter) self.taskViewWidget.hide() self.msgLabel = QLabel() self.statusBar().addWidget(self.msgLabel) def setupViews2(self): self.setupTaskTable() msplitter = QSplitter(Qt.Horizontal) msplitter.addWidget(self.taskTableWidget) rsplitter = QSplitter(Qt.Vertical, msplitter) self.setupResultTable() rsplitter.addWidget(self.reservResultTable) self.taskViewWidget = taskviewwidget.TaskViewWidget() rsplitter.addWidget(self.taskViewWidget) self.setCentralWidget(msplitter) self.msgLabel = QLabel() self.statusBar().addWidget(self.msgLabel) def __init__(self, abscwd, parent=None): super(MainWindow, self).__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.setupViews2() self.appContext = AppContext(abscwd, self) self.setupMembers() self.setupSig2Slot() def setupMembers(self): self.reserverResult = ReserverResult() self.preSelectedRow = None self.store_suburl = {} self.storelist = [] self.finishedAppleId = [] self.initStoreData() self.running = False # ################################### accountfile = self.appContext.getAccountFile() self.appContext.accountManager = AccountManager(accountfile) self.appContext.accountManagerDLG = AccountManagerDLG(self.appContext) self.appContext.accountListDLG = AccountListDLG(self.appContext) self.taskManageDLG = TaskManageDLG(self.appContext, self.storelist, self.reservTypes) self.appContext.taskManageDLG = self.taskManageDLG self.appContext.tasklistDLG = TaskListDLG(self.appContext) # the apply process self.applyTasks = [] self.appleIdToProgresscell = {} # = {id, item} task = self.taskManageDLG.getDefaultTask() if task: self.appContext.setCurrentTask(task) self.fillTaskView(task) def setupSig2Slot(self): self.signalUpdateProgress.connect(self.updateProgress) self.signalStoreResult.connect(self.storeResult) # self.sigUpdateCurrentId.connect(self.updateCurrentApplIdProgress) self.sigTimeSlot.connect(self.selectTimeSlot) self.pBSubmit.clicked.connect(self.submit) self.pBRefresh.clicked.connect(self.refresh) self.taskTableWidget.cellClicked.connect(self.twTasklistCellClicked) def initStoreData(self): # the store name of each url self.stores = AppleGeniusBarReservation.Init_stores_list() for index, item in self.stores.items(): self.store_suburl[item[0]] = item[1] self.storelist.append(item[0]) self.reservTypes = ["serviceType_iPhone", "serviceType_iPad", "serviceType_iPod", "serviceType_Mac"] def fillTaskView(self, task): accounts = task.getAccounts() rowCount = len(accounts) if rowCount is not 0: self.preSelectedRow = 0 # self.ui.gBListName.setTitle(unicode(task.taskName)) self.taskTableWidget.setRowCount(rowCount) row = 0 for count in accounts: item = QtGui.QTableWidgetItem() item.setText(count['appleid']) self.taskTableWidget.setItem(row, 0, item) item = QtGui.QTableWidgetItem() item.setText("0") self.taskTableWidget.setItem(row, 1, item) self.appleIdToProgresscell[count['appleid']] = item item = QtGui.QTableWidgetItem() item.setText(task.proxyServer) self.taskTableWidget.setItem(row, 2, item) item = QtGui.QTableWidgetItem() item.setText(unicode(task.storeName)) self.taskTableWidget.setItem(row, 3, item) item = QtGui.QTableWidgetItem() item.setText(task.reservType) self.taskTableWidget.setItem(row, 4, item) row += 1 def getTaskPool(self): poolSize = multiprocessing.cpu_count() * 2 return Pool(processes=poolSize) def accountManage(self): self.appContext.accountManagerDLG.exec_() # TODO: def taskManage(self): self.taskManageDLG.exec_() # TODO: def getTaskTable(self): return self.taskTableWidget def getTaskView(self): return self.taskViewWidget def twTasklistCellClicked(self, row, col): self.getTaskView().show() if col == 0: item = self.getTaskTable().item(row, 0) appleId = item.text() progress = self.getTaskTable().item(row, 1) progress = progress.text() self.progressBar.setValue(int(progress)) account = self.appContext.accountManager.getAccount(appleId) if account: self.lEPhoneNumber.setText(account['phonenumber']) if int(progress) == 100: self.fillResultView(appleId) self.preSelectedRow = row def getTasksInfo(self, geniusBar=True): taskName = self.appContext.getCurrentTaskName() task = self.appContext.taskManageDLG.tasks[str(taskName)] accounts = task.getAccounts() storeName = task.storeName reservType = task.reservType suburl = self.store_suburl[unicode(storeName)] storeUrl = AppleGeniusBarReservation.Get_store_url(suburl) url = None if geniusBar: url = AppleGeniusBarReservation.Get_suppport_url(storeUrl) else: url = AppleGeniusBarReservation.Get_workshops_url(storeUrl) loginDatas = [] for account in accounts: loginData = {} loginData['appleId'] = account['appleid'] loginData['accountPassword'] = account['passwd'] loginData['phoneNumber'] = account['phonenumber'] loginData['governmentID'] = account['governmentid'] loginData['governmentIDType'] = 'CN.PRCID' loginData['reservType'] = reservType loginData['storeName'] = storeName loginData['enterUrl'] = url loginData['storeUrl'] = storeUrl loginDatas.append(loginData) return loginDatas def createOpener(self): import urllib2 cookie = cookielib.CookieJar() cookie_support = urllib2.HTTPCookieProcessor(cookie) opener = urllib2.build_opener(cookie_support) return opener def startTask(self): self.reserverResult.stopAllTask() self.running = True self.disableStart() geniusBar = True loginDatas = self.getTasksInfo(geniusBar=geniusBar) self.statusTasks = [] self.finishedAppleId = [] pool = self.getTaskPool() for loginData in loginDatas: apy = ApplyTask(loginData) self.applyTasks.append(apy) taskStatus = Manager().dict() taskStatus['prompInfo'] = '' taskStatus['verifyCodeData'] = '' taskStatus['appleId'] = loginData['appleId'] taskStatus['taskProgress'] = '0' taskStatus['taskCmd'] = None taskStatus['cmdStatus'] = None taskStatus['storeUrl'] = loginData['storeUrl'] taskStatus['timeSlots'] = None # timeslot id taskStatus['id'] = None self.statusTasks.append(taskStatus) taskResult = Manager().dict() taskResult['appleId'] = loginData['appleId'] self.finishedAppleId.append(taskStatus) pool.apply_async(Reserver, (apy, taskStatus, geniusBar)) pool.close() debug.debug('have %s task' % len(self.statusTasks)) checking = threading.Thread(target=self.checking, args=(self.statusTasks, self.finishedAppleId)) checking.start() self.twTasklistCellClicked(0, 0) def updateProgress(self, appleId, progress): item = self.appleIdToProgresscell[str(appleId)] item.setText(progress) self.updateCurrentApplIdProgress(appleId) def updateCurrentApplIdProgress(self, appleId): rowindex = self.getTaskTable().currentRow() if rowindex == -1: if self.preSelectedRow: rowindex = self.preSelectedRow else: rowindex = 0 self.preSelectedRow = rowindex appleIdItem = self.getTaskTable().item(rowindex, 0) appleId = appleIdItem.text() progressItem = self.getTaskTable().item(rowindex, 1) progress = int(progressItem.text()) # self.getProcessBar().setValue(progress) self.progressBar.setValue(progress) if progress == 100: self.fillResultView(appleId) time.sleep(1) def __getattr__(self, name): ret = getattr(self.taskTableWidget, name) if not ret: ret = getattr(self.taskViewWidget, name) return ret def fillResultView(self, appleId): currentTaskName = self.appContext.getCurrentTaskName() results = self.reserverResult.getData(currentTaskName) if not results: debug.info('Can not find %s' % currentTaskName) return findResult = None for result in results: if appleId in result.values(): findResult = result if not findResult: debug.error('can not found verifyData %s,%s' % (appleId, currentTaskName)) return verifyData = findResult['verifyCodeData'] if verifyData: self.fillVerifyCodePic(verifyData) else: debug.debug('can not get verfiy pic') smsMsg = findResult['smsMsg'] if smsMsg: self.pTSmsChallengeTip.setPlainText(smsMsg) else: debug.error('Can not found smsMsg %s %s' % (appleId, currentTaskName)) def getTaskResult(self, appleId): currentTaskName = self.appContext.getCurrentTaskName() results = self.reserverResult.getData(currentTaskName) if not results: debug.info('Can not find %s' % currentTaskName) return findResult = None for result in results: if appleId in result.values(): findResult = result if not findResult: debug.error('can not found verifyData %s,%s' % (appleId, currentTaskName)) return return findResult def fillVerifyCodePic(self, verifyData): image = QtGui.QImage.fromData(verifyData) pixmap = QtGui.QPixmap(image) size = QSize(pixmap.width(), pixmap.height()) # self.ui.lbVerifyCodePic self.lbVerifyCodePic.resize(size) # self.ui.lbVerifyCodePic.setPixmap(pixmap) self.lbVerifyCodePic.setPixmap(pixmap) def checking(self, statusTasks, finished): while statusTasks: for index, statusTask in enumerate(statusTasks): progress = str(statusTask['taskProgress']) appleId = statusTask['appleId'] debug.debug('checking %s %s' % (appleId, progress)) if progress == '100': for status in finished: if status['appleId'] == appleId: status = dict(status, **statusTasks[index]) time.sleep(1) self.signalStoreResult.emit(appleId) time.sleep(2) del statusTasks[index] self.signalUpdateProgress.emit(appleId, progress) time.sleep(3) debug.info('Terminal check %s' % self.appContext.getCurrentTaskName()) self.enableStart() def storeResult(self, appleId): debug.debug('store result') curTask = self.appContext.getCurrentTaskName() for status in self.finishedAppleId: if status['appleId'] == appleId: debug.debug('save task %s %s' % (curTask, appleId)) result = { 'appleId': appleId, 'smsMsg': status['prompInfo'], 'verifyCodeData': status['verifyCodeData']} self.reserverResult.add(curTask, result) def closeEvent(self, event): ''' save the current task list ''' task = self.appContext.getCurrentTask() self.appContext.taskManageDLG._storeToDefault(task) def importTask(self): ret = self.appContext.tasklistDLG.exec_() if ret == 0: return tasks = self.appContext.tasklistDLG.getTasks() if tasks: self.fillTaskView(tasks[0]) self.appContext.setCurrentTask(tasks[0]) self.enableStart() def enableStart(self): self.ui.action_start_task.setEnabled(True) def disableStart(self): self.ui.action_start_task.setEnabled(False) def _getCurrentAppleId(self): row = self.preSelectedRow if row == -1: row = self.getTaskTable().currentRow() if row == -1: return self.preSelectedRow = row appleid = self.getTaskTable().item(row, 0).text() return appleid def _getCurrentTaskStatus(self): appleid = self._getCurrentAppleId() for taskstatus in self.finishedAppleId: if taskstatus['appleId'] == appleid: return taskstatus def refresh(self): # appleid = self._getCurrentAppleId() taskstatus = self._getCurrentTaskStatus() if not taskstatus: return appleid = taskstatus['appleId'] taskstatus['verifyCodeData'] = None if taskstatus: taskstatus['taskCmd'] = 'refresh' time.sleep(2) data = taskstatus['verifyCodeData'] counter = 3 while not data and counter > 0: time.sleep(1) data = taskstatus['verifyCodeData'] counter -= 1 if data: self.fillVerifyCodePic(data) taskname = self.appContext.getCurrentTaskName() self.reserverResult.update(taskname, appleid, 'verifyCodeData', data) taskstatus['verifyCodeData'] = None else: debug.info('refresh failed') taskstatus['taskCmd'] = None def selectTimeSlot(self, timeSlotId): '''post the timeslot data''' taskStatus = self._getCurrentTaskStatus() if taskStatus: taskStatus['id'] = timeSlotId taskStatus['taskCmd'] = 'timeslot' taskStatus['clientTimezone'] = 'Asia/Shanghai' taskStatus['cmdStatus'] = None timer = 30 while not taskStatus['cmdStatus'] and timer > 0: time.sleep(1) timer -= 1 if taskStatus['cmdStatus'] == 'OK': # result = self.getTaskResult(taskStatus['appleId']) self.addReservResult(taskStatus['appleId'], taskStatus['prompInfo']) elif taskStatus['cmdStatus'] == 'NOK': debug.error('selected time error') else: debug.error('selectTimeSlot failed') def addReservResult(self, appleId, info): row = self.reservResultTable.ui.tableWidget.rowCount()+1 self.reservResultTable.ui.tableWidget.setRowCount(row) accountitem = QtGui.QTableWidgetItem() accountitem.setText(QString(appleId)) item = QtGui.QTableWidgetItem() item.setText(QString(info)) self.reservResultTable.ui.tableWidget.setItem(row-1, 0, accountitem) self.reservResultTable.ui.tableWidget.setItem(row-1, 1, item) def submit(self): taskStatus = self._getCurrentTaskStatus() if taskStatus: captcha = self.lECaptchaAnswer.text() taskStatus['captchaAnswer'] = str(captcha) phoneNumber = self.lEPhoneNumber.text() taskStatus['phoneNumber'] = str(phoneNumber) taskStatus['smsCode'] = str(self.lESmsCode.text()) taskStatus['clientTimezone'] = 'Asia/Shanghai' taskStatus['countryISDCode'] = '86' taskStatus['cmdStatus'] = None taskStatus['taskCmd'] = 'submit' timer = 30 while not taskStatus['cmdStatus'] and timer > 0: time.sleep(1) #debug.debug('check cmdStatus') timer -= 1 print('end check cmdStatus') if taskStatus['cmdStatus'] == 'NOK': debug.info('submit error') debug.info(taskStatus['prompInfo']) self.refresh() elif taskStatus['cmdStatus'] == 'OK': result = taskStatus['timeSlots'] self.fillTableWidget(result[0], result[1]) self.showTimeSlots(1) else: debug.error('submit task error') else: debug.error('submit error') def isCmdOk(self, status): return status['cmdStatus'] == 'OK' def showTimeSlots(self, index=1): self.taskViewWidget.show() self.taskViewWidget.stackedWidget.setCurrentIndex(index) def showTaskResult(self, index=0): self.taskViewWidget.show() self.taskViewWidget.stackedWidget.setCurrentIndex(index) def viewDetail(self): self.taskViewWidget.show() if self.taskViewWidget.stackedWidget.currentIndex() == 0: self.taskViewWidget.stackedWidget.setCurrentIndex(1) else: self.taskViewWidget.stackedWidget.setCurrentIndex(1)
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.setWindowModality(QtCore.Qt.WindowModal) MainWindow.resize(977, 656) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/img/hack.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 971, 51)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.horizontalLayout = QtWidgets.QHBoxLayout( self.horizontalLayoutWidget) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") self.label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.edit_username = QtWidgets.QLineEdit(self.horizontalLayoutWidget) self.edit_username.setObjectName("edit_username") self.horizontalLayout.addWidget(self.edit_username) self.label_2 = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) self.edit_password = QtWidgets.QLineEdit(self.horizontalLayoutWidget) self.edit_password.setObjectName("edit_password") self.horizontalLayout.addWidget(self.edit_password) self.lb_auth_img = ClickedLabel(self.horizontalLayoutWidget) self.lb_auth_img.setMinimumSize(QtCore.QSize(100, 24)) self.lb_auth_img.setMaximumSize(QtCore.QSize(100, 40)) self.lb_auth_img.setStyleSheet("background-color:white") self.lb_auth_img.setText("") self.lb_auth_img.setObjectName("lb_auth_img") self.horizontalLayout.addWidget(self.lb_auth_img) self.label_3 = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label_3.setObjectName("label_3") self.horizontalLayout.addWidget(self.label_3) self.edit_auth_code = QtWidgets.QLineEdit(self.horizontalLayoutWidget) self.edit_auth_code.setMaximumSize(QtCore.QSize(60, 16777215)) self.edit_auth_code.setObjectName("edit_auth_code") self.horizontalLayout.addWidget(self.edit_auth_code) self.loginBtn = QtWidgets.QPushButton(self.horizontalLayoutWidget) self.loginBtn.setObjectName("loginBtn") self.horizontalLayout.addWidget(self.loginBtn) self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect( 0, 50, 971, 581)) self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2") self.horizontalLayout_2 = QtWidgets.QHBoxLayout( self.horizontalLayoutWidget_2) self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.groupBox = QtWidgets.QGroupBox(self.horizontalLayoutWidget_2) self.groupBox.setMinimumSize(QtCore.QSize(600, 0)) self.groupBox.setObjectName("groupBox") self.memo = QtWidgets.QTextEdit(self.groupBox) self.memo.setGeometry(QtCore.QRect(10, 20, 581, 551)) self.memo.setObjectName("memo") self.horizontalLayout_2.addWidget(self.groupBox) self.groupBox_2 = QtWidgets.QGroupBox(self.horizontalLayoutWidget_2) self.groupBox_2.setObjectName("groupBox_2") self.lb_speed_num = QtWidgets.QLabel(self.groupBox_2) self.lb_speed_num.setGeometry(QtCore.QRect(201, 20, 71, 20)) self.lb_speed_num.setObjectName("lb_speed_num") self.group_query = QtWidgets.QGroupBox(self.groupBox_2) self.group_query.setGeometry(QtCore.QRect(10, 50, 341, 101)) self.group_query.setObjectName("group_query") self.edit_from_station = QtWidgets.QLineEdit(self.group_query) self.edit_from_station.setGeometry(QtCore.QRect(20, 20, 71, 21)) self.edit_from_station.setObjectName("edit_from_station") self.lb_to = QtWidgets.QLabel(self.group_query) self.lb_to.setGeometry(QtCore.QRect(100, 20, 21, 16)) self.lb_to.setObjectName("lb_to") self.edit_to_station = QtWidgets.QLineEdit(self.group_query) self.edit_to_station.setGeometry(QtCore.QRect(130, 20, 71, 21)) self.edit_to_station.setObjectName("edit_to_station") self.dateControl = QtWidgets.QDateEdit(self.group_query) self.dateControl.setGeometry(QtCore.QRect(210, 20, 111, 21)) self.dateControl.setMinimumDate(QtCore.QDate(2014, 1, 1)) self.dateControl.setDate(QtCore.QDate(2014, 9, 14)) self.dateControl.setObjectName("dateControl") self.searchBtn = QtWidgets.QToolButton(self.group_query) self.searchBtn.setGeometry(QtCore.QRect(80, 60, 71, 31)) self.searchBtn.setCheckable(True) self.searchBtn.setChecked(False) self.searchBtn.setAutoRepeat(False) self.searchBtn.setObjectName("searchBtn") self.lb_buy_img = ClickedLabel(self.group_query) self.lb_buy_img.setGeometry(QtCore.QRect(230, 50, 100, 40)) self.lb_buy_img.setMinimumSize(QtCore.QSize(100, 24)) self.lb_buy_img.setMaximumSize(QtCore.QSize(100, 40)) self.lb_buy_img.setStyleSheet("background-color:white") self.lb_buy_img.setText("") self.lb_buy_img.setObjectName("lb_buy_img") self.groupBox_4 = QtWidgets.QGroupBox(self.groupBox_2) self.groupBox_4.setGeometry(QtCore.QRect(10, 160, 351, 351)) self.groupBox_4.setObjectName("groupBox_4") self.passager_table = TableWidget(self.groupBox_4) self.passager_table.setGeometry(QtCore.QRect(10, 20, 331, 221)) font = QtGui.QFont() font.setPointSize(7) self.passager_table.setFont(font) self.passager_table.setSelectionMode( QtWidgets.QAbstractItemView.SingleSelection) self.passager_table.setSelectionBehavior( QtWidgets.QAbstractItemView.SelectRows) self.passager_table.setGridStyle(QtCore.Qt.DashLine) self.passager_table.setObjectName("passager_table") self.passager_table.setColumnCount(5) self.passager_table.setRowCount(0) item = QtWidgets.QTableWidgetItem() font = QtGui.QFont() font.setFamily("Aharoni") font.setPointSize(6) font.setBold(True) font.setWeight(75) item.setFont(font) self.passager_table.setHorizontalHeaderItem(0, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(1, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(2, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(3, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(4, item) self.passager_table.horizontalHeader().setVisible(True) self.passager_table.horizontalHeader().setDefaultSectionSize(82) self.passager_table.horizontalHeader().setHighlightSections(False) self.passager_table.horizontalHeader().setMinimumSectionSize(1) self.passager_table.verticalHeader().setVisible(False) self.passager_table.verticalHeader().setDefaultSectionSize(30) self.passager_table.verticalHeader().setMinimumSectionSize(20) self.cb_first_seat = QtWidgets.QCheckBox(self.groupBox_4) self.cb_first_seat.setGeometry(QtCore.QRect(20, 250, 91, 19)) self.cb_first_seat.setObjectName("cb_first_seat") self.cb_second_seat = QtWidgets.QCheckBox(self.groupBox_4) self.cb_second_seat.setGeometry(QtCore.QRect(120, 250, 91, 19)) self.cb_second_seat.setChecked(True) self.cb_second_seat.setObjectName("cb_second_seat") self.cb_soft_bed = QtWidgets.QCheckBox(self.groupBox_4) self.cb_soft_bed.setGeometry(QtCore.QRect(20, 270, 91, 19)) self.cb_soft_bed.setObjectName("cb_soft_bed") self.cb_hard_bed = QtWidgets.QCheckBox(self.groupBox_4) self.cb_hard_bed.setGeometry(QtCore.QRect(120, 270, 91, 19)) self.cb_hard_bed.setChecked(True) self.cb_hard_bed.setObjectName("cb_hard_bed") self.cb_hard_seat = QtWidgets.QCheckBox(self.groupBox_4) self.cb_hard_seat.setGeometry(QtCore.QRect(20, 290, 91, 19)) self.cb_hard_seat.setChecked(True) self.cb_hard_seat.setObjectName("cb_hard_seat") self.cb_stand = QtWidgets.QCheckBox(self.groupBox_4) self.cb_stand.setGeometry(QtCore.QRect(120, 290, 91, 19)) self.cb_stand.setObjectName("cb_stand") self.edit_train_num = QtWidgets.QLineEdit(self.groupBox_4) self.edit_train_num.setGeometry(QtCore.QRect(100, 320, 241, 21)) self.edit_train_num.setObjectName("edit_train_num") self.label_4 = QtWidgets.QLabel(self.groupBox_4) self.label_4.setGeometry(QtCore.QRect(20, 320, 72, 15)) self.label_4.setObjectName("label_4") self.groupBox_5 = QtWidgets.QGroupBox(self.groupBox_2) self.groupBox_5.setGeometry(QtCore.QRect(10, 520, 261, 51)) self.groupBox_5.setObjectName("groupBox_5") self.btn_my_blog = QtWidgets.QPushButton(self.groupBox_5) self.btn_my_blog.setGeometry(QtCore.QRect(10, 20, 81, 21)) font = QtGui.QFont() font.setFamily("微软雅黑") font.setPointSize(7) self.btn_my_blog.setFont(font) self.btn_my_blog.setObjectName("btn_my_blog") self.btn_url_12306 = QtWidgets.QPushButton(self.groupBox_5) self.btn_url_12306.setGeometry(QtCore.QRect(140, 20, 81, 21)) font = QtGui.QFont() font.setFamily("微软雅黑") font.setPointSize(7) self.btn_url_12306.setFont(font) self.btn_url_12306.setObjectName("btn_url_12306") self.lb_speed = QtWidgets.QLabel(self.groupBox_2) self.lb_speed.setGeometry(QtCore.QRect(12, 22, 72, 16)) self.lb_speed.setObjectName("lb_speed") self.slider = QtWidgets.QSlider(self.groupBox_2) self.slider.setGeometry(QtCore.QRect(61, 22, 131, 20)) self.slider.setMinimum(1) self.slider.setMaximum(10) self.slider.setSingleStep(1) self.slider.setPageStep(1) self.slider.setProperty("value", 4) self.slider.setTracking(True) self.slider.setOrientation(QtCore.Qt.Horizontal) self.slider.setInvertedAppearance(False) self.slider.setInvertedControls(False) self.slider.setTickPosition(QtWidgets.QSlider.TicksAbove) self.slider.setTickInterval(1) self.slider.setObjectName("slider") self.cb_rob_mode = QtWidgets.QCheckBox(self.groupBox_2) self.cb_rob_mode.setGeometry(QtCore.QRect(250, 20, 91, 19)) self.cb_rob_mode.setObjectName("cb_rob_mode") self.horizontalLayout_2.addWidget(self.groupBox_2) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 977, 26)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def setupResultTable(self): headers = [u'账号', u'预约信息'] self.reservResultTable = TableWidget(headers=headers)
def setupTaskTable(self): headers = [u"账号", u"进度", u"代理", u"零售店", u"服务类型"] self.taskTableWidget = TableWidget(headers=headers)
class MainWindow(QtGui.QMainWindow): signalViewTask = pyqtSignal(int) signalUpdateProgress = pyqtSignal(str, str) signalStoreResult = pyqtSignal(str) # sigUpdateCurrentId = pyqtSignal() sigUpdateProgressBar = pyqtSignal(str) def setupTaskTable(self): headers = [u"账号", u"进度", u"代理", u"零售店", u"服务类型"] self.taskTableWidget = TableWidget(headers=headers) def setupResultTable(self): headers = [u'账号', u'预约信息'] self.reservResultTable = TableWidget(headers=headers) def setupViews(self): splitter = QSplitter() self.setupTaskTable() splitter.addWidget(self.taskTableWidget) self.taskViewWidget = taskviewwidget.TaskViewWidget() splitter.addWidget(self.taskViewWidget) splitter.setStretchFactor(0, 0) splitter.setStretchFactor(1, 1) self.setCentralWidget(splitter) self.taskViewWidget.hide() self.msgLabel = QLabel() self.statusBar().addWidget(self.msgLabel) def setupViews2(self): self.setupTaskTable() msplitter = QSplitter(Qt.Horizontal) msplitter.addWidget(self.taskTableWidget) rsplitter = QSplitter(Qt.Vertical, msplitter) self.setupResultTable() rsplitter.addWidget(self.reservResultTable) self.taskViewWidget = taskviewwidget.TaskViewWidget() rsplitter.addWidget(self.taskViewWidget) self.setCentralWidget(msplitter) self.msgLabel = QLabel() self.statusBar().addWidget(self.msgLabel) def __init__(self, abscwd, parent=None): super(MainWindow, self).__init__(parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.setupViews2() self.appContext = AppContext(abscwd, self) self.setupMembers() self.setupSig2Slot() def setupMembers(self): self.reserverResult = ReserverResult() self.preSelectedRow = None self.store_suburl = {} self.storelist = [] self.finishedAppleId = [] self.initStoreData() self.running = False # ################################### accountfile = self.appContext.getAccountFile() self.appContext.accountManager = AccountManager(accountfile) self.appContext.accountManagerDLG = AccountManagerDLG(self.appContext) self.appContext.accountListDLG = AccountListDLG(self.appContext) self.taskManageDLG = TaskManageDLG(self.appContext, self.storelist, self.reservTypes) self.appContext.taskManageDLG = self.taskManageDLG self.appContext.tasklistDLG = TaskListDLG(self.appContext) # the apply process self.applyTasks = [] self.appleIdToProgresscell = {} # = {id, item} task = self.taskManageDLG.getDefaultTask() if task: self.appContext.setCurrentTask(task) self.fillTaskView(task) def setupSig2Slot(self): self.signalUpdateProgress.connect(self.updateProgress) self.signalStoreResult.connect(self.storeResult) # self.sigUpdateCurrentId.connect(self.updateCurrentApplIdProgress) self.sigTimeSlot.connect(self.selectTimeSlot) self.pBSubmit.clicked.connect(self.submit) self.pBRefresh.clicked.connect(self.refresh) self.taskTableWidget.cellClicked.connect(self.twTasklistCellClicked) def initStoreData(self): # the store name of each url self.stores = AppleGeniusBarReservation.Init_stores_list() for index, item in self.stores.items(): self.store_suburl[item[0]] = item[1] self.storelist.append(item[0]) self.reservTypes = [ "serviceType_iPhone", "serviceType_iPad", "serviceType_iPod", "serviceType_Mac" ] def fillTaskView(self, task): accounts = task.getAccounts() rowCount = len(accounts) if rowCount is not 0: self.preSelectedRow = 0 # self.ui.gBListName.setTitle(unicode(task.taskName)) self.taskTableWidget.setRowCount(rowCount) row = 0 for count in accounts: item = QtGui.QTableWidgetItem() item.setText(count['appleid']) self.taskTableWidget.setItem(row, 0, item) item = QtGui.QTableWidgetItem() item.setText("0") self.taskTableWidget.setItem(row, 1, item) self.appleIdToProgresscell[count['appleid']] = item item = QtGui.QTableWidgetItem() item.setText(task.proxyServer) self.taskTableWidget.setItem(row, 2, item) item = QtGui.QTableWidgetItem() item.setText(unicode(task.storeName)) self.taskTableWidget.setItem(row, 3, item) item = QtGui.QTableWidgetItem() item.setText(task.reservType) self.taskTableWidget.setItem(row, 4, item) row += 1 def getTaskPool(self): poolSize = multiprocessing.cpu_count() * 2 return Pool(processes=poolSize) def accountManage(self): self.appContext.accountManagerDLG.exec_() # TODO: def taskManage(self): self.taskManageDLG.exec_() # TODO: def getTaskTable(self): return self.taskTableWidget def getTaskView(self): return self.taskViewWidget def twTasklistCellClicked(self, row, col): self.getTaskView().show() if col == 0: item = self.getTaskTable().item(row, 0) appleId = item.text() progress = self.getTaskTable().item(row, 1) progress = progress.text() self.progressBar.setValue(int(progress)) account = self.appContext.accountManager.getAccount(appleId) if account: self.lEPhoneNumber.setText(account['phonenumber']) if int(progress) == 100: self.fillResultView(appleId) self.preSelectedRow = row def getTasksInfo(self, geniusBar=True): taskName = self.appContext.getCurrentTaskName() task = self.appContext.taskManageDLG.tasks[str(taskName)] accounts = task.getAccounts() storeName = task.storeName reservType = task.reservType suburl = self.store_suburl[unicode(storeName)] storeUrl = AppleGeniusBarReservation.Get_store_url(suburl) url = None if geniusBar: url = AppleGeniusBarReservation.Get_suppport_url(storeUrl) else: url = AppleGeniusBarReservation.Get_workshops_url(storeUrl) loginDatas = [] for account in accounts: loginData = {} loginData['appleId'] = account['appleid'] loginData['accountPassword'] = account['passwd'] loginData['phoneNumber'] = account['phonenumber'] loginData['governmentID'] = account['governmentid'] loginData['governmentIDType'] = 'CN.PRCID' loginData['reservType'] = reservType loginData['storeName'] = storeName loginData['enterUrl'] = url loginData['storeUrl'] = storeUrl loginDatas.append(loginData) return loginDatas def createOpener(self): import urllib2 cookie = cookielib.CookieJar() cookie_support = urllib2.HTTPCookieProcessor(cookie) opener = urllib2.build_opener(cookie_support) return opener def startTask(self): self.reserverResult.stopAllTask() self.running = True self.disableStart() geniusBar = True loginDatas = self.getTasksInfo(geniusBar=geniusBar) self.statusTasks = [] self.finishedAppleId = [] pool = self.getTaskPool() for loginData in loginDatas: apy = ApplyTask(loginData) self.applyTasks.append(apy) taskStatus = Manager().dict() taskStatus['prompInfo'] = '' taskStatus['verifyCodeData'] = '' taskStatus['appleId'] = loginData['appleId'] taskStatus['taskProgress'] = '0' taskStatus['taskCmd'] = None taskStatus['cmdStatus'] = None taskStatus['storeUrl'] = loginData['storeUrl'] taskStatus['timeSlots'] = None # timeslot id taskStatus['id'] = None self.statusTasks.append(taskStatus) taskResult = Manager().dict() taskResult['appleId'] = loginData['appleId'] self.finishedAppleId.append(taskStatus) pool.apply_async(Reserver, (apy, taskStatus, geniusBar)) pool.close() debug.debug('have %s task' % len(self.statusTasks)) checking = threading.Thread(target=self.checking, args=(self.statusTasks, self.finishedAppleId)) checking.start() self.twTasklistCellClicked(0, 0) def updateProgress(self, appleId, progress): item = self.appleIdToProgresscell[str(appleId)] item.setText(progress) self.updateCurrentApplIdProgress(appleId) def updateCurrentApplIdProgress(self, appleId): rowindex = self.getTaskTable().currentRow() if rowindex == -1: if self.preSelectedRow: rowindex = self.preSelectedRow else: rowindex = 0 self.preSelectedRow = rowindex appleIdItem = self.getTaskTable().item(rowindex, 0) appleId = appleIdItem.text() progressItem = self.getTaskTable().item(rowindex, 1) progress = int(progressItem.text()) # self.getProcessBar().setValue(progress) self.progressBar.setValue(progress) if progress == 100: self.fillResultView(appleId) time.sleep(1) def __getattr__(self, name): ret = getattr(self.taskTableWidget, name) if not ret: ret = getattr(self.taskViewWidget, name) return ret def fillResultView(self, appleId): currentTaskName = self.appContext.getCurrentTaskName() results = self.reserverResult.getData(currentTaskName) if not results: debug.info('Can not find %s' % currentTaskName) return findResult = None for result in results: if appleId in result.values(): findResult = result if not findResult: debug.error('can not found verifyData %s,%s' % (appleId, currentTaskName)) return verifyData = findResult['verifyCodeData'] if verifyData: self.fillVerifyCodePic(verifyData) else: debug.debug('can not get verfiy pic') smsMsg = findResult['smsMsg'] if smsMsg: self.pTSmsChallengeTip.setPlainText(smsMsg) else: debug.error('Can not found smsMsg %s %s' % (appleId, currentTaskName)) def getTaskResult(self, appleId): currentTaskName = self.appContext.getCurrentTaskName() results = self.reserverResult.getData(currentTaskName) if not results: debug.info('Can not find %s' % currentTaskName) return findResult = None for result in results: if appleId in result.values(): findResult = result if not findResult: debug.error('can not found verifyData %s,%s' % (appleId, currentTaskName)) return return findResult def fillVerifyCodePic(self, verifyData): image = QtGui.QImage.fromData(verifyData) pixmap = QtGui.QPixmap(image) size = QSize(pixmap.width(), pixmap.height()) # self.ui.lbVerifyCodePic self.lbVerifyCodePic.resize(size) # self.ui.lbVerifyCodePic.setPixmap(pixmap) self.lbVerifyCodePic.setPixmap(pixmap) def checking(self, statusTasks, finished): while statusTasks: for index, statusTask in enumerate(statusTasks): progress = str(statusTask['taskProgress']) appleId = statusTask['appleId'] debug.debug('checking %s %s' % (appleId, progress)) if progress == '100': for status in finished: if status['appleId'] == appleId: status = dict(status, **statusTasks[index]) time.sleep(1) self.signalStoreResult.emit(appleId) time.sleep(2) del statusTasks[index] self.signalUpdateProgress.emit(appleId, progress) time.sleep(3) debug.info('Terminal check %s' % self.appContext.getCurrentTaskName()) self.enableStart() def storeResult(self, appleId): debug.debug('store result') curTask = self.appContext.getCurrentTaskName() for status in self.finishedAppleId: if status['appleId'] == appleId: debug.debug('save task %s %s' % (curTask, appleId)) result = { 'appleId': appleId, 'smsMsg': status['prompInfo'], 'verifyCodeData': status['verifyCodeData'] } self.reserverResult.add(curTask, result) def closeEvent(self, event): ''' save the current task list ''' task = self.appContext.getCurrentTask() self.appContext.taskManageDLG._storeToDefault(task) def importTask(self): ret = self.appContext.tasklistDLG.exec_() if ret == 0: return tasks = self.appContext.tasklistDLG.getTasks() if tasks: self.fillTaskView(tasks[0]) self.appContext.setCurrentTask(tasks[0]) self.enableStart() def enableStart(self): self.ui.action_start_task.setEnabled(True) def disableStart(self): self.ui.action_start_task.setEnabled(False) def _getCurrentAppleId(self): row = self.preSelectedRow if row == -1: row = self.getTaskTable().currentRow() if row == -1: return self.preSelectedRow = row appleid = self.getTaskTable().item(row, 0).text() return appleid def _getCurrentTaskStatus(self): appleid = self._getCurrentAppleId() for taskstatus in self.finishedAppleId: if taskstatus['appleId'] == appleid: return taskstatus def refresh(self): # appleid = self._getCurrentAppleId() taskstatus = self._getCurrentTaskStatus() if not taskstatus: return appleid = taskstatus['appleId'] taskstatus['verifyCodeData'] = None if taskstatus: taskstatus['taskCmd'] = 'refresh' time.sleep(2) data = taskstatus['verifyCodeData'] counter = 3 while not data and counter > 0: time.sleep(1) data = taskstatus['verifyCodeData'] counter -= 1 if data: self.fillVerifyCodePic(data) taskname = self.appContext.getCurrentTaskName() self.reserverResult.update(taskname, appleid, 'verifyCodeData', data) taskstatus['verifyCodeData'] = None else: debug.info('refresh failed') taskstatus['taskCmd'] = None def selectTimeSlot(self, timeSlotId): '''post the timeslot data''' taskStatus = self._getCurrentTaskStatus() if taskStatus: taskStatus['id'] = timeSlotId taskStatus['taskCmd'] = 'timeslot' taskStatus['clientTimezone'] = 'Asia/Shanghai' taskStatus['cmdStatus'] = None timer = 30 while not taskStatus['cmdStatus'] and timer > 0: time.sleep(1) timer -= 1 if taskStatus['cmdStatus'] == 'OK': # result = self.getTaskResult(taskStatus['appleId']) self.addReservResult(taskStatus['appleId'], taskStatus['prompInfo']) elif taskStatus['cmdStatus'] == 'NOK': debug.error('selected time error') else: debug.error('selectTimeSlot failed') def addReservResult(self, appleId, info): row = self.reservResultTable.ui.tableWidget.rowCount() + 1 self.reservResultTable.ui.tableWidget.setRowCount(row) accountitem = QtGui.QTableWidgetItem() accountitem.setText(QString(appleId)) item = QtGui.QTableWidgetItem() item.setText(QString(info)) self.reservResultTable.ui.tableWidget.setItem(row - 1, 0, accountitem) self.reservResultTable.ui.tableWidget.setItem(row - 1, 1, item) def submit(self): taskStatus = self._getCurrentTaskStatus() if taskStatus: captcha = self.lECaptchaAnswer.text() taskStatus['captchaAnswer'] = str(captcha) phoneNumber = self.lEPhoneNumber.text() taskStatus['phoneNumber'] = str(phoneNumber) taskStatus['smsCode'] = str(self.lESmsCode.text()) taskStatus['clientTimezone'] = 'Asia/Shanghai' taskStatus['countryISDCode'] = '86' taskStatus['cmdStatus'] = None taskStatus['taskCmd'] = 'submit' timer = 30 while not taskStatus['cmdStatus'] and timer > 0: time.sleep(1) #debug.debug('check cmdStatus') timer -= 1 print('end check cmdStatus') if taskStatus['cmdStatus'] == 'NOK': debug.info('submit error') debug.info(taskStatus['prompInfo']) self.refresh() elif taskStatus['cmdStatus'] == 'OK': result = taskStatus['timeSlots'] self.fillTableWidget(result[0], result[1]) self.showTimeSlots(1) else: debug.error('submit task error') else: debug.error('submit error') def isCmdOk(self, status): return status['cmdStatus'] == 'OK' def showTimeSlots(self, index=1): self.taskViewWidget.show() self.taskViewWidget.stackedWidget.setCurrentIndex(index) def showTaskResult(self, index=0): self.taskViewWidget.show() self.taskViewWidget.stackedWidget.setCurrentIndex(index) def viewDetail(self): self.taskViewWidget.show() if self.taskViewWidget.stackedWidget.currentIndex() == 0: self.taskViewWidget.stackedWidget.setCurrentIndex(1) else: self.taskViewWidget.stackedWidget.setCurrentIndex(1)
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.setWindowModality(QtCore.Qt.WindowModal) MainWindow.resize(977, 656) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/img/hack.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 971, 51)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") self.label = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label.setObjectName("label") self.horizontalLayout.addWidget(self.label) self.edit_username = QtWidgets.QLineEdit(self.horizontalLayoutWidget) self.edit_username.setObjectName("edit_username") self.horizontalLayout.addWidget(self.edit_username) self.label_2 = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label_2.setObjectName("label_2") self.horizontalLayout.addWidget(self.label_2) self.edit_password = QtWidgets.QLineEdit(self.horizontalLayoutWidget) self.edit_password.setObjectName("edit_password") self.horizontalLayout.addWidget(self.edit_password) self.lb_auth_img = ClickedLabel(self.horizontalLayoutWidget) self.lb_auth_img.setMinimumSize(QtCore.QSize(100, 24)) self.lb_auth_img.setMaximumSize(QtCore.QSize(100, 40)) self.lb_auth_img.setStyleSheet("background-color:white") self.lb_auth_img.setText("") self.lb_auth_img.setObjectName("lb_auth_img") self.horizontalLayout.addWidget(self.lb_auth_img) self.label_3 = QtWidgets.QLabel(self.horizontalLayoutWidget) self.label_3.setObjectName("label_3") self.horizontalLayout.addWidget(self.label_3) self.edit_auth_code = QtWidgets.QLineEdit(self.horizontalLayoutWidget) self.edit_auth_code.setMaximumSize(QtCore.QSize(60, 16777215)) self.edit_auth_code.setObjectName("edit_auth_code") self.horizontalLayout.addWidget(self.edit_auth_code) self.loginBtn = QtWidgets.QPushButton(self.horizontalLayoutWidget) self.loginBtn.setObjectName("loginBtn") self.horizontalLayout.addWidget(self.loginBtn) self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(0, 50, 971, 581)) self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2") self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2) self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.groupBox = QtWidgets.QGroupBox(self.horizontalLayoutWidget_2) self.groupBox.setMinimumSize(QtCore.QSize(600, 0)) self.groupBox.setObjectName("groupBox") self.memo = QtWidgets.QTextEdit(self.groupBox) self.memo.setGeometry(QtCore.QRect(10, 20, 581, 551)) self.memo.setObjectName("memo") self.horizontalLayout_2.addWidget(self.groupBox) self.groupBox_2 = QtWidgets.QGroupBox(self.horizontalLayoutWidget_2) self.groupBox_2.setObjectName("groupBox_2") self.lb_speed_num = QtWidgets.QLabel(self.groupBox_2) self.lb_speed_num.setGeometry(QtCore.QRect(201, 20, 71, 20)) self.lb_speed_num.setObjectName("lb_speed_num") self.group_query = QtWidgets.QGroupBox(self.groupBox_2) self.group_query.setGeometry(QtCore.QRect(10, 50, 341, 101)) self.group_query.setObjectName("group_query") self.edit_from_station = QtWidgets.QLineEdit(self.group_query) self.edit_from_station.setGeometry(QtCore.QRect(20, 20, 71, 21)) self.edit_from_station.setObjectName("edit_from_station") self.lb_to = QtWidgets.QLabel(self.group_query) self.lb_to.setGeometry(QtCore.QRect(100, 20, 21, 16)) self.lb_to.setObjectName("lb_to") self.edit_to_station = QtWidgets.QLineEdit(self.group_query) self.edit_to_station.setGeometry(QtCore.QRect(130, 20, 71, 21)) self.edit_to_station.setObjectName("edit_to_station") self.dateControl = QtWidgets.QDateEdit(self.group_query) self.dateControl.setGeometry(QtCore.QRect(210, 20, 111, 21)) self.dateControl.setMinimumDate(QtCore.QDate(2014, 1, 1)) self.dateControl.setDate(QtCore.QDate(2014, 9, 14)) self.dateControl.setObjectName("dateControl") self.searchBtn = QtWidgets.QToolButton(self.group_query) self.searchBtn.setGeometry(QtCore.QRect(80, 60, 71, 31)) self.searchBtn.setCheckable(True) self.searchBtn.setChecked(False) self.searchBtn.setAutoRepeat(False) self.searchBtn.setObjectName("searchBtn") self.lb_buy_img = ClickedLabel(self.group_query) self.lb_buy_img.setGeometry(QtCore.QRect(230, 50, 100, 40)) self.lb_buy_img.setMinimumSize(QtCore.QSize(100, 24)) self.lb_buy_img.setMaximumSize(QtCore.QSize(100, 40)) self.lb_buy_img.setStyleSheet("background-color:white") self.lb_buy_img.setText("") self.lb_buy_img.setObjectName("lb_buy_img") self.groupBox_4 = QtWidgets.QGroupBox(self.groupBox_2) self.groupBox_4.setGeometry(QtCore.QRect(10, 160, 351, 351)) self.groupBox_4.setObjectName("groupBox_4") self.passager_table = TableWidget(self.groupBox_4) self.passager_table.setGeometry(QtCore.QRect(10, 20, 331, 221)) font = QtGui.QFont() font.setPointSize(7) self.passager_table.setFont(font) self.passager_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) self.passager_table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.passager_table.setGridStyle(QtCore.Qt.DashLine) self.passager_table.setObjectName("passager_table") self.passager_table.setColumnCount(5) self.passager_table.setRowCount(0) item = QtWidgets.QTableWidgetItem() font = QtGui.QFont() font.setFamily("Aharoni") font.setPointSize(6) font.setBold(True) font.setWeight(75) item.setFont(font) self.passager_table.setHorizontalHeaderItem(0, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(1, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(2, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(3, item) item = QtWidgets.QTableWidgetItem() self.passager_table.setHorizontalHeaderItem(4, item) self.passager_table.horizontalHeader().setVisible(True) self.passager_table.horizontalHeader().setDefaultSectionSize(82) self.passager_table.horizontalHeader().setHighlightSections(False) self.passager_table.horizontalHeader().setMinimumSectionSize(1) self.passager_table.verticalHeader().setVisible(False) self.passager_table.verticalHeader().setDefaultSectionSize(30) self.passager_table.verticalHeader().setMinimumSectionSize(20) self.cb_first_seat = QtWidgets.QCheckBox(self.groupBox_4) self.cb_first_seat.setGeometry(QtCore.QRect(20, 250, 91, 19)) self.cb_first_seat.setObjectName("cb_first_seat") self.cb_second_seat = QtWidgets.QCheckBox(self.groupBox_4) self.cb_second_seat.setGeometry(QtCore.QRect(120, 250, 91, 19)) self.cb_second_seat.setChecked(True) self.cb_second_seat.setObjectName("cb_second_seat") self.cb_soft_bed = QtWidgets.QCheckBox(self.groupBox_4) self.cb_soft_bed.setGeometry(QtCore.QRect(20, 270, 91, 19)) self.cb_soft_bed.setObjectName("cb_soft_bed") self.cb_hard_bed = QtWidgets.QCheckBox(self.groupBox_4) self.cb_hard_bed.setGeometry(QtCore.QRect(120, 270, 91, 19)) self.cb_hard_bed.setChecked(True) self.cb_hard_bed.setObjectName("cb_hard_bed") self.cb_hard_seat = QtWidgets.QCheckBox(self.groupBox_4) self.cb_hard_seat.setGeometry(QtCore.QRect(20, 290, 91, 19)) self.cb_hard_seat.setChecked(True) self.cb_hard_seat.setObjectName("cb_hard_seat") self.cb_stand = QtWidgets.QCheckBox(self.groupBox_4) self.cb_stand.setGeometry(QtCore.QRect(120, 290, 91, 19)) self.cb_stand.setObjectName("cb_stand") self.edit_train_num = QtWidgets.QLineEdit(self.groupBox_4) self.edit_train_num.setGeometry(QtCore.QRect(100, 320, 241, 21)) self.edit_train_num.setObjectName("edit_train_num") self.label_4 = QtWidgets.QLabel(self.groupBox_4) self.label_4.setGeometry(QtCore.QRect(20, 320, 72, 15)) self.label_4.setObjectName("label_4") self.groupBox_5 = QtWidgets.QGroupBox(self.groupBox_2) self.groupBox_5.setGeometry(QtCore.QRect(10, 520, 261, 51)) self.groupBox_5.setObjectName("groupBox_5") self.btn_my_blog = QtWidgets.QPushButton(self.groupBox_5) self.btn_my_blog.setGeometry(QtCore.QRect(10, 20, 81, 21)) font = QtGui.QFont() font.setFamily("微软雅黑") font.setPointSize(7) self.btn_my_blog.setFont(font) self.btn_my_blog.setObjectName("btn_my_blog") self.btn_url_12306 = QtWidgets.QPushButton(self.groupBox_5) self.btn_url_12306.setGeometry(QtCore.QRect(140, 20, 81, 21)) font = QtGui.QFont() font.setFamily("微软雅黑") font.setPointSize(7) self.btn_url_12306.setFont(font) self.btn_url_12306.setObjectName("btn_url_12306") self.lb_speed = QtWidgets.QLabel(self.groupBox_2) self.lb_speed.setGeometry(QtCore.QRect(12, 22, 72, 16)) self.lb_speed.setObjectName("lb_speed") self.slider = QtWidgets.QSlider(self.groupBox_2) self.slider.setGeometry(QtCore.QRect(61, 22, 131, 20)) self.slider.setMinimum(1) self.slider.setMaximum(10) self.slider.setSingleStep(1) self.slider.setPageStep(1) self.slider.setProperty("value", 4) self.slider.setTracking(True) self.slider.setOrientation(QtCore.Qt.Horizontal) self.slider.setInvertedAppearance(False) self.slider.setInvertedControls(False) self.slider.setTickPosition(QtWidgets.QSlider.TicksAbove) self.slider.setTickInterval(1) self.slider.setObjectName("slider") self.cb_rob_mode = QtWidgets.QCheckBox(self.groupBox_2) self.cb_rob_mode.setGeometry(QtCore.QRect(250, 20, 91, 19)) self.cb_rob_mode.setObjectName("cb_rob_mode") self.horizontalLayout_2.addWidget(self.groupBox_2) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 977, 26)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)