class Locomotion(object): ''' classdocs ''' def __init__(self): ''' Constructor ''' self.Stop = Stop() self.goStraight = GoStraight() self.Turn = Turn() self.FullTurn = FullTurn() self.Approach = Approach() def action(self, input, states, parameters): if states["locomotionType"] == "Stop": self.Stop.action(input, states, parameters) elif states["locomotionType"] == "GoStraight": self.goStraight.action(input, states, parameters) elif states["locomotionType"] == "Turn": self.Turn.action(input, states, parameters) elif states["locomotionType"] == "FullTurn": if input.has_key("orientation") and input["orientation"]!=None: self.FullTurn.action(input, states, parameters) elif states["locomotionType"] == "Approach": self.Approach.action(input, states, parameters) elif states["locomotionType"] == "Carry": pass
def open_stops_file(self, file_name): logging.info("Opening stops file: %s" % file_name) # Get the stops number, name, poss and max capacity with open(file_name, newline='') as csvfile: reader = csv.DictReader(csvfile) # Get stop first columns for row in reader: stop = Stop(int(row['stop_number']), row['stop_name'], int(row['x_pos']), int(row['y_pos']), int(row['max_capacity'])) self.stops_object_list.append(stop) globalConstants.stops_name_to_num[row['stop_name']] = int(row['stop_number']) # Get stop destination vector with open(file_name, newline='') as csvfile: reader = csv.DictReader(csvfile) # Rows have the destinations of the users' stops for row in reader: i = int(row['stop_number']) self.stops_object_list[i].destination_vector = np.zeros(len(self.stops_object_list), globalConstants.dest_vec_type) for stop in self.stops_object_list: self.stops_object_list[i].destination_vector[stop.number]['dest_total'] = int(row[stop.name]) self.stops_object_list[stop.number].expected_alight_pass += int(row[stop.name]) # Calculate total pass in and input queue for stop in self.stops_object_list: stop.calculate_total_pass_in() globalConstants.results['Total_stops'] = len(self.stops_object_list)
def startup(): for i, (r, direction) in enumerate(ROUTES): stop, route = mbta_api.get_nearest_stop(r, direction) s = Stop( mbta_api=mbta_api, route_id=route["id"], direction_name=route["attributes"]["direction_destinations"] [direction], stop_id=stop["id"], stop_name=stop["attributes"]["name"], ) STOPS.append(s) DISPLAYS.append(RouteDisplay(group=group, stop=s, i=i)) for s in STOPS: s.load_predictions() for s in STOPS: print(s.route_id, s.stop_name) for t in s.predictions: print(t) print()
def export_gtfs(cls, directory): Agency.write_agencies(directory) Calendar.write_calendars(directory) Stop.write_stops(directory) Route.write_routes(directory) Trip.write_trips(directory) Frequency.write_frequencies(directory) Path.write_paths(directory)
def import_gtfs(cls, directory): Agency.import_agencies(directory) Calendar.import_calendars(directory) Stop.import_stops(directory) Path.import_paths(directory) Route.import_routes(directory) Trip.import_trips(directory) Frequency.import_frequencies(directory)
def __init__(self): ''' Constructor ''' self.Stop = Stop() self.goStraight = GoStraight() self.Turn = Turn() self.FullTurn = FullTurn() self.Approach = Approach()
def bus_line_calculator(travel_log): busses = {} stops = set() for log in travel_log: bus = BusLine(log["bus_id"]) if bus.get_id() not in busses: busses[bus.get_id()] = bus stop = Stop(log["stop_id"]) stop_name = log["stop_name"] stop.add_name(stop_name) stop_type = log["stop_type"] busses[bus.get_id()].add_stop(stop) if stop_type == "S": busses[bus.get_id()].set_starting_stop(stop) elif stop_type == "F": busses[bus.get_id()].set_finishing_stop(stop) starting_stops = [] finish_stops = [] all_routes = [] for bus_id, bus in busses.items(): if bus.starting_and_finishing_exists(): if bus.starting_stop.get_name() not in starting_stops: starting_stops.append(bus.starting_stop.get_name()) if bus.finishing_stop.get_name() not in finish_stops: finish_stops.append(bus.finishing_stop.get_name()) all_routes.append(bus.route) else: # print(f"There is no start or end stop for the line: {bus_id}") sys.exit() named_stops_in_routes = [] for route in all_routes: temp_set = set() for stop in route: temp_set.add(stop.get_name()) named_stops_in_routes.append(temp_set) combinations = itertools.combinations(named_stops_in_routes, 2) transfer_stops_initial = [i.intersection(k) for i, k in (combination for combination in combinations)] transfer_stops_set = set() for stop_set in transfer_stops_initial: for name in stop_set: transfer_stops_set.add(name) transfer_stops = [*transfer_stops_set]
def create_stops(): ''' Create stops objects :return list: List of created stops ''' list_stops = list() stops = set() for file in data_file_name: list_stop = elements(file, 'regular_path').split(' + ') for s in list_stop: s = s.split(' N ') for e in s: stops.add(e) #FORK for stop in stops: if stop == 'Vernod': right_stop = Stop('LYCÉE_DE_POISY') left_stop = Stop('POISY_COLLÈGE') s = Stop(stop) s.set_left_stop(left_stop) s.set_right_stop(right_stop) list_stops.append(s) list_stops.append(left_stop) list_stops.append(right_stop) elif stop != 'LYCÉE_DE_POISY' and stop != 'POISY_COLLÈGE': list_stops.append(Stop(stop)) return list_stops
def stop(self): now_page = int( self.pushButton_start.text().split('/')[0].split('(')[-1]) self.thread_stop = Stop(now_page) self.thread_stop.log_append.connect(self.log_append) self.thread_stop.log_moveCursor.connect(self.log_moveCursor) self.thread_stop.enable_start_button.connect(self.enable_start_button) self.thread_stop.disable_stop_button.connect(self.disable_stop_button) self.thread_stop.set_startbutton_text.connect( self.set_startbutton_text) self.thread_stop.stop_worker.connect(self.stop_worker) self.thread_stop.start()
def close(self): self._is_open = False self._dbname = None # clear everything Agency.clear() Calendar.clear() Stop.clear() Path.clear() Route.clear() TripRoute.clear() Trip.clear() Frequency.clear() Picture.clear()
def test_calculate_walking_time_from_starting_position(self): expectedValue = 0 stop = Stop(-36.854134, 174.767841) actualValue = self.user.calculate_walking_time(stop) self.assertEqual(expectedValue, actualValue)
def main(): print("starting") user = User(-36.854134, 174.767841) stop = Stop(-36.843574, 174.766931) print(user.calculate_walking_time(stop))
def add_stop(self, station): """ Add stop to the trip :param station: add the station to the stops :return: Void """ self.stops.append(Stop(station))
def __init__(self): ''' Constructor ''' self.Stop = Stop() self.goStraight = GoStraight() self.Turn = Turn() self.FullTurn = FullTurn()
def test_calculate_distance_from_stop_at_starting_position(self): stop = Stop(-36.854134, 174.767841) distance = self.user.calculate_distance_from_stop(stop) self.assertEqual(distance, self.user.distance) self.assertEqual(distance, 0)
def getAndroclickObject(objectType): if objectType == BUS: return Bus() elif objectType == STOP: return Stop() elif objectType == RESPONSE: return Response() else: print("Invalid object type")
def get_list_of_stops(stops): stop_list = [] for stop in stops['data']['stops']: name = stop['name'] direction = stop['direction'] code = stop['code'] buses = [] for routes in stop['routes']: buses.append(routes['shortName']) print(routes['shortName']) stop = Stop(name,code,buses,direction) stop_list.append(stop) return filterStops(stop_list)[:5]
async def main(): db.init(os.getenv("DB")) db.connect() db.create_tables([User, Raid, Log, PriorActivity]) async with Session() as kol: await kol.login(os.getenv("KOL_USER"), os.getenv("KOL_PASS")) cache = pickle.load(open("oaf.cache", "rb")) bot = commands.Bot("!") bot.kol = kol bot.raid_guild = int(os.getenv("DISCORD_GUILD")) bot.raid_channel = int(os.getenv("DISCORD_CHANNEL")) bot.add_cog(Verification(bot)) bot.add_cog(RaidLogs(bot, clans)) bot.add_cog(Whitelist(bot, clans)) bot.add_cog(OAF(bot, cache)) bot.add_cog(Stop(bot)) await bot.login(os.getenv("DISCORD_TOKEN")) await bot.connect() pickle.dump(cache, open("oaf.cache", "wb"))
def createStop(self,tabStop): res = tabStop listNameStop = self.listStopAller() #nom des stop que l'on veut rajouter tabNameStop = [] #nom des stop qu'on a déjà if (tabStop != []): for i in range(0,len(tabStop)): tabNameStop.append(tabStop[i].name) for j in range(0,len(self.listStopAller())): if not(listNameStop[j] in tabNameStop): nStop = Stop(self.getScheduleAller()[j][0],self.nbLine,self.getScheduleAller()[j][1]) res.append(nStop) else: for n in range(0,len(tabStop)): if listNameStop[j]==tabStop[n].name: tabStop[n].setSchedule(self.nbLine,self.getScheduleAller()[j][1]) for k in range(0,len(listNameStop)-1): for l in range(0,len(res)): if listNameStop[k]==res[l].name: for m in range(0,len(res)): if listNameStop[k+1]==res[m].name: res[l].addNeighbors(res[m]) return res
dic[tmp[0]] = tmp[1:] return dic slited_content = content.split("\n\n") regular_path = slited_content[0] regular_date_go = dates2dic(slited_content[1]) regular_date_back = dates2dic(slited_content[2]) we_holidays_path = slited_content[3] we_holidays_date_go = dates2dic(slited_content[4]) we_holidays_date_back = dates2dic(slited_content[5]) Sibra_Networkw = Network() for element in regular_path.split(): if not (element in ['N', '+']): stop = Stop(element, [regular_date_go[element]]) stop.addSchedule( [regular_date_go[element], regular_date_back[element]]) Sibra_Networkw.addStops([stop]) c = 0 for element in Sibra_Networkw.stops: if c == 0: element.addNextStops([Sibra_Networkw.stops[1]]) elif c == len(Sibra_Networkw.stops) - 1: element.addNextStops([Sibra_Networkw.stops[c - 1]]) else: element.addNextStops( [Sibra_Networkw.stops[c - 1], Sibra_Networkw.stops[c + 1]]) c += 1 """
#!mwd - I'm not sure how to do this. We link # blocks by trip ids, but block ids are # random in gtfs, so we have no way to link # them back except IOError, e: print >> sys.stderr, 'Unable to open trips.txt:', e # load all the stops try: f = open(os.path.join(directory, 'stop_times.txt'), 'rb') reader = csv.reader(f) mappings = {'arrival_time': ('arrival', lambda x: x), 'departure_time': ('departure', lambda x: x), 'stop_id': ('stop', lambda x: Stop.get_by_gtfs_id(x)), } # create a headers with an index headers = reader.next() r_headers = dict([(x, i) for i, x in enumerate(headers)]) for l2 in reader: if len(l2) != len(headers): print >> sys.stderr, 'Invalid line', l2, headers continue kw = {} for i, a in enumerate(l2): key = headers[i] if key in mappings:
import sys import itertools from BusLine import BusLine from Stop import Stop travel_log = json.loads(input()) busses = {} stops = set() for log in travel_log: bus = BusLine(log["bus_id"]) if bus.get_id() not in busses: busses[bus.get_id()] = bus stop = Stop(log["stop_id"]) stop_name = log["stop_name"] stop.add_name(stop_name) stop_type = log["stop_type"] busses[bus.get_id()].add_stop(stop) if stop_type == "S": busses[bus.get_id()].set_starting_stop(stop) elif stop_type == "F": busses[bus.get_id()].set_finishing_stop(stop) starting_stops = [] finish_stops = [] all_routes = []
# -*- coding: utf-8 -*- """ Created on Tue Feb 26 18:54:36 2019 @author: Akanksha Singhal """ from Bus import Bus from Stop import Stop from Route import Route # Initializing the stops on a Route stop1 = Stop(latitude=27.028486, longitude=75.769043, stopname="Todi", stopcode=1000, duration=0, distance=0) stop2 = Stop(latitude=26.9181, longitude=75.8498, stopname="Galta Gate", stopcode=1001, duration=20, distance=5.2) stop3 = Stop(latitude=26.9243, longitude=75.8124, stopname="Chandpole", stopcode=1005, duration=10, distance=3) stops = [stop1, stop2, stop3]
def load(self, fname): try: tree = ElementTree.parse(fname) for agency_node in tree.getroot().findall('Agency'): agency_id = agency_node.get('id', Agency.new_id()) gtfs_id = agency_node.get('gtfs_id', None) name = agency_node.findtext('name') url = agency_node.findtext('url') timezone = agency_node.findtext('timezone') language = agency_node.findtext('language') phone = agency_node.findtext('phone') fare_url = agency_node.findtext('fare_url') a = Agency(name = name, url = url, timezone = timezone, language = language, phone = phone, fare_url = fare_url) a.agency_id = int(agency_id) a.gtfs_id = gtfs_id for calendar_node in tree.getroot().findall('Calendar'): calendar_id = calendar_node.get('id', Calendar.new_id()) gtfs_id = calendar_node.get('gtfs_id', None) name = calendar_node.findtext('name') days = calendar_node.findtext('days') start_date = calendar_node.findtext('start_date') end_date = calendar_node.findtext('end_date') added_excn = calendar_node.findtext('added_excn') or '' remov_excn = calendar_node.findtext('remov_excn') or '' days = [int(x) for x in days.split()] c = Calendar(service_name = name, monday = days[0], tuesday = days[1], wednesday = days[2], thursday = days[3], friday = days[4], saturday = days[5], sunday = days[6], start_date = start_date, end_date = end_date, added_excn = added_excn.split(), remov_excn = remov_excn.split()) c.calendar_id = int(calendar_id) c.gtfs_id = gtfs_id for stop_node in tree.getroot().findall('Stop'): stop_id = stop_node.get('id', Stop.new_id()) gtfs_id = stop_node.get('gtfs_id', None) code = stop_node.findtext('code') name = stop_node.findtext('name') description = stop_node.findtext('description') latitude = stop_node.findtext('latitude') longitude = stop_node.findtext('longitude') zone_id = stop_node.findtext('zone_id') url = stop_node.findtext('url') location_type = stop_node.findtext('location_type') parent_station = stop_node.findtext('parent_station') try: location_type = int(location_type) except: pass try: s = Stop(code = code, name = name, description = description, latitude = float(latitude), longitude = float(longitude), zone_id = zone_id, url = url, location_type = location_type, parent_station = parent_station) s.stop_id = int(stop_id) s.gtfs_id = gtfs_id except Exception, e: print >> sys.stderr, 'Error loading stop', name, e for path_node in tree.getroot().findall('Path'): path_id = path_node.get('id', Path.new_id()) gtfs_id = path_node.get('gtfs_id', None) name = path_node.findtext('name') coords_node = path_node.find('coordinates') coords = [] for coord_node in coords_node.findall('Coordinate'): try: sequence = int(coord_node.get('sequence', -1)) lat = float(coord_node.get('lat', 0.0)) lon = float(coord_node.get('lon', 0.0)) coords.append((lat, lon)) except Exception, e: print >> sys.stderr, 'Invalid coordinate path %s: %s' % (name, e) try: p = Path(name = name, coords = coords) p.path_id = int(path_id) p.gtfs_id = gtfs_id except Exception, e: print >> sys.stderr, 'Error loading path', name, e
calendar = Calendar.get(int(calendar_id)) path = None if path_id != '': path = Path.get(int(path_id)) tr = TripRoute(name, route, calendar, headsign, int(direction), path) tr.trip_route_id = int(trip_route_id) tr.gtfs_id = gtfs_id route.add_trip_route(tr) # stops stops_node = trip_route_node.find('Stops') for stop_node in stops_node.findall('Stop'): stop_id = stop_node.get('id') stop = Stop.get(int(stop_id)) tr.add_stop(stop) # trips trips_node = trip_route_node.find('Trips') for trip_node in trips_node.findall('Trip'): trip_id = trip_node.get('id') trip = tr.add_trip() trip.trip_id = int(trip_id) for trip_node in tree.getroot().findall('Trip'): trip_id = trip_node.get('id', Trip.new_id()) gtfs_id = trip_node.get('gtfs_id', None) name = trip_node.findtext('name')
def setUp(self): self.user = User(-36.854134, 174.767841) self.stop = Stop(-36.843574, 174.766931)
class Ui_SankakuDownloader(object): def setupUi(self, SankakuDownloader): SankakuDownloader.setObjectName("SankakuDownloader") SankakuDownloader.resize(521, 427) SankakuDownloader.setFixedSize(521, 427) self.centralwidget = QtWidgets.QWidget(SankakuDownloader) self.centralwidget.setObjectName("centralwidget") self.pushButton_start = QtWidgets.QPushButton(self.centralwidget) self.pushButton_start.setGeometry(QtCore.QRect(10, 190, 93, 28)) self.pushButton_start.setObjectName("pushButton_start") self.pushButton_stop = QtWidgets.QPushButton(self.centralwidget) self.pushButton_stop.setGeometry(QtCore.QRect(113, 190, 93, 28)) self.pushButton_stop.setObjectName("pushButton_start") self.pushButton_stop.setEnabled(False) self.logBrowser = QtWidgets.QTextBrowser(self.centralwidget) self.logBrowser.setGeometry(QtCore.QRect(10, 260, 501, 141)) self.logBrowser.setObjectName("logBrowser") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(10, 70, 72, 15)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(10, 130, 91, 16)) self.label_2.setObjectName("label_2") self.progressBar = QtWidgets.QProgressBar(self.centralwidget) self.progressBar.setGeometry(QtCore.QRect(10, 227, 511, 21)) self.progressBar.setProperty("value", 0) self.progressBar.setObjectName("progressBar") self.label_3 = QtWidgets.QLabel(self.centralwidget) self.label_3.setGeometry(QtCore.QRect(10, 10, 72, 15)) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(self.centralwidget) self.label_4.setGeometry(QtCore.QRect(130, 10, 72, 15)) self.label_4.setObjectName("label_4") self.label_5 = QtWidgets.QLabel(self.centralwidget) self.label_5.setGeometry(QtCore.QRect(310, 70, 91, 16)) self.label_5.setObjectName("label_5") self.label_6 = QtWidgets.QLabel(self.centralwidget) self.label_6.setGeometry(QtCore.QRect(10, 402, 291, 21)) self.label_6.setObjectName("label_6") self.label_7 = QtWidgets.QLabel(self.centralwidget) self.label_7.setGeometry(QtCore.QRect(380, 402, 131, 21)) self.label_7.setFocusPolicy(QtCore.Qt.NoFocus) self.label_7.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter) self.label_7.setObjectName("label_7") self.pushButton_login = QtWidgets.QPushButton(self.centralwidget) self.pushButton_login.setGeometry(QtCore.QRect(240, 31, 93, 28)) self.pushButton_login.setObjectName("pushButton_login") self.lineEdit_tags = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_tags.setGeometry(QtCore.QRect(10, 90, 291, 31)) self.lineEdit_tags.setObjectName("lineEdit_tags") self.lineEdit_savepath = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_savepath.setGeometry(QtCore.QRect(10, 150, 291, 31)) self.lineEdit_savepath.setObjectName("lineEdit_savepath") self.lineEdit_username = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_username.setGeometry(QtCore.QRect(10, 30, 101, 31)) self.lineEdit_username.setObjectName("lineEdit_username") self.lineEdit_password = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_password.setGeometry(QtCore.QRect(130, 30, 101, 31)) self.lineEdit_password.setObjectName("lineEdit_password") self.lineEdit_password.setEchoMode(QLineEdit.Password) self.lineEdit_startpage = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_startpage.setGeometry(QtCore.QRect(310, 90, 91, 31)) self.lineEdit_startpage.setObjectName("lineEdit_username") self.pushButton_selectpath = QtWidgets.QPushButton(self.centralwidget) self.pushButton_selectpath.setGeometry(QtCore.QRect(310, 150, 51, 31)) self.pushButton_selectpath.setObjectName("pushButton_selectpath") self.statusBar = QtWidgets.QStatusBar(SankakuDownloader) self.statusBar.setObjectName("statusBar") self.lineEdit_startpage.setValidator(QtGui.QIntValidator( 1, 2147483647)) if os.path.exists('user.ini'): with open('user.ini', 'r') as user: user_info = user.readlines() try: self.lineEdit_username.setText(user_info[0].split('\n')[0]) self.lineEdit_password.setText(user_info[1]) except: pass ##开始监控下载速度 self.refreshdlspeed() ##按钮事件 self.pushButton_selectpath.clicked.connect(self.set_path) self.pushButton_start.clicked.connect(self.start) self.pushButton_stop.clicked.connect(self.stop) self.pushButton_login.clicked.connect(self.login) app.aboutToQuit.connect(self.closeEvent) self.retranslateUi(SankakuDownloader) QtCore.QMetaObject.connectSlotsByName(SankakuDownloader) def retranslateUi(self, SankakuDownloader): _translate = QtCore.QCoreApplication.translate SankakuDownloader.setWindowTitle( _translate("SankakuDownloader", "SankakuDownloader v2.0")) SankakuDownloader.setWindowIcon(QtGui.QIcon('icon.png')) self.pushButton_start.setText("开始") self.pushButton_stop.setText("停止") self.logBrowser.setHtml( _translate( "SankakuDownloader", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'SimSun\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>" )) self.label.setText("标签:") self.label_2.setText("保存路径:") self.label_3.setText("用户名:") self.label_4.setText("密码:") self.label_5.setText("开始页码:") self.label_6.setText("等待中") self.pushButton_login.setText("登入") self.pushButton_selectpath.setText("...") ##关闭程序时关闭aria2c def closeEvent(self): #os.system('taskkill /f /im aria2c_sd.exe') call('taskkill /f /im aria2c_sd.exe', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) #process.send_signal(signal.CTRL_C_EVENT) global failed_list if failed_list != []: with open('failed.txt', 'w') as failed: for failed_url in failed_list: failed.write(failed_url + '\n') sys.exit(0) ##设置图片保存目录 def set_path(self): get_directory_path = QFileDialog.getExistingDirectory( None, '请选择保存路径', '') self.lineEdit_savepath.setText(str(get_directory_path)) ##设置start按钮字样 def set_startbutton_text(self, info): self.pushButton_start.setText(info) ##调整进度条 def set_processbar(self, int): self.progressBar.setProperty('value', int) ##添加log信息 def log_append(self, log): self.logBrowser.append(log) ##将log移动到最下面 def log_moveCursor(self): self.logBrowser.moveCursor(self.logBrowser.textCursor().End) ##获取开始下载的页数 def get_start_page(self): global start_page if self.lineEdit_startpage.text() != '': start_page = int(self.lineEdit_startpage.text()) ##关闭和开启开始键 def enable_start_button(self): self.pushButton_start.setEnabled(True) def disable_start_button(self): self.pushButton_start.setEnabled(False) ##设置登录键是否可用 def enable_login_button(self): self.pushButton_login.setEnabled(True) def disable_login_button(self): self.pushButton_login.setEnabled(False) ##设置停止键是否可用 def enable_stop_button(self): self.pushButton_stop.setEnabled(True) def disable_stop_button(self): self.pushButton_stop.setEnabled(False) ##设置用户名密码栏为不可用 def set_usernameedit_disable(self): self.lineEdit_username.setEnabled(False) def set_passwordedit_disable(self): self.lineEdit_password.setEnabled(False) def set_process(self, info, count): if info == '+1': now_info = int(self.label_6.text().split('/')[0].split('(')[-1]) self.label_6.setText('(%d/%d)' % (now_info + 1, count)) self.progressBar.setProperty('value', round((now_info + 1) * 100 / count)) elif info == '0': self.label_6.setText('(%d/%d)' % (0, count)) ##提示框 def info_message(self, title, info): QMessageBox.information(None, title, info, QMessageBox.Yes) ##刷新信息提示 def set_infolabel(self, info): self.label_6.setText(info) return info ##添加failed信息 def add_failed_info(self, info): global failed_list failed_list.append(info) ##结束后处理failed_list def save_failed_list(self): ##保存失败列表 global failed_list if failed_list != []: with open('failed.txt', 'w') as failed: for failed_url in failed_list: failed.write(failed_url + '\n') self.label_6.setText('下载完成,%d个文件下载失败' % len(failed_list)) failed_list = [] else: self.label_6.setText('下载完成') ##刷新下载速度 def set_speedlabel(self, speed): self.label_7.setText(speed) ##设置token和cookies def set_token(self, into_token): global token token = into_token def set_cookies(self, into_cookies): global chan_cookies chan_cookies = into_cookies ##终止主进程 def stop_worker(self): self.thread.terminate() try: self.thread_notifications.stop() except: self.label_6.setText('下载已停止') return global failed_list if failed_list != []: with open('failed.txt', 'w') as failed: for failed_url in failed_list: failed.write(failed_url + '\n') self.label_6.setText('下载已停止,%d个文件下载失败' % len(failed_list)) failed_list = [] else: self.label_6.setText('下载已停止') ##刷新下载速度 def refreshdlspeed(self): self.thread_refreshdlspeed = Refreshdlspeed() self.thread_refreshdlspeed.set_speedlabel.connect(self.set_speedlabel) self.thread_refreshdlspeed.start() ##消息监控 def notifications(self, this_page_count, count): self.thread_notifications = Notifications(this_page_count, count) self.thread_notifications.log_append.connect(self.log_append) self.thread_notifications.log_moveCursor.connect(self.log_moveCursor) self.thread_notifications.set_process.connect(self.set_process) self.thread_notifications.add_failed_info.connect(self.add_failed_info) self.thread_notifications.start() ##用户登录 def login(self): username = self.lineEdit_username.text() password = self.lineEdit_password.text() self.thread_login = Login(username, password) self.thread_login.log_append.connect(self.log_append) self.thread_login.log_moveCursor.connect(self.log_moveCursor) self.thread_login.set_infolabel.connect(self.set_infolabel) self.thread_login.enable_login_button.connect(self.enable_login_button) self.thread_login.disable_login_button.connect( self.disable_login_button) self.thread_login.set_usernameedit_disable.connect( self.set_usernameedit_disable) self.thread_login.set_passwordedit_disable.connect( self.set_passwordedit_disable) self.thread_login.info_message.connect(self.info_message) self.thread_login.set_token.connect(self.set_token) self.thread_login.set_cookies.connect(self.set_cookies) self.pushButton_login.setEnabled(False) self.thread_login.start() ##结束进程 def stop(self): now_page = int( self.pushButton_start.text().split('/')[0].split('(')[-1]) self.thread_stop = Stop(now_page) self.thread_stop.log_append.connect(self.log_append) self.thread_stop.log_moveCursor.connect(self.log_moveCursor) self.thread_stop.enable_start_button.connect(self.enable_start_button) self.thread_stop.disable_stop_button.connect(self.disable_stop_button) self.thread_stop.set_startbutton_text.connect( self.set_startbutton_text) self.thread_stop.stop_worker.connect(self.stop_worker) self.thread_stop.start() ##开始进程 def start(self): tags = self.lineEdit_tags.text() path = self.lineEdit_savepath.text() start_page = self.lineEdit_startpage.text() if start_page == '': start_page = 1 self.thread = Worker(tags, path, start_page, token, chan_cookies) self.thread.set_processbar.connect(self.set_processbar) self.thread.log_append.connect(self.log_append) self.thread.log_moveCursor.connect(self.log_moveCursor) self.thread.enable_start_button.connect(self.enable_start_button) self.thread.disable_start_button.connect(self.disable_start_button) self.thread.enable_stop_button.connect(self.enable_stop_button) self.thread.disable_stop_button.connect(self.disable_stop_button) self.thread.set_infolabel.connect(self.set_infolabel) self.thread.set_speedlabel.connect(self.set_speedlabel) self.thread.set_startbutton_text.connect(self.set_startbutton_text) self.thread.info_message.connect(self.info_message) self.thread.notifications.connect(self.notifications) self.thread.set_process.connect(self.set_process) self.thread.save_failed_list.connect(self.save_failed_list) self.thread.start()