def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setWindowTitle('AtTrackDownloader') self.setCentralWidget(QWidget(self)) self.__create_widgets() self.__autotravel = Autotravel() self.__comboBoxAreas.addItems(sorted(self.__autotravel.get_areas_list()))
class AtdWindow(QMainWindow): def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setWindowTitle('AtTrackDownloader') self.setCentralWidget(QWidget(self)) self.__create_widgets() self.__autotravel = Autotravel() self.__comboBoxAreas.addItems(sorted(self.__autotravel.get_areas_list())) def __update_towns(self, text): self.__comboBoxTowns.clear() self.__comboBoxTowns.addItems(self.__autotravel.get_towns_list(text)) def __save_track(self, state): area = self.__comboBoxAreas.currentText() town = self.__comboBoxTowns.currentText() track_links = self.__autotravel.get_towns_track_links(self.__autotravel.get_town_link(area, town)) filters = [e.upper() + ' треки (*.' + e + ')' for e in track_links] fileName, filter = QFileDialog.getSaveFileName(self, 'Save track', '', ';;'.join(filters)) if fileName: ext = re.search('\\.\\w+', filter).group(0) track = urllib2.urlopen(track_links[ext[1:]]) f = open(fileName if fileName.endswith(ext) else fileName + ext, 'wb') f.write(track.read()) f.close() def __goto_web(self, state): area = self.__comboBoxAreas.currentText() town = self.__comboBoxTowns.currentText() town_link = self.__autotravel.get_town_link(area, town) webbrowser.open(town_link) def __center(self): frameGm = self.frameGeometry() centerPoint = QDesktopWidget().availableGeometry().center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) def __create_widgets(self): self.__l = QFormLayout(self.centralWidget()) self.__comboBoxAreas = QComboBox(self) self.__comboBoxTowns = QComboBox(self) self.__buttonDownload = QPushButton('Скачать трек', self) self.__buttonOpenWebPage = QPushButton('Открыть страницу с городом', self) self.__l.addRow('Области: ', self.__comboBoxAreas) self.__l.addRow('Города: ', self.__comboBoxTowns) self.__l.addRow(self.__buttonDownload) self.__l.addRow(self.__buttonOpenWebPage) self.__buttonDownload.clicked.connect(self.__save_track) self.__buttonOpenWebPage.clicked.connect(self.__goto_web) self.__comboBoxAreas.currentTextChanged.connect(self.__update_towns) def showEvent(self, event): super(QMainWindow, self).showEvent(event) self.setFixedSize(self.size()) self.__center()