Nisha Bhardwaj
2014-04-22 09:44:57 UTC
I am trying to develop application displaying a FlatMenu,toolbar and the
following panel.In toolbar i have put a textctrl. When i am trying to enter
key '2' its not getting typed.I tried to debug code its printing keycode in
log but in textctrl its not getting typed.Apart from '2' all other key i am
able to enter.I am pasting my code here.
I have upgraded my wxPython to WxPython 3.0.0
why i am coming up with this error?
import wx
import os
import sys
import webbrowser
import wx.lib.scrolledpanel as scrolled
import wx.lib.agw.flatmenu as FM
wx.Log.SetLogLevel(0)
class MainPanel(wx.Panel):
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent,style=wx.TAB_TRAVERSAL)
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "FlatMenu Demo")
self.toolbar = self.CreateToolBar()
self.textctrl = wx.TextCtrl( self.toolbar, wx.ID_ANY,
value='',size=(100, -1))
self.textctrl.Bind(wx.EVT_KEY_UP, self.HandleKeyPress)
self.createToolbarItem(0,1,"connect", "new_icons/connect.png",
self.stopLiveUpdate)
self.toolbar.DoInsertTool(1,2, '',
wx.Bitmap('new_icons/install_app.png'))
self.toolbar.DoInsertTool(2,3, '',
wx.Bitmap('new_icons/uninstall.png'))
self.toolbar.InsertControl(3,self.textctrl)
self.toolbar.Realize()
self.CreateMenu()
self.panel = MainPanel(self)
self.PanelSizer = wx.BoxSizer(wx.VERTICAL)
self.PanelSizer.Add( self.menubar, 0,wx.ALL | wx.ALIGN_LEFT |
wx.EXPAND )
self.PanelSizer.Add( self.toolbar, 0, wx.ALL | wx.ALIGN_LEFT |
wx.EXPAND )
self.PanelSizer.Add( self.panel, 1, wx.ALL | wx.ALIGN_LEFT |
wx.EXPAND)
self.SetSizer(self.PanelSizer)
self.Layout()
def HandleKeyPress(self,e):
keycode = e.GetKeyCode()
print keycode
if keycode==50:
print 'entered'
e.Skip()
else:
print 'not entered'
return
e.Skip()
def CreateMenu(self):
self.menubar = FM.FlatMenuBar(self,-1)
file = FM.FlatMenu()
conn = FM.FlatMenu()
help = FM.FlatMenu()
app = FM.FlatMenu()
log = FM.FlatMenu()
file.Append(1,"&Start Stream")
file.Append(2,"&Stop stream")
type = FM.FlatMenu()
self.type1 = FM.FlatMenuItem(type, 3, "Type1", wx.ITEM_CHECK)
type.AppendItem(self.type1)
self.type2 = FM.FlatMenuItem(type, 4, "Type2", wx.ITEM_CHECK)
type.AppendItem(self.type2)
file.AppendMenu(5, "Emulator &Tuner-Type",type)
self.quit = file.Append(6, "&Exit \tAlt+F4", "Quit the Application")
conn.Append(7,"&Connect")
conn.Append(8,"&Disconnect")
conn.Append(9,"&Power Off")
conn.Append(10,"&Shut Down")
app.Append(11,"&Install App")
app.Append(12,"&Transfer Files")
app.Append(13,"&Run App")
app.Append(14,"&Kill App")
app.Append(15,"&Update App")
app.Append(16,"&Uninstall App")
log.Append(17,"&Save Log")
log.Append(18,"&Clear Log")
log.Append(19,"&Refresh Log")
help.Append(20,"&Home")
help.Append(21,"&Google")
help.Append(22,"&User Manual \tF1")
help.Append( 23, "&About")
self.menubar.Append(file, "&Start")
self.menubar.Append(conn, "&Connection")
self.menubar.Append(app, "&App")
self.menubar.Append(log, "&Log")
self.menubar.Append(help, "&Help")
self.Bind(FM.EVT_FLAT_MENU_SELECTED, self.OnQuit, id=5)
self.Bind(FM.EVT_FLAT_MENU_SELECTED,self.launchGoogle,id=21)
def OnQuit(self,e=None):
self.Destroy()
def launchGoogle(self,event=None):
webbrowser.open('http://google.com')
def startLiveUpdate(self, event):
self.createToolbarItem(0,1,"connect", "new_icons/connect.png",
self.stopLiveUpdate)
def stopLiveUpdate(self, event):
self.createToolbarItem(0,1,"disconnect",
"new_icons/disconnected.png", self.startLiveUpdate)
def createToolbarItem(self,pos,id,label,imageName,method=None):
self.toolbar.RemoveTool(id)
self.pos = self.toolbar.GetToolsCount()
self.toolbar.DoInsertTool(pos,id, label, wx.Bitmap(imageName))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, method, id=id)
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
following panel.In toolbar i have put a textctrl. When i am trying to enter
key '2' its not getting typed.I tried to debug code its printing keycode in
log but in textctrl its not getting typed.Apart from '2' all other key i am
able to enter.I am pasting my code here.
I have upgraded my wxPython to WxPython 3.0.0
why i am coming up with this error?
import wx
import os
import sys
import webbrowser
import wx.lib.scrolledpanel as scrolled
import wx.lib.agw.flatmenu as FM
wx.Log.SetLogLevel(0)
class MainPanel(wx.Panel):
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent,style=wx.TAB_TRAVERSAL)
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "FlatMenu Demo")
self.toolbar = self.CreateToolBar()
self.textctrl = wx.TextCtrl( self.toolbar, wx.ID_ANY,
value='',size=(100, -1))
self.textctrl.Bind(wx.EVT_KEY_UP, self.HandleKeyPress)
self.createToolbarItem(0,1,"connect", "new_icons/connect.png",
self.stopLiveUpdate)
self.toolbar.DoInsertTool(1,2, '',
wx.Bitmap('new_icons/install_app.png'))
self.toolbar.DoInsertTool(2,3, '',
wx.Bitmap('new_icons/uninstall.png'))
self.toolbar.InsertControl(3,self.textctrl)
self.toolbar.Realize()
self.CreateMenu()
self.panel = MainPanel(self)
self.PanelSizer = wx.BoxSizer(wx.VERTICAL)
self.PanelSizer.Add( self.menubar, 0,wx.ALL | wx.ALIGN_LEFT |
wx.EXPAND )
self.PanelSizer.Add( self.toolbar, 0, wx.ALL | wx.ALIGN_LEFT |
wx.EXPAND )
self.PanelSizer.Add( self.panel, 1, wx.ALL | wx.ALIGN_LEFT |
wx.EXPAND)
self.SetSizer(self.PanelSizer)
self.Layout()
def HandleKeyPress(self,e):
keycode = e.GetKeyCode()
print keycode
if keycode==50:
print 'entered'
e.Skip()
else:
print 'not entered'
return
e.Skip()
def CreateMenu(self):
self.menubar = FM.FlatMenuBar(self,-1)
file = FM.FlatMenu()
conn = FM.FlatMenu()
help = FM.FlatMenu()
app = FM.FlatMenu()
log = FM.FlatMenu()
file.Append(1,"&Start Stream")
file.Append(2,"&Stop stream")
type = FM.FlatMenu()
self.type1 = FM.FlatMenuItem(type, 3, "Type1", wx.ITEM_CHECK)
type.AppendItem(self.type1)
self.type2 = FM.FlatMenuItem(type, 4, "Type2", wx.ITEM_CHECK)
type.AppendItem(self.type2)
file.AppendMenu(5, "Emulator &Tuner-Type",type)
self.quit = file.Append(6, "&Exit \tAlt+F4", "Quit the Application")
conn.Append(7,"&Connect")
conn.Append(8,"&Disconnect")
conn.Append(9,"&Power Off")
conn.Append(10,"&Shut Down")
app.Append(11,"&Install App")
app.Append(12,"&Transfer Files")
app.Append(13,"&Run App")
app.Append(14,"&Kill App")
app.Append(15,"&Update App")
app.Append(16,"&Uninstall App")
log.Append(17,"&Save Log")
log.Append(18,"&Clear Log")
log.Append(19,"&Refresh Log")
help.Append(20,"&Home")
help.Append(21,"&Google")
help.Append(22,"&User Manual \tF1")
help.Append( 23, "&About")
self.menubar.Append(file, "&Start")
self.menubar.Append(conn, "&Connection")
self.menubar.Append(app, "&App")
self.menubar.Append(log, "&Log")
self.menubar.Append(help, "&Help")
self.Bind(FM.EVT_FLAT_MENU_SELECTED, self.OnQuit, id=5)
self.Bind(FM.EVT_FLAT_MENU_SELECTED,self.launchGoogle,id=21)
def OnQuit(self,e=None):
self.Destroy()
def launchGoogle(self,event=None):
webbrowser.open('http://google.com')
def startLiveUpdate(self, event):
self.createToolbarItem(0,1,"connect", "new_icons/connect.png",
self.stopLiveUpdate)
def stopLiveUpdate(self, event):
self.createToolbarItem(0,1,"disconnect",
"new_icons/disconnected.png", self.startLiveUpdate)
def createToolbarItem(self,pos,id,label,imageName,method=None):
self.toolbar.RemoveTool(id)
self.pos = self.toolbar.GetToolsCount()
self.toolbar.DoInsertTool(pos,id, label, wx.Bitmap(imageName))
self.toolbar.Realize()
self.Bind(wx.EVT_TOOL, method, id=id)
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users