def OnOpen(self, event): open_ = wx.FileDialog(self, localize("Open new document"), wildcard = "SEAL {} MansOS {} (*.sl, *.c, *.h)|*.sl;*.c;*.h;config|{} (.*)|*".format( *localize(["or", "files", "All files"])), style = wx.FD_OPEN | wx.FD_MULTIPLE) if open_.ShowModal() == wx.ID_OK: for x in open_.GetPaths(): if os.path.exists(x) and os.path.isfile(x): self.API.tabManager.addPage(x) open_.Destroy()
def __init__(self, parent, title, size, pos, API): super(Frame, self).__init__(parent, wx.ID_ANY, title, size = size, pos = pos) # Get path, here must use only file name, __file__ sometimes contains more than that self.path = os.path.dirname(os.path.realpath(os.path.split(__file__)[1])) self.API = API self.API.path = self.path self.lastPanel = None self.auiManager = aui.AuiManager() self.loadPositioning() self.exitCalled = False self.blocklyToolVisible = False self.toolbar = None self.menubar = None self.examples = dict() self.initUI() self.SetBackgroundColour("white") flag = aui.AUI_MGR_ALLOW_ACTIVE_PANE | \ aui.AUI_MGR_AUTONB_NO_CAPTION | aui.AUI_MGR_SMOOTH_DOCKING | \ aui.AUI_MGR_TRANSPARENT_HINT | aui.AUI_NB_CLOSE_ON_TAB_LEFT | \ aui.AUI_MGR_AERO_DOCKING_GUIDES | aui.AUI_MGR_TRANSPARENT_DRAG self.auiManager.SetAGWFlags(self.auiManager.GetAGWFlags() ^ flag) self.auiManager.SetAutoNotebookStyle(aui.AUI_NB_TOP | aui.AUI_NB_SMART_TABS | aui.AUI_NB_CLOSE_ON_ALL_TABS) self.auiManager.SetManagedWindow(self) self.API.onExit.append(self.Close) self.API.tabManager.Reparent(self) self.API.editPanel.Reparent(self) if self.API.foundBlockly: self.API.blockly.Reparent(self) self.API.listenModules[0].Reparent(self) self.API.infoArea.Reparent(self) mainPane = (aui.AuiPaneInfo().CenterPane().Name("mainPane"). Caption(localize("Editors")).CaptionVisible(False). BestSize(wx.Size(600, 400))) self.auiManager.AddPane(self.API.tabManager, mainPane) self.infoPane = (aui.AuiPaneInfo().CaptionVisible(True). BestSize(wx.Size(500, 150)).Bottom(). CloseButton(False).MaximizeButton(True).MinimizeButton(True)) self.auiManager.AddPane(self.API.infoArea, self.infoPane.Caption(localize("Info")).Name("infoPane")) self.layoutListenPane(self.API.listenModules[0], localize("Listen module") + " 1", False) self.layoutEditPane() self.layoutBlocklyPane() self.auiManager.Update() self.Bind(wx.EVT_CLOSE, self.OnQuit) self.auiManager.ShowPane(self.API.infoArea, True)
def layoutBlocklyPane(self): if not self.API.foundBlockly: return; blocklyPane = (aui.AuiPaneInfo().Caption(localize("Seal-Blockly handler")). Name("blocklyPane").BestSize(wx.Size(500, 150))) self.auiManager.AddPane(self.API.blockly, blocklyPane, target = self.infoPane)
def OnOutput(self, event): if self.API.tabManager.doPopupSave(None) == True: dialog = wx.Dialog(self, wx.ID_ANY, localize('Configure upload and compile'), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) UploadModule(dialog, self.API) dialog.Fit() dialog.ShowModal() dialog.Destroy()
def OnAbout(self, event): versionFile = os.path.join("../..", "doc/VERSION") f = open(versionFile, "r") lines = f.readlines() f.close() release = "Unknown" date = "Unknown" if len(lines) > 0: release = lines[0].strip() if len(lines) > 1: date = lines[1].strip() text = localize("__ABOUT__").format(release, date) wx.MessageBox(text, 'Info', wx.OK | wx.ICON_INFORMATION)
def initUI(self): self.generateMenu() # Check if we need to update existing toolbar(for rerun) if self.toolbar == None: self.toolbar = self.CreateToolBar() self.toolbar.SetToolBitmapSize((32, 32)) else: self.toolbar.ClearTools() # Note that all icons must be 32x32, so they look good :) self.toolbar.AddLabelTool(wx.ID_NEW, localize('New'), wx.Bitmap(self.path + '/src/Icons/new.png'), shortHelp = localize('New')) self.toolbar.AddSeparator() self.toolbar.AddLabelTool(wx.ID_OPEN, localize('Open'), wx.Bitmap(self.path + '/src/Icons/open.png'), shortHelp = localize('Open')) self.toolbar.AddLabelTool(wx.ID_SAVE, localize('Save'), wx.Bitmap(self.path + '/src/Icons/save.png'), shortHelp = localize('Save')) self.toolbar.AddSeparator() addStatementTool = self.toolbar.AddLabelTool(wx.ID_ADD, localize('Add statement'), wx.Bitmap(self.path + '/src/Icons/add_statement.png'), shortHelp = localize('Add statement')) # Used ID_APPLY for identification, hope nothing else uses it addConditionTool = self.toolbar.AddLabelTool(wx.ID_APPLY, localize('Add condition'), wx.Bitmap(self.path + '/src/Icons/add_condition.png'), shortHelp = localize('Add condition')) #self.toolbar.AddSeparator() #addBlocklyTool = self.toolbar.AddLabelTool(wx.ID_MORE, localize('Open Seal-Blockly editor'), # wx.Bitmap(self.path + '/src/Icons/Seal_blockly.png'), # shortHelp = localize('Open Seal-Blockly editor')) self.toolbar.AddSeparator() compileTool = self.toolbar.AddLabelTool(wx.ID_PREVIEW, localize('Compile'), wx.Bitmap(self.path + '/src/Icons/compile.png'), shortHelp = localize('Compile')) uplTool = self.toolbar.AddLabelTool(wx.ID_PREVIEW_GOTO, localize('Upload'), wx.Bitmap(self.path + '/src/Icons/upload.png'), shortHelp = localize('Upload')) outputTool = self.toolbar.AddLabelTool(wx.ID_PREVIEW_ZOOM, localize('Configure upload and compile'), wx.Bitmap(self.path + '/src/Icons/read.png'), shortHelp = localize('Configure upload and compile')) listenTool = self.toolbar.AddCheckLabelTool(wx.ID_HOME, localize('Listen node\'s output'), wx.Bitmap(self.path + '/src/Icons/listen.png'), shortHelp = localize('Listen node\'s output')) self.toolbar.AddSeparator() self.toolbar.AddLabelTool(wx.ID_EXIT, localize('Exit'), wx.Bitmap(self.path + '/src/Icons/exit.png'), shortHelp = localize('Exit')) self.toolbar.Realize() # Second bind to toolbar, but only items with ID_ANY, because all # defined ID already binded from menu, weird side effect. self.Bind(wx.EVT_TOOL, self.OnCompile, compileTool) self.Bind(wx.EVT_TOOL, self.OnUpload, uplTool) self.Bind(wx.EVT_TOOL, self.OnOutput, outputTool) self.Bind(wx.EVT_TOOL, self.OnAddStatement, addStatementTool) self.Bind(wx.EVT_TOOL, self.OnAddCondition, addConditionTool) self.Bind(wx.EVT_TOOL, self.OnStartListening, listenTool)
def layoutEditPane(self): self.rightPane = (aui.AuiPaneInfo().Floatable(True). Right().Name("editPane").MinimizeButton(True). MaximizeButton(True).CloseButton(True).Caption(localize("Visual edit")). BestSize(wx.Size(320, 400))) self.auiManager.AddPane(self.API.editPanel, self.rightPane)
def generateMenu(self): fileMenu = wx.Menu() new = fileMenu.Append(wx.ID_NEW, '&' + localize('New') + '\tCtrl+N', localize('Create empty document')) open_ = fileMenu.Append(wx.ID_OPEN, '&' + localize('Open') + '\tCtrl+O', localize('Open document')) save = fileMenu.Append(wx.ID_SAVE, '&' + localize('Save') + '\tCtrl+S', localize('Save document')) saveAs = fileMenu.Append(wx.ID_SAVEAS, '&' + localize('Save as') + '\t', localize('Save document as')) upload = fileMenu.Append(wx.ID_ANY, '&' + localize('Upload') + '\tCtrl+U', localize('Open upload window')) recent = wx.Menu() fileMenu.AppendMenu(wx.ID_ANY, '&' + localize('Recently used files'), recent, localize('Recently used files')) close = fileMenu.Append(wx.ID_EXIT, '&' + localize('Exit') + '\tCtrl+Q', localize('Exit application')) self.fileHistory = wx.FileHistory(int(Settings.get('recently_opened_count'))) self.fileHistory.Load(self.API.config) self.fileHistory.UseMenu(recent) self.fileHistory.AddFilesToMenu() self.Bind(wx.EVT_MENU_RANGE, self.on_file_history, id = wx.ID_FILE1, id2 = wx.ID_FILE9) # show menu with mansos demo & test applications exampleMenu = wx.Menu() pathToMansosApps = self.API.path + os.path.normcase("/../../apps/") self.addExampleMenuItems(exampleMenu, pathToMansosApps, maxDepth = 2) optionMenu = wx.Menu() language = wx.Menu() self.langs = [] for i in Translater.translations.keys(): self.langs.append(language.Append(wx.ID_ANY, Translater.translations[i]['langName'], i, kind = wx.ITEM_RADIO)) if i == Settings.get("active_language"): language.Check(self.langs[-1].GetId(), True) self.Bind(wx.EVT_MENU, self.changeLanguage, self.langs[-1]) optionMenu.AppendMenu(wx.ID_ANY, localize('Change language'), language) output = optionMenu.Append(wx.ID_ANY, '&' + localize('Configure upload and compile') + '\tCtrl+R', localize('Open read output window')) windowMenu = wx.Menu() addMenu = wx.Menu() showMenu = wx.Menu() windowMenu.AppendMenu(wx.ID_ANY, localize('Add window'), addMenu) #windowMenu.AppendMenu(wx.ID_ANY, localize('Show window'), showMenu) listen = addMenu.Append(wx.ID_ANY, '&' + localize('Add listen window'), localize('Add listen window')) self.blocklyCheck = showMenu.AppendCheckItem(wx.ID_ANY, '&' + localize('Show blockly window'), localize('Show blockly window')) self.editCheck = showMenu.AppendCheckItem(wx.ID_ANY, '&' + localize('Show edit window'), localize('Show edit window')) helpMenu = wx.Menu() sealHelp = helpMenu.Append(wx.ID_ANY, '&' + localize('Seal documentation'), localize('About')) mansosHelp = helpMenu.Append(wx.ID_ANY, '&' + localize('MansOS documentation'), localize('About')) about = helpMenu.Append(wx.ID_ABOUT, '&' + localize('About') + '\tCtrl+H', localize('About')) # Check if we need to update existing menubar(for translate) if self.menubar == None: self.menubar = wx.MenuBar() else: for i in range(0, self.menubar.GetMenuCount()): self.menubar.Remove(0) self.menubar.Append(fileMenu, '&' + localize('File')) self.menubar.Append(exampleMenu, '&' + localize('Examples')) self.menubar.Append(optionMenu, '&' + localize('Options')) self.menubar.Append(windowMenu, '&' + localize('Windows')) self.menubar.Append(helpMenu, '&' + localize('Help')) self.SetMenuBar(self.menubar) # First bind to menu self.Bind(wx.EVT_MENU, self.OnQuit, close) self.Bind(wx.EVT_MENU, self.OnOpen, open_) self.Bind(wx.EVT_MENU, self.OnSave, save) self.Bind(wx.EVT_MENU, self.OnSaveAs, saveAs) self.Bind(wx.EVT_MENU, self.OnUpload, upload) self.Bind(wx.EVT_MENU, self.OnOutput, output) self.Bind(wx.EVT_MENU, self.OnNew, new) self.Bind(wx.EVT_MENU, self.OnAbout, about) self.Bind(wx.EVT_MENU, self.OnSealHelp, sealHelp) self.Bind(wx.EVT_MENU, self.OnMansosHelp, mansosHelp) self.Bind(wx.EVT_MENU, self.API.addListenWindow, listen) self.Bind(wx.EVT_MENU, self.API.showBlocklyWindow, self.blocklyCheck) self.Bind(wx.EVT_MENU, self.API.showEditWindow, self.editCheck)