本文整理汇总了Python中PyQt4.QtGui.QMenu.menuAction方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.menuAction方法的具体用法?Python QMenu.menuAction怎么用?Python QMenu.menuAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.menuAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _onTvFilesCustomContextMenuRequested
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
def _onTvFilesCustomContextMenuRequested(self, pos ):
"""Connected automatically by uic
"""
menu = QMenu()
menu.addAction( core.actionManager().action( "mFile/mClose/aCurrent" ) )
menu.addAction( core.actionManager().action( "mFile/mSave/aCurrent" ) )
menu.addAction( core.actionManager().action( "mFile/mReload/aCurrent" ) )
menu.addSeparator()
# sort menu
sortMenu = QMenu( self )
group = QActionGroup( sortMenu )
group.addAction( self.tr( "Opening order" ) )
group.addAction( self.tr( "File name" ) )
group.addAction( self.tr( "URL" ) )
group.addAction( self.tr( "Suffixes" ) )
group.triggered.connect(self._onSortTriggered)
sortMenu.addActions( group.actions() )
for i, sortMode in enumerate(["OpeningOrder", "FileName", "URL", "Suffixes"]):
action = group.actions()[i]
action.setData( sortMode )
action.setCheckable( True )
if sortMode == self.model.sortMode():
action.setChecked( True )
aSortMenu = QAction( self.tr( "Sorting" ), self )
aSortMenu.setMenu( sortMenu )
aSortMenu.setIcon( QIcon( ":/enkiicons/sort.png" ))
aSortMenu.setToolTip( aSortMenu.text() )
menu.addAction( sortMenu.menuAction() )
menu.exec_( self.tvFiles.mapToGlobal( pos ) )
示例2: _setupUi
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
def _setupUi(self):
self.setupUi(self)
self.browserView.setModel(self.boardModel)
h = self.browserView.header()
h.setResizeMode(QHeaderView.Fixed)
h.resizeSection(1, 120)
h.setResizeMode(0, QHeaderView.Stretch)
# Action menu
actionMenu = QMenu('Actions', self.toolBar)
actionMenu.setIcon(QIcon(QPixmap(":/actions")))
actionMenu.addAction(self.actionNewFolder)
actionMenu.addAction(self.actionRemoveEmptyFolders)
actionMenu.addAction(self.actionRenameSelected)
actionMenu.addAction(self.actionMoveSelectedToIgnoreBox)
actionMenu.addAction(self.actionSwitchConflictAndOriginal)
actionMenu.addSeparator()
actionMenu.addAction(self.actionMassRename)
actionMenu.addAction(self.actionSplit)
actionMenu.addAction(self.actionUndoSplit)
actionMenu.addAction(self.actionMoveConflicts)
actionMenu.addAction(self.actionMoveConflictsAndOriginals)
self.actionActions.setMenu(actionMenu)
button = QToolButton(self.toolBar)
button.setDefaultAction(actionMenu.menuAction())
button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self.actionsButton = button
self.toolBar.insertWidget(self.actionActions, button) # the action is a placeholder
self.toolBar.removeAction(self.actionActions)
# Materialize menu
materializeMenu = QMenu('Materialize', self.toolBar)
materializeMenu.setIcon(QIcon(QPixmap(":/materialize")))
materializeMenu.addAction(self.actionRenameInRespectiveLocations)
materializeMenu.addAction(self.actionCopyToOtherLocation)
materializeMenu.addAction(self.actionMoveToOtherLocation)
self.actionMaterialize.setMenu(materializeMenu)
button = QToolButton(self.toolBar)
button.setDefaultAction(materializeMenu.menuAction())
button.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self.materializeButton = button
self.toolBar.insertWidget(self.actionMaterialize, button) # the action is a placeholder
self.toolBar.removeAction(self.actionMaterialize)
示例3: init
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
def init(self):
menu = QMenu('', self)
menu.menuAction().setIcon(QIcon('rsc/scene.png'))
a = QAction(QIcon('rsc/scene.png'), 'Scene', self)
a.setIconVisibleInMenu(True)
self.connect(a, SIGNAL('triggered()'), self.menu_action)
menu.addAction(a)
a = QAction(QIcon('rsc/node.png'), 'Node', self)
a.setIconVisibleInMenu(True)
menu.addAction(a)
self.connect(a, SIGNAL('triggered()'), self.menu_action)
a = QAction(QIcon('rsc/tree.png'), 'Tree', self)
a.setIconVisibleInMenu(True)
menu.addAction(a)
self.connect(a, SIGNAL('triggered()'), self.menu_action)
a = QAction(QIcon('rsc/menu.png'), 'Menu', self)
a.setIconVisibleInMenu(True)
self.connect(a, SIGNAL('triggered()'), self.menu_action)
menu.addAction(a)
self.addAction(menu.menuAction())
self.__menu = menu
return
示例4: addContextMenuActions
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
def addContextMenuActions(self, menu):
ExperimentTreeItem.addContextMenuActions(self, menu)
menu.addSeparator()
onlineAction = QAction("Put Online", menu)
onlineAction.triggered.connect(self.device.putOnline)
menu.addAction(onlineAction)
attentionAction = QAction("Draw Attention", menu)
attentionAction.triggered.connect(self.device.drawAttention)
menu.addAction(attentionAction)
if hasattr(self.device, "documentation"):
documentationMenu = QMenu("Documentation", menu)
for name, url in self.device.documentation.items():
urlAction = QAction(name, menu)
urlAction.triggered.connect(lambda: QDesktopServices.openUrl(QUrl(url)))
documentationMenu.addAction(urlAction)
menu.addAction(documentationMenu.menuAction())
示例5: addMenu
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
def addMenu(self, path, text, icon=QIcon() ):
"""Add menu to the main menu or submenu of main menu
"""
action = self.action(path)
if action is not None:
if action.menu():
return action
else:
assert 0 # not a menu!
parentMenuPath = self._parentPath(path)
if parentMenuPath:
parentAction = self.action(parentMenuPath)
else:
parentAction = None
menu = QMenu()
action = menu.menuAction()
action._menu = menu # avoid deleting menu by the garbadge collectors
action.setIcon( icon )
action.setText( text )
if parentAction is not None:
action.setParent( parentAction )
parentAction.menu().addMenu( menu )
else:
action.setParent( self )
self._pathToAction[ path ] = action
action.path = path
action.changed.connect(self._onActionChanged)
self.actionInserted.emit( action )
return action
示例6: View
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
class View(QMainWindow, auxilia.Actions, MainWindow):
partyMode = None
hide_window = True
def __init__(self, modelManager, configuration, mpdclient, library, app):
QMainWindow.__init__(self)
self.modelManager = modelManager
self.app = app
self.app.commitData = self.commitData
self.focus = time()
self.shuttingDown = False
self.config = configuration
self.mpdclient = mpdclient
self.library = library
self.appIcon = os.path.abspath(DATA_DIR+'icons/Pythagora.png')
self.setupUi(self)
self.setWindowTitle('Pythagora')
self.setWindowIcon(QIcon(self.appIcon))
# Create standard views.
self.playerForm = PlayerForm(self.modelManager, self.config)
self.topLayout.addWidget(self.playerForm)
self.connect(self.modelManager.playerState, SIGNAL('currentSongChanged'), self.playerForm.updateSong)
self.connect(self.modelManager.playerState, SIGNAL('volumeChanged'), self.playerForm.setVolume)
self.connect(self.modelManager.playerState, SIGNAL('progressChanged'), self.playerForm.setProgress)
self.connect(self.modelManager.playerState, SIGNAL('playStateChanged'), self.playerForm.setPlayState)
self.connect(self.modelManager.playerState, SIGNAL('bitrateChanged'), self.playerForm.songLabel.setBitrate)
self.dbusNotifications = DBusNotifications(self.config)
self.connect(self.modelManager.playerState, SIGNAL('currentSongChanged'), self.dbusNotifications.showNotification)
self.toolBarLayout = self.playerForm.toolBarLayout
self.currentList = CurrentPlaylistForm.CurrentPlaylistForm(
self.modelManager, self, self.app, self.config)
self.currentListLayout.addWidget(self.currentList)
self.connect(self.playerForm.play, SIGNAL('clicked(bool)'), self.modelManager.playerState.playPause)
self.connect(self.playerForm.back, SIGNAL('clicked(bool)'), self.modelManager.playerState.previousSong)
self.connect(self.playerForm.forward, SIGNAL('clicked(bool)'), self.modelManager.playerState.nextSong)
self.connect(self.playerForm.stop, SIGNAL('clicked(bool)'), self.modelManager.playerState.stop)
self.connect(self.playerForm.volume, SIGNAL('valueChanged(int)'), self.modelManager.playerState.setVolume)
# Standard toolbar buttons.
self.exitAction = self.actionExit(self, self.app.quit)
self.exitButton = QToolButton()
self.exitButton.setAutoRaise(True)
self.exitButton.setIconSize(QSize(22, 22))
self.exitButton.setDefaultAction(self.exitAction)
self.settingsAction = self.actionSettings(self, self.showConfig)
self.settingsButton = QToolButton()
self.settingsButton.setAutoRaise(True)
self.settingsButton.setIconSize(QSize(22, 22))
self.settingsButton.setDefaultAction(self.settingsAction)
# Create 'Connect to' menu.
self.menuConnect = QMenu('Connect To')
self.menuConnect.menuAction().setIcon(auxilia.PIcon('network-disconnect'))
self.connectButton = QToolButton()
self.connectButton.setAutoRaise(True)
self.connectButton.setIconSize(QSize(22, 22))
self.connectButton.setPopupMode(QToolButton.InstantPopup)
self.connectButton.setIcon(auxilia.PIcon('network-disconnect'))
self.connectButton.setText('Connect To')
self.connectButton.setMenu(self.menuConnect)
# Create 'MDP' menu.
self.menuMPD = QMenu('MPD')
self.menuMPD.menuAction().setIcon(auxilia.PIcon('network-workgroup'))
self.connect(self.menuConnect, SIGNAL('aboutToShow()'), self._buildConnectTo)
self.mpdButton = QToolButton()
self.mpdButton.setAutoRaise(True)
self.mpdButton.setIconSize(QSize(22, 22))
self.mpdButton.setPopupMode(QToolButton.InstantPopup)
self.mpdButton.setIcon(auxilia.PIcon('network-workgroup'))
self.mpdButton.setText('MPD')
self.mpdButton.setMenu(self.menuMPD)
self.reloadLibrary = self.actionLibReload(self.menuMPD, lambda: self.modelManager.reloadLibrary(True))
self.updateLibrary = self.actionLibUpdate(self.menuMPD, lambda: self.mpdclient.send('update'))
self.rescanLibrary = self.actionLibRescan(self.menuMPD, lambda: self.mpdclient.send('rescan'))
# Create 'Outputs' menu.
self.menuOutputs = QMenu('Outputs')
self.menuOutputs.menuAction().setIcon(auxilia.PIcon('audio-card'))
self.connect(self.menuOutputs, SIGNAL('aboutToShow()'), self._buildOutputs)
self.outputsButton = QToolButton()
self.outputsButton.setAutoRaise(True)
self.outputsButton.setIconSize(QSize(22, 22))
self.outputsButton.setPopupMode(QToolButton.InstantPopup)
self.outputsButton.setIcon(auxilia.PIcon('audio-card'))
self.outputsButton.setText('Outputs')
self.outputsButton.setMenu(self.menuOutputs)
# Fill Toolbar.
self.toolBarLayout.addWidget(self.exitButton)
self.toolBarLayout.addWidget(self.settingsButton)
self.toolBarLayout.addWidget(self.connectButton)
self.toolBarLayout.addWidget(self.outputsButton)
self.toolBarLayout.addWidget(self.mpdButton)
self.toolBarLayout.addStretch(1)
# Fill Statusbar.
self.serverLabel = QLabel('Not connected')
self.numSongsLabel = QLabel('Songs')
self.playTimeLabel = QLabel('playTime')
self.statusbar.addWidget(self.serverLabel)
self.statusbar.addPermanentWidget(self.numSongsLabel)
self.statusbar.addPermanentWidget(self.playTimeLabel)
# Set up trayicon and menu.
#.........这里部分代码省略.........
示例7: GuiMain
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
#.........这里部分代码省略.........
#Menu bar
self.menubar = QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 818, 25))
self.menubar.setObjectName("menubar")
self.menuMenu = QMenu(self.menubar)
self.menuMenu.setTitle(QApplication.translate("MainWindow", "Menu", None, QApplication.UnicodeUTF8))
self.menuMenu.setObjectName("menuMenu")
MainWindow.setMenuBar(self.menubar)
self.actionSave_Game = QAction(MainWindow)
self.actionSave_Game.setText(QApplication.translate("MainWindow", "Save Game", None, QApplication.UnicodeUTF8))
self.actionSave_Game.setObjectName("actionSave_Game")
self.actionCredits = QAction(MainWindow)
self.actionCredits.setText(QApplication.translate("MainWindow", "Credits", None, QApplication.UnicodeUTF8))
self.actionCredits.setObjectName("actionCredits")
self.actionQuit = QAction(MainWindow)
self.actionQuit.setText(QApplication.translate("MainWindow", "Quit", None, QApplication.UnicodeUTF8))
self.actionQuit.setObjectName("actionQuit")
self.actionSettings = QAction(MainWindow)
self.actionSettings.setText(QApplication.translate("MainWindow", "Settings", None, QApplication.UnicodeUTF8))
self.actionSettings.setObjectName("actionSettings")
self.actionHelp = QAction(MainWindow)
self.actionHelp.setText(QApplication.translate("MainWindow", "Help", None, QApplication.UnicodeUTF8))
self.actionHelp.setObjectName("actionHelp")
self.actionMain_Menu = QAction(MainWindow)
self.actionMain_Menu.setText(QApplication.translate("MainWindow", "Main Menu", None, QApplication.UnicodeUTF8))
self.actionMain_Menu.setObjectName("actionMain_Menu")
self.menuMenu.addAction(self.actionSettings)
self.menuMenu.addAction(self.actionHelp)
self.menuMenu.addAction(self.actionSave_Game)
self.menuMenu.addAction(self.actionCredits)
self.menuMenu.addAction(self.actionMain_Menu)
self.menuMenu.addAction(self.actionQuit)
self.menubar.addAction(self.menuMenu.menuAction())
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
#These are the slots and signals to connect buttons to other functions
self.location = 0
QtCore.QObject.connect(self.actionQuit, QtCore.SIGNAL("triggered()"), MainWindow.close)
QtCore.QObject.connect(self.quitButton, QtCore.SIGNAL("released()"), MainWindow.close)
QtCore.QObject.connect(self.settingsButton, QtCore.SIGNAL("released()"), self.setSettings)
QtCore.QObject.connect(self.actionSettings, QtCore.SIGNAL("triggered()"), self.setSettings)
QtCore.QObject.connect(self.loadButton, QtCore.SIGNAL("released()"), self.load_file_dialog)
QtCore.QObject.connect(self.actionSave_Game, QtCore.SIGNAL("triggered()"),self.save_file_dialog)
QtCore.QObject.connect(self.doneButton, QtCore.SIGNAL("released()"), self.goBack)
QtCore.QObject.connect(self.startButton, QtCore.SIGNAL("released()"), self.newGame)
QtCore.QObject.connect(self.actionMain_Menu, QtCore.SIGNAL("triggered()"), self.setMain)
QtCore.QObject.connect(self.actionHelp, QtCore.SIGNAL("triggered()"), self.setInstructions)
QtCore.QObject.connect(self.instrButton, QtCore.SIGNAL("released()"), self.setInstructions)
QtCore.QObject.connect(self.doneButton2, QtCore.SIGNAL("released()"), self.goBack)
QtCore.QObject.connect(self.doneButton3, QtCore.SIGNAL("released()"), self.goBack)
QtCore.QObject.connect(self.actionCredits, QtCore.SIGNAL("triggered()"), self.setCredits)
self.latLongCheck.stateChanged.connect(self.latLong)
self.colorCheck.stateChanged.connect(self.colorize)
self.legendCheck.stateChanged.connect(self.legend)
QtCore.QObject.connect(self.searchButton, QtCore.SIGNAL("released()"), self.doSearch)
QtCore.QObject.connect(self.nextButton, QtCore.SIGNAL("released()"), self.storyButton)
self.volumeSlider.sliderMoved.connect(self.setVol)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
pass
示例8: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
class Marsis:
"""Implement the main Plug in interface
*Methods*
* __init__ - Inizialize the plug in
* initGui - Create the menu entries and toolbar icons inside the QGIS GUI
* marsis_viewer - Launch the MARSIS/SHARAD viewer
* marsis_free - Remove reference to MARSIS/SHARAD viewer dialog
* radar_3d - Export 3D data in CSV format
* radar_fetch - Fetch radargrams (To be implemented)
* settings - Launch the preferences settings dialog
* update_prefs - Update the plug in preferences
* unload - Remove the plugin menu item and icon from QGIS GUI
"""
def __init__(self, iface):
"""Inizialize the plug in
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
#set preferences
self.prefs = prefs.RadarPrefs()
self.prefs.set_prefs()
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'Marsis_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# self.iface = iface
self.marsis_menu = None
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI
"""
self.marsis_menu = QMenu(QCoreApplication.translate("marsissharadviewer", "Mars Radars"))
self.iface.mainWindow().menuBar().insertMenu(self.iface.firstRightStandardMenu().menuAction(), self.marsis_menu)
icon = QIcon(':/plugins/marsissharadviewer/icon.png')
self.marsis_viewer_action = QAction(icon, "MARSIS/SHARAD Viewer", self.iface.mainWindow())
QObject.connect(self.marsis_viewer_action, SIGNAL("triggered()"), self.marsis_viewer)
self.marsis_menu.addAction(self.marsis_viewer_action)
self.depth_map_action = QAction(icon, "Make depth map", self.iface.mainWindow())
QObject.connect(self.depth_map_action, SIGNAL("triggered()"), self.depth_map)
self.marsis_menu.addAction(self.depth_map_action)
# self.polar_viewer_action = QAction(icon, "Polar viewer", self.iface.mainWindow())
# QObject.connect(self.marsis_viewer_action, SIGNAL("triggered()"), self.polar_viewer)
# self.marsis_menu.addAction(self.polar_viewer_action)
# icon = QIcon(':/plugins/Marsis/icon.png')
# self.radar_3d_action = QAction(icon, "Radar 3D", self.iface.mainWindow())
# QObject.connect(self.radar_3d_action, SIGNAL("triggered()"), self.radar_3d)
# self.marsis_menu.addAction(self.radar_3d_action)
# icon = QIcon(os.path.dirname(__file__) + ":/plugins/Marsis/icon.png")
# self.track_fetch_action = QAction(icon, "Marsis tracks fetch", self.iface.mainWindow())
# QObject.connect(self.track_fetch_action, SIGNAL("triggered()"), self.track_fetch)
# self.marsis_menu.addAction(self.track_fetch_action)
# icon = QIcon(os.path.dirname(__file__) + ":/plugins/Marsis/icon.png")
# self.radar_fetch_action = QAction(icon, "Marsis radargrams fetch", self.iface.mainWindow())
# QObject.connect(self.radar_fetch_action, SIGNAL("triggered()"), self.radar_fetch)
# self.marsis_menu.addAction(self.radar_fetch_action)
# icon = QIcon(os.path.dirname(__file__) + ":/plugins/Marsis/icon.png")
self.settings_action = QAction(icon, "Settings", self.iface.mainWindow())
QObject.connect(self.settings_action, SIGNAL("triggered()"), self.settings)
self.marsis_menu.addAction(self.settings_action)
# Add toolbar button
# self.iface.addToolBarIcon(self.marsis_viewer_action)
self.toolbar = self.iface.addToolBar(u'MarsisViewer')
self.toolbar.setObjectName(u'MarsisViewer')
self.toolbar.addAction(self.marsis_viewer_action)
def marsis_viewer(self):
"""Launch the MARSIS/SHARAD viewer
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
#.........这里部分代码省略.........
scales_list = []
# TODO: remake when fix: http://hub.qgis.org/issues/11915
# QgsScaleUtils.loadScaleList(scales_filename, scales_list, importer_message)
xml_root = ET.parse(scales_filename).getroot()
for scale_el in xml_root.findall('scale'):
scales_list.append(scale_el.get('value'))
return scales_list
@property
def scales_list(self):
if not self._scales_list:
self._scales_list = self._load_scales_list()
return self._scales_list
def set_nearest_scale(self):
#get current scale
curr_scale = self.iface.mapCanvas().scale()
#find nearest
nearest_scale = sys.maxint
for scale_str in self.scales_list:
scale = scale_str.split(':')[1]
scale_int = int(scale)
if abs(scale_int-curr_scale) < abs(nearest_scale - curr_scale):
nearest_scale = scale_int
#set new scale
if nearest_scale != sys.maxint:
self.iface.mapCanvas().zoomScale(nearest_scale)
def set_tms_scales(self):
res = QMessageBox.question(
self.iface.mainWindow(),
self.tr('QuickMapServices'),
self.tr('Set SlippyMap scales for current project? \nThe previous settings will be overwritten!'),
QMessageBox.Yes | QMessageBox.No)
if res == QMessageBox.Yes:
# set scales
QgsProject.instance().writeEntry('Scales', '/ScalesList', self.scales_list)
# activate
QgsProject.instance().writeEntry('Scales', '/useProjectScales', True)
# update in main window
# ???? no way to update: http://hub.qgis.org/issues/11917
def insert_layer(self):
#TODO: need factory!
action = self.menu.sender()
ds = action.data()
if ds.type == KNOWN_DRIVERS.TMS:
service_info = TileServiceInfo(self.tr(ds.alias), ds.copyright_text, ds.tms_url)
service_info.zmin = ds.tms_zmin or service_info.zmin
service_info.zmax = ds.tms_zmax or service_info.zmax
layer = TileLayer(self, service_info, False)
if ds.type == KNOWN_DRIVERS.GDAL:
layer = QgsRasterLayer(ds.gdal_source_file, self.tr(ds.alias))
if ds.type == KNOWN_DRIVERS.WMS:
qgis_wms_uri = u''
if ds.wms_params:
qgis_wms_uri += ds.wms_params
if ds.wms_layers:
layers = ds.wms_layers.split(',')
if layers:
if ds.wms_turn_over:
layers.reverse()
qgis_wms_uri += '&layers='+'&layers='.join(layers)+'&styles='*len(layers)
qgis_wms_uri += '&url=' + ds.wms_url
layer = QgsRasterLayer(qgis_wms_uri, self.tr(ds.alias), KNOWN_DRIVERS.WMS.lower())
if not layer.isValid():
error_message = self.tr('Layer %s can\'t be added to the map!') % ds.alias
self.iface.messageBar().pushMessage(self.tr('Error'),
error_message,
level=QgsMessageBar.CRITICAL)
QgsMessageLog.logMessage(error_message, level=QgsMessageLog.CRITICAL)
else:
# Set attribs
layer.setAttribution(ds.copyright_text)
layer.setAttributionUrl(ds.copyright_link)
# Insert to bottom
QgsMapLayerRegistry.instance().addMapLayer(layer, False)
toc_root = QgsProject.instance().layerTreeRoot()
toc_root.insertLayer(len(toc_root.children()), layer)
# Save link
self.service_layers.append(layer)
def unload(self):
# remove menu
self.iface.webMenu().removeAction(self.menu.menuAction())
# remove toolbar button
self.iface.webToolBar().removeAction(self.tb_action)
# clean vars
self.menu = None
self.toolbutton = None
self.service_actions = None
self.ds_list = None
self.groups_list = None
self.service_layers = None
# Unregister plugin layer type
QgsPluginLayerRegistry.instance().removePluginLayerType(TileLayer.LAYER_TYPE)
示例10: View
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
class View(QMainWindow, auxilia.Actions):
def __init__(self, configuration, mpdclient, app):
QMainWindow.__init__(self)
self.app = app
self.focus = time()
self.shuttingDown = False
self.config = configuration
self.mpdclient = mpdclient
self.appIcon = os.path.abspath(DATA_DIR+'icons/Pythagora.png')
uic.loadUi(DATA_DIR+'ui/Pythagora.ui', self)
self.KDE = KDE
self.setWindowTitle('Pythagora')
self.setWindowIcon(QIcon(self.appIcon))
# Load all forms.
self.createViews()
# Create 'Connect to' menu.
self.menuConnect = QMenu('Connect To')
self.menuConnect.menuAction().setIcon(auxilia.PIcon('network-disconnect'))
self.connectButton = QToolButton()
self.connectButton.setPopupMode(QToolButton.InstantPopup)
self.connectButton.setIcon(auxilia.PIcon('network-disconnect'))
self.connectButton.setMenu(self.menuConnect)
# Create 'MDP' menu.
self.menuMPD = QMenu('MPD')
self.menuMPD.menuAction().setIcon(auxilia.PIcon('network-workgroup'))
self.mpdButton = QToolButton()
self.mpdButton.setPopupMode(QToolButton.InstantPopup)
self.mpdButton.setIcon(auxilia.PIcon('network-workgroup'))
self.mpdButton.setMenu(self.menuMPD)
self.reloadLibrary = self.actionLibReload(self.menuMPD, self.__libReload)
self.updateLibrary = self.actionLibUpdate(self.menuMPD, lambda: self.mpdclient.send('update'))
self.rescanLibrary = self.actionLibRescan(self.menuMPD, lambda: self.mpdclient.send('rescan'))
# Fill Toolbar.
self.toolBar.addWidget(self.connectButton)
self.toolBar.addWidget(self.mpdButton)
# Fill Statusbar.
self.serverLabel = QLabel('Not connected')
self.numSongsLabel = QLabel('Songs')
self.playTimeLabel = QLabel('playTime')
self.statusbar.addWidget(self.serverLabel)
self.statusbar.addPermanentWidget(self.numSongsLabel)
self.statusbar.addPermanentWidget(self.playTimeLabel)
self.connect(self.menuConnect, SIGNAL('aboutToShow()'), self.__buildConnectTo)
self.connect(self.actionExit,SIGNAL('triggered()'),self.app.quit)
self.connect(self.actionSettings,SIGNAL('triggered()'),self.showConfig)
# Set up trayicon and menu.
if KDE:
self.trayIcon = KTrayIcon(self.appIcon, self)
else:
self.trayIcon = QTrayIcon(self.appIcon, self)
connectMenuAction = self.menuConnect.menuAction()
self.trayIcon.addMenuItem(connectMenuAction)
self.trayIcon.addMenuItem(self.actionSettings)
self.connect(self.trayIcon, SIGNAL('activate()'), self.toggleHideRestore)
self.connect(self.trayIcon, SIGNAL('secondaryActivateRequested(QPoint)'), self.__playPause)
self.connect(self.tabs, SIGNAL('currentChanged(int)'), self.__tabsIndexChanged)
self.connect(self.tabs.tabBar(), SIGNAL('tabMoved(int,int)'), self.__tabMoved)
self.connect(self.splitter, SIGNAL('splitterMoved(int, int)'), self.__storeSplitter)
# Apply configuration.
self.resize(configuration.mgrSize)
self.splitter.setSizes(configuration.mgrSplit)
self.tabs.setCurrentIndex(configuration.tabsIndex)
self.closeEvent = self.closeEvent
self.connect(self.app,SIGNAL('aboutToQuit()'),self.shutdown)
self.show()
#==============================================================================
# Code for switching tabs on drag & drop. (__init__() continues)
#==============================================================================
# Instantiate timer
self.tabTimer = QTimer()
self.connect(self.tabTimer, SIGNAL('timeout()'), self.__selectTab)
# Overload the default dragEvents. (none?)
self.tabs.dragLeaveEvent = self.dragLeaveEvent
self.tabs.dragEnterEvent = self.dragEnterEvent
self.tabs.dragMoveEvent = self.dragMoveEvent
def dragEnterEvent(self, event):
'''Starts timer on enter and sets first position.'''
self.tabPos = event.pos()
event.accept()
self.tabTimer.start(500)
def dragLeaveEvent(self, event):
'''If the mouse leaves the tabWidget stop the timer.'''
self.tabTimer.stop()
def dragMoveEvent(self, event):
'''Keep track of the mouse and change the position, restarts the timer when moved.'''
tabPos = event.pos()
moved = tabPos.manhattanLength() - self.tabPos.manhattanLength()
if moved > 7 or moved < -7:
#.........这里部分代码省略.........
示例11: ResultWindow
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
class ResultWindow(QMainWindow):
def __init__(self, app):
QMainWindow.__init__(self, None)
self.app = app
self._setupUi()
self.resultsModel = app.RESULT_MODEL_CLASS(self.app, self.resultsView)
self.stats = StatsLabel(app.model.stats_label, self.statusLabel)
self._update_column_actions_status()
self.menuColumns.triggered[QAction].connect(self.columnToggled)
self.resultsView.doubleClicked.connect(self.resultsDoubleClicked)
self.resultsView.spacePressed.connect(self.resultsSpacePressed)
self.detailsButton.clicked.connect(self.actionDetails.triggered)
self.dupesOnlyCheckBox.stateChanged.connect(self.powerMarkerTriggered)
self.deltaValuesCheckBox.stateChanged.connect(self.deltaTriggered)
self.searchEdit.searchChanged.connect(self.searchChanged)
self.app.willSavePrefs.connect(self.appWillSavePrefs)
def _setupActions(self):
# (name, shortcut, icon, desc, func)
ACTIONS = [
('actionDetails', 'Ctrl+I', '', tr("Details"), self.detailsTriggered),
('actionActions', '', '', tr("Actions"), self.actionsTriggered),
('actionPowerMarker', 'Ctrl+1', '', tr("Show Dupes Only"), self.powerMarkerTriggered),
('actionDelta', 'Ctrl+2', '', tr("Show Delta Values"), self.deltaTriggered),
('actionDeleteMarked', 'Ctrl+D', '', tr("Send Marked to Recycle Bin..."), self.deleteTriggered),
('actionMoveMarked', 'Ctrl+M', '', tr("Move Marked to..."), self.moveTriggered),
('actionCopyMarked', 'Ctrl+Shift+M', '', tr("Copy Marked to..."), self.copyTriggered),
('actionRemoveMarked', 'Ctrl+R', '', tr("Remove Marked from Results"), self.removeMarkedTriggered),
('actionReprioritize', '', '', tr("Re-Prioritize Results..."), self.reprioritizeTriggered),
('actionRemoveSelected', 'Ctrl+Del', '', tr("Remove Selected from Results"), self.removeSelectedTriggered),
('actionIgnoreSelected', 'Ctrl+Shift+Del', '', tr("Add Selected to Ignore List"), self.addToIgnoreListTriggered),
('actionMakeSelectedReference', 'Ctrl+Space', '', tr("Make Selected into Reference"), self.app.model.make_selected_reference),
('actionOpenSelected', 'Ctrl+O', '', tr("Open Selected with Default Application"), self.openTriggered),
('actionRevealSelected', 'Ctrl+Shift+O', '', tr("Open Containing Folder of Selected"), self.revealTriggered),
('actionRenameSelected', 'F2', '', tr("Rename Selected"), self.renameTriggered),
('actionMarkAll', 'Ctrl+A', '', tr("Mark All"), self.markAllTriggered),
('actionMarkNone', 'Ctrl+Shift+A', '', tr("Mark None"), self.markNoneTriggered),
('actionInvertMarking', 'Ctrl+Alt+A', '', tr("Invert Marking"), self.markInvertTriggered),
('actionMarkSelected', '', '', tr("Mark Selected"), self.markSelectedTriggered),
('actionExportToHTML', '', '', tr("Export To HTML"), self.app.model.export_to_xhtml),
('actionExportToCSV', '', '', tr("Export To CSV"), self.app.model.export_to_csv),
('actionSaveResults', 'Ctrl+S', '', tr("Save Results..."), self.saveResultsTriggered),
('actionInvokeCustomCommand', 'Ctrl+Alt+I', '', tr("Invoke Custom Command"), self.app.invokeCustomCommand),
]
createActions(ACTIONS, self)
self.actionDelta.setCheckable(True)
self.actionPowerMarker.setCheckable(True)
def _setupMenu(self):
self.menubar = QMenuBar(self)
self.menubar.setGeometry(QRect(0, 0, 630, 22))
self.menuFile = QMenu(self.menubar)
self.menuFile.setTitle(tr("File"))
self.menuMark = QMenu(self.menubar)
self.menuMark.setTitle(tr("Mark"))
self.menuActions = QMenu(self.menubar)
self.menuActions.setTitle(tr("Actions"))
self.menuColumns = QMenu(self.menubar)
self.menuColumns.setTitle(tr("Columns"))
self.menuView = QMenu(self.menubar)
self.menuView.setTitle(tr("View"))
self.menuHelp = QMenu(self.menubar)
self.menuHelp.setTitle(tr("Help"))
self.setMenuBar(self.menubar)
self.menuActions.addAction(self.actionDeleteMarked)
self.menuActions.addAction(self.actionMoveMarked)
self.menuActions.addAction(self.actionCopyMarked)
self.menuActions.addAction(self.actionRemoveMarked)
self.menuActions.addAction(self.actionReprioritize)
self.menuActions.addSeparator()
self.menuActions.addAction(self.actionRemoveSelected)
self.menuActions.addAction(self.actionIgnoreSelected)
self.menuActions.addAction(self.actionMakeSelectedReference)
self.menuActions.addSeparator()
self.menuActions.addAction(self.actionOpenSelected)
self.menuActions.addAction(self.actionRevealSelected)
self.menuActions.addAction(self.actionInvokeCustomCommand)
self.menuActions.addAction(self.actionRenameSelected)
self.menuMark.addAction(self.actionMarkAll)
self.menuMark.addAction(self.actionMarkNone)
self.menuMark.addAction(self.actionInvertMarking)
self.menuMark.addAction(self.actionMarkSelected)
self.menuView.addAction(self.actionPowerMarker)
self.menuView.addAction(self.actionDelta)
self.menuView.addSeparator()
self.menuView.addAction(self.actionDetails)
self.menuView.addAction(self.app.actionIgnoreList)
self.menuView.addAction(self.app.actionPreferences)
self.menuHelp.addAction(self.app.actionShowHelp)
self.menuHelp.addAction(self.app.actionCheckForUpdate)
self.menuHelp.addAction(self.app.actionOpenDebugLog)
self.menuHelp.addAction(self.app.actionAbout)
self.menuFile.addAction(self.actionSaveResults)
self.menuFile.addAction(self.actionExportToHTML)
self.menuFile.addAction(self.actionExportToCSV)
self.menuFile.addSeparator()
self.menuFile.addAction(self.app.actionQuit)
#.........这里部分代码省略.........
示例12: QDataTableView
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
#.........这里部分代码省略.........
def showVerticalHeaderMenu(self, point):
"""Display the menu that occurs when right clicking on a vertical header."""
rowMenu = QMenu(self)
insertRowAction = QAction("Insert Rows", rowMenu)
deleteRowAction = QAction("Delete Rows", rowMenu)
rowMenu.addAction(insertRowAction)
rowMenu.addAction(deleteRowAction)
# Connect signals
insertRowAction.triggered.connect(self.insertCells)
deleteRowAction.triggered.connect(self.deleteCells)
# Display menu
rowMenu.exec_(self.mapToGlobal(point))
# Disconnect signals
insertRowAction.triggered.disconnect(self.insertCells)
deleteRowAction.triggered.disconnect(self.deleteCells)
def setupHorizontalHeaderMenu(self):
self.horizontalHeader().setContextMenuPolicy(Qt.CustomContextMenu)
self.horizontalHeader().customContextMenuRequested.connect(self.showHorizontalHeaderMenu)
self.horizontalHeaderMenu = QMenu(self.horizontalHeader())
# Create actions
self.renameWaveAction = QAction("Rename Wave", self.horizontalHeaderMenu)
self.removeWaveAction = QAction("Remove Wave", self.horizontalHeaderMenu)
self.addWaveMenu = QMenu("Add Wave", self.horizontalHeaderMenu)
# Add actions to menu
self.horizontalHeaderMenu.addAction(self.addWaveMenu.menuAction())
self.horizontalHeaderMenu.addAction(self.renameWaveAction)
self.horizontalHeaderMenu.addAction(self.removeWaveAction)
def showHorizontalHeaderMenu(self, point):
"""Display the menu that occurs when right clicking on a column header."""
logicalIndex = self.horizontalHeader().logicalIndexAt(point)
visualIndex = self.horizontalHeader().visualIndex(logicalIndex)
self.selectColumn(logicalIndex)
#print "l: " + str(logicalIndex)
#print "v: " + str(visualIndex)
selectedWave = self.model().waves()[logicalIndex]
# Create helper functions, defined for this specific menu location
def renameWaveHelper():
self.renameWave(selectedWave)
def removeWaveHelper():
#self.removeWave(selectedWave)
self.removeWave(visualIndex)
def addWaveHelper(wave):
self.addWave(wave, visualIndex)
def addNewWaveHelper():
wave = Wave(self._app.waves().findGoodWaveName())
self._app.waves().addWave(wave)
self.addWave(wave, visualIndex)
self.addWaveMenu.clear()
示例13: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
#.........这里部分代码省略.........
"""
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
self.toolbar.addAction(action)
if add_to_menu:
self.menu.addAction (action)
self.actions.append(action)
return action
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
self.add_action(
':/plugins/SOSClient/icon_add.png',
text=self.tr(u'SOS Client'),
callback=self.run,
parent=self.iface.mainWindow())
self.add_action(
':/plugins/SOSClient/icon_xml.png',
text=self.tr(u'Show XML'),
callback=self.showLayerXml,
parent=self.iface.mainWindow(),
add_to_toolbar=True)
self.add_action(
':/plugins/SOSClient/icon_plot.png',
text=self.tr(u'Plot'),
callback=self.showPlotDialog,
parent=self.iface.mainWindow(),
add_to_toolbar=True)
self.add_action(
':/plugins/SOSClient/icon.png',
text=self.tr(u'About'),
callback=self.about,
parent=self.iface.mainWindow(),
add_to_toolbar=False)
self.menu.setIcon(QIcon(':/plugins/SOSClient/icon.png'))
self.iface.webMenu().addMenu (self.menu)
def unload(self):
"""Removes the plugin menu item and icon from QGIS GUI."""
for action in self.actions:
self.iface.removeToolBarIcon(action)
self.iface.webMenu().removeAction(self.menu.menuAction())
def run(self):
"""Run method that performs all the real work"""
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result:
# Do something useful here - delete the line containing pass and
# substitute with your code.
pass
def showLayerXml (self):
layer = self.iface.activeLayer()
if layer == None:
self.iface.messageBar().pushMessage (self.tr(u'SOS Client'),self.tr("You must select a layer"), QgsMessageBar.WARNING, 10)
return
xml = layer.customProperty("xml")
if len (xml):
dlg = XmlViewerDialog (self.iface.mainWindow(), QFile(xml), XmlHighlighter)
dlg.show()
dlg.exec_()
else:
self.iface.messageBar().pushMessage (self.tr(u'SOS Client'),self.tr("Layer have not a xml property"), QgsMessageBar.WARNING, 10)
def showPlotDialog (self):
try:
dlg = SOSPlotDialog (self.iface.activeLayer(), parent=self.iface.mainWindow())
dlg.show()
dlg.exec_()
except Exception as error:
self.iface.messageBar().pushMessage (self.tr(u'SOS Client'),unicode(error), QgsMessageBar.CRITICAL, 10)
def about(self):
#TODO
QMessageBox.information(self.iface.mainWindow(), self.tr(u"About SOS Client"),
self.tr(u"SOS Client Plugin<br />This plugin request observations data from OGC SOS server to create a vector layer.<br />Also provides tools to plot observations data<br /><br />Author: Rubén Mosquera Varela<br />E-mail: <a href=\"mailto:[email protected]\">[email protected]</a>"))
示例14: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
#.........这里部分代码省略.........
# Unregister plugin layer type
QgsPluginLayerRegistry.instance().removePluginLayerType(TileLayer.LAYER_TYPE)
def build_menu_tree(self):
# Main Menu
self.menu.clear()
self.groups_list = GroupsList()
self.ds_list = DataSourcesList()
data_sources = self.ds_list.data_sources.values()
data_sources.sort(key=lambda x: x.alias or x.id)
ds_hide_list = PluginSettings.get_hide_ds_id_list()
for ds in data_sources:
if ds.id in ds_hide_list:
continue
ds.action.triggered.connect(self.insert_layer)
gr_menu = self.groups_list.get_group_menu(ds.group)
gr_menu.addAction(ds.action)
if gr_menu not in self.menu.children():
self.menu.addMenu(gr_menu)
# Scales, Settings and About actions
self.menu.addSeparator()
icon_set_nearest_scale_path = self.plugin_dir + "/icons/mActionSettings.png" # TODO change icon
set_nearest_scale_act = QAction(
QIcon(icon_set_nearest_scale_path), self.tr("Set proper scale"), self.iface.mainWindow()
)
set_nearest_scale_act.triggered.connect(self.set_nearest_scale)
self.menu.addAction(set_nearest_scale_act) # TODO: uncomment after fix
self.service_actions.append(set_nearest_scale_act)
icon_scales_path = self.plugin_dir + "/icons/mActionSettings.png" # TODO change icon
scales_act = QAction(QIcon(icon_scales_path), self.tr("Set SlippyMap scales"), self.iface.mainWindow())
scales_act.triggered.connect(self.set_tms_scales)
# self.menu.addAction(scales_act) # TODO: uncomment after fix
self.service_actions.append(scales_act)
icon_settings_path = self.plugin_dir + "/icons/mActionSettings.png"
settings_act = QAction(QIcon(icon_settings_path), self.tr("Settings"), self.iface.mainWindow())
self.service_actions.append(settings_act)
settings_act.triggered.connect(self.show_settings_dialog)
self.menu.addAction(settings_act)
icon_about_path = self.plugin_dir + "/icons/mActionAbout.png"
info_act = QAction(QIcon(icon_about_path), self.tr("About"), self.iface.mainWindow())
self.service_actions.append(info_act)
info_act.triggered.connect(self.info_dlg.show)
self.menu.addAction(info_act)
def remove_menu_buttons(self):
"""
Remove menus/buttons from all toolbars and main submenu
:return:
None
"""
# remove menu
if self.menu:
self.iface.webMenu().removeAction(self.menu.menuAction())
self.iface.addLayerMenu().removeAction(self.menu.menuAction())
# remove toolbar button
if self.tb_action:
self.iface.webToolBar().removeAction(self.tb_action)
self.iface.layerToolBar().removeAction(self.tb_action)
def append_menu_buttons(self):
"""
Append menus and buttons to appropriate toolbar
:return:
"""
# add to QGIS menu
if PluginSettings.move_to_layers_menu():
self.iface.addLayerMenu().addMenu(self.menu)
else:
# need workaround for WebMenu
_temp_act = QAction("temp", self.iface.mainWindow())
self.iface.addPluginToWebMenu("_tmp", _temp_act)
self.iface.webMenu().addMenu(self.menu)
self.iface.removePluginWebMenu("_tmp", _temp_act)
# add to QGIS toolbar
toolbutton = QToolButton()
toolbutton.setPopupMode(QToolButton.InstantPopup)
toolbutton.setMenu(self.menu)
toolbutton.setIcon(self.menu.icon())
toolbutton.setText(self.menu.title())
toolbutton.setToolTip(self.menu.title())
if PluginSettings.move_to_layers_menu():
self.tb_action = self.iface.layerToolBar().addWidget(toolbutton)
else:
self.tb_action = self.iface.webToolBar().addWidget(toolbutton)
def show_settings_dialog(self):
settings_dlg = SettingsDialog()
settings_dlg.exec_()
# apply settings
# self.remove_menu_buttons()
self.build_menu_tree()
示例15: DirectoriesDialog
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import menuAction [as 别名]
class DirectoriesDialog(QMainWindow):
def __init__(self, parent, app):
QMainWindow.__init__(self, None)
self.app = app
self.lastAddedFolder = platform.INITIAL_FOLDER_IN_DIALOGS
self.recentFolders = Recent(self.app, "recentFolders")
self._setupUi()
self.directoriesModel = DirectoriesModel(self.app.model.directory_tree, view=self.treeView)
self.directoriesDelegate = DirectoriesDelegate()
self.treeView.setItemDelegate(self.directoriesDelegate)
self._setupColumns()
self.app.recentResults.addMenu(self.menuLoadRecent)
self.app.recentResults.addMenu(self.menuRecentResults)
self.recentFolders.addMenu(self.menuRecentFolders)
self._updateAddButton()
self._updateRemoveButton()
self._updateLoadResultsButton()
self._setupBindings()
def _setupBindings(self):
self.scanButton.clicked.connect(self.scanButtonClicked)
self.loadResultsButton.clicked.connect(self.actionLoadResults.trigger)
self.addFolderButton.clicked.connect(self.actionAddFolder.trigger)
self.removeFolderButton.clicked.connect(self.removeFolderButtonClicked)
self.treeView.selectionModel().selectionChanged.connect(self.selectionChanged)
self.app.recentResults.itemsChanged.connect(self._updateLoadResultsButton)
self.recentFolders.itemsChanged.connect(self._updateAddButton)
self.recentFolders.mustOpenItem.connect(self.app.model.add_directory)
self.directoriesModel.foldersAdded.connect(self.directoriesModelAddedFolders)
self.app.willSavePrefs.connect(self.appWillSavePrefs)
def _setupActions(self):
# (name, shortcut, icon, desc, func)
ACTIONS = [
("actionLoadResults", "Ctrl+L", "", tr("Load Results..."), self.loadResultsTriggered),
("actionShowResultsWindow", "", "", tr("Results Window"), self.app.showResultsWindow),
("actionAddFolder", "", "", tr("Add Folder..."), self.addFolderTriggered),
]
createActions(ACTIONS, self)
def _setupMenu(self):
self.menubar = QMenuBar(self)
self.menubar.setGeometry(QRect(0, 0, 42, 22))
self.menuFile = QMenu(self.menubar)
self.menuFile.setTitle(tr("File"))
self.menuView = QMenu(self.menubar)
self.menuView.setTitle(tr("View"))
self.menuHelp = QMenu(self.menubar)
self.menuHelp.setTitle(tr("Help"))
self.menuLoadRecent = QMenu(self.menuFile)
self.menuLoadRecent.setTitle(tr("Load Recent Results"))
self.setMenuBar(self.menubar)
self.menuFile.addAction(self.actionLoadResults)
self.menuFile.addAction(self.menuLoadRecent.menuAction())
self.menuFile.addSeparator()
self.menuFile.addAction(self.app.actionQuit)
self.menuView.addAction(self.app.actionPreferences)
self.menuView.addAction(self.actionShowResultsWindow)
self.menuView.addAction(self.app.actionIgnoreList)
self.menuHelp.addAction(self.app.actionShowHelp)
self.menuHelp.addAction(self.app.actionRegister)
self.menuHelp.addAction(self.app.actionCheckForUpdate)
self.menuHelp.addAction(self.app.actionOpenDebugLog)
self.menuHelp.addAction(self.app.actionAbout)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuView.menuAction())
self.menubar.addAction(self.menuHelp.menuAction())
# Recent folders menu
self.menuRecentFolders = QMenu()
self.menuRecentFolders.addAction(self.actionAddFolder)
self.menuRecentFolders.addSeparator()
# Recent results menu
self.menuRecentResults = QMenu()
self.menuRecentResults.addAction(self.actionLoadResults)
self.menuRecentResults.addSeparator()
def _setupUi(self):
self.setWindowTitle(self.app.NAME)
self.resize(420, 338)
self.centralwidget = QWidget(self)
self.verticalLayout = QVBoxLayout(self.centralwidget)
self.promptLabel = QLabel(tr('Select folders to scan and press "Scan".'), self.centralwidget)
self.verticalLayout.addWidget(self.promptLabel)
self.treeView = QTreeView(self.centralwidget)
self.treeView.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.treeView.setSelectionBehavior(QAbstractItemView.SelectRows)
self.treeView.setAcceptDrops(True)
triggers = (
QAbstractItemView.DoubleClicked | QAbstractItemView.EditKeyPressed | QAbstractItemView.SelectedClicked
)
self.treeView.setEditTriggers(triggers)
self.treeView.setDragDropOverwriteMode(True)
self.treeView.setDragDropMode(QAbstractItemView.DropOnly)
self.treeView.setUniformRowHeights(True)
self.verticalLayout.addWidget(self.treeView)
self.horizontalLayout = QHBoxLayout()
#.........这里部分代码省略.........