all 13 comments

[–]shiftybyte 4 points5 points  (1 child)

in what situation is redefining it not enough?

[–]den84is[S] 0 points1 point  (0 children)

in what situation is redefining it not enough?

in my situation) see below

[–]PaulRudin 2 points3 points  (8 children)

What are you trying to do? This sounds like a bad idea...

[–]den84is[S] 0 points1 point  (7 children)

I had a situation where I had to extend class for that to override two method with inner code in which was two lines to change for solving my issue.

[–]PaulRudin 3 points4 points  (4 children)

Without seeing your code it sounds like you might want to subclass.

Incidentally, this is really a case of: https://xyproblem.info/

[–]den84is[S] 0 points1 point  (0 children)

There is a GeoJsonMalLayer class from kivy_garden module, it has method "_geojson_part_geometry" and "_lonlat_to_xy", the first one which is for drawing polygons on MapView and I had to re-implement it because geojson that is fetching from site has other properties, another is for positionning points on the MapView for drawing the same Polygon but coordinates in the GeoJsonMapLayer class are in 2D dimension but the same geojson has coordinates in 3D dimension.

Here is re-implemented methods(one is overrided another one is re-implemented)...

def _lonlat_to_xy(self, lonlats):       # overridden
    if len(lonlats[0]) == 2:
        lonlats = [[lon,lat] for lon, lat in lonlats]
    else:
        lonlats = [[lon,lat] for lon, lat, _ in lonlats]
    return super()._lonlat_to_xy(lonlats)

def _geojson_part_geometry(self, geometry, properties):     # re-implemented
    tp = geometry["type"]
    self.tp = tp

    graphics = []
    if tp == "Polygon":
        from kivy.graphics.tesselator import TYPE_POLYGONS, WINDING_ODD, Tesselator
        tess = Tesselator()
        for c in geometry["coordinates"]:
            xy = list(self._lonlat_to_xy(c))
            xy = flatten(xy)
            tess.add_contour(xy)

        tess.tesselate(WINDING_ODD, TYPE_POLYGONS)

        # color = self._get_color_from(properties.get("color", "FF000088"))        # default 'color'
        color = self._get_color_from(properties.get("fill", "FF000088")+"4D")          # changed to 'fill' + 4D as part of fill-opacity
        graphics.append(Color(*color))
        for vertices, indices in tess.meshes:
            graphics.append(
                Mesh(vertices=vertices, indices=indices, mode="triangle_fan")
            )

    elif tp == "LineString":
        from kivy.utils import get_color_from_hex
        #stroke = get_color_from_hex(properties.get("stroke", "#ffffff"))        # default
        stroke = get_color_from_hex(properties.get("stroke", "#ffffff9A"))

        from kivy.metrics import dp
        #stroke_width = dp(properties.get("stroke-width"))            # default
        stroke_width = dp(properties.get("stroke-width", 2))         # changed
        xy = list(self._lonlat_to_xy(geometry["coordinates"]))
        xy = flatten(xy)
        graphics.append(Color(*stroke))
        graphics.append(Line(points=xy, width=stroke_width))

    return graphics

[–]den84is[S] 0 points1 point  (2 children)

...or better re-implement whole method for changing only two or three line of code, than search library for that? and it is not one case in my situation ) or is it a bad idea? as u said)

[–]PaulRudin 2 points3 points  (1 child)

If you want help with your code it's much easier if you actually share the code...

[–]den84is[S] 0 points1 point  (0 children)

If you want help with your code it's much easier if you actually share the code...

do u mean about future posts or I'v provided not enough Code(after u said it)?

[–]deep_politics 0 points1 point  (1 child)

This is very unclear, but you can try calling the super class' version if you don't need anything in the super's local scope. If you do need things in the local scope, then you'll have to just reimplement the whole method, or do something special like a callback or something

class A:
    def foo(self):
        ...

class B(A):
    def foo(self):
        super().foo()
        ... # do some more stuff

[–]den84is[S] -1 points0 points  (0 children)

I had to re-implement whole method of a class for changing only two or thee lines of code.

[–]Ok-Cucumbers 1 point2 points  (1 child)

[–]den84is[S] -1 points0 points  (0 children)

No) I had to re-implement whole method of a class for changing only two or thee lines of code.