Permalink
Browse files

release 0.1.0 + some tweaks

git-svn-id: file:///Users/arjan/backup/gaphor/trunk/gaphor@131 a8418922-720d-0410-834f-a69b97ada669
  • Loading branch information...
1 parent 8e42703 commit 8e89e0cc4ecffa2adccd5fd2cc1b442a39be5cb9 @amolenaar committed Sep 6, 2002
View
@@ -1,3 +1,11 @@
+2002-09-06 Arjan Molenaar <arjanmolenaar@hetnet.nl>
+
+ * gaphor/misc/conf.py: New file. wrapper for GConf.
+ * gaphor/gaphor.py (get_resource): added gconf support.
+ Renamed gaphorResource to GaphorResource.
+ * gaphor/UML/elementfactory.py, gaphor/diagram/diagramitemfactory.py:
+ No longer singleton. should be called through GaphorResource
+
2002-09-05 Arjan Molenaar <arjanmolenaar@hetnet.nl>
* gaphor/gaphor.py: Added GaphorError here. Added a generic resource
View
@@ -10,7 +10,7 @@ SUBDIRS = utils po doc tests
bin_SCRIPTS = bin/gaphor
-EXTRA_DIST = $(FILES) $(FILES_FILES) bin/gaphor.in gaphor/config.py.in
+EXTRA_DIST = $(FILES) $(FILES_FILES) gaphor.sh bin/gaphor.in gaphor/config.py.in
INSTALL_DIRS = $(DIRS)
INSTALL_FILES = $(FILES) gaphor/config.py gaphor/UML/modelelements.py
View
@@ -148,4 +148,6 @@ Gaphor is configured:
NOTE: You do not need to install Gaphor, just execute './gaphor.sh'
in the current directory.
+
+ Now type 'make' to build gaphor.
"
View
@@ -1,2 +1,4 @@
-EXTRA_DIST= UmlMetaModel.xmi model.txt gaphor.txt implementation.txt plan.txt storage.txt thename.txt usecases.txt relationships.txt
+EXTRA_DIST= UmlMetaModel.xmi model.txt gaphor.txt implementation.txt \
+ plan.txt storage.txt thename.txt usecases.txt \
+ relationships.txt usecasedemo.gaphor
@@ -5,14 +5,13 @@
consistency checking should also be included.'''
#import misc.singleton as Singleton
-from gaphor.misc.singleton import Singleton as _Singleton
from gaphor.misc.signal import Signal as _Signal
#from misc.storage import Storage
import weakref, gc
from element import Element
from diagram import Diagram
-class ElementFactory(_Singleton):
+class ElementFactory(object):
def __element_signal (self, key, old_value, new_value, obj):
element = obj()
@@ -27,7 +26,7 @@ def __element_signal (self, key, old_value, new_value, obj):
self.__elements[element.id] = element
self.__emit_create (element)
- def init (self, *args, **kwargs):
+ def __init__ (self):
self.__elements = { }
self.__index = 1
self.__signal = _Signal()
View
@@ -1,12 +1,14 @@
__init__.py
actor.py
association.py
+classmember.py
comment.py
commentline.py
dependency.py
diagramitem.py
diagramitemfactory.py
generalization.py
+klass.py
metaitem.py
modelelement.py
package.py
@@ -17,7 +17,7 @@
import gaphor.UML as UML
-f = gaphorResource(DiagramItemFactory)
+f = GaphorResource(DiagramItemFactory)
f.register (ActorItem, UML.Actor)
f.register (ClassItem, UML.Class)
f.register (CommentItem, UML.Comment)
@@ -144,7 +144,7 @@ def confirm_connect_handle (self, handle):
s2 = c2.subject
end_head, end_tail, relation = self.find_relationship(s1, s2)
if not relation:
- element_factory = gaphorResource(UML.ElementFactory)
+ element_factory = GaphorResource(UML.ElementFactory)
relation = element_factory.create(UML.Association)
end_head = element_factory.create(UML.AssociationEnd)
end_tail = element_factory.create(UML.AssociationEnd)
@@ -48,7 +48,7 @@ def confirm_connect_handle (self, handle):
s2 = c2.subject
relation = self.find_relationship(s1, s2)
if not relation:
- relation = gaphorResource(UML.ElementFactory).create(UML.Dependency)
+ relation = GaphorResource(UML.ElementFactory).create(UML.Dependency)
relation.supplier = s1
relation.client = s2
self._set_subject(relation)
@@ -3,11 +3,12 @@
import gobject
import gaphor.UML as UML
-from gaphor.misc.singleton import Singleton
-class DiagramItemFactory(Singleton):
+class DiagramItemFactory(object):
"""
Factory class for creating diagram items.
+ Normally one would access this class through by calling
+ GaphorResource(gaphor.diagram.DiagramItemFactory)
"""
__diagram2uml = { }
@@ -33,7 +34,7 @@ def create (self, diagram, type, subject=None):
elif DiagramItemFactory.__diagram2uml.has_key(type):
uml_type = DiagramItemFactory.__diagram2uml[type]
if uml_type:
- factory = gaphorResource(UML.ElementFactory)
+ factory = GaphorResource(UML.ElementFactory)
subject = factory.create (uml_type)
if issubclass (uml_type, UML.Namespace):
subject.namespace = diagram.namespace
@@ -73,7 +73,7 @@ def confirm_connect_handle (self, handle):
s2 = c2.subject
relation = self.find_relationship(s1, s2)
if not relation:
- relation = gaphorResource(UML.ElementFactory).create(UML.Generalization)
+ relation = GaphorResource(UML.ElementFactory).create(UML.Generalization)
relation.parent = s1
relation.child = s2
self._set_subject(relation)
View
@@ -3,12 +3,13 @@
"""
This is the main package for Gaphor, a Python based UML editor.
-An extra function is installed in the builtin namespace: gaphorResource().
+An extra function is installed in the builtin namespace: GaphorResource().
This function can be used to locate application wide resources, such as
object factories.
"""
from misc.singleton import Singleton
+from misc.conf import Conf
import config
import types
@@ -43,6 +44,7 @@ class Gaphor(Singleton):
TITLE='Gaphor v' + VERSION
__resources = { }
+ __conf = Conf(NAME)
def init(self, install=1):
self.__main_window = None
@@ -59,14 +61,24 @@ def main(self):
from ui import MainWindow
program_init(Gaphor.NAME, Gaphor.VERSION)
# should we set a default icon here or something?
- self.__main_window = MainWindow(Gaphor.NAME, Gaphor.TITLE)
+ mainwin = MainWindow(Gaphor.NAME, Gaphor.TITLE)
+ mainwin.get_window().connect("destroy", self.__destroy_cb)
+ Gaphor.__resources[MainWindow] = mainwin
_main()
+ def __destroy_cb(self, win):
+ from ui.command.file import QuitCommand
+ QuitCommand().execute()
+
def get_main_window(self):
"""Return the main window, if any."""
- return self.__main_window
+ from ui import MainWindow
+ try:
+ return Gaphor.__resources[MainWindow]
+ except KeyError:
+ pass
- def getResource(resource):
+ def get_resource(resource):
"""
*Static method*
Locate a resource. Resource should be the class of the resource to
@@ -77,10 +89,10 @@ def getResource(resource):
elemfact = Gaphor.get(gaphor.UML.ElementFactory)
or (with Gaphor installed in the builtin namespace):
- elemfact = gaphorResource(gaphor.UML.ElementFactory)
+ elemfact = GaphorResource(gaphor.UML.ElementFactory)
"""
if isinstance (resource, types.StringType):
- assert 0, 'Gaphor::get() No string resources are implemented'
+ return Gaphor.__conf.get_value(resource)
else:
hash = Gaphor.__resources
if hash.has_key(resource):
@@ -92,10 +104,10 @@ def getResource(resource):
except Exception, e:
raise GaphorError, 'Could not create resource %s (%s)' % (str(resource), str(e))
- getResource = staticmethod(getResource)
+ get_resource = staticmethod(get_resource)
import __builtin__
__builtin__.__dict__['GaphorError'] = GaphorError
-__builtin__.__dict__['gaphorResource'] = Gaphor.getResource
+__builtin__.__dict__['GaphorResource'] = Gaphor.get_resource
View
@@ -1,3 +1,3 @@
-__all__ = [ 'singleton', 'command', 'signal', 'storage', 'menufactory' ]
+__all__ = [ 'singleton', 'command', 'signal', 'storage', 'menufactory', 'conf' ]
View
@@ -0,0 +1,141 @@
+# GConf wrapper
+import gconf
+from gconf import VALUE_BOOL, VALUE_INT, VALUE_STRING, VALUE_FLOAT
+from types import StringType, IntType, FloatType
+
+class Conf:
+ def __init__ (self, appname, allowed={}):
+ self._domain = '/apps/%s/' % appname
+ self._allowed = allowed
+ self._gconf_client = gconf.client_get_default ()
+
+ def __getitem__ (self, attr):
+ return self.get_value (attr)
+
+ def __setitem__ (self, key, val):
+ allowed = self._allowed
+ if allowed.has_key (key):
+ if not key in allowed[key]:
+ good = ', '.join (allowed[key])
+ raise 'ConfError', '%s must be one of: (%s)' % (key, good)
+ self.set_value (key, val)
+
+ def _get_type (self, key):
+ KeyType = type (key)
+ if KeyType == StringType:
+ return 'string'
+ elif KeyType == IntType:
+ return 'int'
+ elif KeyType == FloatType:
+ return 'float'
+ else:
+ raise 'ConfError', 'unsupported type: %s' % str (KeyType)
+
+ # Public functions
+
+ def set_allowed (self, allowed):
+ self._allowed = allowed
+
+ def set_domain (self, domain):
+ self._domain = domain
+
+ def get_domain (self):
+ return self._domain
+
+ def get_gconf_client (self):
+ return self._gconf_client
+
+ def get_value (self, key):
+ '''returns the value of key `key' ''' #'
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ value = self._gconf_client.get (self._domain + key)
+ value_type = value.type
+ if value_type == VALUE_BOOL:
+ return value.get_bool ()
+ elif value_type == VALUE_INT:
+ return value.get_int ()
+ elif value_type == VALUE_STRING:
+ return value.get_string ()
+ elif value_type == VALUE_FLOAT:
+ return value.get_float ()
+
+ def set_value (self, key, value):
+ '''sets the value of key `key' to `value' '''
+ value_type = self._get_type (value)
+
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ func = getattr (self._gconf_client, 'set_' + value_type)
+ apply (func, (self._domain + key, value))
+
+ def get_string (self, key):
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ return self._gconf_client.get_string (self._domain + key)
+
+ def set_string (self, key, value):
+ if type (value) != StringType:
+ raise 'ConfError', 'value must be a string'
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ self._gconf_client.set_string (self._domain + key, value)
+
+ def get_bool (self, key):
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ return self._gconf_client.get_bool (self._domain + key)
+
+ def set_bool (self, key, value):
+ if type (value) != IntType and \
+ (key != 0 or key != 1):
+ raise 'ConfError', 'value must be a boolean'
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ self._gconf_client.set_bool (self._domain + key, value)
+
+ def get_int (self, key):
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ return self._gconf_client.get_int (self._domain + key)
+
+ def set_int (self, key, value):
+ if type (value) != IntType:
+ raise 'ConfError', 'value must be an int'
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ self._gconf_client.set_int (self._domain + key, value)
+
+ def get_float (self, key):
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ return self._gconf_client.get_float (self._domain + key)
+
+ def set_float (self, key, value):
+ if type (value) != FloatType:
+ raise 'ConfError', 'value must be an float'
+
+ #if '/' in key:
+ # raise 'ConfError', 'key must not contain /'
+
+ self._gconf_client.set_float (self._domain + key, value)
+
+def test():
+ c = Conf ('test-gconf')
+ c['foo'] = '1'
+ c['bar'] = 2
+ c['baz'] = 3.0
+
+ print c['foo'], c['bar'], c['baz']
+
+if __name__ == '__main__':
+ test()
@@ -10,8 +10,8 @@
class StorageInfo:
def __init__(self):
- self.factory = gaphorResource(UML.ElementFactory)
- self.itemfactory = gaphorResource(diagram.DiagramItemFactory)
+ self.factory = GaphorResource(UML.ElementFactory)
+ self.itemfactory = GaphorResource(diagram.DiagramItemFactory)
self.cid2item = { }
self.doc=None
@@ -11,8 +11,8 @@
class StorageInfo:
def __init__(self):
- self.factory = gaphorResource(UML.ElementFactory)
- self.itemfactory = gaphorResource(diagram.DiagramItemFactory)
+ self.factory = GaphorResource(UML.ElementFactory)
+ self.itemfactory = GaphorResource(diagram.DiagramItemFactory)
self.cid2item = { }
self.doc=None
@@ -6,6 +6,14 @@
from gaphor.misc.command import Command
import gaphor.UML as UML
+class CreateDiagramCommand(Command):
+
+ def execute(self):
+ elemfact = GaphorResource(UML.ElementFactory)
+ model = elemfact.lookup(1) # model
+ diagram = elemfact.create(UML.Diagram)
+ diagram.namespace = model
+ diagram.name = "New diagram"
class _CanvasViewCommand(Command):
Oops, something went wrong.

0 comments on commit 8e89e0c

Please sign in to comment.