本文整理汇总了Python中PyQt4.QtGui.QMenu.children方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.children方法的具体用法?Python QMenu.children怎么用?Python QMenu.children使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.children方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DragLabel
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import children [as 别名]
class DragLabel(QtGui.QLabel):
def __init__(self, parent):
super(DragLabel, self).__init__(parent)
self.offset = 0
self.icon_path = ""
self.move_icon = None
self.double_click_func = None
self.ecu_key = None
self.selected = False
self.contextMenu = QMenu(str("Context menu"), self);
self.env_view = None
@try_ex
def set_doubleclick_func(self, func):
self.double_click_func = func
@try_ex
def enterEvent(self, *args, **kwargs):
self.setCursor(Qt.OpenHandCursor)
if not self.selected:
self.setStyleSheet('QLabel { border: 2px solid red; padding: 0px; border-radius: 15px} ')
@try_ex
def leaveEvent(self, *args, **kwargs):
if not self.selected:
self.setStyleSheet('QLabel {border: 0px solid red;border-radius: 15px;}')
@try_ex
def mousePressEvent(self, e):
if e.button() == QtCore.Qt.LeftButton:
self.setCursor(Qt.ClosedHandCursor)
self.offset = e.pos()
if e.modifiers() == Qt.ControlModifier:
if self.selected:
self.setStyleSheet('QLabel {border: 0px solid red;border-radius: 15px;}')
self.selected = False
try:
DragSelection().selected.remove(self)
except:
pass
else:
self.setStyleSheet('QLabel { border: 2px solid red; background: darkred; padding: 0px; border-radius: 15px} ')
self.selected = True
DragSelection().selected.append(self)
if e.button() == QtCore.Qt.RightButton:
DragSelection().clicked = self
pop = e.pos() + self.parent().pos()
self.contextMenu.exec(self.mapToParent(pop)); # HERE POSITION
@try_ex
def set_context_menu_actions(self, actions):
try:
self.context_actions = actions
for action in self.context_actions:
if action not in self.contextMenu.children():
self.contextMenu.addAction(action)
except:
pass
@try_ex
def mouseReleaseEvent(self, e):
if e.button() == Qt.LeftButton:
self.setCursor(Qt.ArrowCursor);
cur_pos = e.pos() - self.offset
@try_ex
def mouseMoveEvent(self, event):
self.move(self.mapToParent(event.pos() - self.offset));
a = self.env_view
GBuilder().update_connected(a, None, None, self.env_view.selected_env)
print("Move")
@try_ex
def mouseDoubleClickEvent(self, e):
try:
self.double_click_func(e.pos() - self.offset, self.ecu_key, self)
except:
ECULogger().log_traceback()
示例2: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import children [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)
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import children [as 别名]
#.........这里部分代码省略.........
layer = QgsRasterLayer(qgis_wms_uri, self.tr(ds.alias), KNOWN_DRIVERS.WMS.lower())
layers4add.append(layer)
if ds.type == KNOWN_DRIVERS.WFS:
qgis_wfs_uri_base = ds.wfs_url
o = urlparse.urlparse(qgis_wfs_uri_base)
request_attrs = dict(urlparse.parse_qsl(o.query))
layers_str = request_attrs.get("TYPENAME", "")
layers = layers_str.split(",")
for layer_name in layers:
new_request_attrs = request_attrs
new_request_attrs["TYPENAME"] == layer_name
url_parts = list(o)
url_parts[4] = "&".join(["%s=%s" % (k, v) for k, v in new_request_attrs.items()])
qgis_wfs_uri = urlparse.urlunparse(url_parts)
layer = QgsVectorLayer(qgis_wfs_uri, "%s - %s" % (self.tr(ds.alias), layer_name), "WFS")
layers4add.append(layer)
for layer in layers4add:
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)
# Set OTF CRS Transform for map
if PluginSettings.enable_otf_3857() and ds.type == KNOWN_DRIVERS.TMS:
self.iface.mapCanvas().setCrsTransformEnabled(True)
self.iface.mapCanvas().setDestinationCrs(TileLayer.CRS_3857)
def unload(self):
# remove menu/
self.remove_menu_buttons()
# 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)
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()