-
-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preserve manual code during rework #99
Comments
An alternate solution would be adding a tab in the Property pane to edit relevant Python code snippets; it would be handy if the objects in scope were available. Snippets would be inserted in the generated code and be indented appropriately. Both https://anvil.works and http://www.web2py.com take this approach. Rather than make a code editor and debugger from scratch, perhaps parts of another open-source project, such as IDLE could be reused. |
Another alternate would be to transform pygubu into a plugin for Visual Studio, PyCharm, Eclipse, or other IDE with good Python support. |
Hello. These are all good ideas that could be implemented in the future. Another option that can be implemented (and that would take less time) is to use inheritance.
Example of generated files: myappbase.py: #!/usr/bin/python3
import pathlib
import pygubu
PROJECT_PATH = pathlib.Path(__file__).parent
PROJECT_UI = PROJECT_PATH / "myapp.ui"
class MyappBase:
def __init__(self, master=None):
self.builder = builder = pygubu.Builder()
builder.add_resource_path(PROJECT_PATH)
builder.add_from_file(PROJECT_UI)
self.mainwindow = builder.get_object("mainwindow", master)
builder.connect_callbacks(self)
def run(self):
self.mainwindow.mainloop()
def on_action1_clicked(self):
pass
if __name__ == "__main__":
app = MyappBase()
app.run() myapp.py: #!/usr/bin/python3
from myappbase import MyappBase
class Myapp(MyappBase):
def on_action1_clicked(self):
# Write your code here.
print('Button action 1 clicked.')
if __name__ == "__main__":
app = Myapp()
app.run() After that, user can modify the interface and regenerate the base class and update the other file accordingly. I think I saw this approach in another design app, but not remember which one. I'm using this approach for some projects. Regards |
I gave the inheritance approach a go, and it is working well so far; thanks for suggesting. Should the issue be closed after incorporating your advice into this wiki page? |
Yes, please. Regards |
While editing the wiki, I could not get the python code to look right. Would you please try pasting in the sample code that you provided earlier? |
Added code to the wiki page. Regards |
Possibly the base class could be an ABC, and the methods to be overridden are abstractmethods, so the user has to implement them, that helps to avoid bugs and confusion. |
Inheritance approach implemented in v0.39. |
The handwritten code I put in the generated .py file gets overwritten when making subsequent versions of my application. Reapplying my changes consumes labour and, more importantly, is an opportunity for error.
Could the generator insert tagged comments to delineate where manual code can go? Then when the code generator is re-run, could it preserve manually added code? If something is added, deleted or modified in the UI, the code generator will somehow need to cope.
Step 4 on this page is wiki page is relevant
https://github.com/alejandroautalan/pygubu-designer/wiki/Design-Code-Iteration
A UML diagramming tool that I used 25-years ago generated C++ code with stubs where my handwritten code belonged. It has a feature they called round trip engineering.
A competing tool has this already; search for 'rework problem' here http://page.sourceforge.net
The text was updated successfully, but these errors were encountered: