def On_Eqn_Tex_Button(self, evt): text = self._get_clean_text() pngpath = latex_dvi_png.eq_to_dvi_png(text) if not headless: self.load_png(pngpath)
def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, pos=(150, 500), size=frame_size) # Create the menubar menuBar = wx.MenuBar() # and a menu menu = wx.Menu() # add an item to the menu, using \tKeyName automatically # creates an accelerator, the third param is some help text # that will show up in the statusbar menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit the application") # bind the menu event to an event handler self.Bind(wx.EVT_MENU, self.OnTimeToClose, id=wx.ID_EXIT) # and put the menu on the menubar menuBar.Append(menu, "&File") self.SetMenuBar(menuBar) self.p_re = re.compile('\$\$(.*?)\$\$') #create top level controls (i.e. those not on a notebook page) #create the main directory chooser imageFile = os.path.join(cache_dir, 'temp_out1.png') if not os.path.exists(imageFile): pngpath = latex_dvi_png.eq_to_dvi_png('\v{x} = \\twobyone{1/3}{1}') mysize = self.GetSize() w, h = mysize #w = 500 #h = 100 #pil = Load_PIL_and_Resize(imageFile, [int(0.95*w), int(0.7*h)]) #wxbmp = PIL_to_wx(pil) png1 = wx.Image(imageFile, wx.BITMAP_TYPE_ANY) pw, ph = png1.GetSize() aspect_ratio = float(pw)/float(ph) new_w = 400 new_h = 100 png1.Rescale(int(new_w), int(new_h)) wxbmp = png1.ConvertToBitmap() self.bmp = wx.StaticBitmap(self, -1, wxbmp, \ (10 + wxbmp.GetWidth(), 5), \ (wxbmp.GetWidth(), \ wxbmp.GetHeight())) if not headless: png1 = wx.Image(imageFile, wx.BITMAP_TYPE_ANY) pw, ph = png1.GetSize() aspect_ratio = float(pw)/float(ph) new_w = 400 new_h = 100 png1.Rescale(int(new_w), int(new_h)) wxbmp = png1.ConvertToBitmap() self.bmp = wx.StaticBitmap(self, -1, wxbmp, \ (10 + wxbmp.GetWidth(), 5), \ (wxbmp.GetWidth(), \ wxbmp.GetHeight())) #change the size if headless self.text = wx.TextCtrl(self, -1, "", size=text_ctrl_size, style = wx.TE_MULTILINE |wx.WANTS_CHARS #|wx.TE_CHARWRAP |wx.TE_WORDWRAP #| wx.TE_RICH #| wx.TE_RICH2 ) myfont = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL, \ False, u'Nimbus Roman No 9') #self.bmp.SetSize([300, 100]) self.text.SetFont(myfont) self.exitbutton = wx.Button(self, -1, "Exit") self.refresh_button = wx.Button(self, -1, "Refresh") self.eqn_button = wx.Button(self, -1, "Eqn. LaTeX") self.tex_button = wx.Button(self, -1, "LaTeX") buttonsizer = wx.FlexGridSizer(1, 4, 0, 0) buttonsizer.Add(self.tex_button, 1, wx.ALL, 5) buttonsizer.Add(self.eqn_button, 1, wx.ALL, 5) buttonsizer.Add(self.refresh_button, 1, wx.ALL, 5) buttonsizer.Add(self.exitbutton, 1, wx.ALL, 5) mainsizer = wx.FlexGridSizer(sizer_rows, 1, 0, 0) mainsizer.AddGrowableCol(0) mainsizer.AddGrowableRow(0) #add the controls to the main sizer if not headless: mainsizer.AddGrowableRow(1) mainsizer.Add(self.bmp, 1, wx.EXPAND|wx.ALL|wx.ALIGN_RIGHT, 5) mainsizer.Add(self.text, 1, wx.EXPAND|wx.ALL|wx.ALIGN_RIGHT, 5) mainsizer.Add(buttonsizer, 1, wx.ALL|wx.ALIGN_RIGHT, 5) self.Bind(wx.EVT_BUTTON, self.On_Tex_Button, self.tex_button) self.Bind(wx.EVT_BUTTON, self.On_Eqn_Tex_Button, \ self.eqn_button) self.Bind(wx.EVT_BUTTON, self.On_Refresh_Button,\ self.refresh_button) self.Bind(wx.EVT_BUTTON, self.OnTimeToClose, self.exitbutton) self.text.Bind(wx.EVT_KEY_DOWN, self.KeyPressed, self.text) ## self.startdir = os.getcwd() ## self.settingspath = os.path.join(self.startdir, settingsname) ## if self.startdir not in sys.path: ## sys.path.insert(0, self.startdir) self.SetSizer(mainsizer) ## self.savepanellist = [self.texpypane, self.purelatexpane, self.pyppane, self.fancyhdrpane, self.wltpane] #mainsizer.Fit(self) self.Layout() if not headless: self.load_png(imageFile) self.text.SetFocus() self.my_id = None