Skip to content

Commit b80b176

Browse files
committed
Put command-line code in main method, so the pymw module can be imported with no side-effects
1 parent 3c280ca commit b80b176

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

pymw.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,32 @@ def hex(str):
237237
toret="%s %02x" % (toret,ord(c));
238238
return toret;
239239

240+
def main():
241+
watchaddr=None;
242+
if len(sys.argv)>1: watchaddr=sys.argv[1];
243+
mw=MetaWatch(watchaddr);
240244

241-
watchaddr=None;
242-
if len(sys.argv)>1: watchaddr=sys.argv[1];
243-
mw=MetaWatch(watchaddr);
245+
mode=0;
246+
# Put an image on the display.
247+
# First, clear the draw buffer to a filled template.
248+
mw.clearbuffer(mode=mode,filled=True);
244249

245-
mode=0;
246-
# Put an image on the display.
247-
# First, clear the draw buffer to a filled template.
248-
mw.clearbuffer(mode=mode,filled=True);
249250

251+
imgfile="template.bmp";
252+
if len(sys.argv)>2:
253+
imgfile=sys.argv[2];
250254

251-
imgfile="template.bmp";
252-
if len(sys.argv)>2:
253-
imgfile=sys.argv[2];
255+
#Push a bird into the buffer.
256+
try:
257+
mw.writeimage(mode=mode,image=imgfile,live=True);
258+
except:
259+
print "Error loading image. Probably not in the working directory.";
254260

255-
#Push a bird into the buffer.
256-
try:
257-
mw.writeimage(mode=mode,image=imgfile,live=True);
258-
except:
259-
print "Error loading image. Probably not in the working directory.";
261+
#Test the writing function by writing a checker pattern.
262+
#mw.testwritebuffer(mode=mode);
260263

261-
#Test the writing function by writing a checker pattern.
262-
#mw.testwritebuffer(mode=mode);
263-
264-
mw.close();
264+
mw.close();
265+
266+
if __name__ == '__main__':
267+
main()
265268

0 commit comments

Comments
 (0)