def __init__(self): projName = self.__class__.__name__ manager = Manager() if manager.hasProject(projName): self.project = manager.loadProject(projName) else: self.project = manager.createProject(projName) # Use graph view as default settings = self.project.getSettings() settings.setRunsView(1) # graph view settings.write() self.loadWorkflow()
def _select(self): projName = self.projName.get().strip() projLocation = self.projLocation.get().strip() copyFiles = self.tkCheckVar.get() != 0 searchLocation = self.searchLocation.get().strip() manager = Manager() # If project name is empty we will use the same name as the source if not projName: projName = os.path.basename(projLocation) errorMessage = '' # Validate that project location is not empty if not projLocation: errorMessage = "Project location is empty\n" # Validate that project location exists elif not os.path.exists(projLocation): errorMessage += "Project location does not exist\n" # Validate that project location is a directory elif not os.path.isdir(projLocation): errorMessage += "Project location is not a directory\n" # Validate that the project location is a scipion project folder elif not os.path.exists(os.path.join(projLocation, Project.getDbName())): errorMessage += "Project location doesn't look like a scipion folder\n" # Validate that there isn't already a project with the same name if manager.hasProject(projName): errorMessage += "Project [%s] already exists\n" % projName # Validate that search location exists if searchLocation: if not os.path.exists(searchLocation): errorMessage += "Raw files location does not exist\n" # Validate that search location is a directory elif not os.path.isdir(searchLocation): errorMessage += "Raw files location is not a directory\n" if errorMessage: showError("Validation error", errorMessage, self.root) else: self.parent.importProject(projLocation, copyFiles, projName, searchLocation) self.close()
def main(): if len(sys.argv) != 3: usage("Incorrect number of input parameters") projName = sys.argv[1] searchDir = os.path.abspath(sys.argv[2]) # Create a new project manager = Manager() if not manager.hasProject(projName): usage("Nonexistent project: %s" % pwutils.red(projName)) if not os.path.exists(searchDir): usage("Nonexistent SEARCH_DIR: %s" % pwutils.red(searchDir)) project = manager.loadProject(projName) project.fixLinks(searchDir)
usage("This script accepts 1 mandatory parameter: the project name.") elif n > 2 and sys.argv[2] != '--ignore': usage("The protocol class names to be ignored must be after a '--ignore' flag.") projName = sys.argv[1] # This fails, since it is triggering matplotlib.pyplot and then import error happens: # ... pyworkflow/gui/no-tkinter/_tkinter.py: invalid ELF header. If we want this back we might need to # invest some time "faking" tkinter again for python3. # path = pw.join('gui', 'no-tkinter') # sys.path.insert(1, path) # Create a new project manager = Manager() if not manager.hasProject(projName): usage("There is no project with this name: %s" % pwutils.red(projName)) # the project may be a soft link which may be unavailable to the cluster so get the real path try: projectPath = os.readlink(manager.getProjectPath(projName)) except: projectPath = manager.getProjectPath(projName) project = Project(pw.Config.getDomain(), projectPath) project.load() runs = project.getRuns() # Now assuming that there is no dependencies between runs
class ProjectsView(tk.Frame): _PROJ_CONTAINER = "projectsframe" def __init__(self, parent, windows, **args): tk.Frame.__init__(self, parent, bg='white', **args) self.windows = windows self.manager = windows.manager self.root = windows.root # tkFont.Font(size=12, family='verdana', weight='bold') bigSize = pwgui.cfgFontSize + 2 smallSize = pwgui.cfgFontSize - 2 fontName = pwgui.cfgFontName self.projNameFont = tkFont.Font(size=bigSize, family=fontName, weight='bold') self.projDateFont = tkFont.Font(size=smallSize, family=fontName) self.projDelFont = tkFont.Font(size=smallSize, family=fontName, weight='bold') self.manager = Manager() self.filter = tk.StringVar() self.filterBox = None self.addActionsFrame() self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) text = TaggedText(self, width=40, height=15, bd=0, bg='white') text.grid(row=1, columnspan=2, column=0, sticky='news') self.createProjectList(text) text.setReadOnly(True) self.text = text self.filterBox.focus_set() def addActionsFrame(self): """ Add the "toolbar" for actions like create project, import project or filter""" # Add the create project button bg = "white" btnFrame = tk.Frame(self, bg=bg) btn = HotButton(btnFrame, text=Message.LABEL_CREATE_PROJECT, font=self.projNameFont, command=self._onCreateProject) btn.grid(row=0, column=0, sticky='nw', padx=10, pady=10) # Add the Import project button btn = Button(btnFrame, text=Message.LABEL_IMPORT_PROJECT, font=self.projNameFont, command=self._onImportProject) btn.grid(row=0, column=1, sticky='nw', padx=10, pady=10) btnFrame.grid(row=0, column=0, sticky='nw') # Add a filter box # Add the Import project button btn = tk.Label(btnFrame, bg=bg, text="Filter:", font=self.projNameFont) btn.grid(row=0, column=2, sticky='nse', padx=10, pady=10) self.filterBox = tk.Entry(btnFrame, font=self.projNameFont, textvariable=self.filter) self.filterBox.grid(row=0, column=3, sticky='ne', padx=10, pady=12) self.filterBox.bind('<Return>', self._onFilter) self.filterBox.bind('<KP_Enter>', self._onFilter) def createProjectList(self, text): """Load the list of projects""" r = 0 text.setReadOnly(False) text.clear() parent = tk.Frame(text, bg='white', name=self._PROJ_CONTAINER) parent.columnconfigure(0, weight=1) colors = ['white', '#EAEBFF'] for i, p in enumerate(self.manager.listProjects()): try: # Add creation time to project info # Add if it's a link p.index = "index%s" % i # Consider the filter if not self._doesProjectMatchFilter(p): continue frame = self.createProjectLabel(parent, p, color=colors[i % 2]) frame.grid(row=r, column=0, padx=10, pady=5, sticky='new') r += 1 except Exception as ex: print("ERROR loading project: %s" % p.getName()) print(ex) text.window_create(tk.INSERT, window=parent) text.bindWidget(parent) text.setReadOnly(True) def createProjectLabel(self, parent, projInfo, color): frame = tk.Frame(parent, bg=color, name=projInfo.index) # ROW1 # Project name label = tk.Label(frame, text=projInfo.projName, anchor='nw', bg=color, justify=tk.LEFT, font=self.projNameFont, cursor='hand1', width=50) label.grid(row=0, column=0, padx=2, pady=2, sticky='nw') label.bind('<Button-1>', lambda e: self.openProject(projInfo.projName)) # ROW2 # Timestamp line dateMsg = '%s%s %s%s' % ( Message.LABEL_MODIFIED, prettyDate(projInfo.mTime), Message.LABEL_CREATED, prettyTime(projInfo.cTime, time=False)) dateLabel = tk.Label(frame, text=dateMsg, font=self.projDateFont, bg=color) dateLabel.grid(row=1, column=0, sticky='nw') # Delete action delLabel = tk.Label(frame, text=Message.LABEL_DELETE_PROJECT, font=self.projDelFont, bg=color, cursor='hand1') delLabel.grid(row=1, column=1, padx=10) delLabel.bind('<Button-1>', lambda e: self.deleteProject(projInfo)) # Rename action mvLabel = tk.Label(frame, text=Message.LABEL_RENAME_PROJECT, font=self.projDelFont, bg=color, cursor='hand1') mvLabel.grid(row=1, column=2) mvLabel.bind('<Button-1>', lambda e: self.renameProject(projInfo.projName)) # ROW3 if projInfo.isLink(): linkMsg = 'link --> ' + projInfo.realPath() lblLink = tk.Label(frame, text=linkMsg, font=self.projDateFont, bg=color, fg='grey', justify=tk.LEFT) lblLink.grid(row=2, column=0, columnspan=3, sticky='w') return frame def createNewProject(self, projName, projLocation): proj = self.manager.createProject(projName, location=projLocation) self.createProjectList(self.text) self.openProject(proj.getShortName()) def _onCreateProject(self, e=None): projWindow = ProjectCreateWindow("Create project", self) projWindow.show() def _onImportProject(self, e=None): importProjWindow = ProjectImportWindow("Import project", self) importProjWindow.show() def _onFilter(self, e=None): self.createProjectList(self.text) def _setFocusToList(self, e=None): self.text.focus_set() def _doesProjectMatchFilter(self, project): """ Returns true if the project matches the filter""" # Lets' use the name anc creation date for now: searchString = "~".join([ project.getName().lower(), prettyDate(project.mTime), prettyTime(project.cTime, time=False) ]) return self.filter.get().lower() in searchString def importProject(self, projLocation, copyFiles, projName, searchLocation): self.manager.importProject(projLocation, copyFiles, projName, searchLocation) self.createProjectList(self.text) self.openProject(projName) def openProject(self, projName): from subprocess import Popen script = pw.join(pw.APPS, 'pw_project.py') Popen([pw.PYTHON, script, projName]) def deleteProject(self, projInfo): projName = projInfo.projName if askYesNo( Message.TITLE_DELETE_PROJECT, "Project *%s*. " % projName + Message.MESSAGE_DELETE_PROJECT, self.root): self.manager.deleteProject(projName) #Delete the frame self.text.children[self._PROJ_CONTAINER].children[ projInfo.index].grid_forget() def renameProject(self, projName): newName = askString("Rename project %s" % projName, "Enter new name:", self.root) if not newName or newName == projName: return if self.manager.hasProject(newName): showError("Rename cancelled", "Project name already exists: %s" % newName, self.root) return self.manager.renameProject(projName, newName) self.createProjectList(self.text)
n = len(sys.argv) if n < 2 or n > 4: usage("Incorrect number of input parameters") projName = sys.argv[1] jsonFile = None if n < 3 else os.path.abspath(sys.argv[2]) location = None if n < 4 else sys.argv[3] # This might not be working anymore for python3. # I'm getting invalid ELF header triggered by matplotlib -->from . import _tkagg # path = pw.join('gui', 'no-tkinter') # sys.path.insert(1, path) # Create a new project manager = Manager() if manager.hasProject(projName): usage("There is already a project with this name: %s" % pwutils.red(projName)) if jsonFile is not None and not os.path.exists(jsonFile): usage("Nonexistent json file: %s" % pwutils.red(jsonFile)) project = manager.createProject(projName, location=location) if jsonFile is not None: protDict = project.loadProtocols(jsonFile)