#! /usr/bin/env python

##############################################################################
#
# PyQt MemAid <Peter.Bienstman@ugent.be>
#
##############################################################################

import sys, os
from qt import *
from pyqt_memaid.main_dlg import *
from pyqt_memaid.memaid_core import *

try:
    from sitecustomize import *
except:
    pass

try:
    sys.setappdefaultencoding("utf-8")
except:
    pass

# Set default paths.

if not os.path.exists(os.path.expanduser("~/.memaid")):
    os.mkdir(os.path.expanduser("~/.memaid"))
    
if not os.path.exists(os.path.expanduser("~/.memaid/config")):
    save_config()
    
if not os.path.exists(os.path.expanduser("~/.memaid/default.mem")):
    new_database(os.path.expanduser("~/.memaid/default.mem"))

set_data_dir(os.path.expanduser("~/.memaid"))

# Create main widget.

try:
    filename = sys.argv[1]
except:
    filename = None

try:
    item_id = sys.argv[2]
except:
    item_id = None

a = QApplication(sys.argv)
w = MainDlg(filename, item_id)

QObject.connect(a,SIGNAL("lastWindowClosed()"),w.fileExit)
QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()"))

a.setMainWidget(w)
w.show()
a.exec_loop()

