B4J Question [PyBridge] : RoundedModuleDrawer.initialize() missing 1 required positional argument: 'self'

Erel

B4X founder
Staff member
Licensed User
Longtime User
How did you create the class instance? It sounds like you are holding a class object instead of a class instance.

Example of creating a new Python list, where list is a type in the builtins module:
B4X:
Dim list As PyWrapper = Py.Builtins.GetField("list").Call 'equivalent to: builtins.list()
list.Run("append").Arg(10)
list.Print
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
I am trying to implement the rounded corner effect of QR codes:


B4X:
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer
from qrcode.image.styles.colormasks import RadialGradiantColorMask

qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
qr.add_data('Some data')

img_1 = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer())
img_2 = qr.make_image(image_factory=StyledPilImage, color_mask=RadialGradiantColorMask())

It comes from here:

.....but me still a dummy with classes and instances of classes.

My basic code that I am starting with is:

B4X:
Private Sub CreateQRCode(Code As String) As ResumableSub
    Dim BytesIO As PyWrapper = Py.ImportModuleFrom("io", "BytesIO")
    Dim qrcode As PyWrapper = Py.ImportModule("qrcode")

    
    Dim qr As PyWrapper = qrcode.Run("QRCode").ArgNamed("box_size", 10).ArgNamed("border", 4).ArgNamed("error_correction", qrcode.GetField("ERROR_CORRECT_L"))
    qr.Run("add_data").Arg(Code)
    qr.Run("make").ArgNamed("fit", True)
    Dim Img As PyWrapper = qr.Run("make_image").ArgNamed("fill_color", "white").ArgNamed("back_color" , "black")
    Dim rv As PyWrapper = BytesIO.Call
    Img.Run("save").Arg(rv)
    Wait For (rv.Fetch) Complete (rv As PyWrapper)
    Return Py.ImageFromBytes(rv.Value)
End Sub

Have removed my attempt from the code....
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Dim RoundedModuleDrawerType As PyWrapper = py.ImportModuleFrom("qrcode.image.styles.moduledrawers.pil", "RoundedModuleDrawer")
Dim Img As PyWrapper = qr.Run("make_image").ArgNamed("fill_color", "white").ArgNamed("back_color" , "black") _
  .ArgNamed("module_drawer", RoundedModuleDrawerType.Call) 'Call = ()
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
Try this:
B4X:
Dim RoundedModuleDrawerType As PyWrapper = py.ImportModuleFrom("qrcode.image.styles.moduledrawers.pil", "RoundedModuleDrawer")
Dim Img As PyWrapper = qr.Run("make_image").ArgNamed("fill_color", "white").ArgNamed("back_color" , "black") _
  .ArgNamed("module_drawer", RoundedModuleDrawerType.Call) 'Call = ()
This does compile but I must be missing something else as module corners are not rounded.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
What about the StyledPilImage ? Might be important.
Yes, that solved the problem

 
Upvote 0
Top