Пример #1
0
class CamModule:
	def __init__(self):
		self.name = "Kamere"
		#Cam urls
		self.camUrls = {u"Ribčev Laz (v živo)": "http://firma.sportnet.si:8080/dvs2000/r1.jpg",\
						u"Ribčev Laz": "http://www.bohinj.si/cam/slika3.jpg",\
						u"Vogel - 1" : "http://www.snezni-telefon.si/Images/Kamere/6_a.jpg",\
						u"Vogel - 2" : "http://www.snezni-telefon.si/Images/Kamere/6_b.jpg",\
						u"Vogel - 3" : "http://www.snezni-telefon.si/Images/Kamere/6_c.jpg",\
						u"Vogel - 4" : "http://www.snezni-telefon.si/Images/Kamere/6_d.jpg",\
						u"Bohinjska Češnjica" : "http://www2.arnes.si/~smisma1/canon.jpg",\
						u"Bohinjska Bistrica" : "http://www.drsc.si/kamere/kamslike/bohinjska/slike/boh1_0001.jpg",\
						u"Orožnova koča": "http://www.bohinj.si/cam/lisc/slika1.jpg"}

		self.camSizes ={u"Ribčev Laz (v živo)": "352x228", \
						u"Ribčev Laz": "2048x1536",\
						u"Vogel - 1" : "1280x1024",\
						u"Vogel - 2" : "640x480",\
						u"Vogel - 3" : "1280x1024",\
						u"Vogel - 4" : "640x480",\
						u"Bohinjska Češnjica" : "800x600",\
						u"Bohinjska Bistrica" : "352x228",\
						u"Orožnova koča": "1280x1024"}
						
		self.updateTimer = QTimer()
		self.updateTimer.timeout.connect(self.update)
		
	
	def makeLayout(self):
		self.layout = QGraphicsLinearLayout(Qt.Vertical)
		self.topCamLayout = QGraphicsLinearLayout(Qt.Horizontal)
		
		# Cam layout
		self.camRefreshButton = Plasma.IconWidget()
		self.camRefreshButton.setIcon("view-refresh")
		self.camRefreshButton.clicked.connect(self.update)
		
		self.camTimeLabel = Plasma.Label()
		self.camTimeLabel.setText(u"ob")

		self.camEnlargeButton = Plasma.IconWidget()
		self.camEnlargeButton.setIcon("zoom-in")
		self.camEnlargeButton.clicked.connect(self.showFullCamWidget)

		self.camSelectorCombo = Plasma.ComboBox()
		for source in sorted(self.camUrls.keys()):
			self.camSelectorCombo.addItem(source)
		self.camSelectorCombo.setMinimumWidth(125)
		self.camSelectorCombo.textChanged.connect(self.camChanged)

		self.camView = QGraphicsWebView()
		self.camView.setEnabled(False)

		self.camTimeDataLabel = Plasma.Label()

		self.camUpdateTimeSelector = UpdateTimeSelector()
		self.camUpdateTimeSelector.setDefaultTime(30)
		self.camUpdateTimeSelector.setDefaultInterval('min')
		self.camUpdateTimeSelector.updateTimeSpin.valueChanged.connect(self.camTimeChanged)
		self.camUpdateTimeSelector.updateCheckBox.toggled.connect(self.camTimerToggle)

		self.topCamLayout.addItem(self.camSelectorCombo)
		self.topCamLayout.addItem(self.camTimeLabel)
		self.topCamLayout.addItem(self.camTimeDataLabel)
		self.topCamLayout.addStretch()
		self.topCamLayout.addItem(self.camEnlargeButton)
		self.topCamLayout.addItem(self.camRefreshButton)

		self.layout.addItem(self.topCamLayout)
		self.layout.addItem(self.camView)
		self.layout.addItem(self.camUpdateTimeSelector.layout)
		self.layout.itemAt(0).setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed, QSizePolicy.DefaultType)
		self.layout.itemAt(2).setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed, QSizePolicy.DefaultType)
	
	def update(self, text=None):
		try:
			urllib.urlopen('http://www.google.com', timeout=2)
		except:
			self.offlineMode()
			return
		if not self.camUpdateTimeSelector.updateCheckBox.isChecked():
			self.updateTimer.stop()
		self.camChanged(self.camSelectorCombo.text())
		self.setCamTimeLabel()
		
	def offlineMode(self):
		self.camView.setUrl(QUrl("weather-none-available.png"))
		self.camTimeDataLabel.setText(" ni na voljo.")
		
	def setCamTimeLabel(self):
		hour = time.localtime().tm_hour if not time.localtime().tm_hour in range(10) else '0' + str(time.localtime().tm_hour)
		minute = time.localtime().tm_min if not time.localtime().tm_min in range(10) else '0' + str(time.localtime().tm_min)
		second = time.localtime().tm_sec if not time.localtime().tm_sec in range(10) else '0' + str(time.localtime().tm_sec)
		self.camTimeDataLabel.setText(u'<b>%s:%s:%s</b>' % (str(hour), str(minute), str(second)) )
    
	def camTimerToggle(self, toggled):
		if toggled:
			multiplier = 1
			if self.camUpdateTimeSelector.getInterval() == 'min':
				multiplier = 60
			if self.camUpdateTimeSelector.getInterval() == 'h':
				multiplier = 60 * 60
			self.updateTimer.start(self.camUpdateTimeSelector.getTime() * 1000 * multiplier)
			self.update()
		else:
			self.updateTimer.stop()
	
	def camChanged(self, text):
		self.camView.setUrl( QUrl( self.camUrls[unicode(text)] ) )
		self.setCamTimeLabel()
		
	def camTimeChanged(self, value):
		if self.camUpdateTimeSelector.isChecked():
			self.updateTimer.stop()
		self.camTimerToggle(self.camUpdateTimeSelector.isChecked())
	
	def showFullCamWidget(self):
		fullcamwidget = FullCamWidget()
		size = self.camSizes[unicode(self.camSelectorCombo.text())]
		size = [ int(i) for i in size.split('x')]
		if size[0] < 640 and size[1] < 480:
			fullcamwidget.show(self.camView.url(), size[0] + 25, size[1] + 125)
		else:
			fullcamwidget.show(self.camView.url(), 645, 505)
Пример #2
0
class FlowModule:
	def __init__(self):
		self.name = "Pretok"
		self.updateTimer = QTimer()
		self.updateTimer.timeout.connect(self.update)
	
	def makeLayout(self):
		self.layout = QGraphicsLinearLayout(Qt.Vertical)
		self.flowComboLayout = QGraphicsLinearLayout(Qt.Horizontal)
		self.flowLabelLayout = QGraphicsGridLayout()
		
		#Flow Layout
		self.flowData = SvJanez()
		self.flowView = QGraphicsWebView()
		self.flowView.setUrl( QUrl(self.flowData.flowImageUrl) )
		self.flowView.setEnabled(False)

		self.flowSelectorCombo = Plasma.ComboBox()
		self.flowSelectorCombo.addItem(u"Sveti Janez")
		self.flowSelectorCombo.addItem(u"Soteska")
		self.flowSelectorCombo.setMinimumWidth(125)
		self.flowSelectorCombo.textChanged.connect(self.flowSourceChanged)

		self.flowRefresh = Plasma.IconWidget()
		self.flowRefresh.setIcon("view-refresh")
		self.flowRefresh.clicked.connect(self.update)

		self.flowEnlargeButton = Plasma.IconWidget()
		self.flowEnlargeButton.setIcon("zoom-in")
		self.flowEnlargeButton.clicked.connect(self.showFullFlowWidget)

		self.flowLabel = Plasma.Label()
		self.flowLabel.setText(u"<b>Pretok:</b> ")
		self.flowDataLabel = Plasma.Label()
		self.flowLevelLabel = Plasma.Label()
		self.flowLevelLabel.setText(u"<b>Višina:</b> ")
		self.flowLevelDataLabel = Plasma.Label()
		self.flowTempLabel = Plasma.Label()
		self.flowTempLabel.setText(u"<b>Temperatura:</b> ")
		self.flowTempDataLabel = Plasma.Label()

		self.flowLabelLayout.addItem(self.flowLevelLabel,0,0)
		self.flowLabelLayout.addItem(self.flowLevelDataLabel,0,1)
		self.flowLabelLayout.addItem(self.flowLabel,1,0)
		self.flowLabelLayout.addItem(self.flowDataLabel,1,1)
		self.flowLabelLayout.addItem(self.flowTempLabel,2,0)
		self.flowLabelLayout.addItem(self.flowTempDataLabel,2,1)
		
		self.flowUpdateTimeSelector = UpdateTimeSelector()
		self.flowUpdateTimeSelector.setDefaultTime(4)
		self.flowUpdateTimeSelector.setDefaultInterval('h')
		self.flowUpdateTimeSelector.updateTimeSpin.valueChanged.connect(self.flowTimeChanged)
		self.flowUpdateTimeSelector.updateCheckBox.toggled.connect(self.flowTimerToggle)
		
		
		self.flowComboLayout.addItem(self.flowSelectorCombo)
		self.flowComboLayout.addStretch()
		self.flowComboLayout.addItem(self.flowEnlargeButton)
		self.flowComboLayout.addItem(self.flowRefresh)
		self.layout.addItem(self.flowComboLayout)
		self.layout.addItem(self.flowView)
		self.layout.addItem(self.flowLabelLayout)
		self.layout.addStretch()
		self.layout.addItem(self.flowUpdateTimeSelector.layout)
		self.layout.itemAt(0).setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed, QSizePolicy.DefaultType)
		self.layout.itemAt(2).setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed, QSizePolicy.DefaultType)
	
	def flowTimerToggle(self, toggled):
		if toggled:
			multiplier = 1
			if self.flowUpdateTimeSelector.getInterval() == 'min':
				multiplier = 60
			if self.flowUpdateTimeSelector.getInterval() == 'h':
				multiplier = 60 * 60
			self.updateTimer.start(self.flowUpdateTimeSelector.getTime() * 1000 * multiplier)
			self.update()
		else:
			self.updateTimer.stop()
	
	def flowTimeChanged(self, value):
		if self.flowUpdateTimeSelector.isChecked():
			self.updateTimer.stop()
		self.flowTimerToggle(self.flowUpdateTimeSelector.isChecked())
		
	def flowSourceChanged(self, text):
		if text == "Sveti Janez":
			self.flowData = SvJanez()
		else:
			self.flowData = Soteska()
		self.flowView.setUrl(QUrl(self.flowData.flowImageUrl))
		self.updateFlowLabels()
	
	def updateFlowImage(self):
		self.flowSourceChanged(self.flowSelectorCombo.text())
	
	def updateFlowLabels(self):
		self.flowData.fetchData()
		self.flowDataLabel.setText(u"%s %s" % (self.flowData.currentFlow, u' m3/s'))
		self.flowTempDataLabel.setText(u"%s %s" % (self.flowData.temperature , u' °C'))
		self.flowLevelDataLabel.setText(u"%s %s" % (self.flowData.waterLevel , u' cm'))
	
	def update(self):
		try:
			urllib.urlopen('http://www.google.com', timeout=2)
		except:
			self.offlineMode()
			return
		self.updateFlowLabels()
		self.updateFlowImage()
		
	def offlineMode(self):
		self.flowView.setUrl(QUrl("weather-none-available.png"))
		self.flowDataLabel.setText(u"N/A")
		self.flowTempDataLabel.setText(u"N/A")
		self.flowLevelDataLabel.setText(u"N/A")
	
	def showFullFlowWidget(self):
		fullcamwidget = FullCamWidget()
		fullcamwidget.show(self.flowView.url(), 840, 400)