fontdemo.py :  » Windows » pyExcelerator » pywin32-214 » pythonwin » pywin » Demos » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » pythonwin » pywin » Demos » fontdemo.py
# Demo of Generic document windows, DC, and Font usage
# by Dave Brennan (brennan@hal.com)

# usage examples:

# >>> from fontdemo import *
# >>> d = FontDemo('Hello, Python')
# >>> f1 = { 'name':'Arial', 'height':36, 'weight':win32con.FW_BOLD}
# >>> d.SetFont(f1)
# >>> f2 = {'name':'Courier New', 'height':24, 'italic':1}
# >>> d.SetFont (f2)

import win32ui
import win32con
import win32api

from pywin.mfc import docview


# font is a dictionary in which the following elements matter:
# (the best matching font to supplied parameters is returned)
#   name    string name of the font as known by Windows
#   size    point size of font in logical units
#   weight    weight of font (win32con.FW_NORMAL, win32con.FW_BOLD)
#   italic    boolean; true if set to anything but None
#   underline  boolean; true if set to anything but None

class FontView(docview.ScrollView):
  def __init__(self,  doc, text = 'Python Rules!', font_spec = {'name':'Arial', 'height':42}):
    docview.ScrollView.__init__(self, doc)
    self.font = win32ui.CreateFont (font_spec)
    self.text = text
    self.width = self.height = 0
    # set up message handlers
    self.HookMessage (self.OnSize, win32con.WM_SIZE)
  def OnAttachedObjectDeath(self):
    docview.ScrollView.OnAttachedObjectDeath(self)
    del self.font

  def SetFont (self, new_font):
    # Change font on the fly
    self.font = win32ui.CreateFont (new_font)
    # redraw the entire client window
    selfInvalidateRect (None)
  def OnSize (self, params):
    lParam = params[3]
    self.width = win32api.LOWORD(lParam)
    self.height = win32api.HIWORD(lParam)

  def OnPrepareDC (self, dc, printinfo):
    # Set up the DC for forthcoming OnDraw call
    self.SetScrollSizes(win32con.MM_TEXT, (100,100))
    dc.SetTextColor (win32api.RGB(0,0,255))
    dc.SetBkColor (win32api.GetSysColor (win32con.COLOR_WINDOW))
    dc.SelectObject (self.font)
    dc.SetTextAlign (win32con.TA_CENTER | win32con.TA_BASELINE)

  def OnDraw (self, dc):
    if (self.width == 0 and self.height == 0):
      left, top, right, bottom = self.GetClientRect()
      self.width = right - left
      self.height = bottom - top
    x, y = self.width // 2, self.height // 2
    dc.TextOut (x, y, self.text)
  
def FontDemo():
  # create doc/view
  template = docview.DocTemplate(win32ui.IDR_PYTHONTYPE, None, None, FontView)
  doc=template.OpenDocumentFile(None)
  doc.SetTitle ('Font Demo')
#  print "template is ", template, "obj is", template._obj_
  template.close()
#  print "closed"
#  del template

if __name__=='__main__':
  import demoutils
  if demoutils.NeedGoodGUI():
    FontDemo()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.