def addStation(self,name:str,ddsj,cfsj,*,business=None,auto_cover=False,to_end=True): # 增加站。暂定到达时间、出发时间用datetime类。 if isinstance(ddsj,str): ddsj = strToTime(ddsj) cfsj = strToTime(cfsj) dict = { "zhanming":name, "ddsj":ddsj, "cfsj":cfsj, } if business is None: business = self.graph.lineStationBusiness(name, self.isPassenger(detect=True),default=None) and (ddsj!=cfsj) if business is not None: dict['business']=business if auto_cover: former_dict = self.stationDict(name) if former_dict is not None: index = self.timetable.index(former_dict) self.timetable[index] = dict else: if to_end: self.timetable.append(dict) else: self.timetable.insert(0,dict) else: if to_end: self.timetable.append(dict) else: self.timetable.insert(0, dict)
def _time_changed(self): if self.updating: return row = self.sender().row ddsjEdit: QtWidgets.QTimeEdit = self.timeTable.cellWidget(row, 1) cfsjEdit: QtWidgets.QTimeEdit = self.timeTable.cellWidget(row, 2) ddsjQ: QtCore.QTime = ddsjEdit.time() ddsj = strToTime(ddsjQ.toString("hh:mm:ss")) cfsjQ = cfsjEdit.time() cfsj = strToTime(cfsjQ.toString("hh:mm:ss")) # 设置停靠时间数据 dt: timedelta = cfsj - ddsj seconds = dt.seconds if seconds == 0: time_str = "" else: m = int(seconds / 60) s = seconds % 60 time_str = "{}分".format(m) if s: time_str += str(s) + "秒" self.timeTable.item(row, 5).setText(time_str) if self.timeTable.item(row, 3).checkState() == Qt.Checked: self.timeTable.item(row, 0).setForeground(QtGui.QBrush(Qt.red)) elif time_str: self.timeTable.item(row, 0).setForeground(QtGui.QBrush(Qt.blue)) else: self.timeTable.item(row, 0).setForeground(QtGui.QBrush(Qt.black))
def _transfer_time(self): """ 将读取到的时刻中的时间转为datetime.datetime对象 """ for dict in self.timetable: if isinstance(dict["ddsj"], str): ddsj = strToTime(dict['ddsj']) cfsj = strToTime(dict['cfsj']) dict["ddsj"] = ddsj dict["cfsj"] = cfsj
def _current_ok(self): self.showStatus.emit("车次信息更新中……") if self.train is None: self.train = Train(self.graph) train: Train = self.train fullCheci = self.checiEdit.text() downCheci = self.checiDown.text() upCheci = self.checiUp.text() if self.graph.checiExisted(fullCheci, train): self._derr(f"车次{fullCheci}已存在,请重新输入!") return self.graph.changeTrainCheci(train, fullCheci, downCheci, upCheci) sfz = self.sfzEdit.text() zdz = self.zdzEdit.text() train.setStartEnd(sfz, zdz) trainType = self.comboType.currentText() if not trainType: trainType = train.autoTrainType() elif trainType not in self.graph.typeList: self.graph.typeList.append(trainType) train.setType(trainType) isShow = self.checkShow.isChecked() train.setIsShow(isShow) train.setAutoItem(self.checkAutoItem.isChecked()) train.setIsPassenger(self.checkPassenger.checkState()) train.setUI(color=self.color, width=self.spinWidth.value()) timeTable: QtWidgets.QTableWidget = self.timeTable train.clearTimetable() domain = False for row in range(timeTable.rowCount()): name = timeTable.item(row, 0).text() if not domain and '::' in name: domain = True ddsjSpin: QtWidgets.QTimeEdit = timeTable.cellWidget(row, 1) ddsjQ: QtCore.QTime = ddsjSpin.time() ddsj = strToTime(ddsjQ.toString("hh:mm:ss")) cfsjSpin = timeTable.cellWidget(row, 2) cfsj = strToTime(cfsjSpin.time().toString("hh:mm:ss")) try: note = timeTable.item(row, 4).text() except AttributeError: # item is None note = '' train.addStation(name, ddsj, cfsj, business=bool( timeTable.item(row, 3).checkState()), note=note) # 2019.07.05将setData移动到main中完成。 # self.setData(train) self.currentTrainApplied.emit(train)