You can now find version 0.0.2 posted in the Ephemeris Project section. I got the data classes created and the functions all lined up. This project is working so well that I’m actually starting to think that I’m no longer crazy. As promised here are some lessons learned with PyQt.
self.stupid = QWidget()
Although all classes can see all other classes, unless you specify “self” for your QWidget definitions they can’t be seen by any other functions within that class. It took me a while to figure out that “self” is needed. I’m sure there is some Id and Ego joke in there somewhere …
You can’t re-use widgets.
When creating QWidgets inside a loop, be sure to create unique QWidgets each time, even for non-visual artifacts. In this example I needed to create a list of TableWidgetItem() containing strings based on calculated dateTime() objects. I discovered that unique dateTime() items for each calculation had to be created in addition to the TableWidgetItem(). If the same dateTime() was used for the multiple calculations over and over, even when its associated to a unique TableWidgetItem(), Python eventually crashes if the subroutine is rerun. Weird, I know. Took me a while to fix it because the solution is counter-intuitive.
self.myTable = QTableWidget()
interval = 3600 # 1 hour example
neededRows = 744 #1 month example assuming above interval
stamps = 
cells = 
initialDateTime = self.timelineStartStamp.dateTime()
for n in range(0,neededRows):
Signals and Slots.
Setting up signals is pretty easy, especially for QPushButtons and such. But if you’re needing to run a function triggered by a change in a spinbox, make sure you follow the self.connect definition exactly, otherwise it won’t work. In this example, when the spinbox is used an index is generated and passed to the function. The function NEEDS to accept the index, even if you’re not going to use it. Otherwise nothing happens.
self.myBox = QSpinBox()
def myBoxChanged(self, i):
#continue function even if you don’t use i
Now for the cool part where I get to do work out some Astronomy calculations.