| 
			
			 | 
		#1 | 
| 
			
			
			
			 Member 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 14 
				Karma: 1236266 
				Join Date: Dec 2010 
				
				
				
				Device: None 
				
				
				 | 
	
	
	
		
		
			
			 
				
				FileTypePlugin, config_widget, JSONConfig and Cancel
			 
			
			
			I am working on a FileTypePlugin with a preferences dialog implemented using config_widget, and preferences stored using JSONConfig. 
		
	
		
		
		
		
		
		
		
		
		
		
	
	When my config_widget object initialises, I copy my preferences from my JSONConfig object to local copies in the config_widget object. All changes made by the config_widget are to these local copies. When the user exists the config_widget using the OK button, my save_settings function is called, which copies the preferences back into the JSONConfig object, which writes the preferences out to the .json disk file. This all works fine. When the user exits the config_widget using the Cancel button, my save_settings function is not called, and my JSONConfig preferences and disk file remain unchanged. This all works fine. The problem is that when the configuration dialog is next opened, my config_widget is already initialised, and retains the local copy of the preferences that may not match the preferences in my JSONConfig object. What function do I need to add to my config_widget object so that I can copy the actual JSONConfig preferences to the config_widget local copy of the preferences every time the configuration dialog is opened, not just the first time? I tried adding an initialize() function, but it never got called. I hope that this is just something that I've missed in the documentation....  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#2 | 
| 
			
			
			
			 creator of calibre 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,609 
				Karma: 28549044 
				Join Date: Oct 2006 
				Location: Mumbai, India 
				
				
				Device: Various 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			You should be instantiating a new config widget every tim config_widget() is called on your plugin. If you want to re-use an existing config_widget then you have to manually re-initialize it. calibre itself, will just call config_widget() blindly everytime it needs to reconfigure. See the do_user_config() method in customize/__init__.py
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| Advert | |
| 
         | 
    
| 
			
			 | 
		#3 | 
| 
			
			
			
			 Member 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 14 
				Karma: 1236266 
				Join Date: Dec 2010 
				
				
				
				Device: None 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Thank you Kovid. By checking the sample plugin, I found my mistake (which was, of course, not in the place I was looking for it). 
		
	
		
		
		
		
		
		
		
		
		
		
	
	I am a little embarrassed to admit it was a failure to make a copy of the some of the preferences. Instead I was just getting another reference to the same object.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#4 | 
| 
			
			
			
			 creator of calibre 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,609 
				Karma: 28549044 
				Join Date: Oct 2006 
				Location: Mumbai, India 
				
				
				Device: Various 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Sith happens  
		
	
		
		
		
		
		
		
		
		
		
		
	
	 
		 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
![]()  | 
            
        
    
            
  | 
    
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Will you cancel your Netflix? | markbot | Lounge | 53 | 10-11-2011 08:34 AM | 
| Content cancel a search | hey | Amazon Kindle | 1 | 03-10-2011 04:20 PM | 
| JSONConfig has no delete method | meme | Development | 2 | 02-24-2011 09:38 AM | 
| config_widget doesn't allow early exit | meme | Plugins | 12 | 02-19-2011 12:42 PM | 
| "cannot import name JSONConfig" on launching calibre .42 | hakan42 | Calibre | 4 | 02-27-2010 04:37 AM |