Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dibdemo.py 2.2KB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # A demo which creates a view and a frame which displays a PPM format bitmap
  2. #
  3. # This hasnnt been run in a while, as I dont have many of that format around!
  4. import win32api
  5. import win32con
  6. import win32ui
  7. class DIBView:
  8. def __init__(self, doc, dib):
  9. self.dib = dib
  10. self.view = win32ui.CreateView(doc)
  11. self.width = self.height = 0
  12. # set up message handlers
  13. # self.view.OnPrepareDC = self.OnPrepareDC
  14. self.view.HookMessage(self.OnSize, win32con.WM_SIZE)
  15. def OnSize(self, params):
  16. lParam = params[3]
  17. self.width = win32api.LOWORD(lParam)
  18. self.height = win32api.HIWORD(lParam)
  19. def OnDraw(self, ob, dc):
  20. # set sizes used for "non strecth" mode.
  21. self.view.SetScrollSizes(win32con.MM_TEXT, self.dib.GetSize())
  22. dibSize = self.dib.GetSize()
  23. dibRect = (0, 0, dibSize[0], dibSize[1])
  24. # stretch BMP.
  25. # self.dib.Paint(dc, (0,0,self.width, self.height),dibRect)
  26. # non stretch.
  27. self.dib.Paint(dc)
  28. class DIBDemo:
  29. def __init__(self, filename, *bPBM):
  30. # init data members
  31. f = open(filename, "rb")
  32. dib = win32ui.CreateDIBitmap()
  33. if len(bPBM) > 0:
  34. magic = f.readline()
  35. if magic != "P6\n":
  36. print("The file is not a PBM format file")
  37. raise ValueError("Failed - The file is not a PBM format file")
  38. # check magic?
  39. rowcollist = f.readline().split()
  40. cols = int(rowcollist[0])
  41. rows = int(rowcollist[1])
  42. f.readline() # whats this one?
  43. dib.LoadPBMData(f, (cols, rows))
  44. else:
  45. dib.LoadWindowsFormatFile(f)
  46. f.close()
  47. # create doc/view
  48. self.doc = win32ui.CreateDoc()
  49. self.dibView = DIBView(self.doc, dib)
  50. self.frame = win32ui.CreateMDIFrame()
  51. self.frame.LoadFrame() # this will force OnCreateClient
  52. self.doc.SetTitle("DIB Demo")
  53. self.frame.ShowWindow()
  54. # display the sucka
  55. self.frame.ActivateFrame()
  56. def OnCreateClient(self, createparams, context):
  57. self.dibView.view.CreateWindow(self.frame)
  58. return 1
  59. if __name__ == "__main__":
  60. import demoutils
  61. demoutils.NotAScript()