Advertisement
Guest User

stc

a guest
Jan 16th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.08 KB | None | 0 0
  1. #### IMPORT MODULES ####
  2. import wx
  3. import subprocess
  4. import os
  5. import wx.stc as stc
  6. import keyword
  7.  
  8. #### FILE MENU ####
  9. ID_F_NEW = wx.NewId()
  10. ID_F_OPEN = wx.NewId()
  11. ID_F_SAVE = wx.NewId()
  12. ID_F_SAVEAS = wx.NewId()
  13. ID_F_PREFS = wx.NewId()
  14. ID_F_QUIT = wx.NewId()
  15.  
  16. #### EDIT MENU ####
  17. ID_E_UNDO = wx.NewId()
  18. ID_E_REDO = wx.NewId()
  19. ID_E_CUT = wx.NewId()
  20. ID_E_COPY = wx.NewId()
  21. ID_E_PASTE = wx.NewId()
  22. ID_E_SELECT = wx.NewId()
  23. ID_E_FIND = wx.NewId()
  24. ID_E_REPL = wx.NewId()
  25.  
  26. #### WXPYTHON MENU ####
  27. ID_P_DEF = wx.NewId()
  28. ID_P_PANEL = wx.NewId()
  29. ID_P_MENUB = wx.NewId()
  30. ID_P_TOOLB = wx.NewId()
  31. ID_P_SCD = wx.NewId()
  32. ID_P_MD = wx.NewId()
  33. ID_P_TED = wx.NewId()
  34. ID_P_STAT = wx.NewId()
  35. ID_P_TXTBX = wx.NewId()
  36. ID_P_BUTT = wx.NewId()
  37. ID_P_SLID = wx.NewId()
  38. ID_P_SPIN = wx.NewId()
  39. ID_P_LIST = wx.NewId()
  40. ID_P_CHEK = wx.NewId()
  41. ID_P_IMPORT = wx.NewId()
  42. ID_P_NEWID = wx.NewId()
  43. ID_P_CLASS = wx.NewId()
  44. ID_P_FUNC = wx.NewId()
  45. ID_P_SIZR = wx.NewId()
  46. ID_P_CON_S = wx.NewId()
  47. ID_P_EVT = wx.NewId()
  48. ID_P_BOIL = wx.NewId()
  49. ID_P_DICT = wx.NewId()
  50. ID_P_LIST = wx.NewId()
  51. ID_P_TUPL = wx.NewId()
  52. ID_P_DB = wx.NewId()
  53.  
  54. #### BUILD MENU ####
  55. ID_B_RUN = wx.NewId()
  56. ID_B_SAND = wx.NewId()
  57. ID_B_COMP = wx.NewId()
  58.  
  59. #### HELP MENU ####
  60. ID_H_ABOUT = wx.NewId()
  61. ID_H_HELP = wx.NewId()
  62.  
  63. #### IDENTIFIER / VALUES ####
  64. ID_P_DEF_CODE = ("import wx\n\n"
  65.                 "class nTmp(wx.Frame):\n"
  66.                 "   def __init__(self,parent,id):\n"
  67.                 "       wx.Frame.__init__(self,parent,id,'wxTemplate',size=(450,395))\n"
  68.                 "       panel = wx.Panel(self)\n"
  69.                 "       self.Centre()\n\n\n"
  70.  
  71.                 "       #### CODE GOES HERE ####\n\n\n"
  72.  
  73.                 "if __name__=='__main__':\n"
  74.                 "   app = wx.PySimpleApp()\n"
  75.                 "   frame = nTmp(parent=None,id=-1)\n"
  76.                 "   frame.Show()\n"
  77.                 "   app.MainLoop()\n")
  78.  
  79.  
  80. #### CURRENT WXPYTHON FRAME ####
  81. class Vodka(wx.Frame):
  82.   def __init__(self,parent,id):
  83.  
  84.       #### Set window size to current display size, as well as compensating for task bar. ####
  85.       WINDOW_SIZE = (wx.DisplaySize()[0]-20,wx.DisplaySize()[1]-60)
  86.  
  87.       wx.Frame.__init__(self,parent,id,"Vodka",size=(WINDOW_SIZE),pos=(30,100),style=(wx.BORDER_NONE))
  88.       self.panel = wx.Panel(self)
  89.  
  90.       #### Completely centre the window. ####
  91.       self.Centre()
  92.      
  93.       #### Create the Styled Text Control. ####
  94.       self.text = stc.StyledTextCtrl(self.panel)
  95.       self.text.SetCaretForeground("RED")
  96.       self.text.StyleSetSpec(stc.STC_STYLE_LINENUMBER,  "fore:#C0C0C0,back:#000000")
  97.       self.text.StyleSetSpec(stc.STC_STYLE_DEFAULT, "back:#000000,size:10,face:Courier New")
  98.       self.text.SetWindowStyle(self.text.GetWindowStyle() | wx.NO_BORDER)
  99.       self.text.SetWrapMode(stc.STC_WRAP_WORD)
  100.  
  101.       #### Create syntax highlighting for the STC. ####
  102.       self.text.SetLexer(stc.STC_LEX_PYTHON)
  103.       self.text.SetKeyWords(0, " ".join(keyword.kwlist))
  104.       self.text.StyleSetSpec(wx.stc.STC_P_DEFAULT, 'fore:#FFFFFF,back:#000000')
  105.       self.text.StyleSetSpec(wx.stc.STC_P_COMMENTLINE,  'fore:#00bff3,back:#000000')
  106.       self.text.StyleSetSpec(wx.stc.STC_P_COMMENTBLOCK, 'fore:#00bff3,back:#000000')
  107.       self.text.StyleSetSpec(wx.stc.STC_P_NUMBER, 'fore:#ec008c,back:#000000')
  108.       self.text.StyleSetSpec(wx.stc.STC_P_STRING, 'fore:#ec008c,back:#000000')
  109.       self.text.StyleSetSpec(wx.stc.STC_P_CHARACTER, 'fore:#ec008c,back:#000000')
  110.       self.text.StyleSetSpec(wx.stc.STC_P_WORD, 'fore:#ec008c,back:#000000,bold')
  111.       self.text.StyleSetSpec(wx.stc.STC_P_TRIPLE, 'fore:#ec008c,back:#000000')
  112.       self.text.StyleSetSpec(wx.stc.STC_P_TRIPLEDOUBLE, 'fore:#ec008c,back:#000000')
  113.       self.text.StyleSetSpec(wx.stc.STC_P_CLASSNAME, 'fore:#00ff00,back:#000000,bold')
  114.       self.text.StyleSetSpec(wx.stc.STC_P_DEFNAME, 'fore:#00bff3,back:#000000,bold')
  115.       self.text.StyleSetSpec(wx.stc.STC_P_OPERATOR, 'fore:#FFFFFF,back:#000000,bold')
  116.       self.text.StyleSetSpec(wx.stc.STC_P_IDENTIFIER, 'fore:#00ff00,back:#000000')
  117.       self.text.SetSelBackground(1, '#ffffff')
  118.      
  119.       #### Create the Wxpython Menu bar. ####
  120.       m = wx.MenuBar()
  121.       f = wx.Menu()
  122.       f.Append(wx.ID_ANY,'New')
  123.       f.Append(wx.ID_ANY,'Open...')
  124.       f.AppendSeparator()
  125.       f.Append(wx.ID_ANY,'Save')
  126.       f.Append(wx.ID_ANY,'Save As...')
  127.       f.AppendSeparator()
  128.       f.Append(wx.ID_ANY,'Preferences...')
  129.       f.AppendSeparator()
  130.       f.Append(wx.ID_ANY,'Quit')
  131.       ed = wx.Menu()
  132.       ed.Append(wx.ID_ANY,'Undo')
  133.       ed.Append(wx.ID_ANY,'Redo')
  134.       ed.AppendSeparator()
  135.       ed.Append(wx.ID_ANY,'Cut')
  136.       ed.Append(wx.ID_ANY,'Copy')
  137.       ed.Append(wx.ID_ANY,'Paste')
  138.       ed.Append(wx.ID_ANY,'Select All')
  139.       ed.AppendSeparator()
  140.       ed.Append(wx.ID_ANY,'Find...')
  141.       ed.Append(wx.ID_ANY,'Replace...')
  142.       py = wx.Menu()
  143.       g = wx.Menu()
  144.       g.Append(ID_P_DEF,'Default')
  145.       g.AppendSeparator()
  146.       g.Append(wx.ID_ANY,'Panel')
  147.       g.Append(wx.ID_ANY,'Menu Bar')
  148.       g.Append(wx.ID_ANY,'Toolbar')
  149.       d = wx.Menu()
  150.       d.Append(wx.ID_ANY,'Single-Choice Dialog')
  151.       d.Append(wx.ID_ANY,'Message Dialog')
  152.       d.Append(wx.ID_ANY,'Text-Entry Dialog')
  153.       g.AppendSeparator()
  154.       g.AppendMenu(wx.ID_ANY, '&Dialog', d)
  155.       g.AppendSeparator()
  156.       g.Append(wx.ID_ANY,'Static Text')
  157.       g.Append(wx.ID_ANY,'Text Box')
  158.       g.Append(wx.ID_ANY,'Button')
  159.       g.Append(wx.ID_ANY,'Slider')
  160.       g.Append(wx.ID_ANY,'Spin Control')
  161.       g.Append(wx.ID_ANY,'List Box')
  162.       g.Append(wx.ID_ANY,'Check Box')
  163.       py.AppendMenu(wx.ID_ANY, '&GUI', g)
  164.       py.AppendSeparator()
  165.       py.Append(wx.ID_ANY,'Import')
  166.       py.Append(wx.ID_ANY,'ID')
  167.       py.Append(wx.ID_ANY,'Class')
  168.       py.Append(wx.ID_ANY,'Function')
  169.       py.Append(wx.ID_ANY,'Sizer')
  170.       py.Append(wx.ID_ANY,'Conditional Statement')
  171.       py.Append(wx.ID_ANY,'Event')
  172.       py.Append(wx.ID_ANY,'Boilerplate')
  173.       py.AppendSeparator()
  174.       py.Append(wx.ID_ANY,'Dictionary')
  175.       py.Append(wx.ID_ANY,'List')
  176.       py.Append(wx.ID_ANY,'Tuple')
  177.       py.AppendSeparator()
  178.       py.Append(wx.ID_ANY,'Database Connectivity...')
  179.       b = wx.Menu()
  180.       b.Append(ID_B_RUN,'Run')
  181.       b.Append(wx.ID_ANY,'Sandbox')
  182.       b.Append(wx.ID_ANY,'Compile')
  183.       h = wx.Menu()
  184.       h.Append(wx.ID_ANY,'About Vodka')
  185.       h.AppendSeparator()
  186.       h.Append(wx.ID_ANY,'Vodka Help')
  187.       m.Append(f,'&File')
  188.       m.Append(ed,'&Edit')
  189.       m.Append(py,'&Python')
  190.       m.Append(b,'&Build')
  191.       m.Append(h,'&Help')
  192.       #self.SetMenuBar(m)
  193.  
  194.                
  195.       #### Add the STC to a Sizer. ####
  196.       sizer = wx.BoxSizer(wx.VERTICAL)
  197.       sizer.Add(self.text, 1, wx.EXPAND,border=20)
  198.       self.panel.SetSizer(sizer)
  199.  
  200.       sizer = wx.BoxSizer(wx.VERTICAL)
  201.       sizer.Add(self.panel, 1, wx.EXPAND)
  202.       self.SetSizer(sizer)
  203.  
  204.       self.Layout()
  205.  
  206.  
  207.  
  208.  
  209.       #### EVENT BINDINGS ###############################
  210.  
  211.       #### Add line numbers to the STC upon entering. ###
  212.       self.text.Bind(stc.EVT_STC_CHANGE, self.OnChange)
  213.       self.Show()
  214.  
  215.       #### Add Default wxpython GUI code to the STC. ####
  216.       self.Bind(wx.EVT_MENU,self.DEFAULT_GUI,id=ID_P_DEF)
  217.  
  218.       #### Select 'Run' from the Build Menu. ####
  219.       self.Bind(wx.EVT_MENU,self.RUN_CODE,id=ID_B_RUN)
  220.  
  221.  
  222.   #### EVENT FUNCTIONS ####
  223.  
  224.   #### Add line numbers to the STC upon entering. ###    
  225.   def OnChange(self, e):
  226.       lines = self.text.GetLineCount()
  227.       width = self.text.TextWidth(stc.STC_STYLE_LINENUMBER, " "+str(lines)+" ")
  228.       self.text.SetMarginWidth(0, width)
  229.       self.text.SetMarginLeft(10)
  230.       self.text.SetIndent(2)
  231.  
  232.   #### Add Default wxpython GUI code to the STC. ####
  233.   def DEFAULT_GUI(self, e):
  234.       self.text.AddText(ID_P_DEF_CODE)
  235.  
  236.   #### Select 'Run' from the Build Menu. ####
  237.   def RUN_CODE(self, e):
  238.     pass
  239.    
  240.      
  241.  
  242.  
  243.  
  244.        
  245.      
  246.      
  247.      
  248.  
  249. #### BOILERPLATE ####
  250. if __name__=='__main__':
  251.   app = wx.App()
  252.   Vodka_Frame = Vodka(None,-1)
  253.   Vodka_Frame.Show()
  254.   Vodka_Frame.SetTransparent(230)
  255.   app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement