Exemple #1
0
	def __init__(self):
		QMainWindow.__init__(self)
		self.setWindowTitle("Media Fetcher")
		self.setWindowIcon(QIcon("../img/icon.png"))
		self.tray = TrayIcon(self)
		self.settings = QSettings(QSettings.IniFormat, QSettings.UserScope, "MediaFetcher", "MediaFetcher")
		self.settingsPath = QFileInfo(self.settings.fileName()).absolutePath()
		self.settingsModel = SettingsModel(self.settings)
		self.settingsDialog = SettingsDialog(self, self.settingsModel)
		self.statusBar = SettingsToolBar(self, self.settingsModel)
		self.addToolBar(Qt.BottomToolBarArea, self.statusBar)
		self.toolBar = MainToolBar(self)
		self.addToolBar(Qt.TopToolBarArea, self.toolBar)
		self.initMenus()
		self.initTabs()

		self.loadSettings()
		self.aboutToQuit.connect(self.writeSettings)
		# monitor Clipboard
		QApplication.clipboard().dataChanged.connect(self.clipBoardChanged)
		self.clipboardView.addURL("https://www.youtube.com/watch?v=IsBOoY2zvC0")
Exemple #2
0
class MainWindow(QMainWindow):
	aboutToQuit = Signal()

	def __init__(self):
		QMainWindow.__init__(self)
		self.setWindowTitle("Media Fetcher")
		self.setWindowIcon(QIcon("../img/icon.png"))
		self.tray = TrayIcon(self)
		self.settings = QSettings(QSettings.IniFormat, QSettings.UserScope, "MediaFetcher", "MediaFetcher")
		self.settingsPath = QFileInfo(self.settings.fileName()).absolutePath()
		self.settingsModel = SettingsModel(self.settings)
		self.settingsDialog = SettingsDialog(self, self.settingsModel)
		self.statusBar = SettingsToolBar(self, self.settingsModel)
		self.addToolBar(Qt.BottomToolBarArea, self.statusBar)
		self.toolBar = MainToolBar(self)
		self.addToolBar(Qt.TopToolBarArea, self.toolBar)
		self.initMenus()
		self.initTabs()

		self.loadSettings()
		self.aboutToQuit.connect(self.writeSettings)
		# monitor Clipboard
		QApplication.clipboard().dataChanged.connect(self.clipBoardChanged)
		self.clipboardView.addURL("https://www.youtube.com/watch?v=IsBOoY2zvC0")

	def closeEvent(self, event):
		# http://qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#closeEvent
		# http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#aboutToQuit
		self.aboutToQuit.emit()

	def loadSettings(self):
		self.resize(600, 400)

	def writeSettings(self):
		pass

	def showSettings(self):
		self.settingsDialog.open()

	def initMenus(self):
		# toolbar actions may be set to invisible (exceptions: start, pause), so the main menu can't use these!
		self.openAction = QAction("&Open Container File", self, shortcut=QKeySequence.Open, triggered=self.open)
		self.settingsAction = QAction("Prefere&nces", self, triggered=self.showSettings)
		self.openAction.setIcon(QIcon.fromTheme("folder-open"))
		self.settingsAction.setIcon(QIcon.fromTheme("emblem-system"))

		self.fileMenu = QMenu("&File", self)
		self.fileMenu.addAction(self.openAction)
		self.fileMenu.addSeparator()
		self.fileMenu.addAction(self.toolBar.startAction)
		self.fileMenu.addAction(self.toolBar.pauseAction)
		self.fileMenu.addSeparator()
		self.fileMenu.addAction(self.tray.quitAction)

		self.editMenu = QMenu("&Edit", self)
		self.editMenu.addAction(self.settingsAction)

		self.viewMenu = QMenu("&View", self)
		self.viewMenu.addAction(self.toolBar.toggleViewAction())
		self.viewMenu.addAction(self.statusBar.toggleViewAction())

		self.helpMenu = QMenu("&Help", self)
		self.helpMenu.addAction(QAction("About", self, triggered=self.about))

		self.menuBar().addMenu(self.fileMenu)
		self.menuBar().addMenu(self.editMenu)
		self.menuBar().addMenu(self.viewMenu)
		self.menuBar().addMenu(self.helpMenu)

	def addTab(self, widget, label, closable=True):
		i = self.tabBar.count()
		self.tabBar.addTab(widget, " %s " % label if not closable else label)
		button = self.tabBar.tabBar().tabButton(i, QTabBar.RightSide)
		button.setStyleSheet("QToolButton {margin: 0; padding: 0;}")
		if not closable:
			button.setFixedWidth(0)
		self.tabBar.setCurrentIndex(i)

	def initTabs(self):
		self.tabBar = QTabWidget()
		self.setCentralWidget(self.tabBar)
		self.tabBar.setTabsClosable(True)
		appropriate_height = QLineEdit().sizeHint().height()
		self.tabBar.setStyleSheet("QTabBar::tab {height: %spx;}" % appropriate_height)
		self.tabBar.tabCloseRequested.connect(lambda i: self.tabBar.removeTab(i))
		# Downloads Tab
		self.downloadView = DownloadView(self, self.settings)
		self.addTab(self.downloadView, "Downloads", closable=False)
		# Clipboard Tab
		self.clipboardView = ClipBoardView(self, self.settings, self.downloadView)
		self.addTab(self.clipboardView, "Clipboard", closable=False)

	def clipBoardChanged(self):
		if QApplication.clipboard().mimeData().hasText():
			self.addURL(QApplication.clipboard().text())

	def open(self):
		fileName = QFileDialog.getOpenFileName(self, "Open File", QDir.homePath())
		if fileName:
			pass

	def about(self):
		QMessageBox.about(self, "About Media Fetcher", "Text")

	def addURL(self, url):
		# TODO: ignore/warn/ask when url is already in the clipboard
		for url in re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+])+', url):
			self.clipboardView.addURL(url)
			self.tabBar.setCurrentWidget(self.clipboardView)

	def search(self, text):
		text = text.strip()
		if text == "":
			return
		if 'http' in text:
			return self.addURL(text)
		searchwidget = QLabel("placeholder")
		self.addTab(searchwidget, "Search for %s" % text)