PageRenderTime 31ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Tests/03-label.py

https://bitbucket.org/alsh/pygui-mirror
Python | 65 lines | 42 code | 9 blank | 14 comment | 2 complexity | 5b0a5acde1ea61c4f33bfa0dda73e741 MD5 | raw file
  1. from GUI import Window, Label, Font, application
  2. from GUI.StdColors import red
  3. from GUI.StdFonts import system_font
  4. num_rows = 6
  5. italic_font = Font("Times", 2 * system_font.size, ['italic'])
  6. #def dump_font(caption, f):
  7. # print caption, f.info()
  8. #
  9. #dump_font("System font:", system_font)
  10. #dump_font("Italic font:", italic_font)
  11. def make_label(text, **kwds):
  12. #print "Creating label", text
  13. return Label(text = text, **kwds)
  14. #print "Creating labels"
  15. lbls = [
  16. make_label("ParrotState:"),
  17. make_label("Resting"),
  18. make_label("Spam!\nGlorious Spam!"),
  19. make_label("Red", color = red),
  20. make_label("Big Italic", font = italic_font),
  21. make_label("Pig in the\nMiddle", just = 'center', width = 140),
  22. make_label("Right\nJustified", just = 'right', width = 140),
  23. ]
  24. #print "Setting label positions"
  25. #print "Setting lbls[0].position to (20, 20)"
  26. #print "Before: lbls[0].bounds =", lbls[0].bounds
  27. lbls[0].position = (20, 20)
  28. #print "After: lbls[0].bounds =", lbls[0].bounds
  29. lbls[1].position = (lbls[0].right, lbls[0].top)
  30. for i in range(2, len(lbls)):
  31. lbls[i].position = (lbls[0].left, lbls[i-1].bottom + 20)
  32. #for lbl in lbls:
  33. # print lbl.height
  34. #print "Creating window"
  35. win = Window(title = "Labels")
  36. for lbl in lbls:
  37. win.add(lbl)
  38. win.size = (lbls[-1].right + 20, lbls[-1].bottom + 20)
  39. win.show()
  40. instructions = """
  41. There should be six rows of labels:
  42. 1. Two labels "ParrotState:" and "Resting", abutting but not overlapping.
  43. 2. A two-line label "Spam!\\nGlorious Spam!"
  44. 3. A label "Red" in red text.
  45. 4. A label "Big Italic" in a large italic font.
  46. 5. A two-line label "Pig in the\\nMiddle" centred in the window.
  47. 6. A two-line label "Right\\nJustified" right-aligned.
  48. All labels should remain stationary relative to the top left corner
  49. of the window when it is resized.
  50. """
  51. print instructions
  52. #application().menus = []
  53. application().run()