Kullanıcı ile iletişim¶
Bu bölüm Kullanıcı Arayüzdeki sürekliliği sağlamak amacıyla, kullanıcı ile iletişim kurmak için kullanılan metot ve elementleri gösterir.
Showing messages. The QgsMessageBar class¶
Kullanıcı deneyimi açısından mesaj kutusu kullanmak yanlış olabilir. Küçük bir bilgi veya uyarı/hata mesajı çizgisi göstermek için QGIS mesaj çubuğu kullanmak genellikle en iyi seçenektir.
QGIS arayüz nesnesi için referansı kullanarak bir mesajı, mesaj çubuğundaki sonraki codla gösterebilirsiniz
from qgis.core import Qgis
iface.messageBar().pushMessage("Error", "I'm sorry Dave, I'm afraid I can't do that", level=Qgis.Critical)

QGIS Mesaj çubuğu¶
Bunu sınırlı bir zamanda göstermek için süre ayarı koyabilirsiniz.
iface.messageBar().pushMessage("Ooops", "The plugin is not working as it should", level=Qgis.Critical, duration=3)

Sayaçlı QGIS Mesaj çubuğu¶
The examples above show an error bar, but the level
parameter can be used
to creating warning messages or info messages, using the
Qgis.MessageLevel
enumeration. You can use up to 4 different levels:
Info
Warning
Critical
Success

QGIS Mesaj çubuğu(bilgi için)¶
Mesaj çubuğuna Widgetlar eklenebilir örneğin daha fazla bilgi göstermek için bir buton
def showError():
pass
widget = iface.messageBar().createMessage("Missing Layers", "Show Me")
button = QPushButton(widget)
button.setText("Show Me")
button.pressed.connect(showError)
widget.layout().addWidget(button)
iface.messageBar().pushWidget(widget, Qgis.Warning)

Butonlu bir QGIS Mesaj çubuğu¶
Ana QGIS penceresinde bir mesaj kutusu göstermek gereksizse veya pencerenizde mesaj kutusu göstermek istemiyorsanız kendi pencerenizde bir mesaj çubu kullanabilirsiniz.
class MyDialog(QDialog):
def __init__(self):
QDialog.__init__(self)
self.bar = QgsMessageBar()
self.bar.setSizePolicy( QSizePolicy.Minimum, QSizePolicy.Fixed )
self.setLayout(QGridLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
self.buttonbox = QDialogButtonBox(QDialogButtonBox.Ok)
self.buttonbox.accepted.connect(self.run)
self.layout().addWidget(self.buttonbox, 0, 0, 2, 1)
self.layout().addWidget(self.bar, 0, 0, 1, 1)
def run(self):
self.bar.pushMessage("Hello", "World", level=Qgis.Info)
myDlg = MyDialog()
myDlg.show()

QGIS özel diyalogdaki mesaj çubuğu¶
İlerleme gösteriliyor¶
ilerleme çubukları, gördüğümüz gibi, QGIS mesaj çubukları içine de konulabilir olduğundan, widgetları kabul eder. Konsolda deneyebileceğiniz kodları burada bulabilirsiniz.
import time
from qgis.PyQt.QtWidgets import QProgressBar
from qgis.PyQt.QtCore import *
progressMessageBar = iface.messageBar().createMessage("Doing something boring...")
progress = QProgressBar()
progress.setMaximum(10)
progress.setAlignment(Qt.AlignLeft|Qt.AlignVCenter)
progressMessageBar.layout().addWidget(progress)
iface.messageBar().pushWidget(progressMessageBar, Qgis.Info)
for i in range(10):
time.sleep(1)
progress.setValue(i + 1)
iface.messageBar().clearWidgets()
Also, you can use the built-in status bar to report progress, as in the next example:
vlayer = QgsProject.instance().mapLayersByName("countries")[0]
count = vlayer.featureCount()
features = vlayer.getFeatures()
for i, feature in enumerate(features):
# do something time-consuming here
print('') # printing should give enough time to present the progress
percent = i / float(count) * 100
# iface.mainWindow().statusBar().showMessage("Processed {} %".format(int(percent)))
iface.statusBarIface().showMessage("Processed {} %".format(int(percent)))
iface.statusBarIface().clearMessage()
Kaydoluyor¶
QGIS kayıt sistemini kodunuzun çalışması hakkındaki görmek istediğiniz tüm bilgileri kaydetmek için kullanabilirsiniz.
# You can optionally pass a 'tag' and a 'level' parameters
QgsMessageLog.logMessage("Your plugin code has been executed correctly", 'MyPlugin', level=Qgis.Info)
QgsMessageLog.logMessage("Your plugin code might have some problems", level=Qgis.Warning)
QgsMessageLog.logMessage("Your plugin code has crashed!", level=Qgis.Critical)
Uyarı
Use of the Python print
statement is unsafe to do in any code which may be
multithreaded. This includes expression functions, renderers,
symbol layers and Processing algorithms (amongst others). In these
cases you should always use thread safe classes (QgsLogger
or QgsMessageLog
) instead.
Not
You can see the output of the QgsMessageLog
in the Log Messages Panel
Not
QgsLogger
is for messages for debugging / developers (i.e. you suspect they are triggered by some broken code)QgsMessageLog
is for messages to investigate issues by sysadmins (e.g. to help a sysadmin to fix configurations)