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.

fontdemo.py 2.7KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Demo of Generic document windows, DC, and Font usage
  2. # by Dave Brennan (brennan@hal.com)
  3. # usage examples:
  4. # >>> from fontdemo import *
  5. # >>> d = FontDemo('Hello, Python')
  6. # >>> f1 = { 'name':'Arial', 'height':36, 'weight':win32con.FW_BOLD}
  7. # >>> d.SetFont(f1)
  8. # >>> f2 = {'name':'Courier New', 'height':24, 'italic':1}
  9. # >>> d.SetFont (f2)
  10. import win32api
  11. import win32con
  12. import win32ui
  13. from pywin.mfc import docview
  14. # font is a dictionary in which the following elements matter:
  15. # (the best matching font to supplied parameters is returned)
  16. # name string name of the font as known by Windows
  17. # size point size of font in logical units
  18. # weight weight of font (win32con.FW_NORMAL, win32con.FW_BOLD)
  19. # italic boolean; true if set to anything but None
  20. # underline boolean; true if set to anything but None
  21. class FontView(docview.ScrollView):
  22. def __init__(
  23. self, doc, text="Python Rules!", font_spec={"name": "Arial", "height": 42}
  24. ):
  25. docview.ScrollView.__init__(self, doc)
  26. self.font = win32ui.CreateFont(font_spec)
  27. self.text = text
  28. self.width = self.height = 0
  29. # set up message handlers
  30. self.HookMessage(self.OnSize, win32con.WM_SIZE)
  31. def OnAttachedObjectDeath(self):
  32. docview.ScrollView.OnAttachedObjectDeath(self)
  33. del self.font
  34. def SetFont(self, new_font):
  35. # Change font on the fly
  36. self.font = win32ui.CreateFont(new_font)
  37. # redraw the entire client window
  38. selfInvalidateRect(None)
  39. def OnSize(self, params):
  40. lParam = params[3]
  41. self.width = win32api.LOWORD(lParam)
  42. self.height = win32api.HIWORD(lParam)
  43. def OnPrepareDC(self, dc, printinfo):
  44. # Set up the DC for forthcoming OnDraw call
  45. self.SetScrollSizes(win32con.MM_TEXT, (100, 100))
  46. dc.SetTextColor(win32api.RGB(0, 0, 255))
  47. dc.SetBkColor(win32api.GetSysColor(win32con.COLOR_WINDOW))
  48. dc.SelectObject(self.font)
  49. dc.SetTextAlign(win32con.TA_CENTER | win32con.TA_BASELINE)
  50. def OnDraw(self, dc):
  51. if self.width == 0 and self.height == 0:
  52. left, top, right, bottom = self.GetClientRect()
  53. self.width = right - left
  54. self.height = bottom - top
  55. x, y = self.width // 2, self.height // 2
  56. dc.TextOut(x, y, self.text)
  57. def FontDemo():
  58. # create doc/view
  59. template = docview.DocTemplate(win32ui.IDR_PYTHONTYPE, None, None, FontView)
  60. doc = template.OpenDocumentFile(None)
  61. doc.SetTitle("Font Demo")
  62. # print "template is ", template, "obj is", template._obj_
  63. template.close()
  64. # print "closed"
  65. # del template
  66. if __name__ == "__main__":
  67. import demoutils
  68. if demoutils.NeedGoodGUI():
  69. FontDemo()