/pyApp/GUI/dustFrameImage.py

https://bitbucket.org/marcmorenob/smartmesharduinocam · Python · 115 lines · 76 code · 27 blank · 12 comment · 4 complexity · d36f6b5199796b5bfd6506fd36234cd3 MD5 · raw file

  1. #!/usr/bin/python
  2. import sys
  3. import os
  4. if __name__ == '__main__':
  5. temp_path = sys.path[0]
  6. sys.path.insert(0, os.path.join(temp_path, '..', 'SmartMeshSDK'))
  7. import Tkinter
  8. import dustGuiLib
  9. import dustFrame
  10. from dustStyle import dustStyle
  11. from ApiDefinition import ApiDefinition
  12. import Image
  13. import ImageTk
  14. from Tkinter import Tk, Canvas, Frame, BOTH,NW
  15. from cStringIO import StringIO
  16. class dustFrameImage(dustFrame.dustFrame):
  17. def __init__(self,parentElem,guiLock,inStartCaptureBPCB,inStartCAutoBPCB,inSaveBPCB,frameName="Image Frame",row=0,column=0):
  18. # record params
  19. self.startCaptureBPCB = inStartCaptureBPCB
  20. self.startCAutoBPCB = inStartCAutoBPCB
  21. self.saveBPCB = inSaveBPCB
  22. # init parent
  23. dustFrame.dustFrame.__init__(self,parentElem,guiLock,frameName,row,column)
  24. self.captureButton = dustGuiLib.Button(self.container,
  25. text='Capture',
  26. command=self.startCaptureBPCB)
  27. self.startStopAutoButton = dustGuiLib.Button(self.container,
  28. text='Start Auto',
  29. command=self.startCAutoBPCB)
  30. self.saveButton = dustGuiLib.Button(self.container,
  31. text='Save image',
  32. command=self.saveBPCB)
  33. self._add(self.saveButton,0,0)
  34. self._add(self.captureButton,1,1)
  35. self._add(self.startStopAutoButton,1,2)
  36. self.isAutomatic = False
  37. # row 1: canvas
  38. self.imgCanvas = Tkinter.Canvas(self.container,
  39. width=320,
  40. height=240)
  41. #Simulate In-memory
  42. f = open("geek_inside.jpg","rb")
  43. jpgdata = f.read()
  44. f.close()
  45. ##Draw from in-memory data
  46. file_jpgdata = StringIO(jpgdata)
  47. self.img = Image.open(file_jpgdata)
  48. self.photo = ImageTk.PhotoImage(self.img)
  49. self.item=self.imgCanvas.create_image(0,0,anchor=NW,image=self.photo)
  50. self._add(self.imgCanvas,0,1,columnspan=2)
  51. #======================== private =========================================
  52. def _startStopButtonPressed(self):
  53. self.guiLock.acquire()
  54. print "Capture img"
  55. self.guiLock.release()
  56. def _startStopAutomaticButtonPressed(self):
  57. if self.isAutomatic:
  58. self.guiLock.acquire()
  59. print "Stop automatic capturing ..."
  60. self.startStopButton.configure(text='Start Auto')
  61. self.guiLock.release()
  62. else:
  63. self.guiLock.acquire()
  64. print "Start automatic capturing ..."
  65. self.isAutomatic = True
  66. self.startStopButton.configure(text='Stop Auto')
  67. self.guiLock.release()
  68. #============================ sample app ======================================
  69. # The following gets called only if you run this module as a standalone app, by
  70. # double-clicking on this source file. This code is NOT executed when importing
  71. # this module is a larger application
  72. #
  73. class exampleApp(object):
  74. def __init__(self):
  75. self.window = dustWindow("dustFrameImagesTest",
  76. self._closeCb)
  77. self.guiLock = threading.Lock()
  78. self.frame = dustFrameImage(self.window,self.guiLock,self._startPressedCb,row=0,column=0)
  79. self.frame.show()
  80. self.window.mainloop()
  81. def _startPressedCb(self):
  82. print " _startPressedCb called"
  83. def _closeCb(self):
  84. print " _closeCb called"
  85. if __name__ == '__main__':
  86. import threading
  87. from dustWindow import dustWindow
  88. exampleApp()