[dia] python: drop usage of .data and .diagram



commit cf1631eece6c040ce7c99ab55291f7433bcfcdc8
Author: Zander Brown <zbrown gnome org>
Date:   Thu Apr 23 00:32:28 2020 +0100

    python: drop usage of .data and .diagram

 plug-ins/python/allprops.py        |  4 ++--
 plug-ins/python/aobjects.py        |  4 ++--
 plug-ins/python/autolayoutforce.py |  9 ++++-----
 plug-ins/python/dia_rotate.py      | 11 +++++------
 plug-ins/python/diadissect.py      |  7 +++----
 plug-ins/python/group_props.py     | 10 ++++------
 plug-ins/python/otypes.py          |  4 ++--
 plug-ins/python/pydiadoc.py        |  2 +-
 plug-ins/python/scascale.py        | 11 +++++------
 plug-ins/python/select_by.py       | 32 ++++++++++++++------------------
 plug-ins/python/select_empty.py    |  3 +--
 11 files changed, 43 insertions(+), 54 deletions(-)
---
diff --git a/plug-ins/python/allprops.py b/plug-ins/python/allprops.py
index ab736365..2c00d344 100644
--- a/plug-ins/python/allprops.py
+++ b/plug-ins/python/allprops.py
@@ -27,11 +27,11 @@ _ = gettext.gettext
 def allprops_cb(data, flags) :
 
        # copied from otypes.py
-       if data :
+       if data:
                diagram = None # we may be running w/o GUI
        else :
                diagram = dia.new("All Object Properties.dia")
-               data = diagram.data
+               data = diagram
        layer = data.active_layer
 
        props_by_name = {}
diff --git a/plug-ins/python/aobjects.py b/plug-ins/python/aobjects.py
index d93ae170..9be5a388 100644
--- a/plug-ins/python/aobjects.py
+++ b/plug-ins/python/aobjects.py
@@ -37,11 +37,11 @@ def set_object_string (o) :
 def aobjects_cb(data, flags) :
 
        # copied from otypes.py
-       if data :
+       if data:
                diagram = None # we may be running w/o GUI
        else :
                diagram = dia.new("All Objects.dia")
-               data = diagram.data
+               data = diagram
        layer = data.active_layer
 
        otypes = dia.registered_types()
diff --git a/plug-ins/python/autolayoutforce.py b/plug-ins/python/autolayoutforce.py
index 65e2c189..8b452e62 100644
--- a/plug-ins/python/autolayoutforce.py
+++ b/plug-ins/python/autolayoutforce.py
@@ -99,8 +99,7 @@ def layout_force (nodes, rconst, aconst, timestep, damping) :
                energy[1] += mass * math.pow (velocity[1], 2) / 2
        return energy
 
-def layout_force_cb (data, flags) :
-       diagram = dia.active_display().diagram
+def layout_force_cb(data, flags):
        # the things (nodes) we are moving around are all connected 'elements',
        # connection objects are only moving as a side effect
        nodes = []
@@ -117,10 +116,10 @@ def layout_force_cb (data, flags) :
                e = layout_force (nodes, 2.0, 3.0, 2e-1, 5e-1)
                n += 1
        for o in nodes :
-               diagram.update_connections (o)
+               data.update_connections (o)
        data.active_layer.update_extents() # data/diagram _update_extents don't recalculate?
-       diagram.update_extents ()
-       diagram.flush()
+       data.update_extents ()
+       data.flush()
        print n, "iterations"
 
 dia.register_action ("LayoutForcePy", _("_Layout (force)"),
diff --git a/plug-ins/python/dia_rotate.py b/plug-ins/python/dia_rotate.py
index 392604ac..619d7b73 100644
--- a/plug-ins/python/dia_rotate.py
+++ b/plug-ins/python/dia_rotate.py
@@ -22,7 +22,7 @@ import gettext
 _ = gettext.gettext
 
 class CRotateDialog :
-       def __init__(self, d, data) :
+       def __init__(self, data) :
                import pygtk
                pygtk.require("2.0")
                import gtk
@@ -30,8 +30,7 @@ class CRotateDialog :
                win.connect("delete_event", self.on_delete)
                win.set_title(_("Rotate counter-clockwise"))
 
-               self.diagram = d
-               self.data = data
+               self.diagram = data
                self.win = win
 
                box1 = gtk.VBox()
@@ -74,8 +73,8 @@ class CRotateDialog :
                s = self.entry.get_text()
                angle = float(s)
                if angle >= 0 and angle <= 360 :
-                       SimpleRotate (self.data, angle)
-                       self.data.update_extents()
+                       SimpleRotate (self.diagram, angle)
+                       self.diagram.update_extents()
                        self.diagram.flush()
                else :
                        dia.message(1, "Please enter an angle between 0 and 360 degrees.")
@@ -121,7 +120,7 @@ def SimpleRotate(data, angle) :
        dia.active_display().add_update_all()
 
 def rotate_cb(data, flags) :
-       dlg = CRotateDialog(dia.active_display().diagram, data)
+       dlg = CRotateDialog(data)
 
 dia.register_action ("ObjectsSimplerotation", _("Simple _Rotation"),
                     "/DisplayMenu/Objects/ObjectsExtensionStart",
diff --git a/plug-ins/python/diadissect.py b/plug-ins/python/diadissect.py
index abbca6be..50e668e8 100644
--- a/plug-ins/python/diadissect.py
+++ b/plug-ins/python/diadissect.py
@@ -44,10 +44,9 @@ class DissectRenderer :
                self._open (filename)
                self.extents = data.extents
                try :
-                       # this can fail for two reason:
-                       #  1) data.diagram is None, e.g. when running from pure bindings
-                       #  2) there is no member data.diagram because Dia is just too old
-                       self.f.write ("# Dissect %s\n" % (data.diagram.filename,))
+                       # this can fail when data is not interative,
+                       # e.g. when running from pure bindings
+                       self.f.write ("# Dissect %s\n" % (data.filename,))
                except :
                        self.f.write ("# Dissect %s\n" % (filename,))
        def end_render (self) :
diff --git a/plug-ins/python/group_props.py b/plug-ins/python/group_props.py
index e847ee7e..7606b2fe 100644
--- a/plug-ins/python/group_props.py
+++ b/plug-ins/python/group_props.py
@@ -31,13 +31,12 @@ import gettext
 _ = gettext.gettext
 
 class CPropsDialog :
-       def __init__(self, diagram, data, props) :
+       def __init__(self, diagram, props) :
                import pygtk
                pygtk.require("2.0")
                import gtk
 
                self.diagram = diagram
-               self.data = data
                self.props = props
 
                self.win = gtk.Window ()
@@ -118,7 +117,7 @@ class CPropsDialog :
                                for o in grp :
                                        s = self.props.keys()[i]
                                        o.properties[s] = self.props[s].opts[om.get_history()]
-               self.data.update_extents ()
+               self.diagram.update_extents ()
                self.diagram.flush()
                self.win.destroy()
 
@@ -138,8 +137,7 @@ class PropInfo :
                self.opts.append(o)
 
 def dia_objects_props_cb (data, flags) :
-       d = dia.active_display().diagram
-       grp = d.get_sorted_selected()
+       grp = data.get_sorted_selected()
        allProps = {}
        numProps = len(grp)
        # check for properties common to all select objects
@@ -176,7 +174,7 @@ def dia_objects_props_cb (data, flags) :
                                allProps[s].opts.append(uniques[v])
        # display the dialog
        try :
-               dlg = CPropsDialog(d, data, allProps)
+               dlg = CPropsDialog(data, allProps)
        except ImportError :
                dia.message(0, "Dialog creation failed. Missing pygtk?")
 
diff --git a/plug-ins/python/otypes.py b/plug-ins/python/otypes.py
index ee51c1fd..a3db90da 100644
--- a/plug-ins/python/otypes.py
+++ b/plug-ins/python/otypes.py
@@ -35,11 +35,11 @@ def _log(s, append=1) :
 
 def otypes_cb(data, flags) :
 
-       if data :
+       if data:
                diagram = None # we may be running w/o GUI
        else :
                diagram = dia.new("Object Types.dia")
-               data = diagram.data
+               data = diagram
        layer = data.active_layer
 
        otypes = dia.registered_types()
diff --git a/plug-ins/python/pydiadoc.py b/plug-ins/python/pydiadoc.py
index bff71fdc..ad1958bb 100644
--- a/plug-ins/python/pydiadoc.py
+++ b/plug-ins/python/pydiadoc.py
@@ -77,7 +77,7 @@ def autodoc_cb (data, flags, update) :
        if not data : # not set when called by the toolbox menu
                diagram = dia.new("PyDiaObjects.dia")
                # passed in data is not necessary valid - we are called from the Toolbox menu
-               data = diagram.data
+               data = diagram
                display = diagram.display()
        else :
                diagram = None
diff --git a/plug-ins/python/scascale.py b/plug-ins/python/scascale.py
index 2bc68c4f..e73859d4 100644
--- a/plug-ins/python/scascale.py
+++ b/plug-ins/python/scascale.py
@@ -29,7 +29,7 @@ import gettext
 _ = gettext.gettext
 
 class CScaleDialog :
-       def __init__(self, d, data) :
+       def __init__(self, data) :
                import pygtk
                pygtk.require("2.0")
                import gtk
@@ -37,8 +37,7 @@ class CScaleDialog :
                win.connect("delete_event", self.on_delete)
                win.set_title(_("Simple Scaling"))
 
-               self.diagram = d
-               self.data = data
+               self.diagram = data
                self.win = win
 
                box1 = gtk.VBox()
@@ -76,8 +75,8 @@ class CScaleDialog :
                s = self.entry.get_text()
                scale = float(s)
                if scale > 0.001 and scale < 1000 :
-                       SimpleScale (self.data, float(s))
-                       self.data.update_extents ()
+                       SimpleScale (self.diagram, float(s))
+                       self.diagram.update_extents ()
                        self.diagram.flush()
                else :
                        dia.message(1, "Value out of range!")
@@ -147,7 +146,7 @@ def SimpleScale(data, factor) :
        dia.active_display().add_update_all()
 
 def scale_cb(data, flags) :
-       dlg = CScaleDialog(dia.active_display().diagram, data)
+       dlg = CScaleDialog(data)
 
 dia.register_action ("ObjectsSimplescaling", _("Simple _Scaling"),
                     "/DisplayMenu/Objects/ObjectsExtensionStart",
diff --git a/plug-ins/python/select_by.py b/plug-ins/python/select_by.py
index f21d44d4..2ba5c68b 100644
--- a/plug-ins/python/select_by.py
+++ b/plug-ins/python/select_by.py
@@ -28,7 +28,7 @@ import gettext
 _ = gettext.gettext
 
 class CFindDialog :
-       def __init__(self, d, data) :
+       def __init__(self, data) :
                import pygtk
                pygtk.require("2.0")
                import gtk
@@ -37,8 +37,7 @@ class CFindDialog :
                win.connect("delete_event", self.on_delete)
                win.set_title(_("Select by name"))
 
-               self.diagram = d
-               self.data = data
+               self.diagram = data
                self.win = win
 
                box1 = gtk.VBox()
@@ -74,41 +73,39 @@ class CFindDialog :
 
        def on_find(self, *args) :
                s = self.entry.get_text()
-               select_by (self.diagram, self.data, "name", s)
-               self.data.update_extents ()
+               select_by (self.diagram, "name", s)
+               self.diagram.update_extents ()
                self.diagram.flush()
 
        def on_delete (self, *args) :
                self.win.destroy ()
 
-def do_dialog (d, data) :
+def do_dialog(data):
        # let the dialog do it's work
-       dlg = CFindDialog (d, data)
+       dlg = CFindDialog(data)
 
-def select_by (diagram, data, name, value) :
-       objs = data.active_layer.objects
+def select_by (diagram, name, value) :
+       objs = diagram.active_layer.objects
        for o in objs :
                if o.properties.has_key (name) :
                        print "<==", o.properties[name].value
                        if value == None or o.properties[name].value == value :
                                diagram.select (o)
 
-def select_by_name_cb (data, flags) :
-       d = dia.active_display().diagram
-       do_dialog (d, data)
+def select_by_name_cb (data, flags):
+       do_dialog (data)
 
 def select_by_selected (data, name) :
-       d = dia.active_display().diagram
        grp = data.get_sorted_selected()
        bFoundAny = 0
        for o in grp :
                if o.properties.has_key(name) :
-                       select_by (d, data, name, o.properties[name].value)
+                       select_by (data, name, o.properties[name].value)
                        bFoundAny = 1
        if not bFoundAny :
                dia.message(0, "No selected object has the property '%s'." % name)
        data.update_extents ()
-       d.flush()
+       data.flush()
 
 def select_by_fill_color_cb (data, flags) :
        select_by_selected (data, "fill_colour")
@@ -121,7 +118,6 @@ def select_by_size_cb (data, flags) :
        """ From the diagrams selection derive the minimum and maximum object size.
            Select every other object within this range.
        """
-       d = dia.active_display().diagram
        grp = data.get_sorted_selected()
        smin = 100000
        smax = 0
@@ -139,8 +135,8 @@ def select_by_size_cb (data, flags) :
                h = o.bounding_box.bottom - o.bounding_box.top
                s = w * h
                if s >= smin and s <= smax :
-                       d.select(o)
-       d.flush()
+                       data.select(o)
+       data.flush()
 
 
 dia.register_action ("SelectByName", _("_Name"),
diff --git a/plug-ins/python/select_empty.py b/plug-ins/python/select_empty.py
index 0b0b65b9..8bc5e1fa 100644
--- a/plug-ins/python/select_empty.py
+++ b/plug-ins/python/select_empty.py
@@ -21,12 +21,11 @@ import gettext
 _ = gettext.gettext
 
 def select_empty_cb (data, flags) :
-       diagram = dia.active_display().diagram
        objs = data.active_layer.objects
        for o in objs :
                if o.bounding_box.right == o.bounding_box.left \
                        or o.bounding_box.top == o.bounding_box.bottom :
-                       diagram.select (o)
+                       data.select (o)
 
 dia.register_action ("SelectEmpty", _("_Empty"),
                        "/DisplayMenu/Select/By/SelectByExtensionStart",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]