2009-11-01 07:36:18 +01:00
|
|
|
"""Database manager
|
|
|
|
|
|
|
|
@todo: (gtk) how to validate user input in gtk.Dialog? as soon as the user clicks ok the dialog is dead. we use a while loop as workaround. not nice
|
|
|
|
@todo: (fpdb) we need the application name 'fpdb' from somewhere to put it in dialog titles
|
2009-11-01 20:07:41 +01:00
|
|
|
@todo: (fpdb) config object should be initialized globally and accessible from all modules via Configuration.py
|
2009-11-01 07:36:18 +01:00
|
|
|
|
|
|
|
@todo: (all dialogs) save/restore size and pos
|
|
|
|
|
|
|
|
@todo: (WidgetDatabaseManager) give database status meaningful colors
|
|
|
|
@todo: (WidgetDatabaseManager) implement database purging
|
|
|
|
@todo: (WidgetDatabaseManager) implement database export
|
|
|
|
@todo: (WidgetDatabaseManager) what to do on database doubleclick?
|
|
|
|
@todo: (WidgetDatabaseManager) context menu for database tree
|
|
|
|
@todo: (WidgetDatabaseManager) initializing/validating databases may take a while. how to give feedback?
|
|
|
|
|
|
|
|
"""
|
2009-10-27 09:01:06 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gtk
|
2009-10-31 12:12:17 +01:00
|
|
|
import gobject
|
2009-10-27 09:01:06 +01:00
|
|
|
|
|
|
|
#*******************************************************************************************************
|
2009-10-31 12:12:17 +01:00
|
|
|
class DatabaseManager(gobject.GObject):
|
2009-10-27 11:04:24 +01:00
|
|
|
DatabaseTypes = {}
|
|
|
|
|
2009-10-29 19:32:41 +01:00
|
|
|
@classmethod
|
|
|
|
def from_fpdb(klass, data, defaultDatabaseType=None):
|
2009-11-01 20:07:41 +01:00
|
|
|
|
|
|
|
#NOTE: if no databases are present in config fpdb fails with
|
|
|
|
# Traceback (most recent call last):
|
|
|
|
# File "/home/me2/Scr/Repos/fpdb-mme/pyfpdb/DatabaseManager.py", line 783, in <module>
|
|
|
|
# databaseManager = DatabaseManager.from_fpdb('', defaultDatabaseType=DatabaseTypeSqLite)
|
|
|
|
# File "/home/me2/Scr/Repos/fpdb-mme/pyfpdb/DatabaseManager.py", line 36, in from_fpdb
|
|
|
|
# config = Configuration.Config(file=options.config, dbname=options.dbname)
|
|
|
|
# File "/home/me2/Scr/Repos/fpdb-mme/pyfpdb/Configuration.py", line 436, in __init__
|
|
|
|
# db = self.get_db_parameters()
|
|
|
|
# File "/home/me2/Scr/Repos/fpdb-mme/pyfpdb/Configuration.py", line 583, in get_db_parameters
|
|
|
|
# name = self.db_selected
|
|
|
|
# AttributeError: Config instance has no attribute 'db_selected'
|
|
|
|
import sys
|
|
|
|
import Options
|
|
|
|
import Configuration
|
|
|
|
#NOTE: fpdb should perform this globally
|
|
|
|
(options, sys.argv) = Options.fpdb_options()
|
|
|
|
config = Configuration.Config(file=options.config, dbname=options.dbname)
|
|
|
|
#TODO: handle no database present
|
|
|
|
defaultDatabaseName = config.get_db_parameters().get('db-databaseName', None)
|
|
|
|
#TODO: fpdb stores databases in no particular order. this has to be fixed somehow
|
|
|
|
databases = []
|
|
|
|
for name, fpdbDatabase in config.supported_databases.items():
|
|
|
|
databaseKlass = klass.DatabaseTypes.get(fpdbDatabase.db_type, None)
|
|
|
|
#NOTE: Config does not seem to validate user input, so anything may end up here
|
|
|
|
if databaseKlass is None:
|
|
|
|
raise ValueError('Unknown databasetype: %s' % fpdbDatabase.db_type)
|
|
|
|
|
|
|
|
database = databaseKlass()
|
|
|
|
if database.Type == 'sqlite':
|
|
|
|
database.name = fpdbDatabase.db_name
|
|
|
|
database.file = fpdbDatabase.db_server
|
|
|
|
else:
|
|
|
|
database.name = fpdbDatabase.db_name
|
|
|
|
database.host = fpdbDatabase.db_server
|
|
|
|
#NOTE: fpdbDatabase.db_ip is no is a string
|
|
|
|
database.port = int(fpdbDatabase.db_ip)
|
|
|
|
database.user = fpdbDatabase.db_user
|
|
|
|
database.password = fpdbDatabase.db_pass
|
|
|
|
databases.append(database)
|
|
|
|
|
2009-10-29 19:32:41 +01:00
|
|
|
return klass(databases=databases, defaultDatabaseType=defaultDatabaseType)
|
|
|
|
|
2009-10-31 12:12:17 +01:00
|
|
|
def to_fpdb(self):
|
|
|
|
pass
|
|
|
|
|
2009-10-29 19:32:41 +01:00
|
|
|
|
|
|
|
def __init__(self, databases=None, defaultDatabaseType=None):
|
2009-10-31 12:12:17 +01:00
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
self._defaultDatabaseType = defaultDatabaseType
|
2009-10-29 19:32:41 +01:00
|
|
|
self._databases = [] if databases is None else list(databases)
|
2009-10-31 12:12:17 +01:00
|
|
|
self._activeDatabase = None
|
2009-10-29 19:32:41 +01:00
|
|
|
def __iter__(self):
|
|
|
|
return iter(self._databases)
|
2009-10-27 11:04:24 +01:00
|
|
|
def set_default_database_type(self, databaseType):
|
|
|
|
self._defaultDatabaseType = defaultDatabaseType
|
|
|
|
def get_default_database_type(self):
|
|
|
|
return self._defaultDatabaseType
|
2009-10-29 19:32:41 +01:00
|
|
|
def database_from_id(self, idDatabase):
|
|
|
|
for database in self._databases:
|
2009-10-31 12:12:17 +01:00
|
|
|
if idDatabase == self.database_id(database):
|
2009-10-29 19:32:41 +01:00
|
|
|
return database
|
|
|
|
def database_id(self, database):
|
|
|
|
return id(database)
|
2009-10-30 14:23:27 +01:00
|
|
|
def add_database(self, database):
|
|
|
|
if database in self._databases:
|
|
|
|
raise ValueError('database already registered')
|
2009-10-29 19:32:41 +01:00
|
|
|
self._databases.append(database)
|
|
|
|
def remove_database(self, database):
|
|
|
|
self._databases.remove(database)
|
2009-11-01 07:36:18 +01:00
|
|
|
|
2009-10-31 12:12:17 +01:00
|
|
|
def activate_database(self, database):
|
|
|
|
if self._activeDatabase is not None:
|
|
|
|
self._activeDatabase.status = self._activeDatabase.StatusInactive
|
|
|
|
#TODO: finalize database
|
|
|
|
self.emit('database-deactivated', self.database_id(self._activeDatabase) )
|
|
|
|
|
|
|
|
database.status = database.StatusActive
|
|
|
|
#TODO: activate database
|
|
|
|
self._activeDatabase = database
|
|
|
|
self.emit('database-activated', self.database_id(database) )
|
|
|
|
|
|
|
|
def active_database(self):
|
|
|
|
return self._activeDatabase
|
|
|
|
|
|
|
|
# register DatabaseManager signals
|
|
|
|
gobject.type_register(DatabaseManager)
|
|
|
|
gobject.signal_new('database-activated', DatabaseManager, gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (int, ))
|
|
|
|
gobject.signal_new('database-deactivated', DatabaseManager, gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (int, ))
|
2009-11-01 07:36:18 +01:00
|
|
|
gobject.signal_new('database-error', DatabaseManager, gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (int, ))
|
2009-10-29 19:32:41 +01:00
|
|
|
|
2009-10-27 09:01:06 +01:00
|
|
|
class DatabaseTypeMeta(type):
|
2009-10-27 11:04:24 +01:00
|
|
|
def __new__(klass, name, bases, kws):
|
|
|
|
newKlass = type.__new__(klass, name, bases, kws)
|
|
|
|
if newKlass.Type is not None:
|
|
|
|
if newKlass.Type in DatabaseManager.DatabaseTypes:
|
|
|
|
raise ValueError('data base type already registered for: %s' % newKlass.Type)
|
|
|
|
DatabaseManager.DatabaseTypes[newKlass.Type] = newKlass
|
|
|
|
return newKlass
|
2009-10-27 09:01:06 +01:00
|
|
|
|
|
|
|
class DatabaseTypeBase(object):
|
2009-10-27 11:04:24 +01:00
|
|
|
__metaclass__ = DatabaseTypeMeta
|
|
|
|
Type = None
|
2009-10-31 12:12:17 +01:00
|
|
|
StatusActive = 'active'
|
|
|
|
StatusInactive = 'inactive'
|
|
|
|
StatusError = 'error' #TODO: not implemented
|
|
|
|
|
2009-11-01 07:36:18 +01:00
|
|
|
#TODO: not happy with returning error string. just being too lazy to impl dozens of error codes for later translation
|
|
|
|
def init_new_database(self):
|
|
|
|
"""initializes a new empty database
|
|
|
|
@return: (str) error if something goes wrong, None otherwise
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def validate_database(self):
|
|
|
|
"""checks if the database is valid
|
|
|
|
@return: (str) error if something goes wrong, None otherwise
|
|
|
|
"""
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2009-10-27 09:01:06 +01:00
|
|
|
class DatabaseTypePostgres(DatabaseTypeBase):
|
2009-11-01 20:07:41 +01:00
|
|
|
Type = 'postgresql'
|
2009-10-30 14:23:27 +01:00
|
|
|
@classmethod
|
|
|
|
def display_name(klass):
|
|
|
|
return 'Postgres'
|
2009-10-29 19:32:41 +01:00
|
|
|
def __init__(self, name='', host='localhost', port=5432, user='postgres', password='', database='fpdb'):
|
|
|
|
self.name = name
|
2009-10-27 11:04:24 +01:00
|
|
|
self.host = host
|
|
|
|
self.port = port
|
|
|
|
self.user = user
|
|
|
|
self.password = password
|
|
|
|
self.database = database
|
2009-10-31 12:12:17 +01:00
|
|
|
self.status = self.StatusInactive
|
2009-11-01 07:36:18 +01:00
|
|
|
|
|
|
|
#TODO: implement
|
|
|
|
def init_new_database(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
#TODO: implement
|
|
|
|
def validate_database(self):
|
|
|
|
pass
|
2009-10-31 12:12:17 +01:00
|
|
|
|
2009-10-27 09:01:06 +01:00
|
|
|
class DatabaseTypeMysql(DatabaseTypeBase):
|
2009-10-27 11:04:24 +01:00
|
|
|
Type = 'mysql'
|
2009-10-30 14:23:27 +01:00
|
|
|
@classmethod
|
|
|
|
def display_name(klass):
|
|
|
|
return 'MySql'
|
2009-10-29 19:32:41 +01:00
|
|
|
def __init__(self, name='', host='localhost', port=3306, user='root', password='', database='fpdb'):
|
|
|
|
self.name = name
|
2009-10-27 11:04:24 +01:00
|
|
|
self.host = host
|
|
|
|
self.port = port
|
|
|
|
self.user = user
|
|
|
|
self.password = password
|
|
|
|
self.database = database
|
2009-10-31 12:12:17 +01:00
|
|
|
self.status = self.StatusInactive
|
2009-11-01 07:36:18 +01:00
|
|
|
|
|
|
|
#TODO: implement
|
|
|
|
def init_new_database(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
#TODO: implement
|
|
|
|
def validate_database(self):
|
|
|
|
pass
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
|
2009-10-27 09:01:06 +01:00
|
|
|
class DatabaseTypeSqLite(DatabaseTypeBase):
|
2009-10-27 11:04:24 +01:00
|
|
|
Type = 'sqlite'
|
2009-10-30 14:23:27 +01:00
|
|
|
@classmethod
|
|
|
|
def display_name(klass):
|
|
|
|
return 'SqLite'
|
2009-10-30 16:48:51 +01:00
|
|
|
def __init__(self, name='', host='', file='', database='fpdb'):
|
2009-10-27 11:04:24 +01:00
|
|
|
self.name = name
|
2009-10-29 19:32:41 +01:00
|
|
|
self.file = file
|
2009-10-31 12:12:17 +01:00
|
|
|
self.status = self.StatusInactive
|
2009-11-01 07:36:18 +01:00
|
|
|
|
|
|
|
def init_new_database(self):
|
|
|
|
# make shure all attrs are specified
|
|
|
|
if not self.file:
|
|
|
|
return 'no database file specified'
|
|
|
|
# create file if necessary (this will truncate file if it exists)
|
|
|
|
try:
|
|
|
|
open(self.file, 'w').close()
|
|
|
|
except IOError:
|
|
|
|
return 'can not write file'
|
|
|
|
|
|
|
|
#TODO: init tables (...)
|
|
|
|
|
|
|
|
|
|
|
|
def validate_database(self):
|
|
|
|
pass
|
|
|
|
#TODO: check if tables (...) exist
|
|
|
|
|
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
#TODO: how do we want to handle unsupported database types?
|
|
|
|
# ..uncomment to remove unsupported database types
|
|
|
|
#try: import psycopg2
|
|
|
|
#except ImportError: del DatabaseManager.DatabaseTypes['postgres']
|
|
|
|
#try: import MySQLdb
|
|
|
|
#except ImportError: del DatabaseManager.DatabaseTypes['mysql']
|
|
|
|
#try: import sqlite3
|
|
|
|
#except ImportError: del DatabaseManager.DatabaseTypes['sqlite']
|
|
|
|
|
2009-10-27 09:01:06 +01:00
|
|
|
#***************************************************************************************************************************
|
2009-11-01 20:07:41 +01:00
|
|
|
#TODO: there is no title (on linux), wtf?
|
2009-11-01 07:36:18 +01:00
|
|
|
def DialogError(parent=None, msg=''):
|
|
|
|
dlg = gtk.MessageDialog(
|
|
|
|
parent=parent,
|
|
|
|
flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
type=gtk.MESSAGE_ERROR,
|
|
|
|
buttons=gtk.BUTTONS_OK,
|
|
|
|
message_format=msg,
|
|
|
|
)
|
|
|
|
dlg.run()
|
|
|
|
dlg.destroy()
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
#TODO: derrive from gtk.VBox?
|
2009-10-27 11:04:24 +01:00
|
|
|
class WidgetDatabaseProperties(gtk.VBox):
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
ModeNew = 0
|
|
|
|
ModeEdit = 1
|
|
|
|
ModeAdd = 2
|
2009-10-30 16:48:51 +01:00
|
|
|
|
|
|
|
class SqLiteFileChooserButton(gtk.HBox):
|
|
|
|
#NOTE: for some weird reason it is impossible to let the user choose a non exiting filename with gtk.FileChooserButton, so impl our own on the fly
|
|
|
|
def __init__(self, widgetDatabaseProperties, parentWidget):
|
|
|
|
gtk.HBox.__init__(self)
|
|
|
|
self.set_homogeneous(False)
|
|
|
|
|
|
|
|
self.parentWidget = parentWidget
|
|
|
|
self.widgetDatabaseProperties = widgetDatabaseProperties
|
|
|
|
self.entry = gtk.Entry()
|
|
|
|
self.button = gtk.Button('...')
|
|
|
|
self.button.connect('clicked', self.on_button_clicked)
|
|
|
|
|
|
|
|
# layout widgets
|
|
|
|
self.pack_start(self.entry, True, True)
|
|
|
|
self.pack_start(self.button, False, False)
|
|
|
|
|
|
|
|
def get_filename(self):
|
|
|
|
return self.entry.get_text()
|
|
|
|
|
|
|
|
def set_filename(self, name):
|
|
|
|
self.entry.set_text(name)
|
|
|
|
|
|
|
|
def on_button_clicked(self, button):
|
|
|
|
if self.widgetDatabaseProperties.mode == WidgetDatabaseProperties.ModeAdd:
|
|
|
|
action = gtk.FILE_CHOOSER_ACTION_OPEN
|
|
|
|
elif self.widgetDatabaseProperties.mode == WidgetDatabaseProperties.ModeNew:
|
|
|
|
action = gtk.FILE_CHOOSER_ACTION_SAVE
|
|
|
|
else:
|
|
|
|
raise ValueError('unsupported dialog mode')
|
|
|
|
dlg = gtk.FileChooserDialog(
|
|
|
|
title='Choose an exiting database file or type in name of a new one',
|
|
|
|
parent=self.parentWidget,
|
|
|
|
action=action,
|
|
|
|
buttons=(
|
|
|
|
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
|
|
|
gtk.STOCK_OK, gtk.RESPONSE_OK,
|
|
|
|
),
|
|
|
|
backend=None
|
|
|
|
)
|
|
|
|
dlg.set_default_response(gtk.RESPONSE_OK)
|
|
|
|
dlg.set_do_overwrite_confirmation(True)
|
|
|
|
if dlg.run() == gtk.RESPONSE_OK:
|
|
|
|
fileName = dlg.get_filename()
|
|
|
|
self.set_filename(fileName)
|
|
|
|
dlg.destroy()
|
|
|
|
|
|
|
|
|
2009-11-01 07:36:18 +01:00
|
|
|
#TODO: bit ugly this thingy. try to find a better way to map database attrs to gtk widgets
|
2009-10-27 11:04:24 +01:00
|
|
|
class FieldWidget(object):
|
|
|
|
def __init__(self, text='', attrDatabase='', widget=None, attrGet=None, attrSet=None, defaultValue=None, canEdit=False, tooltip=''):
|
|
|
|
"""
|
|
|
|
@param canEdit: True if the user can edit the attr in edit mode, False otherwise
|
|
|
|
"""
|
|
|
|
self._label = gtk.Label(text)
|
|
|
|
self._attrDatabase = attrDatabase
|
|
|
|
self._widget = widget
|
|
|
|
self._defaultValue = defaultValue
|
|
|
|
self._attrGetter=None,
|
|
|
|
self._attrGet = attrGet
|
|
|
|
self._attrSet = attrSet
|
|
|
|
self._canEdit = canEdit
|
|
|
|
|
|
|
|
self._label.set_tooltip_text(tooltip)
|
|
|
|
self._widget.set_tooltip_text(tooltip)
|
|
|
|
|
|
|
|
def widget(self):
|
|
|
|
return self._widget
|
|
|
|
def label(self):
|
|
|
|
return self._label
|
|
|
|
def is_sensitive(self, database):
|
|
|
|
return hasattr(database, self._attrDatabase)
|
|
|
|
def can_edit(self):
|
|
|
|
return self._canEdit
|
|
|
|
def set_sensitive(self, flag):
|
|
|
|
self._label.set_sensitive(flag)
|
|
|
|
self._widget.set_sensitive(flag)
|
|
|
|
def value_from_database(self, database):
|
|
|
|
getattr(self._widget, self._attrSet)( getattr(database, self._attrDatabase) )
|
|
|
|
def value_to_database(self, database):
|
|
|
|
setattr(database, self._attrDatabase, getattr(self._widget, self._attrGet)() )
|
|
|
|
def reset_value(self):
|
|
|
|
getattr(self._widget, self._attrSet)(self._defaultValue)
|
|
|
|
|
2009-10-30 16:48:51 +01:00
|
|
|
def __init__(self, databaseManager, database, mode=ModeEdit, parentWidget=None):
|
2009-10-27 11:04:24 +01:00
|
|
|
gtk.VBox.__init__(self)
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
self.databaseManager = databaseManager
|
|
|
|
self.database = database
|
|
|
|
self.mode = mode
|
2009-10-30 16:48:51 +01:00
|
|
|
self.parentWidget = parentWidget
|
2009-10-29 19:32:41 +01:00
|
|
|
self.fieldWidgets = (
|
2009-10-27 11:04:24 +01:00
|
|
|
self.FieldWidget(
|
|
|
|
text='Name:',
|
|
|
|
attrDatabase='name',
|
|
|
|
widget=gtk.Entry(),
|
|
|
|
defaultValue='',
|
|
|
|
attrGet='get_text',
|
|
|
|
attrSet='set_text',
|
|
|
|
canEdit=True,
|
2009-10-30 16:48:51 +01:00
|
|
|
tooltip='Any name you like to name the database '
|
|
|
|
),
|
2009-10-27 11:04:24 +01:00
|
|
|
self.FieldWidget(
|
|
|
|
text='File:',
|
|
|
|
attrDatabase='file',
|
2009-10-30 16:48:51 +01:00
|
|
|
widget=self.SqLiteFileChooserButton(self, self.parentWidget),
|
2009-10-27 11:04:24 +01:00
|
|
|
defaultValue='',
|
|
|
|
attrGet='get_filename',
|
|
|
|
attrSet='set_filename',
|
|
|
|
canEdit=False,
|
2009-10-30 16:48:51 +01:00
|
|
|
tooltip='Fully qualified path of the file to hold the database '
|
2009-10-27 11:04:24 +01:00
|
|
|
),
|
|
|
|
self.FieldWidget(
|
|
|
|
text='Host:',
|
|
|
|
attrDatabase='host',
|
|
|
|
widget=gtk.Entry(),
|
|
|
|
defaultValue='',
|
|
|
|
attrGet='get_text',
|
|
|
|
attrSet='set_text',
|
|
|
|
canEdit=False,
|
2009-10-30 16:48:51 +01:00
|
|
|
tooltip='Host the database is located at'
|
2009-10-27 11:04:24 +01:00
|
|
|
),
|
|
|
|
self.FieldWidget(
|
|
|
|
text='Port:',
|
|
|
|
attrDatabase='port',
|
|
|
|
widget=gtk.SpinButton(adjustment=gtk.Adjustment(value=0, lower=0, upper=999999, step_incr=1, page_incr=10) ),
|
|
|
|
defaultValue=0,
|
|
|
|
attrGet='get_value',
|
|
|
|
attrSet='set_value',
|
|
|
|
canEdit=False,
|
2009-10-30 16:48:51 +01:00
|
|
|
tooltip='Port to use to connect to the host'
|
2009-10-27 11:04:24 +01:00
|
|
|
),
|
|
|
|
self.FieldWidget(
|
|
|
|
text='User:',
|
|
|
|
attrDatabase='user',
|
|
|
|
widget=gtk.Entry(),
|
|
|
|
defaultValue='',
|
|
|
|
attrGet='get_text',
|
|
|
|
attrSet='set_text',
|
|
|
|
canEdit=False,
|
2009-10-30 16:48:51 +01:00
|
|
|
tooltip='User name used to login to the host'
|
2009-10-27 11:04:24 +01:00
|
|
|
),
|
|
|
|
self.FieldWidget(
|
|
|
|
text='Pwd:',
|
|
|
|
attrDatabase='password',
|
|
|
|
widget=gtk.Entry(),
|
|
|
|
defaultValue='',
|
|
|
|
attrGet='get_text',
|
|
|
|
attrSet='set_text',
|
|
|
|
canEdit=False,
|
2009-10-30 16:48:51 +01:00
|
|
|
tooltip='Password used to login to the host'
|
2009-10-27 11:04:24 +01:00
|
|
|
),
|
2009-11-01 07:36:18 +01:00
|
|
|
self.FieldWidget(
|
|
|
|
text='Db:',
|
|
|
|
attrDatabase='database',
|
|
|
|
widget=gtk.Entry(),
|
|
|
|
defaultValue='',
|
|
|
|
attrGet='get_text',
|
|
|
|
attrSet='set_text',
|
|
|
|
canEdit=False,
|
|
|
|
tooltip='Name of the database'
|
|
|
|
),
|
2009-10-27 11:04:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# setup database type combo
|
|
|
|
self.comboType = gtk.ComboBox()
|
|
|
|
listStore= gtk.ListStore(str, str)
|
|
|
|
self.comboType.set_model(listStore)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.comboType.pack_start(cell, True)
|
|
|
|
self.comboType.add_attribute(cell, 'text', 0)
|
|
|
|
self.comboType.connect('changed', self.on_combo_type_changed)
|
2009-10-30 14:23:27 +01:00
|
|
|
|
|
|
|
# fill database type combo with available database klasses. we store (databaseDisplayName, databaseType) in our model for later lookup
|
|
|
|
iCurrentDatabase = 0
|
|
|
|
databaseTypes = [(klass.display_name(), klass.Type) for klass in databaseManager.DatabaseTypes.values()]
|
|
|
|
databaseTypes.sort()
|
|
|
|
for i, (databaseDisplayName, databaseType) in enumerate(databaseTypes):
|
|
|
|
listStore.append( (databaseDisplayName, databaseType) )
|
|
|
|
if databaseType == self.database.Type:
|
|
|
|
iCurrentDatabase = i
|
|
|
|
if self.mode == self.ModeEdit or len(databaseTypes) < 2:
|
|
|
|
self.comboType.set_button_sensitivity(gtk.SENSITIVITY_OFF)
|
2009-10-27 11:04:24 +01:00
|
|
|
|
|
|
|
# init and layout field widgets
|
|
|
|
self.pack_start(self.comboType, False, False, 2)
|
|
|
|
table = gtk.Table(rows=len(self.fieldWidgets) +1, columns=2, homogeneous=False)
|
|
|
|
self.pack_start(table, False, False, 2)
|
|
|
|
for i,fieldWidget in enumerate(self.fieldWidgets):
|
|
|
|
table.attach(fieldWidget.label(), 0, 1, i, i+1, xoptions=gtk.FILL)
|
|
|
|
table.attach(fieldWidget.widget(), 1, 2, i, i+1)
|
|
|
|
|
|
|
|
# init widget
|
2009-10-30 14:23:27 +01:00
|
|
|
self.comboType.set_active(iCurrentDatabase)
|
|
|
|
self._adjust_widgets(self.database)
|
2009-10-27 11:04:24 +01:00
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
def _adjust_widgets(self, database):
|
2009-10-27 11:04:24 +01:00
|
|
|
for fieldWidget in self.fieldWidgets:
|
2009-10-30 14:23:27 +01:00
|
|
|
isSensitive = fieldWidget.is_sensitive(database)
|
2009-10-27 11:04:24 +01:00
|
|
|
if isSensitive:
|
2009-10-30 14:23:27 +01:00
|
|
|
fieldWidget.value_from_database(database)
|
2009-10-27 11:04:24 +01:00
|
|
|
else:
|
|
|
|
fieldWidget.reset_value()
|
2009-10-30 14:23:27 +01:00
|
|
|
if self.mode == self.ModeEdit:
|
2009-10-27 11:04:24 +01:00
|
|
|
isSensitive = isSensitive and fieldWidget.can_edit()
|
|
|
|
fieldWidget.set_sensitive(isSensitive)
|
2009-10-30 14:23:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
def on_combo_type_changed(self, combo):
|
|
|
|
i = self.comboType.get_active()
|
|
|
|
if i < 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
# check if we need to init a new database
|
|
|
|
currentDatabaseType = self.comboType.get_model()[i][1]
|
|
|
|
if currentDatabaseType == self.database.Type:
|
|
|
|
return
|
|
|
|
|
|
|
|
# create new empty database
|
|
|
|
#NOTE: we dont register it in DatabaseManager
|
|
|
|
self.database = self.databaseManager.DatabaseTypes[currentDatabaseType]()
|
|
|
|
self._adjust_widgets(self.database)
|
|
|
|
|
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
def get_database(self):
|
|
|
|
for fieldWidget in self.fieldWidgets:
|
|
|
|
if fieldWidget.is_sensitive(self.database):
|
|
|
|
fieldWidget.value_to_database(self.database)
|
|
|
|
return self.database
|
2009-10-27 09:01:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DialogDatabaseProperties(gtk.Dialog):
|
2009-10-30 14:23:27 +01:00
|
|
|
def __init__(self, databaseManager, database, parent=None, mode=WidgetDatabaseProperties.ModeEdit, title=''):
|
2009-10-27 11:04:24 +01:00
|
|
|
gtk.Dialog.__init__(self,
|
|
|
|
title=title,
|
|
|
|
parent=parent,
|
|
|
|
flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
buttons=(
|
|
|
|
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
|
|
|
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.connect('response', self.on_dialog_response)
|
|
|
|
|
|
|
|
# setup widget
|
2009-10-30 16:48:51 +01:00
|
|
|
self.widgetDatabaseProperties = WidgetDatabaseProperties(databaseManager,database, mode=mode, parentWidget=self)
|
2009-10-27 11:04:24 +01:00
|
|
|
self.vbox.pack_start(self.widgetDatabaseProperties, True, True)
|
2009-10-30 14:23:27 +01:00
|
|
|
self.show_all()
|
2009-10-27 09:01:06 +01:00
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
def get_widget_database_properties(self):
|
|
|
|
return self.widgetDatabaseProperties
|
2009-10-27 11:04:24 +01:00
|
|
|
|
|
|
|
def on_dialog_response(self, dlg, responseId):
|
|
|
|
if responseId == gtk.RESPONSE_REJECT:
|
|
|
|
pass
|
|
|
|
elif responseId == gtk.RESPONSE_ACCEPT:
|
|
|
|
pass
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
|
|
|
|
#TODO: derrive from gtk.VBox?
|
|
|
|
# ..is there a way to derrive from gtk.Widget or similar? this would make parentWidget kw obsolete
|
|
|
|
class WidgetDatabaseManager(gtk.VBox):
|
2009-11-01 07:36:18 +01:00
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
def __init__(self, databaseManager, parentWidget=None):
|
|
|
|
gtk.VBox.__init__(self)
|
2009-10-27 11:04:24 +01:00
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
self.parentWidget = parentWidget
|
2009-10-31 12:12:17 +01:00
|
|
|
self.databaseManager = databaseManager
|
2009-11-01 07:36:18 +01:00
|
|
|
self.databaseManager.connect('database-activated', self.on_database_manager_database_activated)
|
|
|
|
self.databaseManager.connect('database-deactivated', self.on_database_manager_database_deactivated)
|
2009-10-31 12:12:17 +01:00
|
|
|
self.databaseStatusNames = {
|
|
|
|
DatabaseTypeBase.StatusActive: 'Active',
|
|
|
|
DatabaseTypeBase.StatusInactive: 'Inactive',
|
|
|
|
DatabaseTypeBase.StatusError: 'Error',
|
|
|
|
}
|
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
|
|
|
|
#TODO: dono how to make word wrap work as expected
|
|
|
|
self.labelInfo = gtk.Label('database management')
|
|
|
|
self.labelInfo.set_line_wrap(True)
|
|
|
|
self.labelInfo.set_selectable(True)
|
|
|
|
self.labelInfo.set_single_line_mode(False)
|
|
|
|
self.labelInfo.set_alignment(0, 0)
|
|
|
|
|
|
|
|
# database management buttons
|
|
|
|
|
|
|
|
#TODO: bit messy the distinction New/Add/Edit. we'd have to pass three flags to DialogDatabaseProperties
|
|
|
|
# to handle this. maybe drop Edit (is just a Remove + Add), to keep things simple
|
2009-10-31 12:12:17 +01:00
|
|
|
self.buttonDatabaseActivate = gtk.Button("Activate")
|
|
|
|
self.buttonDatabaseActivate.set_tooltip_text('activates the database')
|
|
|
|
self.buttonDatabaseActivate.connect('clicked', self.on_button_database_activate_clicked)
|
|
|
|
self.buttonDatabaseActivate.set_sensitive(False)
|
2009-10-27 11:04:24 +01:00
|
|
|
self.buttonDatabaseNew = gtk.Button("New..")
|
|
|
|
self.buttonDatabaseNew.set_tooltip_text('creates a new database')
|
|
|
|
self.buttonDatabaseNew.connect('clicked', self.on_button_database_new_clicked)
|
|
|
|
self.buttonDatabaseAdd = gtk.Button("Add..")
|
|
|
|
self.buttonDatabaseAdd.set_tooltip_text('adds an existing database')
|
|
|
|
self.buttonDatabaseAdd.connect('clicked', self.on_button_database_add_clicked)
|
|
|
|
self.buttonDatabaseEdit = gtk.Button("Edit..")
|
|
|
|
self.buttonDatabaseEdit.set_tooltip_text('edit database settings')
|
|
|
|
self.buttonDatabaseEdit.connect('clicked', self.on_button_database_edit_clicked)
|
|
|
|
self.buttonDatabaseEdit.set_sensitive(False)
|
|
|
|
self.buttonDatabaseRemove = gtk.Button("Remove")
|
|
|
|
self.buttonDatabaseRemove.set_tooltip_text('removes the database from the list')
|
|
|
|
self.buttonDatabaseRemove.set_sensitive(False)
|
2009-10-31 12:12:17 +01:00
|
|
|
self.buttonDatabaseRemove.connect('clicked', self.on_button_database_remove_clicked)
|
2009-10-27 11:04:24 +01:00
|
|
|
|
|
|
|
#TODO: i dont think we should do any real database management here. maybe drop it
|
2009-10-31 12:12:17 +01:00
|
|
|
#self.buttonDatabaseDelete = gtk.Button("Delete")
|
|
|
|
#self.buttonDatabaseDelete.set_tooltip_text('removes the database from the list and deletes it')
|
|
|
|
#self.buttonDatabaseDelete.set_sensitive(False)
|
2009-10-27 11:04:24 +01:00
|
|
|
|
2009-10-29 19:32:41 +01:00
|
|
|
# init database tree
|
2009-10-27 11:04:24 +01:00
|
|
|
self.treeDatabases = gtk.TreeView()
|
2009-10-31 12:12:17 +01:00
|
|
|
treeDatabaseColumns = ( # name, displayName, dataType
|
|
|
|
('name', 'Name', str),
|
|
|
|
('status', 'Status', str),
|
|
|
|
('type', 'Type', str),
|
|
|
|
('_id', '', int),
|
2009-10-29 19:32:41 +01:00
|
|
|
)
|
2009-10-31 12:12:17 +01:00
|
|
|
self.treeDatabaseColumns = {} # name --> index
|
|
|
|
store = gtk.ListStore( *[i[2] for i in treeDatabaseColumns] )
|
2009-10-27 11:04:24 +01:00
|
|
|
self.treeDatabases.set_model(store)
|
2009-10-31 12:12:17 +01:00
|
|
|
for i, (name, displayName, dataType) in enumerate(treeDatabaseColumns):
|
|
|
|
col = gtk.TreeViewColumn(displayName, gtk.CellRendererText(), text=i)
|
2009-10-27 11:04:24 +01:00
|
|
|
self.treeDatabases.append_column(col)
|
2009-10-31 12:12:17 +01:00
|
|
|
if name.startswith('_'):
|
2009-10-29 19:32:41 +01:00
|
|
|
col.set_visible(False)
|
2009-10-31 12:12:17 +01:00
|
|
|
self.treeDatabaseColumns[name] = i
|
2009-10-27 11:04:24 +01:00
|
|
|
self.treeDatabases.get_selection().connect('changed', self.on_tree_databases_selection_changed)
|
|
|
|
|
|
|
|
# layout widgets
|
2009-10-30 14:23:27 +01:00
|
|
|
vbox = gtk.VBox(self)
|
|
|
|
vbox.pack_start(self.labelInfo, False, False, 2)
|
|
|
|
vbox.pack_start(gtk.HSeparator(), False, False, 2)
|
2009-10-27 11:04:24 +01:00
|
|
|
hbox = gtk.HBox()
|
2009-10-30 14:23:27 +01:00
|
|
|
self.add(hbox)
|
2009-10-27 11:04:24 +01:00
|
|
|
hbox.set_homogeneous(False)
|
|
|
|
vbox = gtk.VBox()
|
|
|
|
hbox.pack_start(vbox, False, False, 2)
|
2009-10-31 12:12:17 +01:00
|
|
|
vbox.pack_start(self.buttonDatabaseActivate, False, False, 2)
|
2009-10-27 11:04:24 +01:00
|
|
|
vbox.pack_start(self.buttonDatabaseNew, False, False, 2)
|
|
|
|
vbox.pack_start(self.buttonDatabaseAdd, False, False, 2)
|
|
|
|
vbox.pack_start(self.buttonDatabaseEdit, False, False, 2)
|
|
|
|
vbox.pack_start(self.buttonDatabaseRemove, False, False, 2)
|
2009-10-31 12:12:17 +01:00
|
|
|
#vbox.pack_start(self.buttonDatabaseDelete, False, False, 2)
|
2009-10-27 11:04:24 +01:00
|
|
|
box = gtk.VBox()
|
|
|
|
vbox.pack_start(box, True, True, 0)
|
|
|
|
|
|
|
|
hbox.pack_start(gtk.VSeparator(), False, False, 2)
|
|
|
|
hbox.pack_end(self.treeDatabases, True, True, 2)
|
|
|
|
|
|
|
|
self.show_all()
|
2009-10-29 19:32:41 +01:00
|
|
|
|
|
|
|
# init widget
|
2009-10-31 12:12:17 +01:00
|
|
|
model = self.treeDatabases.get_model()
|
2009-10-29 19:32:41 +01:00
|
|
|
for database in self.databaseManager:
|
2009-10-31 12:12:17 +01:00
|
|
|
it = model.append()
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['name'], database.name)
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['status'], self.databaseStatusNames[database.status] )
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['type'], database.display_name() )
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['_id'], self.databaseManager.database_id(database))
|
|
|
|
|
|
|
|
|
2009-11-01 07:36:18 +01:00
|
|
|
def on_database_manager_database_activated(self, databaseManager, idDatabase):
|
2009-10-31 12:12:17 +01:00
|
|
|
database = self.databaseManager.database_from_id(idDatabase)
|
|
|
|
model = self.treeDatabases.get_model()
|
|
|
|
for row in iter(model):
|
|
|
|
if row[self.treeDatabaseColumns['_id']] == idDatabase:
|
|
|
|
row[self.treeDatabaseColumns['status']] = self.databaseStatusNames[database.StatusActive]
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ValueError('database not found')
|
2009-10-29 19:32:41 +01:00
|
|
|
|
2009-10-31 12:12:17 +01:00
|
|
|
|
2009-11-01 07:36:18 +01:00
|
|
|
def on_database_manager_database_deactivated(self, databaseManager, idDatabase):
|
2009-10-31 12:12:17 +01:00
|
|
|
database = self.databaseManager.database_from_id(idDatabase)
|
|
|
|
model = self.treeDatabases.get_model()
|
|
|
|
for row in iter(model):
|
|
|
|
if row[self.treeDatabaseColumns['_id']] == idDatabase:
|
|
|
|
row[self.treeDatabaseColumns['status']] = self.databaseStatusNames[database.StatusInactive]
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ValueError('database not found')
|
|
|
|
|
|
|
|
|
|
|
|
def on_button_database_activate_clicked(self, button):
|
|
|
|
selection = self.treeDatabases.get_selection()
|
|
|
|
if selection is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
model, it = selection.get_selected()
|
|
|
|
idDatabase = model.get_value(it, self.treeDatabaseColumns['_id'])
|
|
|
|
database = self.databaseManager.database_from_id(idDatabase)
|
|
|
|
self.databaseManager.activate_database(database)
|
|
|
|
|
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
#TODO: for some reason i have to click OK/Cancel twice to close the dialog
|
|
|
|
def on_button_database_new_clicked(self, button):
|
2009-11-01 07:36:18 +01:00
|
|
|
databaseKlass = self.databaseManager.get_default_database_type()
|
|
|
|
if databaseKlass is None:
|
|
|
|
raise ValueError('no default database type set')
|
|
|
|
database = databaseKlass()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
dlg = DialogDatabaseProperties(
|
|
|
|
self.databaseManager,
|
|
|
|
database,
|
|
|
|
parent=self.parentWidget,
|
|
|
|
mode=WidgetDatabaseProperties.ModeNew,
|
|
|
|
title='New database'
|
|
|
|
)
|
|
|
|
response = dlg.run()
|
|
|
|
if response == gtk.RESPONSE_ACCEPT:
|
|
|
|
database = dlg.get_widget_database_properties().get_database()
|
|
|
|
#TODO: initing may or may not take a while. how to handle?
|
|
|
|
error = database.init_new_database()
|
|
|
|
if error:
|
|
|
|
DialogError(parent=dlg, msg=error)
|
|
|
|
dlg.destroy()
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
database = None
|
|
|
|
dlg.destroy()
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if database is None:
|
|
|
|
return
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
self.databaseManager.add_database(database)
|
2009-11-01 07:36:18 +01:00
|
|
|
model = self.treeDatabases.get_model()
|
|
|
|
it = model.append()
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['name'], database.name)
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['status'], self.databaseStatusNames[database.status] )
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['type'], database.display_name() )
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['_id'], self.databaseManager.database_id(database))
|
|
|
|
|
2009-10-31 12:12:17 +01:00
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
def on_button_database_add_clicked(self, button):
|
2009-11-01 07:36:18 +01:00
|
|
|
databaseKlass = self.databaseManager.get_default_database_type()
|
|
|
|
if databaseKlass is None:
|
2009-10-30 14:23:27 +01:00
|
|
|
raise ValueError('no defult database type set')
|
2009-11-01 07:36:18 +01:00
|
|
|
database = databaseKlass()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
dlg = DialogDatabaseProperties(
|
|
|
|
self.databaseManager,
|
|
|
|
database,
|
|
|
|
parent=self.parentWidget,
|
|
|
|
mode=WidgetDatabaseProperties.ModeAdd,
|
|
|
|
title='Add database'
|
|
|
|
)
|
|
|
|
response = dlg.run()
|
|
|
|
if response == gtk.RESPONSE_ACCEPT:
|
|
|
|
database = dlg.get_widget_database_properties().get_database()
|
|
|
|
#TODO: validating may or may not take a while. how to handle?
|
|
|
|
error = database.validate_database()
|
|
|
|
if error:
|
|
|
|
DialogError(parent=self.parentWidget, msg=error)
|
|
|
|
dlg.destroy()
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
database = None
|
|
|
|
dlg.destroy()
|
|
|
|
break
|
|
|
|
|
|
|
|
if database is None:
|
|
|
|
return
|
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
self.databaseManager.add_database(database)
|
2009-10-31 12:12:17 +01:00
|
|
|
model = self.treeDatabases.get_model()
|
|
|
|
it = model.append()
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['name'], database.name)
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['status'], self.databaseStatusNames[database.status] )
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['type'], database.display_name() )
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['_id'], self.databaseManager.database_id(database))
|
2009-10-27 11:04:24 +01:00
|
|
|
dlg.destroy()
|
|
|
|
|
|
|
|
def on_button_database_edit_clicked(self, button):
|
2009-10-29 19:32:41 +01:00
|
|
|
selection = self.treeDatabases.get_selection()
|
|
|
|
if selection is None:
|
|
|
|
return
|
|
|
|
|
2009-10-31 12:12:17 +01:00
|
|
|
model, it = selection.get_selected()
|
|
|
|
idDatabase = model.get_value(it, self.treeDatabaseColumns['_id'])
|
2009-10-29 19:32:41 +01:00
|
|
|
database = self.databaseManager.database_from_id(idDatabase)
|
2009-10-30 14:23:27 +01:00
|
|
|
dlg = DialogDatabaseProperties(
|
|
|
|
self.databaseManager,
|
2009-10-31 12:12:17 +01:00
|
|
|
database,
|
2009-10-30 14:23:27 +01:00
|
|
|
parent=self.parentWidget,
|
|
|
|
mode=WidgetDatabaseProperties.ModeEdit,
|
2009-11-01 07:36:18 +01:00
|
|
|
title='Edit database'
|
2009-10-30 14:23:27 +01:00
|
|
|
)
|
2009-11-01 07:36:18 +01:00
|
|
|
response = dlg.run()
|
|
|
|
if response == gtk.RESPONSE_REJECT:
|
2009-10-27 11:04:24 +01:00
|
|
|
pass
|
2009-11-01 07:36:18 +01:00
|
|
|
elif response == gtk.RESPONSE_ACCEPT:
|
2009-10-27 11:04:24 +01:00
|
|
|
database = dlg.get_database()
|
|
|
|
selection = self.treeDatabases.get_selection()
|
|
|
|
if selection is not None:
|
2009-10-31 12:12:17 +01:00
|
|
|
model, it = selection.get_selected()
|
|
|
|
model.set_value(it, self.treeDatabaseColumns['name'], database.name)
|
2009-10-27 11:04:24 +01:00
|
|
|
dlg.destroy()
|
2009-10-27 09:01:06 +01:00
|
|
|
|
2009-10-31 12:12:17 +01:00
|
|
|
|
|
|
|
def on_button_database_remove_clicked(self, button):
|
|
|
|
selection = self.treeDatabases.get_selection()
|
|
|
|
if selection is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
model, it = selection.get_selected()
|
|
|
|
#TODO: finalize database
|
|
|
|
model.remove(it)
|
|
|
|
|
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
def on_tree_databases_selection_changed(self, treeSelection):
|
|
|
|
hasSelection = bool(treeSelection.count_selected_rows())
|
|
|
|
|
2009-10-31 12:12:17 +01:00
|
|
|
# enable/disable selection dependend widgets
|
|
|
|
self.buttonDatabaseActivate.set_sensitive(hasSelection)
|
2009-10-27 11:04:24 +01:00
|
|
|
self.buttonDatabaseEdit.set_sensitive(hasSelection)
|
|
|
|
self.buttonDatabaseRemove.set_sensitive(hasSelection)
|
2009-10-31 12:12:17 +01:00
|
|
|
#self.buttonDatabaseDelete.set_sensitive(hasSelection)
|
2009-10-27 11:04:24 +01:00
|
|
|
|
2009-10-27 09:01:06 +01:00
|
|
|
|
2009-10-30 14:23:27 +01:00
|
|
|
class DialogDatabaseManager(gtk.Dialog):
|
|
|
|
def __init__(self, databaseManager, parent=None):
|
|
|
|
gtk.Dialog.__init__(self,
|
2009-11-01 07:36:18 +01:00
|
|
|
title="Databases",
|
2009-10-30 14:23:27 +01:00
|
|
|
parent=parent,
|
|
|
|
flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
buttons=(
|
|
|
|
gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT,
|
|
|
|
gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
|
|
|
|
))
|
|
|
|
#self.set_size_request(260, 250)
|
|
|
|
self.widgetDatabaseManager = WidgetDatabaseManager(databaseManager, parentWidget=self)
|
|
|
|
self.vbox.pack_start(self.widgetDatabaseManager, True, True)
|
|
|
|
self.show_all()
|
|
|
|
|
2009-10-27 09:01:06 +01:00
|
|
|
#**************************************************************************************************
|
|
|
|
if __name__ == '__main__':
|
2009-10-29 19:32:41 +01:00
|
|
|
databaseManager = DatabaseManager.from_fpdb('', defaultDatabaseType=DatabaseTypeSqLite)
|
|
|
|
|
2009-10-27 11:04:24 +01:00
|
|
|
#d = DialogDatabaseProperties(
|
|
|
|
# DatabaseManager(defaultDatabaseType=DatabaseTypeSqLite),
|
|
|
|
#database=DatabaseTypePostgres(),
|
|
|
|
# database=None,
|
|
|
|
# )
|
2009-10-30 14:23:27 +01:00
|
|
|
d = DialogDatabaseManager(databaseManager)
|
2009-10-27 11:04:24 +01:00
|
|
|
d.connect("destroy", gtk.main_quit)
|
|
|
|
d.run()
|
|
|
|
#gtk.main()
|
2009-10-27 09:01:06 +01:00
|
|
|
|
|
|
|
|