def run(self): filename = os.path.join(self.API.path, Settings.get('blockly_location')) host = Settings.get('blockly_host') port = int(Settings.get('blockly_port')) con1, con2 = Pipe() p1 = Process(target = listen, args = (host, port, con2, True)) p1.daemon = False p1.name = "Socket listening thread" try: p1.start() self.printLine("Service started successfully.") if p1.is_alive(): # Damn linux if os.name == 'posix': Popen(['xdg-open', filename]) # other OS else: webbrowser.open_new_tab(filename) else: self.printLine("Failed to open {}:{}, port might be in use.".format(host, port)) lastSync = time.time() + 20 self.API.onExit.append(p1.terminate) while p1.is_alive() and self.active: if con1.poll(0.1): data = con1.recv() if data != "Sync recieved": self.handleRecievedCode(data) lastSync = time.time() if time.time() - lastSync > 20: self.printLine("No sync for 20 sec.\nTerminating...") self.API.onExit.remove(p1.terminate) p1.terminate() break wx.YieldIfNeeded() if p1.is_alive(): self.printLine("Service terminated successfully.") self.API.onExit.remove(p1.terminate) p1.terminate() except: self.printLine("Exception occurred, terminating...") if p1.terminate in self.API.onExit: self.API.onExit.remove(p1.terminate)
def loadPositioning(self): width = Settings.get("Width") if width == '': width = 800 else: width = int(width) height = Settings.get("Height") if height == '': height = 600 else: height = int(height) self.SetSize((width, height)) locX = Settings.get("LocX") if locX == '': # Center locX = (wx.GetDisplaySize()[0] - width) / 2 else: locX = int(locX) locY = Settings.get("LocY") if locY == '': # Center locY = (wx.GetDisplaySize()[1] - height) / 2 else: locY = int(locY) self.SetPosition((locX, locY)) maximized = Settings.get("Maximized") if maximized == '': maximized = False else: maximized = bool(maximized == "True") self.Maximize(maximized)
def translate(data, lang = ''): # This happens when no language is set if lang == '': lang = Settings.get("active_language") if lang != '': if type(data) is str or type(data) is unicode: if data in Translater.translations[lang]: return Translater.translations[lang][data] elif type(data) is list: retVal = list() for val in data: retVal.append(localize(str(val))) return retVal # Don't log ENG, because it's not ment to be translated if lang != "ENG": Translater.parent.logMsg(LOG_WARNING, "No translation for '{}':'{}'".format(lang, data)) return data
def loadRememberedTabs(self): tabs = Settings.get('openedTabs').split(';') # Remove automatically created first page self.DeletePage(0) if tabs != ['']: # Add all Tabs for x in tabs: self.addPage(x) return # Open default files if no tabs were saved path = join(self.API.path, "../../apps/seal/Empty/") if exists(path): filename = self.API.frame.findFirstSourceFile(path) if filename: self.addPage(filename) return self.addPage('sampleCode.sl')
def translate(data, lang=''): # This happens when no language is set if lang == '': lang = Settings.get("active_language") if lang != '': if type(data) is str or type(data) is unicode: if data in Translater.translations[lang]: return Translater.translations[lang][data] elif type(data) is list: retVal = list() for val in data: retVal.append(localize(str(val))) return retVal # Don't log ENG, because it's not ment to be translated if lang != "ENG": Translater.parent.logMsg( LOG_WARNING, "No translation for '{}':'{}'".format(lang, data)) return data
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)