本文整理汇总了Python中PyQt4.QtGui.QActionGroup.checkedAction方法的典型用法代码示例。如果您正苦于以下问题:Python QActionGroup.checkedAction方法的具体用法?Python QActionGroup.checkedAction怎么用?Python QActionGroup.checkedAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QActionGroup
的用法示例。
在下文中一共展示了QActionGroup.checkedAction方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FloatingToolBar
# 需要导入模块: from PyQt4.QtGui import QActionGroup [as 别名]
# 或者: from PyQt4.QtGui.QActionGroup import checkedAction [as 别名]
class FloatingToolBar(QToolBar):
"""
A floating QToolBar with no border and is offset under its parent
"""
def __init__(self, name, parent):
"""
parent: The parent of this toolbar. Should be another toolbar
"""
QToolBar.__init__(self, name, parent)
self.setMovable(False)
self.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint | Qt.X11BypassWindowManagerHint)
self.setAllowedAreas(Qt.NoToolBarArea)
self.actiongroup = QActionGroup(self)
def addToActionGroup(self, action):
self.actiongroup.addAction(action)
def showToolbar(self, parentaction, defaultaction, toggled):
if toggled:
self.show()
if defaultaction:
defaultaction.toggle()
widget = self.parent().widgetForAction(parentaction)
x = self.parent().mapToGlobal(widget.pos()).x()
y = self.parent().mapToGlobal(widget.pos()).y()
newpoint = QPoint(x, y + self.parent().rect().height())
# if self.orientation() == Qt.Vertical:
# newpoint = QPoint(x, y + self.parent().rect().width())
self.move(newpoint)
else:
action = self.actiongroup.checkedAction()
if action:
action.toggle()
self.hide()
示例2: __init__
# 需要导入模块: from PyQt4.QtGui import QActionGroup [as 别名]
# 或者: from PyQt4.QtGui.QActionGroup import checkedAction [as 别名]
#.........这里部分代码省略.........
action)
if checkable:
self.exclusive.addAction( action )
self.actions.append(action)
return action
def initGui(self):
icon_path = ":/plugins/qgeric/resources/icon_geocode.png"
self.add_action(
icon_path,
text=self.tr("Geocoding"),
callback=self.geocoding,
parent=self.iface.mainWindow()
)
icon_path = ":/plugins/qgeric/resources/icon_reversegeocode.png"
self.add_action(
icon_path,
checkable = True,
text=self.tr("Reverse geocoding"),
callback=self.reverseGeocoding,
parent=self.iface.mainWindow()
)
def geocoding(self):
self.rb.reset( QGis.Point )
address, ok = QInputDialog.getText(self.iface.mainWindow(), self.tr("Address"), self.tr("Input address to geocode:"))
if ok and address:
self.doGeocoding(address)
def doGeocoding(self, address):
address = unicodedata.normalize('NFKD', unicode(address)).encode('ASCII', 'ignore')
url = "http://api-adresse.data.gouv.fr/search/?q="+address.replace(" ", "%20")
result = self.request(url)
try:
data = json.loads(result)
features = data["features"]
if len(features) > 0:
feature_list = []
for feature in features:
feature_list.append(feature["properties"]["label"]+" - "+str(round(feature["properties"]["score"]*100))+"%")
feature, ok = QInputDialog.getItem(self.iface.mainWindow(), self.tr("Result"), "", feature_list)
if ok:
index = feature_list.index(feature)
x = features[index]["geometry"]["coordinates"][0]
y = features[index]["geometry"]["coordinates"][1]
point_4326 = QgsPoint(x, y)
transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem(4326),
self.canvas.mapSettings().destinationCrs())
point_2154 = transform.transform(point_4326)
self.rb.addPoint(point_2154)
self.iface.mapCanvas().setCenter(point_2154)
self.iface.mapCanvas().refresh()
else:
QMessageBox.information(self.iface.mainWindow(), self.tr("Result"), self.tr("No result."))
except ValueError:
QMessageBox.critical(self.iface.mainWindow(), self.tr("Error"), self.tr("An error occured. Check your network settings (proxy)."))
def reverseGeocoding(self):
self.canvas.setMapTool(self.tool)
def doReverseGeocoding(self, point_orig):
transform = QgsCoordinateTransform(self.canvas.mapSettings().destinationCrs(),
QgsCoordinateReferenceSystem(4326))
point_4326 = transform.transform(point_orig)
url = "http://api-adresse.data.gouv.fr/reverse/?lon="+str(point_4326.x())+"&lat="+str(point_4326.y())
result = self.request(url)
try:
data = json.loads(result)
if len(data["features"]) > 0:
address = data["features"][0]["properties"]["label"]
clicked = QMessageBox.information(self.iface.mainWindow(), self.tr("Result"), address, QDialogButtonBox.Ok, QDialogButtonBox.Save)
if clicked == QDialogButtonBox.Save:
QApplication.clipboard().setText(address)
else:
QMessageBox.information(self.iface.mainWindow(), self.tr("Result"), self.tr("No result."))
except ValueError:
QMessageBox.critical(self.iface.mainWindow(), self.tr("Error"), self.tr("An error occured. Check your network settings (proxy)."))
def uncheckReverseGeocoding(self):
self.exclusive.checkedAction().setChecked(False)
def request(self, url):
''' prepare the request and return the result of the reply
'''
request = QNetworkRequest(QUrl(url))
reply = self.manager.get(request)
reply.deleteLater()
evloop = QEventLoop()
reply.finished.connect(evloop.quit)
evloop.exec_(QEventLoop.ExcludeUserInputEvents)
return unicode(reply.readAll())
示例3: QMap
# 需要导入模块: from PyQt4.QtGui import QActionGroup [as 别名]
# 或者: from PyQt4.QtGui.QActionGroup import checkedAction [as 别名]
#.........这里部分代码省略.........
labelaction = self.menutoolbar.insertWidget(self.configAction, self.userlabel)
self.menutoolbar.insertWidget(labelaction, quitspacewidget)
self.menutoolbar.insertWidget(labelaction, self.projectlabel)
self.setupIcons()
self.stack.currentChanged.connect(self.updateUIState)
def updateUIState(self, page):
"""
Update the UI state to reflect the currently selected
page in the stacked widget
"""
def setToolbarsActive(enabled):
toolbars = self.mainwindow.findChildren(QToolBar)
for toolbar in toolbars:
if toolbar == self.menutoolbar:
continue
toolbar.setEnabled(enabled)
def setPanelsVisible(visible):
for panel in self.panels:
panel.setVisible(visible)
ismapview = page == 0
setToolbarsActive(ismapview)
setPanelsVisible(ismapview)
self.infodock.hide()
def addAtGPS(self):
"""
Add a record at the current GPS location.
"""
action = self.actionGroup.checkedAction()
if not action:
return
layer = action.data()
if not layer:
return
point = self.gpsAction.position
self.addNewFeature(layer=layer, geometry=point)
def zoomToDefaultView(self):
"""
Zoom the mapview canvas to the extents the project was opened at i.e. the
default extent.
"""
self.iface.mapCanvas().setExtent(self.defaultextent)
self.iface.mapCanvas().refresh()
def toggleRasterLayers(self):
"""
Toggle all raster layers on or off.
"""
legend = self.iface.legendInterface()
#Freeze the canvas to save on UI refresh
self.iface.mapCanvas().freeze()
for layer in self._mapLayers.values():
if layer.type() == QgsMapLayer.RasterLayer:
isvisible = legend.isLayerVisible(layer)
legend.setLayerVisible(layer, not isvisible)
self.iface.mapCanvas().freeze(False)
self.iface.mapCanvas().refresh()
def setupIcons(self):
示例4: Viewer
# 需要导入模块: from PyQt4.QtGui import QActionGroup [as 别名]
# 或者: from PyQt4.QtGui.QActionGroup import checkedAction [as 别名]
#.........这里部分代码省略.........
enabledelete = layer.isEditable() and layer.selectedFeatureCount()
enablemove = layer.geometryType() == QGis.Point and layer.isEditable()
else:
enabledselecttools = False
enableedittools = False
enabledelete = False
enablemove = False
self.set_button_states(enabledselecttools, enableedittools, enabledelete, enablemove)
self.action_triggered()
self.layerChanged.emit(layer)
def selection_changed(self, layer):
if layer == self.active_layer:
enabledelete = layer.isEditable() and layer.selectedFeatureCount()
self.deleteaction.setEnabled(enabledelete)
def set_button_states(self, selecttools, edittools, deleteenabled, moveenabled):
actions = [self.selectaction, self.infoaction]
for action in actions:
action.setEnabled(selecttools)
editactions = [self.deleteaction, self.moveaction, self.addaction]
for action in editactions:
action.setEnabled(edittools)
if edittools:
self.deleteaction.setEnabled(deleteenabled)
self.moveaction.setEnabled(moveenabled)
for action in editactions:
if action is self.actiongroup.checkedAction() and not action.isEnabled():
self.infoaction.toggle()
break
layer = self.active_layer
if not layer:
enablez = False
else:
enablez = layer.type() == QgsMapLayer.VectorLayer and layer.geometryType() == QGis.Point
self.zvalueaction.setEnabled(enablez)
@property
def current_action_color(self):
action = self.actiongroup.checkedAction()
color = int("0x00ff00", 16)
if action == self.measureaction:
if self.mode == "Vertical":
color = int("0x0000ff", 16)
return color
def action_triggered(self, *args):
action = self.actiongroup.checkedAction()
layer = self.activelayercombo.currentLayer()
self.clear_line()
if not action:
return
if not action == self.measureaction and (not layer or not layer.type() == QgsMapLayer.VectorLayer):
return
color = self.current_action_color
示例5: ActionSettingsTool
# 需要导入模块: from PyQt4.QtGui import QActionGroup [as 别名]
# 或者: from PyQt4.QtGui.QActionGroup import checkedAction [as 别名]
class ActionSettingsTool(QToolButton):
settingsChanged = pyqtSignal()
mapActionChanged = pyqtSignal(int)
filterActionChanged = pyqtSignal(int)
drawingActionChanged = pyqtSignal(int)
def __init__(self, parent=None):
super(ActionSettingsTool, self).__init__(parent)
self._mapActionGroup = QActionGroup(self)
self._noMapAction = self._addMapAction(MapAction.NoMapAction, 'No map action')
self._zoomMapAction = self._addMapAction(MapAction.ZoomMap, 'Zoom map view')
self._panMapAction = self._addMapAction(MapAction.PanMap, 'Pan map view')
self._moveMapAction = self._addMapAction(MapAction.MoveMap, 'Move map view')
self._moveMapAction.setChecked(True)
self._filterActionGroup = QActionGroup(self)
self._noFilterAction = self._addFilterAction(FilterAction.NoFilterAction, 'No filter action')
self._includeFilterAction = self._addFilterAction(FilterAction.IncludeFilter, 'Add to filter')
self._exclusiveFilterAction = self._addFilterAction(FilterAction.ExclusiveFilter, 'Exclusive filter')
self._selectFilterAction = self._addFilterAction(FilterAction.SelectFilter, 'Add to selection')
self._exclusiveSelectFilterAction = self._addFilterAction(
FilterAction.ExclusiveSelectFilter, 'Exclusive selection')
self._highlightFilterAction = self._addFilterAction(FilterAction.HighlightFilter, 'Add to highlight')
self._exclusiveHighlightFilterAction = self._addFilterAction(
FilterAction.ExclusiveHighlightFilter, 'Exclusive highlight')
self._exclusiveHighlightFilterAction.setChecked(True)
self._drawingActionGroup = QActionGroup(self)
self._noDrawingAction = self._addDrawingAction(DrawingAction.NoDrawingAction, 'No drawing action')
self._noDrawingAction.setChecked(True)
self._loadDrawingsAction = self._addDrawingAction(DrawingAction.LoadDrawings, 'Load drawings')
self._addDrawingsAction = self._addDrawingAction(DrawingAction.AddDrawings, 'Add drawings')
self._settingsMenu = QMenu(self)
self._settingsMenu.addActions(self._mapActionGroup.actions())
self._settingsMenu.addSeparator()
self._settingsMenu.addActions(self._filterActionGroup.actions())
self._settingsMenu.addSeparator()
self._settingsMenu.addActions(self._drawingActionGroup.actions())
self._settingsAction = QAction(QIcon(':/plugins/ark/settings.svg'), "Action Settings", self)
self._settingsAction.setMenu(self._settingsMenu)
self.setDefaultAction(self._settingsAction)
self.setPopupMode(QToolButton.InstantPopup)
def setMapAction(self, mapAction):
if mapAction == MapAction.NoMapAction:
self._noMapAction.setChecked(True)
elif mapAction == MapAction.ZoomMap:
self._zoomMapAction.setChecked(True)
elif mapAction == MapAction.PanMap:
self._panMapAction.setChecked(True)
elif mapAction == MapAction.MoveMap:
self._moveMapAction.setChecked(True)
def setFilterAction(self, filterAction):
if filterAction == FilterAction.NoFilterAction:
self._noFilterAction.setChecked(True)
elif filterAction == FilterAction.IncludeFilter:
self._includeFilterAction.setChecked(True)
elif filterAction == FilterAction.ExclusiveFilter:
self._exclusiveFilterAction.setChecked(True)
elif filterAction == FilterAction.SelectFilter:
self._selectFilterAction.setChecked(True)
elif filterAction == FilterAction.ExclusiveSelectFilter:
self._exclusiveSelectFilterAction.setChecked(True)
elif filterAction == FilterAction.HighlightFilter:
self._highlightFilterAction.setChecked(True)
elif filterAction == FilterAction.ExclusiveHighlightFilter:
self._exclusiveHighlightFilterAction.setChecked(True)
def setDrawingAction(self, drawingAction):
if drawingAction == DrawingAction.NoDrawingAction:
self._noDrawingAction.setChecked(True)
elif drawingAction == DrawingAction.LoadDrawings:
self._loadDrawingsAction.setChecked(True)
elif drawingAction == DrawingAction.AddDrawings:
self._addDrawingsAction.setChecked(True)
def _addMapAction(self, mapAction, text):
action = QAction(text, self)
action.setCheckable(True)
action.setData(mapAction)
action.triggered.connect(self._mapActionSelected)
self._mapActionGroup.addAction(action)
return action
def _mapActionSelected(self):
self.mapActionChanged.emit(self._mapActionGroup.checkedAction().data())
self.settingsChanged.emit()
def _addFilterAction(self, filterAction, text):
action = QAction(text, self)
action.setCheckable(True)
action.setData(filterAction)
action.triggered.connect(self._filterActionSelected)
self._filterActionGroup.addAction(action)
return action
#.........这里部分代码省略.........
示例6: MainWindow
# 需要导入模块: from PyQt4.QtGui import QActionGroup [as 别名]
# 或者: from PyQt4.QtGui.QActionGroup import checkedAction [as 别名]
#.........这里部分代码省略.........
}
""")
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self._isDragging = True
self._dragPos = event.globalPos() - self.pos()
event.accept()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton and self._isDragging and not self.isMaximized():
self.move(event.globalPos() - self._dragPos)
event.accept()
def mouseReleaseEvent(self, event):
self._isDragging = False
event.accept()
def SaveSettings(self):
root = ET.Element("MyTerm")
GUISettings = ET.SubElement(root, "GUISettings")
PortCfg = ET.SubElement(GUISettings, "PortConfig")
ET.SubElement(PortCfg, "port").text = self.cmbPort.currentText()
ET.SubElement(PortCfg, "baudrate").text = self.cmbBaudRate.currentText()
ET.SubElement(PortCfg, "databits").text = self.cmbDataBits.currentText()
ET.SubElement(PortCfg, "parity").text = self.cmbParity.currentText()
ET.SubElement(PortCfg, "stopbits").text = self.cmbStopBits.currentText()
ET.SubElement(PortCfg, "rtscts").text = self.chkRTSCTS.isChecked() and "on" or "off"
ET.SubElement(PortCfg, "xonxoff").text = self.chkXonXoff.isChecked() and "on" or "off"
View = ET.SubElement(GUISettings, "View")
ET.SubElement(View, "LocalEcho").text = self.actionLocal_Echo.isChecked() and "on" or "off"
ET.SubElement(View, "ReceiveView").text = self._viewGroup.checkedAction().text()
with open(get_config_path('settings.xml'), 'w') as f:
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write(ET.tostring(root, encoding='utf-8', pretty_print=True).decode("utf-8"))
def LoadSettings(self):
if os.path.isfile(get_config_path("settings.xml")):
with open(get_config_path("settings.xml"), 'r') as f:
tree = safeET.parse(f)
port = tree.findtext('GUISettings/PortConfig/port', default='')
if port != '':
self.cmbPort.setProperty("currentText", port)
baudrate = tree.findtext('GUISettings/PortConfig/baudrate', default='38400')
if baudrate != '':
self.cmbBaudRate.setProperty("currentText", baudrate)
databits = tree.findtext('GUISettings/PortConfig/databits', default='8')
id = self.cmbDataBits.findText(databits)
if id >= 0:
self.cmbDataBits.setCurrentIndex(id)
parity = tree.findtext('GUISettings/PortConfig/parity', default='None')
id = self.cmbParity.findText(parity)
if id >= 0:
self.cmbParity.setCurrentIndex(id)
stopbits = tree.findtext('GUISettings/PortConfig/stopbits', default='1')
id = self.cmbStopBits.findText(stopbits)
if id >= 0:
self.cmbStopBits.setCurrentIndex(id)
示例7: XViewProfileToolBar
# 需要导入模块: from PyQt4.QtGui import QActionGroup [as 别名]
# 或者: from PyQt4.QtGui.QActionGroup import checkedAction [as 别名]
class XViewProfileToolBar(XToolBar):
profileCreated = qt.Signal(qt.PyObject)
profileChanged = qt.Signal(qt.PyObject)
profileRemoved = qt.Signal(qt.PyObject)
currentProfileChanged = qt.Signal(qt.PyObject)
def __init__( self, parent ):
super(XViewProfileToolBar, self).__init__(parent)
# create custom properties
self._editingEnabled = True
self._viewWidget = None
self._profileGroup = QActionGroup(self)
# set the default options
self.setIconSize(QSize(48, 48))
self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self.setContextMenuPolicy(Qt.CustomContextMenu)
# create connections
self.actionTriggered.connect(self.handleActionTrigger)
self.customContextMenuRequested.connect(self.showProfileMenu)
def addProfile(self, profile):
"""
Adds the inputed profile as an action to the toolbar.
:param profile | <projexui.widgets.xviewwidget.XViewProfile>
"""
act = XViewProfileAction(profile, self)
self._profileGroup.addAction(act)
self.addAction(act)
return act
def currentProfile( self ):
"""
Returns the current profile for this toolbar.
:return <projexui.widgets.xviewwidget.XViewProfile> || None
"""
act = self._profileGroup.checkedAction()
if ( act ):
return act.profile()
return None
def createProfile( self, profile = None, clearLayout = True ):
"""
Prompts the user to create a new profile.
"""
if ( profile ):
prof = profile
elif ( not self.viewWidget() or clearLayout ):
prof = XViewProfile()
else:
prof = self.viewWidget().saveProfile()
blocked = self.signalsBlocked()
self.blockSignals(False)
changed = self.editProfile(prof)
self.blockSignals(blocked)
if ( not changed ):
return
act = self.addProfile(prof)
act.setChecked(True)
# update the interface
if ( self.viewWidget() and (profile or clearLayout) ):
self.viewWidget().restoreProfile(prof)
if ( not self.signalsBlocked() ):
self.profileCreated.emit(prof)
@qt.Slot(qt.PyObject)
def editProfile( self, profile ):
"""
Prompts the user to edit the given profile.
:param profile | <projexui.widgets.xviewwidget.XViewProfile>
"""
mod = XViewProfileDialog.edit(self, profile)
if ( not mod ):
return False
# update the action interface
for act in self._profileGroup.actions():
if ( act.profile() == profile ):
act.setProfile(profile)
break
# signal the change
if ( not self.signalsBlocked() ):
self.profileChanged.emit(profile)
return True
def exportProfiles( self, filename = None ):
"""
Exports this toolbar to the given filename.
#.........这里部分代码省略.........