@@ -160,8 +160,9 @@ class Rui(object):
160160
161161 """
162162
163- def __init__ (self , filepath ):
163+ def __init__ (self , filepath , guid = None ):
164164 self .filepath = filepath
165+ self .guid = guid or uuid .uuid4 ()
165166 self .icons = []
166167 self .macros = {}
167168 self .toolbars = {}
@@ -187,7 +188,7 @@ def check(self):
187188
188189 def init (self ):
189190 with open (self .filepath , "w+" ) as f :
190- f .write (TPL_RUI .format (uuid . uuid4 (), uuid . uuid4 () ))
191+ f .write (TPL_RUI .format (self . guid , self . guid ))
191192 self .xml = ET .parse (self .filepath )
192193 self .root = self .xml .getroot ()
193194 self .root_bitmaps = self .root .find ("bitmaps" )
@@ -207,13 +208,17 @@ def write(self):
207208 fh .write (xml )
208209
209210 @classmethod
210- def from_json (cls , uipath , ruipath ) :
211+ def from_json (cls , uipath , ruipath , guid = None ) -> "Rui" :
211212 """Construct a RUI object from a JSON config file.
212213
213214 Parameters
214215 ----------
215- configpath : str
216- Path to the config file.
216+ uipath : str
217+ Path to the UI config file.
218+ ruipath : str
219+ Path of the output file.
220+ guid : uuid, optional
221+ The guid of the plugin.
217222
218223 Returns
219224 -------
@@ -225,7 +230,7 @@ def from_json(cls, uipath, ruipath):
225230 with open (uipath , "r" ) as f :
226231 ui = json .load (f )
227232
228- self = cls (ruipath )
233+ self = cls (ruipath , guid = guid )
229234 self .init ()
230235 if ui ["icons" ]["bitmap" ]:
231236 bitmap = os .path .join (root , ui ["icons" ]["bitmap" ])
@@ -310,7 +315,9 @@ def add_macro(
310315 icon_guid ,
311316 )
312317 else :
313- s_macro = TPL_MACRO .format (guid , name , script , tooltip , help_text , button_text , menu_text )
318+ s_macro = TPL_MACRO .format (
319+ guid , name , script , tooltip , help_text , button_text , menu_text
320+ )
314321 e_macro = ET .fromstring (s_macro )
315322 self .root_macros .append (e_macro )
316323 self .macros [name ] = e_macro
0 commit comments