Exemplo n.º 1
0
    def __init__(self, title, parent=None, weight=True, minsize=(400, 110),
                 icon="scipion_bn.xbm", **args):
        """
         We assume the parent should be of ProjectsView
        """
        Window.__init__(self, title, parent.windows, weight=weight,
                        icon=icon, minsize=minsize, enableQueue=True)
        self.root['background'] = 'white'

        self.parent = parent
        self.projectsPath = self.parent.manager.PROJECTS
        self.projName = tk.StringVar()
        self.projName.set('')
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=3)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news', padx=5, pady=5)

        #  Project name line
        labelName = tk.Label(content, text=Message.LABEL_PROJECT + ' name', bg='white', bd=0)
        labelName.grid(row=0, sticky=tk.W, padx=5, pady=5)
        entryName = tk.Entry(content, bg=cfgEntryBgColor, width=20, textvariable=self.projName)
        entryName.grid(row=0, column=1, columnspan=2, sticky=tk.W, padx=5, pady=5)

        # Project location line
        labelLocation = tk.Label(content, text=Message.LABEL_PROJECT + ' location', bg='white', bd=0)
        labelLocation.grid(row=1, column=0, sticky='nw', padx=5, pady=5)

        self.entryBrowse = tk.Entry(content, bg=cfgEntryBgColor, width=40, textvariable=self.projLocation)
        self.entryBrowse.grid(row=1, column=1, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(content, 'Browse', Icon.ACTION_BROWSE, highlightthickness=0, command=self._browsePath)
        self.btnBrowse.grid(row=1, column=2, sticky='e', padx=5, pady=5)

        self.initial_focus = entryName

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=2, column=0, sticky='sew', padx=5, pady=(0, 5), columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame, 'Create', Icon.BUTTON_SELECT, command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame, 'Cancel', Icon.BUTTON_CANCEL, command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)
Exemplo n.º 2
0
    def __init__(self, title, parent=None, weight=True, minsize=(400, 150),
                 icon="scipion_bn.xbm", **args):
        """
         We assume the parent should be of ProjectsView
        """
        Window.__init__(self, title, parent.windows, weight=weight,
                        icon=icon, minsize=minsize, enableQueue=True)

        self.parent = parent
        self.projectsPath = self.parent.manager.PROJECTS
        self.projName = tk.StringVar()
        self.projName.set('')
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=1)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news',
                       padx=5, pady=5)
        labelName = tk.Label(content, text=Message.LABEL_PROJECT, bg='white', bd=0)
        labelName.grid(row=0, column=0, sticky='nw', padx=5, pady=5)
        entryName = tk.Entry(content, bg=cfgEntryBgColor, width=20, textvariable=self.projName)
        entryName.grid(row=0, column=1, sticky='nw', padx=5, pady=5)

        labelCheck = tk.Label(content, text="Use default location", bg='white', bd=0)
        labelCheck.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        self.tkCheckVar = tk.IntVar()
        btnCheck = tk.Checkbutton(content, variable=self.tkCheckVar, bg='white', bd=0)
        btnCheck.grid(row=1, column=1, sticky='nw', padx=5, pady=5)

        self.browseFrame = tk.Frame(content, bg='white')
        #self.browseFrame.columnconfigure(1, weight=1)
        self.browseFrame.grid(row=2, column=0, padx=0, pady=0, columnspan=2, sticky='nw')
        self.entryBrowse = tk.Entry(self.browseFrame, bg=cfgEntryBgColor, width=40, textvariable=self.projLocation)
        self.entryBrowse.grid(row=0, column=0, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(self.browseFrame, 'Browse', Icon.ACTION_BROWSE, command=self._browsePath)
        self.btnBrowse.grid(row=0, column=1, sticky='e', padx=5, pady=5)

        self.initial_focus = entryName
        self.tkCheckVar.trace('w', self._onVarChanged)
        btnCheck.select()

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=3, column=0, sticky='sew', padx=5, pady=(0, 5), columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame, 'Create', Icon.BUTTON_SELECT, command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame, 'Cancel', Icon.BUTTON_CANCEL, command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)
Exemplo n.º 3
0
    def __init__(self,
                 title,
                 parent=None,
                 weight=True,
                 minsize=(400, 150),
                 icon="scipion_bn.xbm",
                 **args):
        """
         We assume the parent should be of ProjectsView
        """
        Window.__init__(self,
                        title,
                        parent.windows,
                        weight=weight,
                        icon=icon,
                        minsize=minsize,
                        enableQueue=True)

        self.parent = parent
        self.projectsPath = self.parent.manager.PROJECTS
        self.projName = tk.StringVar()
        self.projName.set('')
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=1)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news', padx=5, pady=5)
        labelName = tk.Label(content,
                             text=Message.LABEL_PROJECT,
                             bg='white',
                             bd=0)
        labelName.grid(row=0, column=0, sticky='nw', padx=5, pady=5)
        entryName = tk.Entry(content,
                             bg=cfgEntryBgColor,
                             width=20,
                             textvariable=self.projName)
        entryName.grid(row=0, column=1, sticky='nw', padx=5, pady=5)

        labelCheck = tk.Label(content,
                              text="Use default location",
                              bg='white',
                              bd=0)
        labelCheck.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        self.tkCheckVar = tk.IntVar()
        btnCheck = tk.Checkbutton(content,
                                  variable=self.tkCheckVar,
                                  bg='white',
                                  bd=0)
        btnCheck.grid(row=1, column=1, sticky='nw', padx=5, pady=5)

        self.browseFrame = tk.Frame(content, bg='white')
        #self.browseFrame.columnconfigure(1, weight=1)
        self.browseFrame.grid(row=2,
                              column=0,
                              padx=0,
                              pady=0,
                              columnspan=2,
                              sticky='nw')
        self.entryBrowse = tk.Entry(self.browseFrame,
                                    bg=cfgEntryBgColor,
                                    width=40,
                                    textvariable=self.projLocation)
        self.entryBrowse.grid(row=0, column=0, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(self.browseFrame,
                                    'Browse',
                                    Icon.ACTION_BROWSE,
                                    command=self._browsePath)
        self.btnBrowse.grid(row=0, column=1, sticky='e', padx=5, pady=5)

        self.initial_focus = entryName
        self.tkCheckVar.trace('w', self._onVarChanged)
        btnCheck.select()

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=3,
                      column=0,
                      sticky='sew',
                      padx=5,
                      pady=(0, 5),
                      columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame,
                              'Create',
                              Icon.BUTTON_SELECT,
                              command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame,
                           'Cancel',
                           Icon.BUTTON_CANCEL,
                           command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)
Exemplo n.º 4
0
class ProjectCreateWindow(Window):
    """ Windows to create a project. """
    def __init__(self,
                 title,
                 parent=None,
                 weight=True,
                 minsize=(400, 150),
                 icon="scipion_bn.xbm",
                 **args):
        """
         We assume the parent should be of ProjectsView
        """
        Window.__init__(self,
                        title,
                        parent.windows,
                        weight=weight,
                        icon=icon,
                        minsize=minsize,
                        enableQueue=True)

        self.parent = parent
        self.projectsPath = self.parent.manager.PROJECTS
        self.projName = tk.StringVar()
        self.projName.set('')
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=1)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news', padx=5, pady=5)
        labelName = tk.Label(content,
                             text=Message.LABEL_PROJECT,
                             bg='white',
                             bd=0)
        labelName.grid(row=0, column=0, sticky='nw', padx=5, pady=5)
        entryName = tk.Entry(content,
                             bg=cfgEntryBgColor,
                             width=20,
                             textvariable=self.projName)
        entryName.grid(row=0, column=1, sticky='nw', padx=5, pady=5)

        labelCheck = tk.Label(content,
                              text="Use default location",
                              bg='white',
                              bd=0)
        labelCheck.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        self.tkCheckVar = tk.IntVar()
        btnCheck = tk.Checkbutton(content,
                                  variable=self.tkCheckVar,
                                  bg='white',
                                  bd=0)
        btnCheck.grid(row=1, column=1, sticky='nw', padx=5, pady=5)

        self.browseFrame = tk.Frame(content, bg='white')
        #self.browseFrame.columnconfigure(1, weight=1)
        self.browseFrame.grid(row=2,
                              column=0,
                              padx=0,
                              pady=0,
                              columnspan=2,
                              sticky='nw')
        self.entryBrowse = tk.Entry(self.browseFrame,
                                    bg=cfgEntryBgColor,
                                    width=40,
                                    textvariable=self.projLocation)
        self.entryBrowse.grid(row=0, column=0, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(self.browseFrame,
                                    'Browse',
                                    Icon.ACTION_BROWSE,
                                    command=self._browsePath)
        self.btnBrowse.grid(row=0, column=1, sticky='e', padx=5, pady=5)

        self.initial_focus = entryName
        self.tkCheckVar.trace('w', self._onVarChanged)
        btnCheck.select()

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=3,
                      column=0,
                      sticky='sew',
                      padx=5,
                      pady=(0, 5),
                      columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame,
                              'Create',
                              Icon.BUTTON_SELECT,
                              command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame,
                           'Cancel',
                           Icon.BUTTON_CANCEL,
                           command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)

    def _onVarChanged(self, *args):
        if self.tkCheckVar.get() == 0:
            self.entryBrowse.config(state='normal')
            self.btnBrowse.config(state='normal')
        else:
            self.projLocation.set(self.projectsPath)
            self.entryBrowse.config(state='readonly')
            self.btnBrowse.config(state='disabled')

    def _browsePath(self, e=None):
        def onSelect(obj):
            self.projLocation.set(obj.getPath())

        v = self.projLocation.get().strip()
        path = None
        if v:
            v = os.path.dirname(v)
            if os.path.exists(v):
                path = v
        if not path:
            path = self.projectsPath

        browser = FileBrowserWindow("Browsing",
                                    self,
                                    path=path,
                                    onSelect=onSelect)
        browser.show()

    def _select(self):
        projName = self.projName.get().strip()
        projLocation = self.projLocation.get().strip()

        # Validate that project name is not empty
        if not projName:
            showError("Validation error", "Project name is empty", self.root)
        # Validate that project location is not empty
        elif not projLocation:
            showError("Validation error", "Project location is empty",
                      self.root)
        # Validate that project location exists
        elif not os.path.exists(projLocation):
            showError("Validation error", "Project location does not exist",
                      self.root)
        # Validate that project location is a directory
        elif not os.path.isdir(projLocation):
            showError("Validation error",
                      "Project location is not a directory", self.root)
        # Validate that project path (location + name) ddoes not exists
        elif os.path.exists(os.path.join(projLocation, projName)):
            showError("Validation error", "Project path already exists",
                      self.root)
        else:
            self.parent.createNewProject(projName, projLocation)
            self.close()
Exemplo n.º 5
0
    def __init__(self, title, parent=None, weight=True, minsize=(400, 150),
                 icon="scipion_bn.xbm", **args):
        """
         We assume the parent should be ProjectsView
        """
        Window.__init__(self, title, parent.windows, weight=weight,
                        icon=icon, minsize=minsize, enableQueue=True)
        self.root['background'] = 'white'
        self.parent = parent
        # Dirty hack, need to add a slash for the explorer to pick up the right default path.
        self.projectsPath = getHomePath()+"/"
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        self.projName = tk.StringVar()
        self.projName.set('')

        self.searchLocation = tk.StringVar()
        self.searchLocation.set('')

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=1)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news',
                       padx=5, pady=5)

        # Path explorer
        labelProjectLocation = tk.Label(content, text="Project location", bg='white', bd=0)
        labelProjectLocation.grid(row=0, column=0, sticky='nw', padx=5, pady=5)

        self.entryBrowse = tk.Entry(content, bg=cfgEntryBgColor, width=40, textvariable=self.projLocation)
        self.entryBrowse.grid(row=0, column=1, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(content, 'Browse', Icon.ACTION_BROWSE, highlightthickness=0,
                                    command=self._browseProjectLocation)
        self.btnBrowse.grid(row=0, column=2, sticky='e', padx=5, pady=5)

        # Copy files check
        labelCheck = tk.Label(content, text="Copy project", bg='white', borderwidth=0)
        labelCheck.grid(row=1, column=0, sticky='nw', padx=5, pady=5)

        self.tkCheckVar = tk.IntVar()
        btnCheck = tk.Checkbutton(content, variable=self.tkCheckVar, highlightthickness=0, activebackground='white',
                                  bg='white', bd=0)
        btnCheck.grid(row=1, column=1, sticky='nw', padx=0, pady=5)

        btnCopyHelp = IconButton(content, Message.LABEL_BUTTON_HELP, Icon.ACTION_HELP, highlightthickness=0,
             command=lambda: self.showInfo('If checked, \"Project location\" will be copied. Otherwise a soft link to it will be created.'))
        btnCopyHelp.grid(row=1, column=3, sticky='e', padx=2, pady=2)

        # Project name
        labelName = tk.Label(content, text='Project name (Optional)', bg='white', bd=0)
        labelName.grid(row=2, column=0, sticky='nw', padx=5, pady=5)
        entryName = tk.Entry(content, bg='white', width=20, textvariable=self.projName)
        entryName.grid(row=2, column=1, sticky='nw', padx=5, pady=5)

        # Path to search for raw data and restore broken links.
        labelSearchLocation = tk.Label(content, text="Raw files location (Optional)", bg='white', bd=0)
        labelSearchLocation.grid(row=3, column=0, sticky='nw', padx=5, pady=5)

        self.entrySearchLocation = tk.Entry(content, bg='white', width=40, textvariable=self.searchLocation)
        self.entrySearchLocation.grid(row=3, column=1, sticky='nw', padx=5, pady=5)
        self.btnSearch = IconButton(content, 'Browse', Icon.ACTION_BROWSE, highlightthickness=0, command=self._browseSearchLocation)
        self.btnSearch.grid(row=3, column=2, sticky='e', padx=5, pady=5)
        btnSearchHelp = IconButton(content, Message.LABEL_BUTTON_HELP, Icon.ACTION_HELP, highlightthickness=0,
             command=lambda: self.showInfo('Optional: Folder where raw files, binaries (movies, migcrographs,..) can be found. Used to repair broken links.'))
        btnSearchHelp.grid(row=3, column=3, sticky='e', padx=2, pady=2)

        self.initial_focus = entryName
        btnCheck.select()

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=4, column=0, sticky='sew', padx=5, pady=(0, 5), columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame, 'Import', Icon.BUTTON_SELECT, command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame, 'Cancel', Icon.BUTTON_CANCEL, command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)
Exemplo n.º 6
0
class ProjectImportWindow(Window):
    """ Windows to import a project. """
    def __init__(self, title, parent=None, weight=True, minsize=(400, 150),
                 icon="scipion_bn.xbm", **args):
        """
         We assume the parent should be ProjectsView
        """
        Window.__init__(self, title, parent.windows, weight=weight,
                        icon=icon, minsize=minsize, enableQueue=True)
        self.root['background'] = 'white'
        self.parent = parent
        # Dirty hack, need to add a slash for the explorer to pick up the right default path.
        self.projectsPath = getHomePath()+"/"
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        self.projName = tk.StringVar()
        self.projName.set('')

        self.searchLocation = tk.StringVar()
        self.searchLocation.set('')

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=1)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news',
                       padx=5, pady=5)

        # Path explorer
        labelProjectLocation = tk.Label(content, text="Project location", bg='white', bd=0)
        labelProjectLocation.grid(row=0, column=0, sticky='nw', padx=5, pady=5)

        self.entryBrowse = tk.Entry(content, bg=cfgEntryBgColor, width=40, textvariable=self.projLocation)
        self.entryBrowse.grid(row=0, column=1, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(content, 'Browse', Icon.ACTION_BROWSE, highlightthickness=0,
                                    command=self._browseProjectLocation)
        self.btnBrowse.grid(row=0, column=2, sticky='e', padx=5, pady=5)

        # Copy files check
        labelCheck = tk.Label(content, text="Copy project", bg='white', borderwidth=0)
        labelCheck.grid(row=1, column=0, sticky='nw', padx=5, pady=5)

        self.tkCheckVar = tk.IntVar()
        btnCheck = tk.Checkbutton(content, variable=self.tkCheckVar, highlightthickness=0, activebackground='white',
                                  bg='white', bd=0)
        btnCheck.grid(row=1, column=1, sticky='nw', padx=0, pady=5)

        btnCopyHelp = IconButton(content, Message.LABEL_BUTTON_HELP, Icon.ACTION_HELP, highlightthickness=0,
             command=lambda: self.showInfo('If checked, \"Project location\" will be copied. Otherwise a soft link to it will be created.'))
        btnCopyHelp.grid(row=1, column=3, sticky='e', padx=2, pady=2)

        # Project name
        labelName = tk.Label(content, text='Project name (Optional)', bg='white', bd=0)
        labelName.grid(row=2, column=0, sticky='nw', padx=5, pady=5)
        entryName = tk.Entry(content, bg='white', width=20, textvariable=self.projName)
        entryName.grid(row=2, column=1, sticky='nw', padx=5, pady=5)

        # Path to search for raw data and restore broken links.
        labelSearchLocation = tk.Label(content, text="Raw files location (Optional)", bg='white', bd=0)
        labelSearchLocation.grid(row=3, column=0, sticky='nw', padx=5, pady=5)

        self.entrySearchLocation = tk.Entry(content, bg='white', width=40, textvariable=self.searchLocation)
        self.entrySearchLocation.grid(row=3, column=1, sticky='nw', padx=5, pady=5)
        self.btnSearch = IconButton(content, 'Browse', Icon.ACTION_BROWSE, highlightthickness=0, command=self._browseSearchLocation)
        self.btnSearch.grid(row=3, column=2, sticky='e', padx=5, pady=5)
        btnSearchHelp = IconButton(content, Message.LABEL_BUTTON_HELP, Icon.ACTION_HELP, highlightthickness=0,
             command=lambda: self.showInfo('Optional: Folder where raw files, binaries (movies, migcrographs,..) can be found. Used to repair broken links.'))
        btnSearchHelp.grid(row=3, column=3, sticky='e', padx=2, pady=2)

        self.initial_focus = entryName
        btnCheck.select()

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=4, column=0, sticky='sew', padx=5, pady=(0, 5), columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame, 'Import', Icon.BUTTON_SELECT, command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame, 'Cancel', Icon.BUTTON_CANCEL, command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)

    def _browseProjectLocation(self, e=None):
        self._browsePath(self.projLocation)

    def _browseSearchLocation(self, e=None):
        self._browsePath(self.searchLocation)

    def _browsePath(self, location):
        def onSelect(obj):
            location.set(obj.getPath())

        v = location.get().strip()
        path = None
        if v:
            v = os.path.dirname(v)
            if os.path.exists(v):
                path = v
        if not path:
            path = self.projectsPath

        browser = FileBrowserWindow("Browsing",
                                    self, path=path,
                                    onSelect=onSelect,
                                    onlyFolders=True)
        browser.show()

    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_DBNAME)):
            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()
Exemplo n.º 7
0
class ProjectCreateWindow(Window):
    """ Windows to create a project. """
    def __init__(self, title, parent=None, weight=True, minsize=(400, 110),
                 icon="scipion_bn.xbm", **args):
        """
         We assume the parent should be of ProjectsView
        """
        Window.__init__(self, title, parent.windows, weight=weight,
                        icon=icon, minsize=minsize, enableQueue=True)
        self.root['background'] = 'white'

        self.parent = parent
        self.projectsPath = self.parent.manager.PROJECTS
        self.projName = tk.StringVar()
        self.projName.set('')
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=3)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news', padx=5, pady=5)

        #  Project name line
        labelName = tk.Label(content, text=Message.LABEL_PROJECT + ' name', bg='white', bd=0)
        labelName.grid(row=0, sticky=tk.W, padx=5, pady=5)
        entryName = tk.Entry(content, bg=cfgEntryBgColor, width=20, textvariable=self.projName)
        entryName.grid(row=0, column=1, columnspan=2, sticky=tk.W, padx=5, pady=5)

        # Project location line
        labelLocation = tk.Label(content, text=Message.LABEL_PROJECT + ' location', bg='white', bd=0)
        labelLocation.grid(row=1, column=0, sticky='nw', padx=5, pady=5)

        self.entryBrowse = tk.Entry(content, bg=cfgEntryBgColor, width=40, textvariable=self.projLocation)
        self.entryBrowse.grid(row=1, column=1, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(content, 'Browse', Icon.ACTION_BROWSE, highlightthickness=0, command=self._browsePath)
        self.btnBrowse.grid(row=1, column=2, sticky='e', padx=5, pady=5)

        self.initial_focus = entryName

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=2, column=0, sticky='sew', padx=5, pady=(0, 5), columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame, 'Create', Icon.BUTTON_SELECT, command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame, 'Cancel', Icon.BUTTON_CANCEL, command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)

    def _browsePath(self, e=None):
        def onSelect(obj):
            self.projLocation.set(obj.getPath())

        v = self.projLocation.get().strip()
        path = None
        if v:
            v = os.path.dirname(v)
            if os.path.exists(v):
                path = v
        if not path:
            path = self.projectsPath

        browser = FileBrowserWindow("Browsing", self, path=path, onSelect=onSelect, onlyFolders=True)
        browser.show()

    def _select(self):
        projName = self.projName.get().strip()
        projLocation = self.projLocation.get().strip()

        # Validate that project name is not empty
        if not projName:
            showError("Validation error", "Project name is empty", self.root)
        # Validate that project location is not empty
        elif not projLocation:
            showError("Validation error", "Project location is empty", self.root)
        # Validate that project location exists
        elif not os.path.exists(projLocation):
            showError("Validation error", "Project location does not exist", self.root)
        # Validate that project location is a directory
        elif not os.path.isdir(projLocation):
            showError("Validation error", "Project location is not a directory", self.root)
        # Validate that project path (location + name) ddoes not exists
        elif os.path.exists(os.path.join(projLocation, projName)):
            showError("Validation error", "Project path already exists", self.root)
        else:
            self.parent.createNewProject(projName, projLocation)
            self.close()
Exemplo n.º 8
0
class ProjectCreateWindow(Window):
    """ Windows to create a project. """
    def __init__(self,
                 title,
                 parent=None,
                 weight=True,
                 minsize=(400, 110),
                 icon=Icon.SCIPION_ICON,
                 **args):
        """
         We assume the parent should be of ProjectsView
        """
        Window.__init__(self,
                        title,
                        parent.windows,
                        weight=weight,
                        icon=icon,
                        minsize=minsize,
                        enableQueue=True)
        self.root['background'] = 'white'

        self.parent = parent
        self.projectsPath = self.parent.manager.PROJECTS
        self.projName = tk.StringVar()
        self.projName.set('')
        self.projLocation = tk.StringVar()
        self.projLocation.set(self.projectsPath)

        content = tk.Frame(self.root)
        content.columnconfigure(0, weight=1)
        content.columnconfigure(1, weight=3)
        content.config(bg='white')
        content.grid(row=0, column=0, sticky='news', padx=5, pady=5)

        #  Project name line
        labelName = tk.Label(content,
                             text=Message.LABEL_PROJECT + ' name',
                             bg='white',
                             bd=0)
        labelName.grid(row=0, sticky=tk.W, padx=5, pady=5)
        entryName = tk.Entry(content,
                             bg=cfgEntryBgColor,
                             width=20,
                             textvariable=self.projName)
        entryName.grid(row=0,
                       column=1,
                       columnspan=2,
                       sticky=tk.W,
                       padx=5,
                       pady=5)

        # Project location line
        labelLocation = tk.Label(content,
                                 text=Message.LABEL_PROJECT + ' location',
                                 bg='white',
                                 bd=0)
        labelLocation.grid(row=1, column=0, sticky='nw', padx=5, pady=5)

        self.entryBrowse = tk.Entry(content,
                                    bg=cfgEntryBgColor,
                                    width=40,
                                    textvariable=self.projLocation)
        self.entryBrowse.grid(row=1, column=1, sticky='nw', padx=5, pady=5)
        self.btnBrowse = IconButton(content,
                                    'Browse',
                                    Icon.ACTION_BROWSE,
                                    highlightthickness=0,
                                    command=self._browsePath)
        self.btnBrowse.grid(row=1, column=2, sticky='e', padx=5, pady=5)

        self.initial_focus = entryName
        self.initial_focus.focus()

        btnFrame = tk.Frame(content)
        btnFrame.columnconfigure(0, weight=1)
        btnFrame.grid(row=2,
                      column=0,
                      sticky='sew',
                      padx=5,
                      pady=(0, 5),
                      columnspan=2)
        btnFrame.config(bg='white')

        # Create buttons
        btnSelect = HotButton(btnFrame,
                              'Create',
                              Icon.BUTTON_SELECT,
                              command=self._select)
        btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
        btnCancel = Button(btnFrame,
                           'Cancel',
                           Icon.BUTTON_CANCEL,
                           command=self.close)
        btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)

    def _browsePath(self, e=None):
        def onSelect(obj):
            self.projLocation.set(obj.getPath())

        v = self.projLocation.get().strip()
        path = None
        if v:
            v = os.path.dirname(v)
            if os.path.exists(v):
                path = v
        if not path:
            path = self.projectsPath

        browser = FileBrowserWindow("Browsing",
                                    self,
                                    path=path,
                                    onSelect=onSelect,
                                    onlyFolders=True)
        browser.show()

    def _select(self):
        projName = self.projName.get().strip()
        projLocation = self.projLocation.get().strip()

        # Validate that project name is not empty
        if not projName:
            showError("Validation error", "Project name is empty", self.root)
        # Validate that project location is not empty
        elif not projLocation:
            showError("Validation error", "Project location is empty",
                      self.root)
        # Validate that project location exists
        elif not os.path.exists(projLocation):
            showError("Validation error", "Project location does not exist",
                      self.root)
        # Validate that project location is a directory
        elif not os.path.isdir(projLocation):
            showError("Validation error",
                      "Project location is not a directory", self.root)
        # Validate that project path (location + name) ddoes not exists
        elif os.path.exists(os.path.join(projLocation, projName)):
            showError("Validation error", "Project path already exists",
                      self.root)
        else:
            self.parent.createNewProject(projName, projLocation)
            self.close()