PythonCE Wiki : VensterCE

HomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
VensterCE is a thin layer on Win32 Api using ctypes. It allows you to develop python apps with responsive and native ui rendering for PythonCE. Knowing basic Win32 programming is advised for undestanding and extending venster, but you can do a lot of things without.

You can get the latest release on sourceforge.
This release contains a quick-start tutorial to help you develop VensterCE apps.

Here are some examples :

Basic window


from venster.ce import *
class MyWindow(CeMainWindow):
   _window_title_ = u"Tutorial Window"

   @msg_handler(WM_PAINT)
   def OnPaint(self, event):
	   ps = PAINTSTRUCT()
	   hdc = self.BeginPaint(ps)
	   rc = self.clientRect
	   msg = u"Hello VensterCE"
	   DrawText(hdc, msg, len(msg), byref(rc), 1|4)
	   self.EndPaint(ps)

def main() :
   w = MyWindow()
   app = Application()
   app.Run()

if __name__ == '__main__' : main()


Common controls and the layout system


from venster.ce import *
from venster.layout import *
class MyWindow(CeMainWindow):
  _window_title_ = u"Tutorial Window"
  BUT1ID = 1001
  BUT2ID = 1002

  @msg_handler(WM_CREATE)
  def OnCreate(self, event):
	# Create the controls
	self.titre = StaticCenter(u"VensterCE\nCommon controls", parent=self)
	label1 = Static(u"Temp Celsius :", parent=self)
	self.edit1 = EditLine(u"", parent=self)
	self.edit2 = EditLine(u"", parent=self)
	self.but1 = Button(u"To Kelvin", parent = self, menu=self.BUT1ID)
	self.but2 = Button(u"To Celsius", parent = self, menu=self.BUT2ID)
	label2 = Static(u"Temp Kelvin :", parent=self)
	# Do the layout (negative numbers are to fix the size)
	LABELH = -20
	EDITH = -22
	# Set the sizer attribute to a BoxSizer instance
	# CeMainWindow.OnSize will automatically use it
	# for the layout
	self.sizer = BoxSizer(VERTICAL, border=(2,2,2,2))
	sizer1 = BoxSizer(VERTICAL)
	sizer1.append(self.titre, 2*LABELH)
	sizer1.append(label1, LABELH)
	sizer1.append(self.edit1, EDITH)
	sizer2 = BoxSizer(HORIZONTAL, border=(0,2,0,2))
	sizer2.append(self.but1)
	sizer2.appendspace(-2)
	sizer2.append(self.but2)
	sizer1.append(sizer2, 1)
	sizer1.append(label2, LABELH)
	sizer1.append(self.edit2, EDITH)
	self.sizer.append(sizer1)
	CeMainWindow.OnCreate(self, event)

  @cmd_handler(BUT1ID, BN_CLICKED)
  def ToKelvin(self, event):
	cel = self.edit1.GetText()
	try :
	  cel = float(cel)
	except :
	  self.edit2.SetText(u"ERR")
	  return
	kel = cel + 273.5
	self.edit2.SetText(unicode(kel))

  @cmd_handler(BUT2ID, BN_CLICKED)
  def ToCelsius(self, event):
	kel = self.edit2.GetText()
	try :
	  kel = float(kel)
	except :
	  self.edit1.SetText(u"ERR")
	  return
	cel = kel - 273.5
	self.edit1.SetText(unicode(cel))

def main() :
  w = MyWindow()
  app = Application()
  app.Run()
if __name__ == '__main__' : main() 


Modal Dialogs


from venster.ce import *
from venster.layout import *
from venster.newdialog import ModalDialog

IDBUTT = 0x8000
ES_PASSWORD = 0x20

class MainWindow(CeMainWindow):
	_window_title_ = u"Modal dialogs"

	def OnCreate(self, event):
	    self.but = Button(u"Identification", parent=self, menu=IDBUTT)
	    self.label = Static(u"", parent=self)
	    self.sizer = BoxSizer(VERTICAL, (2,2,2,2))
	    self.sizer.append(self.but, -20)
	    self.sizer.appendspace(-2)
	    self.sizer.append(self.label)
	    CeMainWindow.OnCreate(self, event)

	@cmd_handler(IDBUTT, BN_CLICKED)
	def OnClick(self, event):
	    dlg = IdentificationDialog()
	    if dlg.Popup(self) == IDOK :
	        text = u"You are logged as : %s, password : %s" %dlg.GetInfos()
	    else :
	        text = u"You have cancelled"
	    self.label.SetText(text)

class IdentificationDialog(ModalDialog):
	_window_title_ = u"Identification"
	def OnCreate(self, event):
	    self.label1 = Static(u"Login :", parent=self)
	    self.label2 = Static(u"Password :", parent=self)
	    self.edit1 = EditLine(parent=self)
	    self.edit2 = EditLine(parent=self, orStyle=ES_PASSWORD)
	    self.cancel = Button(u"Cancel", parent=self, menu=IDCANCEL)
	    self.sizer = BoxSizer(VERTICAL, (2,2,2,2))

	    sizer2 = BoxSizer(HORIZONTAL)
	    sizer2.appendspace()
	    sizer2.append(self.cancel, -60)
	    for ctl in [self.label1,self.edit1, self.label2,self.edit2]:
	        self.sizer.append(ctl, -20)
	    self.sizer.appendspace(-2)
	    self.sizer.append(sizer2, -20)

	    ModalDialog.OnCreate(self, event)


	def GetInfos(self):
	    return self.edit1.GetText(), self.edit2.GetText()

def main():
	w = MainWindow()
	app = Application()
	app.Run()

if __name__ == '__main__' : main() 


Coming soon : embedding ActiveX controls in VensterCE (Flash Player, Pocket IE, Windows Media Player and more ...)

There are 2798 comments on this page. [Display comments]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.3
Page was generated in 0.1821 seconds