Changeset 241

Show
Ignore:
Timestamp:
03/22/04 07:15:14 (5 years ago)
Author:
arjanmol
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gaphor/TODO

    r220 r241  
    77  the canvas item once a reference is destroyed. 
    88   
     9- Define a proper scheme for flushing models. Currently a lot of elements 
     10  have references around. This has to do with how PyGtk references python 
     11  and C objects. We should do something like: clean all diagram items, 
     12  then clean the rest of the elements in the ElementFactory. 
     13 
    914- Class: Association end properties are shown in the tree view 
    1015- Undo/redo functionality doesn;t work as espected 
    11 - Implement and test attribute/operation parser. 
     16#- Implement and test attribute/operation parser. 
    1217- Convert Data model to use the parsed attributes + operations. 
    1318- Attributes are not added to classes that are loaded. 
    14 - Operation is not part of namespace (assoc. should be bi-dir.) 
     19#- Operation is not part of namespace (assoc. should be bi-dir.) 
    1520 
    1621- Make sure than, when a model is loaded and saved again, both save files do 
  • trunk/gaphor/gaphor/UML/diagram.py

    r231 r241  
    8787        self.canvas.clear_undo() 
    8888        self.canvas.clear_redo() 
     89        def dispose(item): 
     90            try: 
     91                for i in item.groupable_iter(): 
     92                    dispose(i) 
     93            except AttributeError: 
     94                pass 
     95            try: 
     96                item.unlink() 
     97            except: 
     98                pass 
     99            # Clear all references on a C-level 
     100            item.dispose() 
     101 
     102        #for i in self.canvas.root.children: 
     103        #    dispose(i) 
     104 
    89105        Namespace.unlink(self) 
    90         for i in self.canvas.root.children: 
    91             i.unlink() 
  • trunk/gaphor/gaphor/UML/elementfactory.py

    r231 r241  
    33""" 
    44 
    5 from diagram import Diagram 
    65import gaphor 
    76import gaphor.misc.uniqueid as uniqueid 
    87#import weakref 
    98from element import Element 
     9from diagram import Diagram 
    1010#from gaphor.misc.weakmethod import WeakMethod 
    1111 
     
    7979        """Flush all elements (remove them from the factory).""" 
    8080        self.notify(None, 'flush') 
     81        # First flush all diagrams: 
     82        for value in self.select(lambda e: isinstance(e, Diagram)): 
     83            value.unlink() 
     84 
    8185        for key, value in self._elements.items(): 
    8286            #print 'ElementFactory: unlinking', value 
    8387            #print 'references:', gc.get_referrers(value) 
    8488            value.unlink() 
     89 
    8590        assert len(self._elements) == 0, 'Still items in the factory: %s' % str(self._elements.values()) 
     91 
    8692        import gc 
    8793        for i in range(4): gc.collect() 
  • trunk/gaphor/gaphor/UML/properties.py

    r231 r241  
    8080            obj.notify(self.name, pspec=self) 
    8181        except Exception, e: 
    82             log.error(str(e)
     82            log.error(str(e), e
    8383 
    8484        # we need to check if a deriviate is part of the current object: 
     
    9898                        d.notify(obj) 
    9999                    except Exception, e: 
    100                         log.error(e
     100                        log.error(e, e
    101101 
    102102 
  • trunk/gaphor/gaphor/__init__.py

    r225 r241  
    7777 
    7878    example: Get the element factory: 
    79             elemfact = gaphor.resource(gaphor.UML.ElementFactory) 
     79            factory = gaphor.resource(gaphor.UML.ElementFactory) 
    8080 
    8181    Also builtin resources are 'Name', 'Version' and 'DataDir'. In case main() 
     
    108108__builtin__.__dict__['log'] = misc.logger.Logger() 
    109109 
     110try:  
     111    # Keep track of all model elements that are created 
     112    from misc.aspects import ReferenceAspect, weave_method 
     113    import UML.elementfactory 
     114    import UML.diagram 
     115    refs = [] 
     116    weave_method(UML.elementfactory.ElementFactory.create, ReferenceAspect, refs) 
     117    weave_method(UML.diagram.Diagram.create, ReferenceAspect, refs) 
     118except ImportError: 
     119    pass 
     120 
  • trunk/gaphor/gaphor/diagram/modelelement.py

    r225 r241  
    6161 
    6262    def on_glue(self, handle, wx, wy): 
     63        #import sys 
     64        #print self, handle, '=>', sys.getrefcount(self), sys.getrefcount(handle) 
    6365        return self._on_glue(handle, wx, wy, diacanvas.CanvasElement) 
    6466 
  • trunk/gaphor/gaphor/diagram/operation.py

    r221 r241  
    2222    def on_subject_notify__name(self, subject, pspec): 
    2323        self._expression.set_text(self.subject.render()) 
    24         #self.request_update() 
     24        self.request_update() 
    2525 
    2626    on_subject_notify__visibility = on_subject_notify__name 
  • trunk/gaphor/gaphor/misc/action.py

    r231 r241  
    149149    def execute(self, action_id): 
    150150        global _dependent_actions 
    151         print 'ActionPool: executing', action_id 
     151        #print 'ActionPool: executing', action_id 
    152152        action = self.get_action(action_id) 
    153153        action.execute() 
     
    155155        for d in _dependent_actions.get(action_id) or (): 
    156156            dep_action = self.get_action(d) 
    157             print 'ActionPool: updating', d 
     157            #print 'ActionPool: updating', d 
    158158            dep_action.update() 
    159159 
  • trunk/gaphor/gaphor/ui/diagramtab.py

    r231 r241  
    1212        self.owning_window = owning_window 
    1313 
    14     #def set_owning_window(self, owning_window): 
    15         #self.owning_window = owning_window 
    16  
    1714    def get_diagram(self): 
    1815        return self.diagram 
    1916 
    2017    def get_view(self): 
    21         #self._check_state(AbstractWindow.STATE_ACTIVE) 
    2218        return self.view 
    2319 
     
    8480        #toolbar.show() 
    8581        #vbox.show_all() 
    86         self.table = table 
     82        #self.table = table 
    8783        #self._construct_window(name='diagram', 
    8884        #                       title=title, 
     
    9894        self.owning_window.remove_tab(self) 
    9995        self.set_diagram(None) 
     96        # We need this to get the view deleted properly: 
     97        del self.view.diagram 
    10098        del self.view 
    10199        del self.diagram 
    102100 
    103101    def __on_view_event_after(self, view, event): 
    104         #self._check_state(AbstractWindow.STATE_ACTIVE) 
    105102        # handle mouse button 3 (popup menu): 
    106103        if event.type == gtk.gdk.BUTTON_PRESS: 
     
    114111                self.owning_window._construct_popup_menu(menu_def=item.get_popup_menu(), 
    115112                                           event=event) 
    116                 #self.stop_emission('event-after') 
    117113            return True 
    118114        return False 
  • trunk/gaphor/gaphor/ui/diagramview.py

    r215 r241  
    66from diacanvas import CanvasView 
    77import gaphor 
     8from gaphor.diagram import get_diagram_item 
    89 
    910class DiagramView(CanvasView): 
     
    4748    
    4849    def on_drag_data_received(self, context, x, y, data, info, time): 
    49         print 'drag_data_received' 
     50        #rint 'drag_data_received' 
    5051        if data and data.format == 8 and info == DiagramView.TARGET_ELEMENT_ID: 
    51             from gaphor.diagram import get_diagram_item 
    52             print 'drag_data_received:', data.data, info 
     52            #print 'drag_data_received:', data.data, info 
    5353            elemfact = gaphor.resource('ElementFactory') 
    5454            element = elemfact.lookup(data.data) 
     
    7070 
    7171    def do_drag_drop(self, context, x, y, time): 
    72         print 'drag_drop' 
     72        #print 'drag_drop' 
    7373        return 1 
    7474 
  • trunk/gaphor/gaphor/ui/mainwindow.py

    r231 r241  
    5252                'separator', 
    5353                'FileSave', 
    54                 'FileSaveAs', 
    55                 'separator', 
    56                 'Pointer', 
     54                'FileSaveAs') 
     55 
     56    wrapbox =  ('Pointer', 
    5757                'separator', 
    5858                'InsertClass', 
     
    112112        scrolled_window = gtk.ScrolledWindow() 
    113113        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 
    114         scrolled_window.set_shadow_type(gtk.SHADOW_ETCHED_IN) 
     114        #scrolled_window.set_shadow_type(gtk.SHADOW_ETCHED_IN) 
    115115        scrolled_window.add(view) 
    116116         
     
    121121 
    122122        #scrolled_window.show_all() 
     123        #ns_paned = gtk.VPaned() 
     124        #ns_paned.pack1(scrolled_window)#, expand=True) 
     125        vbox = gtk.VBox() 
     126        vbox.pack_start(scrolled_window, expand=True) 
    123127 
    124128        paned = gtk.HPaned() 
    125         paned.pack1(scrolled_window) 
    126  
     129        #paned.pack1(scrolled_window) 
     130        #paned.pack1(ns_paned) 
     131        paned.pack1(vbox) 
    127132        notebook = gtk.Notebook() 
    128133        #notebook.popup_enable() 
     
    144149                               contents=paned) 
    145150                               #contents=scrolled_window) 
     151        wrapbox = self.menu_factory.create_wrapbox(self.wrapbox) 
     152        #wrapbox.set_aspect_ratio(1/256) 
     153        vbox.pack_start(wrapbox, expand=False) 
     154        wrapbox.show() 
     155        #vbox.set_resize_mode(gtk.RESIZE_QUEUE) 
     156        #wrapbox.set_resize_mode(gtk.RESIZE_QUEUE) 
     157        #scrolled_window = gtk.ScrolledWindow() 
     158        #scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) 
     159        #scrolled_window.set_shadow_type(gtk.SHADOW_ETCHED_IN) 
     160        #scrolled_window.add_with_viewport(wrapbox) 
     161        #scrolled_window.show() 
     162        #ns_paned.pack2(scrolled_window)#, expand=False) 
     163        #wrapbox.queue_resize() 
     164        #wrapbox.set_size_request(0,0) 
     165 
     166        #def print_me(wrapbox, rect, mutex): 
     167        #    print wrapbox, rect, mutex 
     168        #    if not mutex: 
     169        #        mutex.append(1) 
     170        #        wrapbox.queue_resize() 
     171        #        mutex.remove(1) 
     172 
     173        #paned.connect('motion-notify-event', print_me) 
     174        #wrapbox.connect('size-allocate', print_me, []) 
    146175 
    147176    def add_transient_window(self, window): 
     
    175204        return page_num 
    176205 
    177         current = self.notebook.get_current_page() 
    178         content = self.notebook.get_nth_page(current) 
    179         return self.notebook_map[content] 
    180  
    181206    def get_current_tab(self): 
    182207        current = self.notebook.get_current_page() 
  • trunk/gaphor/gaphor/ui/menufactory.py

    r225 r241  
    99import gtk 
    1010from gaphor.misc.action import ActionError, Action, CheckAction, RadioAction 
     11import gaphor.misc.wrapbox 
    1112 
    1213#from logilab.aspects.weaver import weaver 
     
    4647        except ActionError: 
    4748            return None 
     49 
     50    def get_icon_and_label(self, action, icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR): 
     51        if action.stock_id: 
     52            # Fetch stock icon, and probably a text and tooltip: 
     53            stock_info = gtk.stock_lookup(action.stock_id) 
     54            #print stock_info # (id, label, mod, key, translationdomain) 
     55            try: 
     56                label = stock_info[1].replace('_', '') 
     57            except TypeError: 
     58                label = action.label.replace('_', '') 
     59            icon = gtk.Image() 
     60            icon.set_from_stock(action.stock_id, icon_size) 
     61        else: 
     62            label = action.label.replace('_', '') 
     63            icon = None 
     64        return icon, label 
    4865 
    4966    def on_item_activate(self, menu_item, action_id): 
     
    225242                                    user_data=None) 
    226243            else: 
    227                 if action.stock_id: 
    228                     # Fetch stock icon, and probably a text and tooltip: 
    229                     stock_info = gtk.stock_lookup(action.stock_id) 
    230                     #print stock_info # (id, label, mod, key, translationdomain) 
    231                     try: 
    232                         label = stock_info[1].replace('_', '') 
    233                     except TypeError: 
    234                         label = action.label.replace('_', '') 
    235                     icon = gtk.Image() 
    236                     icon.set_from_stock(action.stock_id, toolbar.get_icon_size()) 
    237                 else: 
    238                     label = action.label.replace('_', '') 
    239                     icon = None 
     244                icon, label = self.get_icon_and_label(action, toolbar.get_icon_size()) 
    240245                if isinstance(action, RadioAction): 
    241246                    try: 
     
    279284        return toolbar 
    280285 
     286    def create_wrapbox(self, menu_def): 
     287        """Create a Wrapbox. items in menu_def should not be nested as 
     288        they are when creating a normal menu. 
     289        """ 
     290        wrapbox = gaphor.misc.wrapbox.HWrapBox() 
     291        groups = { } 
     292        for id in menu_def: 
     293            action = self.get_action(id) 
     294            if not action: 
     295                if id == 'separator': 
     296                    sep = gtk.HSeparator() 
     297                    wrapbox.add(sep) 
     298                    sep.show() 
     299                    continue 
     300                label = id 
     301                icon = None 
     302                item = gtk.Button() 
     303            else: 
     304                icon, label = self.get_icon_and_label(action) 
     305                if isinstance(action, RadioAction): 
     306                    try: 
     307                        group = groups[action.group] 
     308                    except KeyError: 
     309                        group = None 
     310                    item = gtk.RadioButton(group) 
     311                    item.set_mode(False) 
     312                    item.connect('toggled', self.on_radio_item_activate, action.id) 
     313                    self.connect_item_to_action('notify::active', action, item, 
     314                                                self.on_radio_menu_item_notify_active) 
     315                    self.in_activation = True 
     316                    if not group: 
     317                        groups[action.group] = item 
     318                    #else: 
     319                    #    item.set_group(group) 
     320                    item.set_active(action.active) 
     321                    self.in_activation = False 
     322                elif isinstance(action, CheckAction): 
     323                    item = gtk.CheckButton() 
     324                    item.set_mode(False) 
     325                    item.connect('toggled', self.on_check_item_activate, action.id) 
     326                    self.connect_item_to_action('notify::active', action, item, 
     327                                                self.on_menu_item_notify_action) 
     328                    self.in_activation = True 
     329                    item.set_active(action.active) 
     330                    self.in_activation = False 
     331                else: 
     332                    #if action.stock_id: 
     333                        #item = gtk.Button(action.stock_id) 
     334                        #item.set_property('use-stock', True) 
     335                    #else: 
     336                    item = gtk.Button() 
     337                if action.stock_id: 
     338                    #item.set_property('stock-id', action.stock_id) 
     339                    item.add(icon) 
     340                    icon.show() 
     341                    pass 
     342                else: 
     343                    item.set_label(label) 
     344                item.set_property('visible', action.visible) 
     345                item.set_property('sensitive', action.sensitive) 
     346                self.connect_item_to_action('notify::visible', action, item, 
     347                                            self.on_menu_item_notify_action) 
     348                self.connect_item_to_action('notify::sensitive', action, item, 
     349                                            self.on_menu_item_notify_action) 
     350                wrapbox.pack(item, False, False, False, False) 
     351                item.show() 
     352        return wrapbox 
     353 
  • trunk/gaphor/gaphor/ui/namespace.py

    r225 r241  
    1010 
    1111import gaphor.UML as UML 
     12 
     13# The following items will not be shown in the treeview, although they 
     14# are UML.Namespace elements. 
     15_default_exclude_list = ( UML.Parameter, UML.Association ) 
    1216 
    1317class NamespaceModel(gtk.GenericTreeModel): 
     
    3438        self.root = (None, []) 
    3539 
     40        self.exclude = _default_exclude_list 
    3641 
    3742    def new_node_from_element(self, element, parent): 
    3843        """Create a new node for an element. Owned members are also created.""" 
     44        if isinstance(element, self.exclude): 
     45            return 
    3946        node = (element, []) 
    4047        parent[1].append(node) 
     
    155162        node_members = map(lambda e: e[0], node[1]) 
    156163        # The elements that are now children of the element 
    157         owned_members = element.ownedMember 
     164        owned_members = filter(lambda e: not isinstance(e, self.exclude), element.ownedMember) 
     165        #owned_members = element.ownedMember 
    158166        if len(node_members) < len(owned_members): 
    159167            # element added 
  • trunk/gaphor/setup.py

    r228 r241  
    298298 
    299299 
     300from dsextras import TemplateExtension, BuildExt, GLOBAL_INC 
     301 
     302pygtkincludedir = getoutput('pkg-config --variable pygtkincludedir pygtk-2.0') 
     303codegendir = getoutput('pkg-config --variable codegendir pygtk-2.0') 
     304defsdir = getoutput('pkg-config --variable defsdir pygtk-2.0') 
     305 
     306sys.path.append(codegendir) 
     307 
     308GLOBAL_INC.append(pygtkincludedir) 
     309GLOBAL_INC.append('.') 
     310GTKDEFS = [os.path.join(defsdir, 'gtk-types.defs')] 
     311 
     312ext_modules = [] 
     313gtkwrapbox = TemplateExtension(name='wrapbox', 
     314                               pkc_name='gtk+-2.0', 
     315                               pkc_version='2.0.0', 
     316                               output='gaphor.misc.wrapbox', 
     317                               defs='src/wrapbox.defs', 
     318                               sources=['src/gtkwrapbox.c', 
     319                                        'src/gtkhwrapbox.c', 
     320                                        'src/wrapbox.c', 
     321                                        'src/wrapboxmodule.c'], 
     322                               register=GTKDEFS, 
     323                               override='src/wrapbox.override') 
     324 
     325if gtkwrapbox.can_build(): 
     326    ext_modules.append(gtkwrapbox) 
     327else: 
     328    pass 
     329 
    300330setup(name='gaphor', 
    301331      version=VERSION, 
     
    315345                'gaphor.misc' 
    316346      ], 
     347      ext_modules=ext_modules, 
    317348      # data files are relative to <prefix>/share/gaphor (see setup.cfg) 
    318349      data_files=[('', ['data/gaphor-main-ui.xml', 
     
    329360                #'install_schemas': install_schemas, 
    330361                'build': build, 
     362                'build_ext': BuildExt, 
    331363                'build_mo': build_mo, 
    332364                'build_pot': build_pot, 
  • trunk/gaphor/tests/menu.py

    r225 r241  
    214214vbox.pack_start(event_box, expand=gtk.TRUE) 
    215215 
     216wrap_box = menu_factory.create_wrapbox(('FileNew', 'FileCheck', 'separator', 'Green', 'Yellow', 'Blue')) 
     217vbox.pack_start(wrap_box, expand=gtk.TRUE) 
     218wrap_box.show() 
     219 
    216220vbox.pack_end(statusbar, expand=gtk.FALSE) 
    217221vbox.show()