本文整理汇总了Python中PyQt4.QtGui.QMenu.icon方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.icon方法的具体用法?Python QMenu.icon怎么用?Python QMenu.icon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.icon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import icon [as 别名]
class QuickMapServices:
"""QGIS Plugin Implementation."""
def __init__(self, iface):
"""Constructor.
: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
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
self.translator = QTranslator()
self.locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'QuickMapServices_{}.qm'.format(self.locale))
if os.path.exists(locale_path):
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
self.custom_translator = CustomTranslator()
QCoreApplication.installTranslator(self.custom_translator)
# Create the dialog (after translation) and keep reference
self.settings_dlg = SettingsDialog()
self.info_dlg = AboutDialog()
# Declare instance attributes
self.service_actions = []
self.service_layers = [] # TODO: id and smart remove
self._scales_list = None
# TileLayer assets
self.crs3857 = None
self.downloadTimeout = 30 # TODO: settings
self.navigationMessagesEnabled = Qt.Checked # TODO: settings
self.pluginName = 'QuickMapServices'
# noinspection PyMethodMayBeStatic
def tr(self, message):
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('QuickMapServices', message)
def initGui(self):
#import pydevd
#pydevd.settrace('localhost', port=9921, stdoutToServer=True, stderrToServer=True, suspend=False)
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
# Main Menu
icon_path = self.plugin_dir + '/icons/mActionAddLayer.png'
self.menu = QMenu(self.tr(u'QuickMapServices'))
self.menu.setIcon(QIcon(icon_path))
# DataSources Actions
# Register plugin layer type
self.tileLayerType = TileLayerType(self)
QgsPluginLayerRegistry.instance().addPluginLayerType(self.tileLayerType)
self.groups_list = DsGroupsList(self.locale, self.custom_translator)
self.ds_list = DataSourcesList(self.locale, self.custom_translator)
data_sources = self.ds_list.data_sources.values()
data_sources.sort(key=lambda x: x.alias or x.id)
for ds in data_sources:
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
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)
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import icon [as 别名]
class QuickMapServices:
"""QGIS Plugin Implementation."""
def __init__(self, iface):
"""Constructor.
: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
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__).decode(sys.getfilesystemencoding())
# initialize locale
self.translator = QTranslator()
self.locale = Locale.get_locale()
locale_path = os.path.join(self.plugin_dir, "i18n", "QuickMapServices_{}.qm".format(self.locale))
if os.path.exists(locale_path):
self.translator.load(locale_path)
if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
self.custom_translator = CustomTranslator()
QCoreApplication.installTranslator(self.custom_translator)
# Create the dialog (after translation) and keep reference
self.info_dlg = AboutDialog()
# Check Contrib and User dirs
try:
ExtraSources.check_extra_dirs()
except:
error_message = self.tr("Extra dirs for %s can't be created: %s %s") % (
PluginSettings.product_name(),
sys.exc_type,
sys.exc_value,
)
self.iface.messageBar().pushMessage(self.tr("Error"), error_message, level=QgsMessageBar.CRITICAL)
# Declare instance attributes
self.service_actions = []
self.service_layers = [] # TODO: id and smart remove
self._scales_list = None
# noinspection PyMethodMayBeStatic
def tr(self, message):
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate("QuickMapServices", message)
def initGui(self):
# import pydevd
# pydevd.settrace('localhost', port=9921, stdoutToServer=True, stderrToServer=True, suspend=False)
# Register plugin layer type
self.tileLayerType = TileLayerType(self)
QgsPluginLayerRegistry.instance().addPluginLayerType(self.tileLayerType)
# Create menu
icon_path = self.plugin_dir + "/icons/mActionAddLayer.png"
self.menu = QMenu(self.tr(u"QuickMapServices"))
self.menu.setIcon(QIcon(icon_path))
self.build_menu_tree()
# add to QGIS menu/toolbars
self.append_menu_buttons()
def _load_scales_list(self):
scales_filename = os.path.join(self.plugin_dir, "scales.xml")
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:
#.........这里部分代码省略.........