I am working in an extension of the library PySimpleGUI. Basically I would extend(subclass) some classes and inject them in the PySimpleGUI module.
Is that pythonic or should I leave alone the original module and access the derived classes through my own extending module?
This is the code I wrote:
PySimpleGUIExt.py
import PySimpleGUI as sg
class TreeExt(sg.Tree):
def insert_item(self, parent, key, text, values, icon=None):
#...
pass
sg.TreeExt = TreeExt
example.py
from PySimpleGUIExt import sg
data = sg.TreeData() # using base class
tree = sg.TreeExt(data, headings=['Column1']) # using extended class!
win = sg.Window('title', [[tree]])
win.finalize()
tree.insert_item('', 'key', 'text', ['value1']) # using new method!
win.read()
I think that putting the derived class in the PySimpleGUI module makes things simpler because I just use the same module for all classes.
The normal approach would be maybe not to inject the classes and use them like this:
example2.py
import extendPySimpleGUI as esg
import PySimpleGUI as sg
data = sg.TreeData() # using base class
tree = sge.TreeExt(data, headings=['Column1]) # using extended class!
win = sg.Window('title', [[tree]]) # using base class
win.finalize()
tree.insert_item('', 'key', 'text', ['value1']) # using new method!
win.read()