def cascading_properties_test(container): t = Text(container) p = Picture(container) container.bg = "red" container.text_color = "purple" container.text_size = 16 container.font = "Times New Roman" container.enabled = False assert t.bg == "red" assert t.text_color == "purple" assert t.text_size == 16 assert t.font == "Times New Roman" assert t.enabled == False assert p.bg == "red" assert p.enabled == False # test that destroying widgets removes them as children p.destroy() container.bg = "green" assert t.bg == "green"
def cascading_properties_test(container): t = Text(container, color=None, size=None, font=None) p = Picture(container) container.bg = "red" container.text_color = "purple" container.text_size = 16 container.font = SET_FONT container.enabled = False assert t.bg == "red" assert t.text_color == "purple" assert t.text_size == 16 assert t.font in TEST_FONTS assert t.enabled == False assert p.bg == "red" assert p.enabled == False # test that destroying widgets removes them as children p.destroy() container.bg = "green" assert t.bg == "green"
def LiveCollection(cycles): printedData = [] liveTime = [] liveTemp = [] liveHumid = [] livePress = [] liveWindow = Window(app, title="Data Collection Window", layout="grid") liveWindow.width = 620 liveWindow.height = 920 try: localCycles = int(cycles) except: print("invalid variable") liveWindow.error("Error", "Invalid Variable") else: x = 0 localCycles = int(cycles) liveDataList = ListBox(liveWindow) imageContainer = Box(liveWindow, layout="grid", grid=[1, 0], align="top", border=True) imageContainer.border = 10 liveTempImage = Picture(imageContainer) liveHumidImage = Picture(imageContainer) livePressImage = Picture(imageContainer) while x < (localCycles): currentTemperature = (round(sense.get_temperature(), 2)) currentHumidity = round(sense.get_humidity(), 2) currentPressure = round(sense.get_pressure(), 2) currentTime = time.strftime("%H%M%S", time.localtime()) currentDate = time.strftime("%Y%m%d", gmtime()) ID = str(currentTime) + str(currentDate) liveTime.append(currentTime) liveTemp.append(currentTemperature) liveHumid.append(currentHumidity) livePress.append(currentPressure) printedData.append(("ID:", ID)) printedData.append(("Temp:", currentTemperature)) printedData.append(("Humidity:", currentHumidity)) printedData.append(("Pressure:", currentPressure)) printedData.append(("Time:", currentTime)) printedData.append(("Date:", currentDate)) printedData.append( ("Entry: {0} Out of: {1}".format(x + 1, localCycles))) printedData.append("") connection.execute( "INSERT INTO WeatherData (ID, Temp, Humid, Press, Time, Date) Values ({0}, {1}, {2}, {3}, {4}, {5});" .format(ID, currentTemperature, currentHumidity, currentPressure, currentTime, currentDate)) connection.commit() plt.clf() plt.plot(liveTime, liveTemp) plt.ylabel("Temperature") plt.xlabel("Time") plt.savefig("liveTemp.png") plt.clf() plt.plot(liveTime, liveHumid) plt.ylabel("Pressure") plt.xlabel("Time") plt.savefig("liveHumid.png") plt.clf() plt.plot(liveTime, livePress) plt.ylabel("Humidity") plt.xlabel("Time") plt.savefig("livePress.png") plt.clf() liveDataList.destroy() liveDataList = ListBox(liveWindow, items=printedData, grid=[0, 0], scrollbar=True) liveDataList.width = 200 liveDataList.height = 920 liveTempImage.destroy() liveTempImage = Picture(imageContainer, image="liveTemp.png", grid=[0, 0]) liveTempImage.width = 400 liveTempImage.height = 300 liveHumidImage.destroy() liveHumidImage = Picture(imageContainer, image="liveHumid.png", grid=[0, 1]) liveHumidImage.width = 400 liveHumidImage.height = 300 livePressImage.destroy() livePressImage = Picture(imageContainer, image="livePress.png", grid=[0, 2]) livePressImage.width = 400 livePressImage.height = 300 liveWindow.update() time.sleep(10) x += 1 liveWindow.focus()