Skip to content
Snippets Groups Projects
Commit 5d951ba2 authored by ptangu01's avatar ptangu01
Browse files

refactoring method name and variabls to fit with changement in xAAL stack for PEP8 support

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@1366 b32b6428-25c9-4566-ad07-03861ab6144f
parent d5e31f56
No related branches found
No related tags found
No related merge requests found
......@@ -3,66 +3,69 @@
#
# Copyright 2014 Jérôme Kerdreux, Telecom Bretagne.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from __future__ import print_function
from gi.repository import Gtk,GObject
# xAAL
import xAAL
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
class DummyLamp(xAAL.devices.Device):
def __init__(self,addr):
xAAL.devices.Device.__init__(self,"lamp.dimmer",addr,None)
self.setVersion(0.2)
self.setProductID('DUMMYGTKLAMP')
self.setURL('http://www.acme.org')
self.__light=xAAL.devices.XAALAttribute('light',self,default="unknow")
self.__dimmer=xAAL.devices.XAALAttribute('dimmer',self,default="unknow")
def __init__(self, addr):
xAAL.devices.Device.__init__(self, "lamp.dimmer", addr, None)
self.set_version(0.2)
self.set_product_id('DUMMYGTKLAMP')
self.set_url('http://www.acme.org')
self.__light = xAAL.devices.XAALAttribute(
'light', self, default="unknow")
self.__dimmer = xAAL.devices.XAALAttribute(
'dimmer', self, default="unknow")
self.__update = False
def get(self):
if self.__update :
if self.__update:
self.__update = False
return (self.__light.getValue(),self.__dimmer.getValue())
return (self.__light.get_value(), self.__dimmer.get_value())
#####################################################
# Actions
# Actions
#####################################################
def on(self):
if self.__light.getValue() in ['unknow',False]:
self.__light.setValue(True)
if self.__light.get_value() in ['unknow', False]:
self.__light.set_value(True)
self.__update = True
on.exposed=True
on.exposed = True
def off(self):
if self.__light.getValue() in ['unknow',True]:
self.__light.setValue(False)
if self.__light.get_value() in ['unknow', True]:
self.__light.set_value(False)
self.__update = True
off.exposed=True
def dim(self,target=50):
if int(target)>100:
raise xAAL.devices.XAALDeviceError(300,"Dimmer target cannot be higher than 100")
else:
self.__dimmer.setValue(target)
off.exposed = True
def dim(self, target=50):
if int(target) > 100:
raise xAAL.devices.XAALDeviceError(
300, "Dimmer target cannot be higher than 100")
else:
self.__dimmer.set_value(target)
self.__update = True
dim.exposed=True
dim.exposed = True
class MyWindow(Gtk.Window):
......@@ -73,7 +76,7 @@ class MyWindow(Gtk.Window):
self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
self.add(self.vbox)
# light
# light
self.light = Gtk.Image()
self.light.set_from_file('./OffLamp.png')
self.vbox.add(self.light)
......@@ -92,26 +95,26 @@ class MyWindow(Gtk.Window):
self.button = Gtk.Button(label="xAAL debug")
self.button.connect("clicked", self.on_button_clicked)
self.vbox.add(self.button)
# xAAL
self.startXAAL()
GObject.timeout_add(100,self.run)
def startXAAL(self):
# xAAL
self.start_xaal()
GObject.timeout_add(100, self.run)
def start_xaal(self):
# load config file
addr = xAAL.tools.getConfigFileAddr('DummyGtkLamp')
addr = xAAL.tools.get_cfg_addr('DummyGtkLamp')
self.engine = xAAL.core.Engine()
self.lamp = DummyLamp(addr)
self.lamp.setAlivePeriod(100)
self.engine.registerDevices([self.lamp,])
self.lamp.set_alive_period(100)
self.engine.register_devices([self.lamp, ])
self.engine.start()
def run(self):
self.engine.loop()
r = self.lamp.get()
if r :
(light,dim) = r
if r:
(light, dim) = r
if light:
self.light.set_from_file('./OnLamp.png')
else:
......@@ -121,8 +124,8 @@ class MyWindow(Gtk.Window):
return True
def on_button_clicked(self, widget):
import pdb;pdb.set_trace()
import pdb
pdb.set_trace()
def run():
......@@ -134,5 +137,3 @@ def run():
if __name__ == '__main__':
run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment