#! /usr/bin/env python
# -*- coding: utf-8 -*-
import ConfigParser
import os
import sys
try:
import pygtk
pygtk.require("2.0")
import gobject
except:
print("pygtk Not Availible")
sys.exit(1)
try:
import gtk
except:
print("GTK Not Availible")
sys.exit(1)
class Config(ConfigParser.RawConfigParser):
def __init__(self):
ConfigParser.RawConfigParser.__init__(self)
cf_dir = os.path.join(os.path.expanduser('~'), '.minimpy')
bu_dir = os.path.join(cf_dir, 'minimpy_data')
self.first_run = False
self.config_file = os.path.join(cf_dir, 'config.cfg')
if not os.path.exists(cf_dir):
os.mkdir(cf_dir)
self.add_section('interface')
self.add_section('project')
self.add_section('operations')
self.set('interface', 'locale', 'en_US')
self.set('interface', 'layout_dir', 'ltr')
self.set('interface', 'batch_allocation', False)
self.set('interface', 'tab_pos', 2)
self.set('project', 'recent_trial', '')
self.set('project', 'load_recent', True)
self.set('operations', 'backup_network_path', bu_dir)
self.set('operations', 'alt_random', False)
self.set('operations', 'cach_cred', True)
self.set('operations', 'backup_network', True)
self.first_run = True
self.write_config()
self.read_config()
# setting the interface direction
if self.get('interface', 'layout_dir') == 'rtl':
gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL)
elif self.get('interface', 'layout_dir') == 'ltr':
gtk.widget_set_default_direction(gtk.TEXT_DIR_LTR)
def read_config(self):
self.read(self.config_file)
def write_config(self):
with open(self.config_file, 'wb') as config_file:
self.write(config_file)
config_file.flush()
config_file.close()
self.read(self.config_file)