patternpythonMinor
Pillow-based basic GUI library for an LCD
Viewed 0 times
lcdpillowforlibrarybasedguibasic
Problem
I am working with an LCD screen and an RPi. The library I use sends 1-bit images to the screen, so I wrote this library based on Pillow to help developing the on-screen GUI. I am playing with the thought to release this on the appropriate forums.
I would really appreciate some feedback, and this is one of the only places where I can get any. Apart from that, I am also curious if the approach I took is good, and what should I do before actually releasing the code.
About the code:
I made it running without the two device-specific modules. Normally it would work as in the
```
#!/usr/bin/env python
# -- coding: utf-8 --
#
# untitled.py
#
# Copyright 2016 Gergely Nagy
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
__author__ = "Gergely Nagy"
__license__ = "GPL"
__version__ = "0.1b"
__status__ = "development"
import time
from PIL import Image, ImageDraw, ImageFont, ImageChops
debugging = True
if not debugging or __name__!='__main__':
# These device-specific modules are only neccessary if using a real Nokia 5110
# LCD screen, for debug usage (LcdCanvas.target is None) they can be left out
import PCD8544 as LCD
import Adafruit_GPIO.SPI as SPI
# Nokia LCD s
I would really appreciate some feedback, and this is one of the only places where I can get any. Apart from that, I am also curious if the approach I took is good, and what should I do before actually releasing the code.
About the code:
I made it running without the two device-specific modules. Normally it would work as in the
main() function. I tried to be as documented and readable as I could, and I also included some error handling.```
#!/usr/bin/env python
# -- coding: utf-8 --
#
# untitled.py
#
# Copyright 2016 Gergely Nagy
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
__author__ = "Gergely Nagy"
__license__ = "GPL"
__version__ = "0.1b"
__status__ = "development"
import time
from PIL import Image, ImageDraw, ImageFont, ImageChops
debugging = True
if not debugging or __name__!='__main__':
# These device-specific modules are only neccessary if using a real Nokia 5110
# LCD screen, for debug usage (LcdCanvas.target is None) they can be left out
import PCD8544 as LCD
import Adafruit_GPIO.SPI as SPI
# Nokia LCD s
Solution
Test code shouldn't be part of production code. It should be straightforward to convert
The only tests are in
Running
Your shebang line will not be Python 3 on many common platforms. Personally I'd recommend using a service like Travis CI to run your tests with all versions of Python you intend to support, and to support at least the latest 2.x and 3.x versions. I've created an example Python skeleton project just for this use case.
main and debug_main to something compatible with nosetests. This has several advantages:- Integration with xUnit frameworks
- Integration with code coverage tools
- One-word test script:
nosetests
The only tests are in
main and debug_main, which are acceptance or journey tests. This means your test pyramid completely missing several levels.Running
pep8 on the code would reveal some stylistic issues. Whether you agree to them is one thing, but Python users in general will for example expect local variable and parameter names to be all lower case, even if they contain abbreviations.Your shebang line will not be Python 3 on many common platforms. Personally I'd recommend using a service like Travis CI to run your tests with all versions of Python you intend to support, and to support at least the latest 2.x and 3.x versions. I've created an example Python skeleton project just for this use case.
Context
StackExchange Code Review Q#132682, answer score: 3
Revisions (0)
No revisions yet.