def SetDefaultInterpreter(self, event): index = self.dvlc.GetSelectedRow() if index == wx.NOT_FOUND: return item = self.dvlc.RowToItem(index) id = self.dvlc.GetItemData(item) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterById(id) if interpreter.Default: return interpretermanager.InterpreterManager().SetDefaultInterpreter( interpreter) self.ReloadAllInterpreters()
def AddInterpreter(self, event): dlg = AddInterpreterDialog(self, -1, _("Add Interpreter")) dlg.CenterOnParent() status = dlg.ShowModal() passedCheck = False while status == wx.ID_OK and not passedCheck: if 0 == len(dlg.path_ctrl.GetValue()): wx.MessageBox(_("Interpreter Path is empty"), _("Error"), wx.OK | wx.ICON_ERROR, self) status = dlg.ShowModal() elif 0 == len(dlg.name_ctrl.GetValue()): wx.MessageBox(_("Interpreter Name is empty"), _("Error"), wx.OK | wx.ICON_ERROR, self) status = dlg.ShowModal() elif not os.path.exists(dlg.path_ctrl.GetValue()): wx.MessageBox(_("Interpreter Path is not exist"), _("Error"), wx.OK | wx.ICON_ERROR, self) status = dlg.ShowModal() else: try: interpreter = interpretermanager.InterpreterManager( ).AddPythonInterpreter(dlg.path_ctrl.GetValue(), dlg.name_ctrl.GetValue()) self.AddOneInterpreter(interpreter) self.SmartAnalyse(interpreter) passedCheck = True except Exception, e: wx.MessageBox(e.msg, _("Error"), wx.OK | wx.ICON_ERROR, self) status = dlg.ShowModal()
def ModifyInterpreterNameDlg(self, event): index = self.dvlc.GetSelectedRow() if index == wx.NOT_FOUND: self.UpdateUI() return item = self.dvlc.RowToItem(index) id = self.dvlc.GetItemData(item) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterById(id) dlg = AddInterpreterDialog(self, -1, _("Modify Interpreter Name")) dlg.path_ctrl.SetValue(interpreter.Path) dlg.path_ctrl.Enable(False) dlg.browser_btn.Enable(False) dlg.name_ctrl.SetValue(interpreter.Name) dlg.CenterOnParent() status = dlg.ShowModal() passedCheck = False while status == wx.ID_OK and not passedCheck: if 0 == len(dlg.name_ctrl.GetValue()): wx.MessageBox(_("Interpreter Name is empty"), _("Error"), wx.OK | wx.ICON_ERROR, self) status = dlg.ShowModal() else: name = dlg.name_ctrl.GetValue() interpreter.Name = name self.dvlc.SetTextValue(interpreter.Name, index, 0) passedCheck = True dlg.Destroy()
def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) pathLabel = wx.StaticText(self, -1, _("Interpreters:")) config = wx.ConfigBase_Get() ### path = config.Read("ActiveGridPythonLocation") choices,default_selection = interpretermanager.InterpreterManager().GetChoices() self._pathTextCtrl = wx.ComboBox(self, -1,choices=choices, style = wx.CB_READONLY) if len(choices) > 0: self._pathTextCtrl.SetSelection(default_selection) ## self._pathTextCtrl.SetToolTipString(self._pathTextCtrl.GetValue()) ##self._pathTextCtrl.SetInsertionPointEnd() choosePathButton = wx.Button(self, -1, _("Configure...")) pathSizer = wx.BoxSizer(wx.HORIZONTAL) HALF_SPACE = 5 SPACE = 10 pathSizer.Add(pathLabel, 0, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.TOP, HALF_SPACE) pathSizer.Add(self._pathTextCtrl, 1, wx.EXPAND|wx.LEFT|wx.TOP, HALF_SPACE) pathSizer.Add(choosePathButton, 0, wx.ALIGN_RIGHT|wx.LEFT|wx.RIGHT|wx.TOP, HALF_SPACE) wx.EVT_BUTTON(self, choosePathButton.GetId(), self.OnChoosePath) mainSizer = wx.BoxSizer(wx.VERTICAL) mainSizer.Add(pathSizer, 0, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP, SPACE) self._otherOptions = STCTextEditor.TextOptionsPanel(self, -1, configPrefix = "Python", label = "Python", hasWordWrap = True, hasTabs = True, addPage=False, hasFolding=True) mainSizer.Add(self._otherOptions, 0, wx.EXPAND|wx.BOTTOM, SPACE) self.SetSizer(mainSizer) parent.AddPage(self, _("Python"))
def __init__(self, parent=None, name=''): self._parentProj = parent self.name = name interpreter = interpretermanager.InterpreterManager( ).GetInterpreterByName(self.name) if interpreter is None: return self.version = interpreter.Version self.path = interpreter.Path
def SmartAnalyseIntreprter(self, event): index = self.dvlc.GetSelectedRow() if index == wx.NOT_FOUND: return item = self.dvlc.RowToItem(index) id = self.dvlc.GetItemData(item) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterById(id) self.SmartAnalyse(interpreter)
def OnChoosePath(self, event): dlg = configruation.InterpreterConfigDialog(self,-1,_("Configure Interpreter")) dlg.CenterOnParent() dlg.ShowModal() choices,default_selection = interpretermanager.InterpreterManager().GetChoices() self._pathTextCtrl.Clear() if len(choices) > 0: self._pathTextCtrl.InsertItems(choices,0) self._pathTextCtrl.SetSelection(default_selection) wx.GetApp().AddInterpreters()
def OnGotoLink(event): option_service = wx.GetApp().GetService(OptionService.OptionsService) option_service.OnOption(option_name=_("Python Interpreter")) choices, default_selection = interpretermanager.InterpreterManager( ).GetChoices() interpreterCombo.Clear() if len(choices) > 0: interpreterCombo.InsertItems(choices, 0) interpreterCombo.SetSelection(default_selection) wx.GetApp().AddInterpreters()
def generate_default_intellisence_data(self): current_interpreter = interpretermanager.InterpreterManager().GetCurrentInterpreter() if current_interpreter is None: return try: self.generate_intellisence_data(current_interpreter,load_data_end=True) except Exception as e: app_debugLogger.error('load interpreter name %s path %s version %s intellisence data path %s error: %s',current_interpreter.Name,\ current_interpreter.Path,current_interpreter.Version,\ os.path.join(self.data_root_path,str(current_interpreter.Id)),e)
def LoadProjectMetaData(self, project): interpreter_path = project.Interpreter.Path interpreter = interpretermanager.InterpreterManager( ).GetInterpreterByPath(interpreter_path) if interpreter is None: return project_location = project.homeDir metadata_path = os.path.join(project_location, ".metadata") intellisence_data_path = os.path.join(metadata_path, str(interpreter.Id)) self.LoadMetadataPath(intellisence_data_path)
def OnOK(self, optionsDialog): try: self.path_panel.GetPythonPathList() self.environment_panel.GetEnviron() interpretermanager.InterpreterManager( ).SavePythonInterpretersConfig() self.Destroy() except Exception as e: wx.MessageBox(e.msg, _("Save Interpreter Error"), wx.OK | wx.ICON_ERROR, wx.GetApp().GetTopWindow())
def OnGotoLink(event): dlg = configruation.InterpreterConfigDialog(parent, -1, _("Configure Interpreter")) dlg.CenterOnParent() dlg.ShowModal() choices, default_selection = interpretermanager.InterpreterManager( ).GetChoices() interpreterCombo.Clear() if len(choices) > 0: interpreterCombo.InsertItems(choices, 0) interpreterCombo.SetSelection(default_selection) wx.GetApp().AddInterpreters()
def UpdateUI(self, event): index = self.dvlc.GetSelectedRow() if index == wx.NOT_FOUND: self.smart_analyse_btn.Enable(False) self.remove_btn.Enable(False) self.set_default_btn.Enable(False) else: self.remove_btn.Enable(True) self.set_default_btn.Enable(True) item = self.dvlc.RowToItem(index) id = self.dvlc.GetItemData(item) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterById(id) if interpretermanager.InterpreterManager().IsInterpreterAnalysing( ) or not interpreter.IsValidInterpreter: self.smart_analyse_btn.Enable(False) else: self.smart_analyse_btn.Enable(True) self.path_panel.AppendSysPath(interpreter) self.builtin_panel.SetBuiltiins(interpreter) self.environment_panel.SetVariables(interpreter) self.package_panel.LoadPackages(interpreter)
def RemoveInterpreter(self, event): index = self.dvlc.GetSelectedRow() if index == wx.NOT_FOUND: return item = self.dvlc.RowToItem(index) id = self.dvlc.GetItemData(item) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterById(id) if interpreter.Default: wx.MessageBox(_("Default Interpreter cannot be remove"), _("Warning"), wx.OK | wx.ICON_WARNING, self) return ret = wx.MessageBox( _("Interpreter remove action cannot be recover,Do you want to continue remove this interpreter?" ), _("Warning"), wx.YES_NO | wx.ICON_QUESTION, self) if ret == wx.YES: interpretermanager.InterpreterManager().RemovePythonInterpreter( interpreter) self.ReloadAllInterpreters() self.UpdateUI(None)
def parse_project(self, doc): assert (doc != None) project = doc.GetModel() interpreter_path = project.Interpreter.Path interpreter = interpretermanager.InterpreterManager( ).GetInterpreterByPath(interpreter_path) if interpreter is None: return project_location = os.path.dirname(doc.GetFilename()) path_list = [project_location] metadata_path = os.path.join(project_location, ".metadata") intellisence_data_path = os.path.join(metadata_path, str(interpreter.Id)) self.last_update_time = self.get_last_update(intellisence_data_path) if not os.path.exists(intellisence_data_path): parserutils.MakeDirs(intellisence_data_path) #hidden intellisence data path on windows and linux if sysutilslib.isWindows(): import win32api import win32con win32api.SetFileAttributes(metadata_path, win32con.FILE_ATTRIBUTE_HIDDEN) update_file_count = 0 for filepath in project.filePaths: if self._stop: break file_dir = os.path.dirname(filepath) is_package_dir = fileparser.is_package_dir(file_dir) if is_package_dir or parserutils.PathsContainPath( path_list, file_dir): ext = strutils.GetFileExt(filepath) if ext in ['py', 'pyw']: mk_time = os.path.getmtime(filepath) relative_module_name, is_package = parserutils.get_relative_name( filepath, path_list) if mk_time > self.last_update_time or not os.path.exists( os.path.join(intellisence_data_path, relative_module_name + ".$members")): app_debugLogger.debug('update file %s ,relative module name is %s',\ filepath,parserutils.get_relative_name(filepath,path_list)[0]) fileparser.dump(filepath, relative_module_name, intellisence_data_path, is_package) update_file_count += 1 else: app_debugLogger.debug('%s is not valid parse dir', file_dir) app_debugLogger.debug('total update %d files', update_file_count) if update_file_count > 0: self.update_last_time(intellisence_data_path)
def ProcessUpdateUIEvent(self, event): index = self.dvlc.GetSelectedRow() if index == wx.NOT_FOUND: event.Enable(False) return False if event.GetId() == ID_NEW_INTERPRETER_VIRTUALENV: item = self.dvlc.RowToItem(index) id = self.dvlc.GetItemData(item) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterById(id) if interpreter.IsBuiltIn: event.Enable(False) return True event.Enable(True) return True
def OnOKClick(self, event): if self.value_ctrl.GetValue().strip() == "": wx.MessageBox(_("package name is empty")) return interpreter_name = self._interpreterCombo.GetStringSelection() interpreter = interpretermanager.InterpreterManager( ).GetInterpreterByName(interpreter_name) if interpreter.IsBuiltIn or interpreter.GetPipPath() is None: wx.MessageBox(_("Could not find pip on the path"), style=wx.OK | wx.ICON_ERROR) return self.value_ctrl.Enable(False) self.ok_btn.Enable(False) if self._manage_action == ManagePackagesDialog.MANAGE_INSTALL_PACKAGE: self.InstallPackage(interpreter) else: self.UninstallPackage(interpreter)
def generate_intellisence_data(self,interpreter,progress_dlg = None,load_data_end=False): if interpreter.IsBuiltIn: return sys_path_list = interpreter.SysPathList script_path = os.path.join(sysutilslib.mainModuleDir, "noval", "parser", "factory.py") database_version = config.DATABASE_VERSION cmd_list = [interpreter.Path,script_path,os.path.join(self.data_root_path,str(interpreter.Id)),\ database_version] if sysutilslib.isWindows(): startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE else: startupinfo = None self._process_obj = subprocess.Popen(cmd_list,startupinfo=startupinfo,cwd=os.path.join(sysutilslib.mainModuleDir, "noval", "parser")) interpreter.Analysing = True self._is_running = interpreter.Analysing #if current interpreter is analysing,load data at end if interpreter == interpretermanager.InterpreterManager().GetCurrentInterpreter(): load_data_end = True self.Wait(interpreter,progress_dlg,load_data_end)
def ProcessEvent(self, event): index = self.dvlc.GetSelectedRow() if index == wx.NOT_FOUND: return item = self.dvlc.RowToItem(index) id = self.dvlc.GetItemData(item) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterById(id) id = event.GetId() if id == ID_COPY_INTERPRETER_NAME: sysutils.CopyToClipboard(interpreter.Name) return True elif id == ID_COPY_INTERPRETER_VERSION: sysutils.CopyToClipboard(interpreter.Version) return True elif id == ID_COPY_INTERPRETER_PATH: sysutils.CopyToClipboard(interpreter.Path) return True elif id == ID_MODIFY_INTERPRETER_NAME: self.ModifyInterpreterNameDlg(None) return True elif id == ID_REMOVE_INTERPRETER: self.RemoveInterpreter(None) return True elif id == ID_NEW_INTERPRETER_VIRTUALENV: dlg = NewVirtualEnvDialog(self, interpreter, -1, _("New Virtual Env")) dlg.CenterOnParent() python_path = dlg._interprterChoice.GetClientData( dlg._interprterChoice.GetSelection()) interpreter = interpretermanager.InterpreterManager( ).GetInterpreterByPath(python_path) status = dlg.ShowModal() if status == wx.ID_OK: name = dlg.name_ctrl.GetValue().strip() location = dlg.path_ctrl.GetValue().strip() include_site_packages = dlg._includeSitePackgaes.GetValue() dlg.Destroy() progress_dlg = NewVirtualEnvProgressDialog(self) try: self.CreateVirtualEnv(name, location, include_site_packages, interpreter, progress_dlg) except: return while True: if not progress_dlg.KeepGoing: break wx.MilliSleep(250) wx.Yield() progress_dlg.Pulse(progress_dlg.msg) progress_dlg.Destroy() if sysutils.isWindows(): python_path = os.path.join(location, "Scripts\\python.exe") else: python_path = os.path.join(location, "bin/python") try: interpreter = interpretermanager.InterpreterManager( ).AddPythonInterpreter(python_path, name) self.AddOneInterpreter(interpreter) self.SmartAnalyse(interpreter) except Exception, e: wx.MessageBox(e.msg, _("Error"), wx.OK | wx.ICON_ERROR, self) return True
def CreateDirectoryControl(parent, fileLabel=_("File Name:"), dirLabel=_("Directory:"), fileExtension="*", startingName="", startingDirectory=None, choiceDirs=None, appDirDefaultStartDir=False, returnAll=False, useDirDialog=False): if not choiceDirs: choiceDirs = [] projectDirs = [] if appDirDefaultStartDir: appDirectory = wx.ConfigBase_Get().Read( project.ProjectEditor.PROJECT_DIRECTORY_KEY, project.ProjectEditor.NEW_PROJECT_DIRECTORY_DEFAULT) else: appDirectory = wx.ConfigBase_Get().Read( project.ProjectEditor.PROJECT_DIRECTORY_KEY) if appDirectory: choiceDirs.append(appDirectory) if appDirDefaultStartDir and not startingDirectory: startingDirectory = appDirectory projectService = wx.GetApp().GetService( project.ProjectEditor.ProjectService) if projectService: curProjectDoc = projectService.GetCurrentProject() if curProjectDoc: homeDir = curProjectDoc.GetAppDocMgr().homeDir if homeDir and (homeDir not in choiceDirs): choiceDirs.append(homeDir) if not startingDirectory: startingDirectory = homeDir for projectDoc in projectService.GetOpenProjects(): if projectDoc == curProjectDoc: continue homeDir = projectDoc.GetAppDocMgr().homeDir if homeDir and (homeDir not in projectDirs): projectDirs.append(homeDir) projectDirs.sort(CaseInsensitiveCompare) for projectDir in projectDirs: if projectDir not in choiceDirs: choiceDirs.append(projectDir) if startingDirectory and (startingDirectory not in choiceDirs): choiceDirs.insert(0, startingDirectory) cwdir = None try: cwdir = os.getcwd() except Exception as e: print 'UICommon waring ,getcwd error', e if cwdir and cwdir not in choiceDirs: choiceDirs.append(cwdir) if appdirs.getSystemDir() not in choiceDirs: choiceDirs.append(appdirs.getSystemDir()) if not startingDirectory and cwdir: startingDirectory = cwdir nameControl = wx.TextCtrl(parent, -1, startingName, size=(-1, -1)) nameLabelText = wx.StaticText(parent, -1, fileLabel) dirLabelText = wx.StaticText(parent, -1, dirLabel) dirControl = wx.ComboBox(parent, -1, startingDirectory, size=(-1, -1), choices=choiceDirs) dirControl.SetToolTipString(startingDirectory) button = wx.Button(parent, -1, _("Browse...")) interpreterLabelText = wx.StaticText(parent, -1, _("Interpreter:")) choices, default_selection = interpretermanager.InterpreterManager( ).GetChoices() interpreterCombo = wx.ComboBox(parent, -1, size=(-1, -1), choices=choices, style=wx.CB_READONLY) if len(choices) > 0: interpreterCombo.SetSelection(default_selection) hyperLinkCtrl = hl.HyperLinkCtrl(parent, wx.ID_ANY, _("Configuration")) hyperLinkCtrl.SetColours("BLUE", "BLUE", "BLUE") hyperLinkCtrl.AutoBrowse(False) hyperLinkCtrl.SetBold(True) hyperLinkCtrl.SetToolTip(wx.ToolTip(_("Click to Configure Interpreters"))) allControls = [ nameControl, nameLabelText, dirLabelText, dirControl, button ] def OnGotoLink(event): option_service = wx.GetApp().GetService(OptionService.OptionsService) option_service.OnOption(option_name=_("Python Interpreter")) choices, default_selection = interpretermanager.InterpreterManager( ).GetChoices() interpreterCombo.Clear() if len(choices) > 0: interpreterCombo.InsertItems(choices, 0) interpreterCombo.SetSelection(default_selection) wx.GetApp().AddInterpreters() parent.Bind(hl.EVT_HYPERLINK_LEFT, OnGotoLink, hyperLinkCtrl) def OnFindDirClick(event): name = "" nameCtrlValue = nameControl.GetValue() if nameCtrlValue: root, ext = os.path.splitext(nameCtrlValue) if ext == '.' + fileExtension: name = nameCtrlValue else: name = _("%s.%s") % (nameCtrlValue, fileExtension) if not useDirDialog: dlg = wx.FileDialog(parent, _("Choose a filename and directory"), defaultDir=dirControl.GetValue().strip(), defaultFile=name, wildcard="*.%s" % fileExtension, style=wx.SAVE | wx.CHANGE_DIR) else: dlg = wx.DirDialog(wx.GetApp().GetTopWindow(), _("Choose a directory:"), defaultPath=dirControl.GetValue().strip(), style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON) if dlg.ShowModal() != wx.ID_OK: dlg.Destroy() return path = dlg.GetPath() dlg.Destroy() if path: if not useDirDialog: dir, filename = os.path.split(path) if dirControl.FindString(dir) == wx.NOT_FOUND: dirControl.Insert(dir, 0) dirControl.SetValue(dir) dirControl.SetToolTipString(dir) nameControl.SetValue(filename) else: dirControl.SetValue(path) dirControl.SetToolTipString(path) parent.Bind(wx.EVT_BUTTON, OnFindDirClick, button) def Validate(allowOverwriteOnPrompt=False, infoString='', validClassName=False, ignoreFileConflicts=False): projName = nameControl.GetValue().strip() if projName == "": wx.MessageBox( _("Please provide a %sfile name.") % infoString, _("Provide a File Name")) return False, None if projName.find(' ') != -1: wx.MessageBox( _("Please provide a %sfile name that does not contains spaces." ) % infoString, _("Spaces in File Name")) return False, None if validClassName: if projName[0].isdigit(): wx.MessageBox( _("File name cannot start with a number. Please enter a different name." ), _("Invalid File Name")) return False, None if projName.endswith(PROJECT_EXTENSION): projName2 = projName[:-4] else: projName2 = projName if not projName2.replace("_", "a").isalnum( ): # [a-zA-Z0-9_] note '_' is allowed and ending '.agp'. wx.MessageBox( _("Name must be alphanumeric ('_' allowed). Please enter a valid name." ), _("Project Name")) return False, None dirName = dirControl.GetValue().strip() if dirName == "": wx.MessageBox(_("No directory. Please provide a directory."), _("Provide a Directory")) return False, None if os.sep == "\\" and dirName.find("/") != -1: wx.MessageBox( _("Wrong delimiter '/' found in directory path. Use '%s' as delimiter." ) % os.sep, _("Provide a Valid Directory")) return False, None if -1 == interpreterCombo.GetSelection(): wx.MessageBox(_("You do not Choose any interpreter,Please choose a valid interpreter or click Configuration link to add new interpreter"),\ _("Choose a Interpreter")) return False, None if dirCheck.GetValue(): dirName = os.path.join(dirName, projName) #if dir not exist,create it first if not os.path.exists(dirName): dirutils.MakeDirs(dirName) if not os.path.exists(dirName): wx.MessageBox( _("That %sdirectory does not exist. Please choose an existing directory." ) % infoString, _("Provide a Valid Directory")) return False, None if not ignoreFileConflicts: filePath = os.path.join( dirName, MakeNameEndInExtension(projName, "." + fileExtension)) if os.path.exists(filePath): if allowOverwriteOnPrompt: res = wx.MessageBox(_( "That %sfile already exists. Would you like to overwrite it." ) % infoString, "File Exists", style=wx.YES_NO | wx.NO_DEFAULT) if res != wx.YES: return False, None else: wx.MessageBox( _("That %sfile already exists. Please choose a different name." ) % infoString, "File Exists") return False, None pythonpath_pattern = projectconfiguration.ProjectConfiguration.NONE_PATH_ADD_TO_PYTHONPATH if addsrcPathRadioBtn.GetValue(): pythonpath_pattern = projectconfiguration.ProjectConfiguration.PROJECT_SRC_PATH_ADD_TO_PYTHONPATH project_src_path = os.path.join( dirName, projectconfiguration.ProjectConfiguration. DEFAULT_PROJECT_SRC_PATH) if not os.path.exists(project_src_path): dirutils.MakeDirs(project_src_path) elif addProjectPathRadioBtn.GetValue(): pythonpath_pattern = projectconfiguration.ProjectConfiguration.PROJECT_PATH_ADD_TO_PYTHONPATH elif configureNonePathRadioBtn.GetValue(): pythonpath_pattern = projectconfiguration.ProjectConfiguration.NONE_PATH_ADD_TO_PYTHONPATH pjconfiguration = projectconfiguration.ProjectConfiguration( nameControl.GetValue().strip(), dirControl.GetValue().strip(), interpreterCombo.GetValue(), dirCheck.GetValue(), pythonpath_pattern) return True, pjconfiguration flexGridSizer = wx.FlexGridSizer(cols=3, vgap=HALF_SPACE, hgap=HALF_SPACE) flexGridSizer.AddGrowableCol(1, 1) if not useDirDialog: flexGridSizer.Add(nameLabelText, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT) flexGridSizer.Add(nameControl, 2, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) flexGridSizer.Add(button, flag=wx.ALIGN_RIGHT | wx.LEFT, border=HALF_SPACE) flexGridSizer.Add(dirLabelText, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT) flexGridSizer.Add(dirControl, 2, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) flexGridSizer.Add(wx.StaticText(parent, -1, ""), 0) else: flexGridSizer.Add(nameLabelText, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT) flexGridSizer.Add(nameControl, 2, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) flexGridSizer.Add(wx.StaticText(parent, -1, ""), 0) flexGridSizer.Add(dirLabelText, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT) flexGridSizer.Add(dirControl, 2, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) flexGridSizer.Add(button, flag=wx.ALIGN_RIGHT | wx.LEFT, border=HALF_SPACE) flexGridSizer.Add(interpreterLabelText, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT) flexGridSizer.Add(interpreterCombo, 2, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND) flexGridSizer.Add(hyperLinkCtrl, flag=wx.ALIGN_LEFT | wx.LEFT, border=HALF_SPACE) parent.GetSizer().Add(flexGridSizer, 0, flag=wx.EXPAND) option_sizer = wx.BoxSizer(wx.VERTICAL) dirCheck = wx.CheckBox(parent, -1, _("Create Project Name Directory")) option_sizer.Add(dirCheck, 0, flag=wx.TOP, border=HALF_SPACE) addsrcPathRadioBtn = wx.RadioButton(parent,-1, label = "Create '%s' Folder And Add it to the PYTHONPATH" % \ projectconfiguration.ProjectConfiguration.DEFAULT_PROJECT_SRC_PATH,style = wx.RB_GROUP) option_sizer.Add(addsrcPathRadioBtn, 0, flag=wx.TOP, border=HALF_SPACE) addProjectPathRadioBtn = wx.RadioButton( parent, -1, label='Add Project Directory to the PYTHONPATH') option_sizer.Add(addProjectPathRadioBtn, 0, flag=wx.TOP, border=HALF_SPACE) configureNonePathRadioBtn = wx.RadioButton( parent, -1, label='Don\'t Configure PYTHONPATH(later manually configure it)') option_sizer.Add(configureNonePathRadioBtn, 0, flag=wx.TOP, border=HALF_SPACE) parent.GetSizer().Add(option_sizer, 0, flag=wx.TOP | wx.ALIGN_LEFT, border=SPACE) if returnAll: return Validate, allControls else: return Validate
def __init__(self, parent, dlg_id, title, manage_action, interpreter, package_name=''): self.interpreter = interpreter self._manage_action = manage_action wx.Dialog.__init__(self, parent, dlg_id, title, size=(-1, -1)) box_sizer = wx.BoxSizer(wx.VERTICAL) lineSizer = wx.BoxSizer(wx.HORIZONTAL) if self._manage_action == ManagePackagesDialog.MANAGE_INSTALL_PACKAGE: lineSizer.Add( wx.StaticText(self, -1, _("Type the name of package to install")), 0, wx.ALIGN_CENTER, 0) else: lineSizer.Add( wx.StaticText(self, -1, _("Type the name of package to uninstall")), 0, wx.ALIGN_CENTER, 0) box_sizer.Add(lineSizer, 0, wx.EXPAND | wx.ALL, SPACE) lineSizer = wx.BoxSizer(wx.HORIZONTAL) if self._manage_action == ManagePackagesDialog.MANAGE_INSTALL_PACKAGE: lineSizer.Add(wx.StaticText(self, -1, _("We will download and install it in the interpreter:")), 0, \ wx.ALIGN_CENTER | wx.LEFT, SPACE) else: lineSizer.Add(wx.StaticText(self, -1, _("We will uninstall it in the interpreter:")), 0, \ wx.ALIGN_CENTER | wx.LEFT, SPACE) choices, default_selection = interpretermanager.InterpreterManager( ).GetChoices() self._interpreterCombo = wx.ComboBox(self, -1, choices=choices, value=self.interpreter.Name, style=wx.CB_READONLY) lineSizer.Add(self._interpreterCombo, 0, wx.EXPAND | wx.LEFT, SPACE) box_sizer.Add(lineSizer, 0, wx.EXPAND | wx.RIGHT | wx.BOTTOM, SPACE) lineSizer = wx.BoxSizer(wx.HORIZONTAL) self.value_ctrl = wx.TextCtrl(self, -1, "", size=(-1, -1)) lineSizer.Add(self.value_ctrl, 1, wx.LEFT | wx.EXPAND, SPACE) if self._manage_action == ManagePackagesDialog.MANAGE_UNINSTALL_PACKAGE: self.value_ctrl.SetValue(package_name) self.browser_btn = wx.Button(self, -1, _("Browse...")) wx.EVT_BUTTON(self.browser_btn, -1, self.BrowsePath) lineSizer.Add(self.browser_btn, 0, flag=wx.LEFT, border=SPACE) box_sizer.Add(lineSizer, 0, flag=wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=SPACE) lineSizer = wx.BoxSizer(wx.HORIZONTAL) if self._manage_action == ManagePackagesDialog.MANAGE_INSTALL_PACKAGE: lineSizer.Add(wx.StaticText(self, -1, _("To install the specific version,type \"xxx==1.0.1\"\nTo install more packages,please specific the path of requirements.txt")), \ 0, wx.ALIGN_CENTER | wx.LEFT, SPACE) else: lineSizer.Add(wx.StaticText(self, -1, _("To uninstall more packages,please specific the path of requirements.txt")), \ 0, wx.ALIGN_CENTER | wx.LEFT, SPACE) box_sizer.Add(lineSizer, 0, wx.RIGHT | wx.BOTTOM | wx.EXPAND, SPACE) self.detailSizer = wx.BoxSizer(wx.HORIZONTAL) self.output_ctrl = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE, size=(-1, 250)) self.output_ctrl.Enable(False) self.detailSizer.Add(self.output_ctrl, 1, wx.LEFT | wx.BOTTOM, SPACE) box_sizer.Add(self.detailSizer, 0, wx.RIGHT | wx.BOTTOM | wx.EXPAND, SPACE) box_sizer.Hide(self.detailSizer) bsizer = wx.BoxSizer(wx.HORIZONTAL) self.detail_btn = wx.Button(self, -1, _("Show Details") + "↓") self._show_details = False wx.EVT_BUTTON(self.detail_btn, -1, self.ShowHideDetails) bsizer.Add(self.detail_btn, 0, flag=wx.LEFT, border=SPACE) bsizer.Add(wx.StaticText(self, -1, ""), 1, wx.LEFT | wx.EXPAND, 0) self.ok_btn = wx.Button(self, wx.ID_OK, _("&OK")) #set ok button default focused self.ok_btn.SetDefault() wx.EVT_BUTTON(self.ok_btn, -1, self.OnOKClick) bsizer.Add(self.ok_btn, 0, flag=wx.RIGHT, border=SPACE) cancel_btn = wx.Button(self, wx.ID_CANCEL, _("&Cancel")) bsizer.Add(cancel_btn, 0, flag=wx.RIGHT, border=SPACE) box_sizer.Add(bsizer, 0, wx.EXPAND | wx.BOTTOM, SPACE) self.SetSizer(box_sizer) self.Fit()