本文整理汇总了Python中PySide.QtGui.QDesktopServices类的典型用法代码示例。如果您正苦于以下问题:Python QDesktopServices类的具体用法?Python QDesktopServices怎么用?Python QDesktopServices使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDesktopServices类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printPreview
def printPreview(self):
"""
export to a temporary PDF file and open in the default pdf viewer
Raises `NotImplemented` if print preview is not supported on this platform (yet?)
"""
pdf_file = NamedTemporaryFile(suffix='.pdf',delete=False)
try:
self.exportToPDF(pdf_file)
"""
#this clever pure-python implementation is probably not as portable as letting Qt handle it
#though I'm not sure
#get appropriate "document opener" program for the platform
if 'linux' in sys.platform:
prog_name = 'xdg-open'
elif sys.platform == 'darwin': #Mac OS X
prog_name = 'open'
elif sys.platform == 'win32': #64 bit windows is still "win32"
prog_name = 'start'
else:
raise NotImplemented('Your Platform (%s) does not support the print preview feature,'\
'Export to PDF instead, please report this error' % sys.platform)
subprocess.check_call([prog_name, pdf_file.name])
"""
QDesktopServices.openUrl(QUrl.fromLocalFile(pdf_file.name))
finally:
pdf_file.close()
示例2: link_click_handler
def link_click_handler(self, url):
if url.path() == u'blank':
if url.hasFragment():
if url.fragment() == u'quit':
QApplication.instance().quit()
else:
QDesktopServices.openUrl(url)
示例3: email_note
def email_note(self):
body = self.page.mainFrame().toPlainText()[
len(self.title):
].strip()
url = QUrl("mailto:")
url.addQueryItem("subject", self.title)
url.addQueryItem("body", body)
QDesktopServices.openUrl(url)
示例4: www_view
def www_view(self):
"""
Context Menu Action.
Opens the stream in a web page.
"""
if self.stream is not None:
print "Opening %s in a web browser..." % self.stream
QDesktopServices.openUrl(self.stream.url)
示例5: askOpenFile
def askOpenFile(self):
if not self.askSaveChanges():
return
directory = QDesktopServices.storageLocation(
QDesktopServices.DocumentsLocation)
filename, selected_filter = QFileDialog.getOpenFileName(
self, self.trUtf8(b'Open file'), directory)
if filename:
self.load(filename)
示例6: browseMediapath
def browseMediapath(self):
self.loadMediaBrowseSettings()
options = QtGui.QFileDialog.Options()
if (os.path.isdir(self.mediadirectory)):
defaultdirectory = self.mediadirectory
elif (os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.MoviesLocation))):
defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.MoviesLocation)
elif (os.path.isdir(QDesktopServices.storageLocation(QDesktopServices.HomeLocation))):
defaultdirectory = QDesktopServices.storageLocation(QDesktopServices.HomeLocation)
else:
defaultdirectory = ""
browserfilter = "All Files (*)"
fileName, filtr = QtGui.QFileDialog.getOpenFileName(self,"Browse for media files",defaultdirectory,
browserfilter, "", options)
if fileName:
self.mediapathTextbox.setText(fileName)
self.mediadirectory = os.path.dirname(fileName)
self.saveMediaBrowseSettings()
示例7: askSaveFile
def askSaveFile(self):
if self.currentFilename:
directory = os.path.dirname(self.currentFilename)
else:
directory = QDesktopServices.storageLocation(
QDesktopServices.DocumentsLocation)
filename, selected_filter = QFileDialog.getSaveFileName(
self, self.trUtf8(b'Save file'), directory)
if not filename:
return False
return self.saveFile()
示例8: __init__
def __init__(self, app):
super(MainWindow, self).__init__()
# Window layout - a splitter with the image on the left and controls
# on the right
self._image_widget = ImageLabel(self)
self._controls = Controls(self)
self._splitter = QSplitter()
self._splitter.addWidget(self._image_widget)
self._splitter.addWidget(self._controls)
self._splitter.setSizes([1200, 600])
# Main window layout
self.setCentralWidget(self._splitter)
# Connect controls to handlers
self._controls.ok.clicked.connect(self.ok)
self._controls.cancel.clicked.connect(self.cancel)
self._controls.inbox.choose_directory.clicked.connect(self.choose_inbox)
self._controls.processed.choose_directory.clicked.connect(self.choose_processed)
# Directories
mydocuments = QDesktopServices.storageLocation(
QDesktopServices.DocumentsLocation)
self._inbox = Path(QSettings().value('inbox',
str(Path(mydocuments) / 'inbox')))
self._processed = Path(QSettings().value('processed',
str(Path(mydocuments) / 'processed')))
self._controls.inbox.set_link(str(self._inbox.as_uri()), self._inbox.name)
self._controls.processed.set_link(str(self._processed.as_uri()), self._processed.name)
# A stack of Path objects to be processed
self._pending_files = []
# The Path currently shown in the UI
self._under_review = None
# Watch the inbox directory, if it exists
self.new_pending_files.connect(self.process_next_pending,
QtCore.Qt.QueuedConnection)
if self._inbox.is_dir():
self._watcher = NewFileWatcher(self._inbox, IMAGE_SUFFIXES_RE)
self._watcher.new_file.connect(self.new_image_file)
else:
self._watcher = None
self.empty_controls()
# Setup drag-drop handling
self.setAcceptDrops(True)
self._controls.installEventFilter(self)
self._splitter.installEventFilter(self)
示例9: event_link_clicked
def event_link_clicked(self, url):
url_string = url.toString()
if 'file' in urlparse.parse_qs(urlparse.urlparse(url_string).query):
msgbox = QMessageBox()
msgbox.setWindowTitle('Installing')
msgbox.setText('Installing theme. Please wait...')
msgbox.setStandardButtons(0)
msgbox.setAttribute(Qt.WA_DeleteOnClose)
msgbox.setWindowModality(Qt.NonModal)
msgbox.show()
msgbox.repaint() # Qt didn't want to show the text so we force a repaint
# Download and install the theme
package = self.module.download('http://localhost/test/download.php?file=2800&name=Fat-flat.xpf')
#package = self.module.download(url_string)
try:
self.module.install(package)
msgbox.close()
complete_msgbox = QMessageBox()
complete_msgbox.setWindowTitle('Complete')
complete_msgbox.setText('Install complete.')
complete_msgbox.setStandardButtons(QMessageBox.Ok)
complete_msgbox.setAttribute(Qt.WA_DeleteOnClose)
complete_msgbox.exec_()
except:
msgbox.close()
print "Unexpected error:", sys.exc_info()[:2]
failed_msgbox = QMessageBox()
failed_msgbox.setWindowTitle('Failed')
failed_msgbox.setText('Install failed. Please try again later.')
failed_msgbox.setStandardButtons(QMessageBox.Ok)
failed_msgbox.setAttribute(Qt.WA_DeleteOnClose)
failed_msgbox.exec_()
else:
QDesktopServices.openUrl(url)
示例10: appdata
def appdata():
"""
Return the path that application data should be stored in. This acts a bit
special on Windows machines as Qt doesn't return the right path itself.
"""
if os.name == "nt":
path = os.getenv("APPDATA")
app = QCoreApplication.instance()
if app:
if app.organizationName():
path = os.path.join(path, app.organizationName())
if app.applicationName():
path = os.path.join(path, app.applicationName())
return path
return QDesktopServices.storageLocation(QDesktopServices.DataLocation)
示例11: _on_export
def _on_export(self):
if len(self.test.array) == 0:
QMessageBox.warning(self, self.tr("IrregularVerbsTestGenerator"),
self.tr("You need to generate a test first !"))
return
export_file, export_format = QFileDialog.getSaveFileName(
self,
self.tr("Save test"),
QDesktopServices.storageLocation(QDesktopServices.DesktopLocation),
self.tr("Xls file (*.xls)"))
if not export_file:
return
include_solutions = self.mIncludeSolutions.isChecked()
export_file = "{0}.xls".format(os.path.splitext(export_file)[0])
_export_test_to_xls_file(self.test, export_file, include_solutions)
示例12: get_data_path
def get_data_path():
"""
Returns the path that application data should be stored in. This acts a bit
special on Windows machines, using the APPDATA environment variable to
ensure things go to AppData\Roaming and not AppData\Local.
"""
if os.name == 'nt':
qapp = QCoreApplication.instance()
path = os.getenv('APPDATA')
if qapp.organizationName():
path = os.path.join(path, qapp.organizationName())
if qapp.applicationName():
path = os.path.join(path, qapp.applicationName())
return path
return QDesktopServices.storageLocation(QDesktopServices.DataLocation)
示例13: ensure_paths
def ensure_paths():
""" Ensure cache_path, profile_path, and root_path are set. """
global cache_path
global profile_path
global root_path
if not root_path:
root_path = os.path.abspath(os.path.dirname(sys.argv[0]))
if not profile_path:
# The profile path is a bit trickier than the root path, since it can
# move depending on the portability flag.
if portable:
path = root_path
else:
path = os.path.abspath(get_data_path())
# Add the Profiles/<profile> bit to the profile path, and ensure the
# path actually exists.
path = os.path.join(path, u'Profiles', name)
if not os.path.exists(path):
os.makedirs(path)
profile_path = path
if not cache_path:
# The cache path is like the profile path, in that it varies based on
# the portability flag.
if portable:
path = os.path.join(root_path, u'cache')
else:
path = QDesktopServices.storageLocation(
QDesktopServices.CacheLocation)
# Add the Profiles/<profile> bit to the cache path, and ensure the path
# actually exists.
path = os.path.join(path, u'Profiles', name)
if not os.path.exists(path):
os.makedirs(path)
cache_path = path
示例14: __init__
def __init__(self, parent=None, flags=Qt.Widget):
super(FileBrowser, self).__init__(parent, flags)
self.gallery = QDocumentGallery(self)
self.fileSystemModel = QFileSystemModel(self)
self.rootPath = QDesktopServices.storageLocation(QDesktopServices.HomeLocation)
self.fileSystemModel.setRootPath(self.rootPath)
self.view = QListView()
self.view.setModel(self.fileSystemModel)
self.view.activated.connect(self.activated)
self.setCentralWidget(self.view)
self.menuBar().addAction(self.tr("Documents"), self.browseDocuments)
self.menuBar().addAction(self.tr("Audio"), self.browseAudio)
self.menuBar().addAction(self.tr("Images"), self.browseImages)
self.menuBar().addAction(self.tr("Videos"), self.browseVideos)
self.browseDocuments()
示例15: __init__
def __init__(self):
dbus_main_loop = dbus.glib.DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus(dbus_main_loop)
bus_name = dbus.service.BusName("com.mikeasoft.statusnet", bus=session_bus)
dbus.service.Object.__init__(self, object_path="/synchronize", bus_name=bus_name)
self.app = QCoreApplication(sys.argv)
signal.signal(signal.SIGINT, signal.SIG_DFL)
self.client = gconf.client_get_default()
self.api_path = self.client.get_string('/apps/ControlPanel/Statusnet/api_path')
self.latest = self.client.get_int('/apps/ControlPanel/Statusnet/latest')
self.eventService = EventFeedService('statusnet', 'StatusNet')
self.eventService.local_name = "com.mikeasoft.statusnet.eventcallback"
self.eventService.DEFAULT_INTF = "com.mikeasoft.statusnet.eventcallback"
if not self.api_path:
return
self.cacheDir = QDesktopServices.storageLocation(QDesktopServices.CacheLocation)
if not os.path.exists(self.cacheDir):
os.mkdir(self.cacheDir)
sys.exit(self.app.exec_())