Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've written a small app that creates a GUI for setting up uShare. Currently it depends heavily on the 'w' (write) and 'a' (append) functions to generate/edit ushare.conf file. But I've been trying to find a way for the app to store all the changes until a save button is pressed, and only then committing them to the actual file. I think that would be the best way of getting around having the user press enter every time they change any field (and indeed allow for GtkCheckButton).

share|improve this question
1  
It seems your question is more of a programming one than ubuntu related. If that is the case you should ask in stackoverflow –  santiagozky Jun 22 '12 at 13:01
    
Your post is more appropriate at stackoverflow tagged as a GTK+ question or at the gtk forums.Since it has nothing to do with Ubuntu but the GTK+ UI toolkit itself,its offtopic. –  Nickolas Jun 22 '12 at 17:59
1  
The question is totally on topic for this site and the application-development tag –  David Planella Jun 22 '12 at 19:27

1 Answer 1

up vote 3 down vote accepted

If you want to store configuration like this, what I recommend you do is to use the Python ConfigParser module. Please note you should ensure you store config files in ~/.config/<your-app-name>. You can store config like this:

import ConfigParser
import xdg.BaseDirectory

# set the configdir to ~/.config/ushare
configdir = os.path.join(xdg.BaseDirectory.xdg_config_home, "ushare")

# check if the dir exists and if not, create it
if not os.path.exists(configdir):
    os.makedirs(configdir)

# create configparser object
config = ConfigParser.RawConfigParser()
cfile = os.path.join(configdir, "ushare.conf")

# add your config items - see the ConfigParser docs for how to do this

# later in your app add this when the user presses the button to save the config:

with open(cfile, 'wb') as configfile:
    config.write(configfile)

Please note: I didn't actually run this code and just wrote it here, but it should work fine.

share|improve this answer
    
I've actually found an answer yesterday. I'm using String.IO and have a signal that dumps whatever has been written into the dummy file, onto the actual file. As for the directory, the ushare.conf file is in /etc and that is the target directory. But I think I might just have the app save it to the desktop, and have the user then do sudo mv ~/Desktop/ushare.conf /etc. Otherwise I'd just script it so it's done upon exit but after save. Thank you for your answer, though, I have another app idea where it'd come in handy! –  boywithaxe Jun 24 '12 at 1:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.