-
Notifications
You must be signed in to change notification settings - Fork 0
Qt Notes and Guidelines
Connor Finley edited this page Sep 8, 2019
·
13 revisions
Basically, widgets hold layouts which hold widgets which hold layouts and so on...
It all starts with QWidget
(seen in ui.py
).
From there we have a layout (QVBoxLayout
in ui.py
) which holds widgets and so on.
Documentation:
Note: may change soon with introduction of .ui files
Each visual component should probably have its own class that implements some widget or layout. Within each of those classes there should be the presentation logic, at least.
- The presentation logic can be handled within
self.render()
(arbitrary name I used) which is called by the__init__()
class constructor.-
self.render()
would create child widgets/layouts which would be added to the class (e.g.self.addLayout(...)
orself.addWidget(...)
)
-
- The business logic can be handled here, but we might want to separate things into another class if things get crowded. This is probably a good idea to do early anyway since we know the add-on will grow.
# views/custom_widget.py
from aqt.qt import *
class CustomWidget(QWidget):
def __init__(self):
super().__init__()
self.render()
def render(self):
self.layout = QVBoxLayout()
self.button = QPushButton()
self.button.clicked.connect(self.doSomething)
self.layout.addWidget(self.button)
self.addLayout(self.layout)
def doSomething(self):
# Biz logic
pass
- PyCharm users: clone anki source somewhere and open it in alongside addon project.
- Go to Settings -> Project: -> Project Dependencies -> Check "anki" for your addon project's dependencies, leave anki dependencies blank.
- The addon reloader allows you to refresh the addon with couple of clicks vs. restarting Anki
- Attach to the Anki process in your IDE/editor to help reduce debugging time significantly
- Tutorials: PyCharm (Linux-only), VS Code
Other links:
- Glutanimate's Anki Add-on Builder: Github, Documentation