4747# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4848
4949from .dtype_uielement import dtype_uielement_class
50+ from .error import QgistUnnamedElementError
51+ from ..config import config_class
5052from ..error import (
5153 QgistTypeError ,
5254 QgistValueError ,
@@ -68,8 +70,14 @@ def __init__(self,
6870 toolbars_list = None ,
6971 dockwidgets_list = None ,
7072 mainwindow = None ,
73+ config = None ,
7174 ):
7275
76+ if not isinstance (config , config_class ) and config is not None :
77+ raise QgistTypeError (translate ('global' , '"config" must be a "config_class" object or None. (dtype_workbench)' ))
78+
79+ self ._config = config
80+
7381 if not isinstance (name , str ):
7482 raise QgistTypeError (translate ('global' , '"name" must be str. (dtype_workbench)' ))
7583 if len (name ) == 0 :
@@ -144,8 +152,18 @@ def activate(self, mainwindow):
144152 qtoolbars_dict = dtype_workbench_class ._get_uielements_from_mainwindow (mainwindow , QToolBar )
145153 qdockwidgets_dict = dtype_workbench_class ._get_uielements_from_mainwindow (mainwindow , QDockWidget )
146154
147- dtype_workbench_class ._activate_uielements (qtoolbars_dict , self ._toolbars_dict )
148- dtype_workbench_class ._activate_uielements (qdockwidgets_dict , self ._dockwidgets_dict )
155+ show_unnamed_warning = False if self ._config is None else self ._config .get ('show_unnamed_warning' , False )
156+
157+ dtype_workbench_class ._activate_uielements (
158+ uiobjects_dict = qtoolbars_dict ,
159+ uielements_dict = self ._toolbars_dict ,
160+ show_unnamed_warning = show_unnamed_warning ,
161+ )
162+ dtype_workbench_class ._activate_uielements (
163+ uiobjects_dict = qdockwidgets_dict ,
164+ uielements_dict = self ._dockwidgets_dict ,
165+ show_unnamed_warning = show_unnamed_warning ,
166+ )
149167
150168 mainwindow .restoreState (self ._mainwindow_state )
151169
@@ -180,7 +198,7 @@ def toolbars(self):
180198 return (self ._toolbars_dict [name ] for name in sorted (self .toolbars_keys ()))
181199
182200 @staticmethod
183- def _activate_uielements (uiobjects_dict , uielements_dict ):
201+ def _activate_uielements (uiobjects_dict , uielements_dict , show_unnamed_warning ):
184202
185203 for name_internal , uiobject in uiobjects_dict .items ():
186204 if name_internal in uielements_dict .keys ():
@@ -191,6 +209,11 @@ def _activate_uielements(uiobjects_dict, uielements_dict):
191209 try :
192210 uielement = dtype_uielement_class .from_uiobject (uiobject )
193211 uielements_dict [uielement .name_internal ] = uielement
212+ except QgistUnnamedElementError as e :
213+ """implementing #8, enabling the user to disable warnings
214+ which are mainly caused by other plugins"""
215+ if show_unnamed_warning :
216+ msg_warning (e )
194217 except Qgist_ALL_Errors as e :
195218 msg_warning (e )
196219 for name_internal in (uielements_dict .keys () - uiobjects_dict .keys ()):
@@ -243,10 +266,14 @@ def name(self, value):
243266 def from_mainwindow (
244267 name = '' ,
245268 mainwindow = None ,
269+ config = None ,
246270 ):
247271
272+ # name is checked by dtype_workbench_class.__init__
248273 if not isinstance (mainwindow , QMainWindow ):
249274 raise QgistTypeError (translate ('global' , '"mainwindow" must be a QGIS mainwindow. (dtype_workbench from_mainwindow)' ))
275+ if not isinstance (config , config_class ) and config is not None :
276+ raise QgistTypeError (translate ('global' , '"config" must be a "config_class" object or None. (dtype_workbench from_mainwindow)' ))
250277
251278 toolbars_list = [
252279 dtype_uielement_class .from_uiobject (uiobject ).as_dict ()
@@ -270,4 +297,5 @@ def from_mainwindow(
270297 toolbars_list = toolbars_list ,
271298 dockwidgets_list = dockwidgets_list ,
272299 mainwindow = mainwindow ,
300+ config = config ,
273301 )
0 commit comments