scipion-pyworkflow 3.11.0__py3-none-any.whl → 3.11.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. pyworkflow/apps/__init__.py +29 -0
  2. pyworkflow/apps/pw_manager.py +37 -0
  3. pyworkflow/apps/pw_plot.py +51 -0
  4. pyworkflow/apps/pw_project.py +130 -0
  5. pyworkflow/apps/pw_protocol_list.py +143 -0
  6. pyworkflow/apps/pw_protocol_run.py +51 -0
  7. pyworkflow/apps/pw_run_tests.py +268 -0
  8. pyworkflow/apps/pw_schedule_run.py +322 -0
  9. pyworkflow/apps/pw_sleep.py +37 -0
  10. pyworkflow/apps/pw_sync_data.py +440 -0
  11. pyworkflow/apps/pw_viewer.py +78 -0
  12. pyworkflow/constants.py +1 -1
  13. pyworkflow/gui/__init__.py +36 -0
  14. pyworkflow/gui/browser.py +768 -0
  15. pyworkflow/gui/canvas.py +1190 -0
  16. pyworkflow/gui/dialog.py +981 -0
  17. pyworkflow/gui/form.py +2727 -0
  18. pyworkflow/gui/graph.py +247 -0
  19. pyworkflow/gui/graph_layout.py +271 -0
  20. pyworkflow/gui/gui.py +571 -0
  21. pyworkflow/gui/matplotlib_image.py +233 -0
  22. pyworkflow/gui/plotter.py +247 -0
  23. pyworkflow/gui/project/__init__.py +25 -0
  24. pyworkflow/gui/project/base.py +193 -0
  25. pyworkflow/gui/project/constants.py +139 -0
  26. pyworkflow/gui/project/labels.py +205 -0
  27. pyworkflow/gui/project/project.py +491 -0
  28. pyworkflow/gui/project/searchprotocol.py +240 -0
  29. pyworkflow/gui/project/searchrun.py +181 -0
  30. pyworkflow/gui/project/steps.py +171 -0
  31. pyworkflow/gui/project/utils.py +332 -0
  32. pyworkflow/gui/project/variables.py +179 -0
  33. pyworkflow/gui/project/viewdata.py +472 -0
  34. pyworkflow/gui/project/viewprojects.py +519 -0
  35. pyworkflow/gui/project/viewprotocols.py +2141 -0
  36. pyworkflow/gui/project/viewprotocols_extra.py +562 -0
  37. pyworkflow/gui/text.py +774 -0
  38. pyworkflow/gui/tooltip.py +185 -0
  39. pyworkflow/gui/tree.py +684 -0
  40. pyworkflow/gui/widgets.py +307 -0
  41. pyworkflow/mapper/__init__.py +26 -0
  42. pyworkflow/mapper/mapper.py +226 -0
  43. pyworkflow/mapper/sqlite.py +1583 -0
  44. pyworkflow/mapper/sqlite_db.py +145 -0
  45. pyworkflow/object.py +1 -0
  46. pyworkflow/plugin.py +4 -4
  47. pyworkflow/project/__init__.py +31 -0
  48. pyworkflow/project/config.py +454 -0
  49. pyworkflow/project/manager.py +180 -0
  50. pyworkflow/project/project.py +2095 -0
  51. pyworkflow/project/usage.py +165 -0
  52. pyworkflow/protocol/__init__.py +38 -0
  53. pyworkflow/protocol/bibtex.py +48 -0
  54. pyworkflow/protocol/constants.py +87 -0
  55. pyworkflow/protocol/executor.py +515 -0
  56. pyworkflow/protocol/hosts.py +318 -0
  57. pyworkflow/protocol/launch.py +277 -0
  58. pyworkflow/protocol/package.py +42 -0
  59. pyworkflow/protocol/params.py +781 -0
  60. pyworkflow/protocol/protocol.py +2712 -0
  61. pyworkflow/resources/protlabels.xcf +0 -0
  62. pyworkflow/resources/sprites.png +0 -0
  63. pyworkflow/resources/sprites.xcf +0 -0
  64. pyworkflow/template.py +1 -1
  65. pyworkflow/tests/__init__.py +29 -0
  66. pyworkflow/tests/test_utils.py +25 -0
  67. pyworkflow/tests/tests.py +342 -0
  68. pyworkflow/utils/__init__.py +38 -0
  69. pyworkflow/utils/dataset.py +414 -0
  70. pyworkflow/utils/echo.py +104 -0
  71. pyworkflow/utils/graph.py +169 -0
  72. pyworkflow/utils/log.py +293 -0
  73. pyworkflow/utils/path.py +528 -0
  74. pyworkflow/utils/process.py +154 -0
  75. pyworkflow/utils/profiler.py +92 -0
  76. pyworkflow/utils/progressbar.py +154 -0
  77. pyworkflow/utils/properties.py +618 -0
  78. pyworkflow/utils/reflection.py +129 -0
  79. pyworkflow/utils/utils.py +880 -0
  80. pyworkflow/utils/which.py +229 -0
  81. pyworkflow/webservices/__init__.py +8 -0
  82. pyworkflow/webservices/config.py +8 -0
  83. pyworkflow/webservices/notifier.py +152 -0
  84. pyworkflow/webservices/repository.py +59 -0
  85. pyworkflow/webservices/workflowhub.py +86 -0
  86. pyworkflowtests/tests/__init__.py +0 -0
  87. pyworkflowtests/tests/test_canvas.py +72 -0
  88. pyworkflowtests/tests/test_domain.py +45 -0
  89. pyworkflowtests/tests/test_logs.py +74 -0
  90. pyworkflowtests/tests/test_mappers.py +392 -0
  91. pyworkflowtests/tests/test_object.py +507 -0
  92. pyworkflowtests/tests/test_project.py +42 -0
  93. pyworkflowtests/tests/test_protocol_execution.py +146 -0
  94. pyworkflowtests/tests/test_protocol_export.py +78 -0
  95. pyworkflowtests/tests/test_protocol_output.py +158 -0
  96. pyworkflowtests/tests/test_streaming.py +47 -0
  97. pyworkflowtests/tests/test_utils.py +210 -0
  98. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.2.dist-info}/METADATA +2 -2
  99. scipion_pyworkflow-3.11.2.dist-info/RECORD +162 -0
  100. scipion_pyworkflow-3.11.0.dist-info/RECORD +0 -71
  101. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.2.dist-info}/WHEEL +0 -0
  102. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.2.dist-info}/entry_points.txt +0 -0
  103. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.2.dist-info}/licenses/LICENSE.txt +0 -0
  104. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,519 @@
1
+ # **************************************************************************
2
+ # *
3
+ # * Authors: J.M. De la Rosa Trevin (delarosatrevin@scilifelab.se) [1]
4
+ # *
5
+ # * [1] SciLifeLab, Stockholm University
6
+ # *
7
+ # * This program is free software: you can redistribute it and/or modify
8
+ # * it under the terms of the GNU General Public License as published by
9
+ # * the Free Software Foundation, either version 3 of the License, or
10
+ # * (at your option) any later version.
11
+ # *
12
+ # * This program is distributed in the hope that it will be useful,
13
+ # * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # * GNU General Public License for more details.
16
+ # *
17
+ # * You should have received a copy of the GNU General Public License
18
+ # * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ # *
20
+ # * All comments concerning this program package may be sent to the
21
+ # * e-mail address 'scipion@cnb.csic.es'
22
+ # *
23
+ # **************************************************************************
24
+ import datetime
25
+ import logging
26
+
27
+ REFRESH_WAIT_SEC = 60
28
+ logger = logging.getLogger(__name__)
29
+
30
+ import os
31
+ import tkinter as tk
32
+ import tkinter.font as tkFont
33
+
34
+ import pyworkflow as pw
35
+ from pyworkflow.project import Project
36
+ from pyworkflow.utils.utils import prettyDate, prettyTime
37
+ from pyworkflow.utils.path import getHomePath
38
+
39
+ from pyworkflow.project import Manager
40
+ from pyworkflow.gui.text import TaggedText
41
+ from pyworkflow.gui.dialog import askString, askYesNo, showError
42
+
43
+ from pyworkflow.gui import Message, Window, cfgEntryBgColor, ToolTip
44
+ from pyworkflow.gui.browser import FileBrowserWindow
45
+ from pyworkflow.gui.widgets import IconButton, HotButton, Button
46
+ from pyworkflow.utils.properties import Icon
47
+
48
+
49
+ class ProjectsView(tk.Frame):
50
+ _PROJ_CONTAINER = "projectsframe"
51
+
52
+ def __init__(self, parent, windows, **args):
53
+ tk.Frame.__init__(self, parent, bg=pw.Config.SCIPION_BG_COLOR, **args)
54
+ self.windows = windows
55
+ self.manager = windows.manager
56
+ self.root = windows.root
57
+ self.lastLoad = None
58
+
59
+ # Bind to root "focus in"
60
+ self.root.bind("<FocusIn>", self._onWindowFocusIn)
61
+ smallSize = pw.Config.SCIPION_FONT_SIZE - 2
62
+ fontName = pw.Config.SCIPION_FONT_NAME
63
+
64
+ self.projNameFont = tkFont.Font(size=pw.Config.SCIPION_FONT_SIZE+2, family=fontName,
65
+ weight='bold')
66
+ self.projDateFont = tkFont.Font(size=smallSize, family=fontName)
67
+ self.projDelFont = tkFont.Font(size=smallSize, family=fontName,
68
+ weight='bold')
69
+ self.manager = Manager()
70
+
71
+ self.filter = tk.StringVar()
72
+ self.filterBox = None
73
+ self.addActionsFrame()
74
+
75
+ self.columnconfigure(0, weight=1)
76
+ self.rowconfigure(1, weight=1)
77
+ text = TaggedText(self, width=40, height=15, bd=0, bg=pw.Config.SCIPION_BG_COLOR)
78
+ text.grid(row=1, columnspan=2, column=0, sticky='news')
79
+ text.setReadOnly(True)
80
+ self.text = text
81
+ self.filterBox.focus_set()
82
+
83
+ # Content load happens automatically _onWindowFocusIn
84
+
85
+ def _onWindowFocusIn(self, event):
86
+ """ Refresh on windows get focus """
87
+ if event.widget == self.root:
88
+ # Get the delta from the last time refreshed
89
+ delta = REFRESH_WAIT_SEC if self.lastLoad is None else (datetime.datetime.now() - self.lastLoad).seconds
90
+ if delta >= REFRESH_WAIT_SEC:
91
+ self.createProjectList()
92
+
93
+ def addActionsFrame(self):
94
+ """ Add the "toolbar" for actions like create project, import
95
+ project or filter"""
96
+ # Add the create project button
97
+ bg = pw.Config.SCIPION_BG_COLOR
98
+ btnFrame = tk.Frame(self, bg=bg)
99
+ btn = HotButton(btnFrame, text=Message.LABEL_CREATE_PROJECT,
100
+ font=self.projNameFont,
101
+ command=self._onCreateProject)
102
+ btn.grid(row=0, column=0, sticky='nw', padx=10, pady=10)
103
+ # Add the Import project button
104
+ btn = Button(btnFrame, text=Message.LABEL_IMPORT_PROJECT,
105
+ font=self.projNameFont,
106
+ command=self._onImportProject)
107
+ btn.grid(row=0, column=1, sticky='nw', padx=10, pady=10)
108
+ btnFrame.grid(row=0, column=0, sticky='nw')
109
+
110
+ # Add a filter box
111
+ # Add the Import project button
112
+ btn = tk.Label(btnFrame, bg=bg, text="Filter:", font=self.projNameFont)
113
+ btn.grid(row=0, column=2, sticky='nse', padx=10, pady=10)
114
+ self.filterBox = tk.Entry(btnFrame, font=self.projNameFont, textvariable=self.filter)
115
+ self.filterBox.grid(row=0, column=3, sticky='ne', padx=10, pady=12)
116
+ self.filterBox.bind('<Return>', self._onFilter)
117
+ self.filterBox.bind('<KP_Enter>', self._onFilter)
118
+ self.filterBox.bind("<F5>", self.createProjectList)
119
+ ToolTip(self.filterBox, "Return/enter to filter. F5 to refresh the list")
120
+
121
+
122
+ def createProjectList(self, event=None):
123
+ """Load the list of projects"""
124
+
125
+ self.lastLoad = datetime.datetime.now()
126
+ r = 0
127
+ text = self.text
128
+ text.setReadOnly(False)
129
+ text.clear()
130
+ parent = tk.Frame(text, bg=pw.Config.SCIPION_BG_COLOR, name=self._PROJ_CONTAINER)
131
+ parent.columnconfigure(0, weight=1)
132
+ colors = [pw.Config.SCIPION_BG_COLOR, '#EAEBFF']
133
+ for i, p in enumerate(self.manager.listProjects()):
134
+ try:
135
+ # Add creation time to project info
136
+ # Add if it's a link
137
+ p.index = "index%s" % i
138
+
139
+ # Consider the filter
140
+ if not self._doesProjectMatchFilter(p):
141
+ continue
142
+
143
+ frame = self.createProjectLabel(parent, p, color=colors[i % 2])
144
+ frame.grid(row=r, column=0, padx=10, pady=5, sticky='new')
145
+ r += 1
146
+
147
+ except Exception as ex:
148
+ logger.error("Couldn't load project %s" % p.getName(), exc_info=True)
149
+
150
+ text.window_create(tk.INSERT, window=parent)
151
+ text.bindWidget(parent)
152
+ text.setReadOnly(True)
153
+
154
+ def createProjectLabel(self, parent, projInfo, color):
155
+ frame = tk.Frame(parent, bg=color, name=projInfo.index)
156
+ # ROW1
157
+ # Project name
158
+ label = tk.Label(frame, text=projInfo.projName, anchor='nw', bg=color,
159
+ justify=tk.LEFT, font=self.projNameFont, cursor='hand1', width=50)
160
+ label.grid(row=0, column=0, padx=2, pady=2, sticky='nw')
161
+ label.bind('<Button-1>', lambda e: self.openProject(projInfo.projName))
162
+
163
+ # ROW2
164
+ # Timestamp line
165
+ dateMsg = '%s%s %s%s' % (Message.LABEL_MODIFIED, prettyDate(projInfo.mTime),
166
+ Message.LABEL_CREATED, prettyTime(projInfo.cTime, time=False))
167
+ dateLabel = tk.Label(frame, text=dateMsg, font=self.projDateFont, bg=color)
168
+ dateLabel.grid(row=1, column=0, sticky='nw')
169
+ # Delete action
170
+ delLabel = tk.Label(frame, text=Message.LABEL_DELETE_PROJECT, font=self.projDelFont, bg=color, cursor='hand1')
171
+ delLabel.grid(row=1, column=1, padx=10)
172
+ delLabel.bind('<Button-1>', lambda e: self.deleteProject(projInfo))
173
+ # Rename action
174
+ mvLabel = tk.Label(frame, text=Message.LABEL_RENAME_PROJECT, font=self.projDelFont, bg=color, cursor='hand1')
175
+ mvLabel.grid(row=1, column=2)
176
+ mvLabel.bind('<Button-1>', lambda e: self.renameProject(projInfo.projName))
177
+
178
+ # ROW3
179
+ if projInfo.isLink():
180
+ linkMsg = 'link --> ' + projInfo.realPath()
181
+ lblLink = tk.Label(frame, text=linkMsg, font=self.projDateFont, bg=color, fg='grey', justify=tk.LEFT)
182
+ lblLink.grid(row=2, column=0, columnspan=3, sticky='w')
183
+
184
+ return frame
185
+
186
+ def createNewProject(self, projName, projLocation):
187
+ proj = self.manager.createProject(projName, location=projLocation)
188
+ self.createProjectList()
189
+ self.openProject(proj.getShortName())
190
+
191
+ def _onCreateProject(self, e=None):
192
+ projWindow = ProjectCreateWindow("Create project", self)
193
+ projWindow.show()
194
+
195
+ def _onImportProject(self, e=None):
196
+ importProjWindow = ProjectImportWindow("Import project", self)
197
+ importProjWindow.show()
198
+
199
+ def _onFilter(self, e=None):
200
+ self.createProjectList()
201
+
202
+ def _setFocusToList(self, e=None):
203
+ self.text.focus_set()
204
+
205
+ def _doesProjectMatchFilter(self, project):
206
+ """ Returns true if the project matches the filter"""
207
+ # Lets' use the name anc creation date for now:
208
+ searchString = "~".join([project.getName().lower(),
209
+ prettyDate(project.mTime),
210
+ prettyTime(project.cTime, time=False)])
211
+
212
+ return self.filter.get().lower() in searchString
213
+
214
+ def importProject(self, projLocation, copyFiles, projName, searchLocation):
215
+
216
+ self.manager.importProject(projLocation, copyFiles, projName, searchLocation)
217
+ self.createProjectList()
218
+ self.openProject(projName)
219
+
220
+ def openProject(self, projName):
221
+ from subprocess import Popen
222
+ script = pw.join(pw.APPS, 'pw_project.py')
223
+ args=[pw.PYTHON, "-O", script, projName]
224
+
225
+ # Launcher is the ona calling this process. Since launcher does not deal
226
+ # with __debug__ we should use the variable in the config
227
+ if pw.Config.debugOn():
228
+ # If not optimizing code, remove -O
229
+ logger.warning(f"Launching project {projName} in debug mode.")
230
+ del args[1]
231
+
232
+ Popen(args)
233
+
234
+ def deleteProject(self, projInfo):
235
+
236
+ projName = projInfo.projName
237
+
238
+ if askYesNo(Message.TITLE_DELETE_PROJECT,
239
+ "Project *%s*. " % projName + Message.MESSAGE_DELETE_PROJECT, self.root):
240
+
241
+ logger.info("User agreed to delete project %s" % projName)
242
+ self.manager.deleteProject(projName)
243
+
244
+ #Delete the frame
245
+ self.text.children[self._PROJ_CONTAINER].children[projInfo.index].grid_forget()
246
+
247
+
248
+ def renameProject(self, projName):
249
+ newName = askString("Rename project %s" % projName, "Enter new name:", self.root)
250
+ if not newName or newName == projName:
251
+ return
252
+ if self.manager.hasProject(newName):
253
+ showError("Rename cancelled",
254
+ "Project name already exists: %s" % newName, self.root)
255
+ return
256
+ self.manager.renameProject(projName, newName)
257
+ self.createProjectList()
258
+
259
+
260
+ class ProjectCreateWindow(Window):
261
+ """ Windows to create a project. """
262
+
263
+ def __init__(self, title, parent=None, weight=True, minsize=(400, 110),
264
+ icon=Icon.SCIPION_ICON, **args):
265
+ """
266
+ We assume the parent should be of ProjectsView
267
+ """
268
+ Window.__init__(self, title, parent.windows, weight=weight,
269
+ icon=icon, minsize=minsize, enableQueue=True)
270
+ self.root['background'] = pw.Config.SCIPION_BG_COLOR
271
+
272
+ self.parent = parent
273
+ self.projectsPath = self.parent.manager.PROJECTS
274
+ self.projName = tk.StringVar()
275
+ self.projName.set('')
276
+ self.projLocation = tk.StringVar()
277
+ self.projLocation.set(self.projectsPath)
278
+
279
+ content = tk.Frame(self.root)
280
+ content.columnconfigure(0, weight=1)
281
+ content.columnconfigure(1, weight=3)
282
+ content.config(bg=pw.Config.SCIPION_BG_COLOR)
283
+ content.grid(row=0, column=0, sticky='news', padx=5, pady=5)
284
+
285
+ # Info line
286
+ labelInfo = tk.Label(content, text="Spaces will be replaced by underscores!", bg=pw.Config.SCIPION_BG_COLOR, bd=0)
287
+ labelInfo.grid(row=0, sticky=tk.W, padx=5, pady=5)
288
+ # Project name line
289
+ labelName = tk.Label(content, text=Message.LABEL_PROJECT + ' name', bg=pw.Config.SCIPION_BG_COLOR, bd=0)
290
+ labelName.grid(row=1, sticky=tk.W, padx=5, pady=5)
291
+ entryName = tk.Entry(content, bg=cfgEntryBgColor, width=20, textvariable=self.projName)
292
+ entryName.grid(row=1, column=1, columnspan=2, sticky=tk.EW, padx=5, pady=5)
293
+ entryName.bind("<Return>", self._create)
294
+ entryName.bind("<KP_Enter>", self._create)
295
+ # Project location line
296
+ labelLocation = tk.Label(content, text=Message.LABEL_PROJECT + ' location', bg=pw.Config.SCIPION_BG_COLOR, bd=0)
297
+ labelLocation.grid(row=2, column=0, sticky='nw', padx=5, pady=5)
298
+
299
+ self.entryBrowse = tk.Entry(content, bg=cfgEntryBgColor, width=40, textvariable=self.projLocation)
300
+ self.entryBrowse.grid(row=2, column=1, sticky='nw', padx=5, pady=5)
301
+ self.btnBrowse = IconButton(content, 'Browse', Icon.ACTION_BROWSE,
302
+ highlightthickness=0, command=self._browsePath)
303
+ self.btnBrowse.grid(row=2, column=2, sticky='e', padx=5, pady=5)
304
+
305
+ self.initial_focus = entryName
306
+ self.initial_focus.focus()
307
+
308
+ btnFrame = tk.Frame(content)
309
+ btnFrame.columnconfigure(0, weight=1)
310
+ btnFrame.grid(row=3, column=0, sticky='sew', padx=5, pady=(0, 5), columnspan=2)
311
+ btnFrame.config(bg=pw.Config.SCIPION_BG_COLOR)
312
+
313
+ # Create buttons
314
+ btnCreate = HotButton(btnFrame, 'Create', Icon.BUTTON_SELECT, command=self._create)
315
+ btnCreate.grid(row=0, column=0, sticky='e', padx=5, pady=5)
316
+ btnCancel = Button(btnFrame, 'Cancel', Icon.BUTTON_CANCEL, command=self.close)
317
+ btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)
318
+
319
+ def _browsePath(self, e=None):
320
+ def onSelect(obj):
321
+ self.projLocation.set(obj.getPath())
322
+
323
+ v = self.projLocation.get().strip()
324
+ path = None
325
+ if v:
326
+ v = os.path.dirname(v)
327
+ if os.path.exists(v):
328
+ path = v
329
+ if not path:
330
+ path = self.projectsPath
331
+
332
+ browser = FileBrowserWindow("Browsing", self, path=path, onSelect=onSelect, onlyFolders=True)
333
+ browser.show()
334
+
335
+ def _create(self, e=None):
336
+ projName = self.projName.get().strip()
337
+ projLocation = self.projLocation.get().strip()
338
+
339
+ # Validate that project name is not empty
340
+ if not projName:
341
+ showError("Validation error", "Project name is empty", self.root)
342
+ # Validate that project location is not empty
343
+ elif not projLocation:
344
+ showError("Validation error", "Project location is empty", self.root)
345
+ # Validate that project location exists
346
+ elif not os.path.exists(projLocation):
347
+ showError("Validation error", "Project location does not exist", self.root)
348
+ # Validate that project location is a directory
349
+ elif not os.path.isdir(projLocation):
350
+ showError("Validation error", "Project location is not a directory", self.root)
351
+ # Validate that project path (location + name) does not exists
352
+ elif os.path.exists(os.path.join(projLocation, projName)):
353
+ showError("Validation error", "Project path already exists", self.root)
354
+ else:
355
+ self.parent.createNewProject(projName, projLocation)
356
+ self.close()
357
+
358
+
359
+ class ProjectImportWindow(Window):
360
+ """ Windows to import a project. """
361
+
362
+ def __init__(self, title, parent=None, weight=True, minsize=(400, 150),
363
+ icon=Icon.SCIPION_ICON, **args):
364
+ """
365
+ We assume the parent should be ProjectsView
366
+ """
367
+ Window.__init__(self, title, parent.windows, weight=weight,
368
+ icon=icon, minsize=minsize, enableQueue=True)
369
+ self.root['background'] = pw.Config.SCIPION_BG_COLOR
370
+ self.parent = parent
371
+ # Dirty hack, need to add a slash for the explorer to pick up the right default path.
372
+ self.projectsPath = getHomePath() + "/"
373
+ self.projLocation = tk.StringVar()
374
+ self.projLocation.set(self.projectsPath)
375
+
376
+ self.projName = tk.StringVar()
377
+ self.projName.set('')
378
+
379
+ self.searchLocation = tk.StringVar()
380
+ self.searchLocation.set('')
381
+
382
+ content = tk.Frame(self.root)
383
+ content.columnconfigure(0, weight=1)
384
+ content.columnconfigure(1, weight=1)
385
+ content.config(bg=pw.Config.SCIPION_BG_COLOR)
386
+ content.grid(row=0, column=0, sticky='news',
387
+ padx=5, pady=5)
388
+
389
+ # Path explorer
390
+ labelProjectLocation = tk.Label(content, text="Project location", bg=pw.Config.SCIPION_BG_COLOR, bd=0)
391
+ labelProjectLocation.grid(row=0, column=0, sticky='nw', padx=5, pady=5)
392
+ # it seems tk.Entry does not uses default font...grrrr!!
393
+ self.entryBrowse = tk.Entry(content, bg=cfgEntryBgColor, width=40,
394
+ textvariable=self.projLocation, font=self.font)
395
+ self.entryBrowse.grid(row=0, column=1, sticky='nw', padx=5, pady=5)
396
+ self.btnBrowse = IconButton(content, 'Browse', Icon.ACTION_BROWSE, highlightthickness=0,
397
+ command=self._browseProjectLocation)
398
+ self.btnBrowse.grid(row=0, column=2, sticky='e', padx=5, pady=5)
399
+
400
+ # Copy files check
401
+ labelCheck = tk.Label(content, text="Copy project", bg=pw.Config.SCIPION_BG_COLOR, borderwidth=0)
402
+ labelCheck.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
403
+
404
+ self.tkCheckVar = tk.IntVar()
405
+ btnCheck = tk.Checkbutton(content, variable=self.tkCheckVar, highlightthickness=0, activebackground=pw.Config.SCIPION_BG_COLOR,
406
+ bg=pw.Config.SCIPION_BG_COLOR, bd=0)
407
+ btnCheck.grid(row=1, column=1, sticky='nw', padx=0, pady=5)
408
+
409
+ btnCopyHelp = IconButton(content, Message.LABEL_BUTTON_HELP, Icon.ACTION_HELP, highlightthickness=0,
410
+ command=lambda: self.showInfo(
411
+ 'If checked, \"Project location\" will be copied. Otherwise a soft link to it will be created.'))
412
+ btnCopyHelp.grid(row=1, column=3, sticky='e', padx=2, pady=2)
413
+
414
+ # Project name
415
+ labelName = tk.Label(content, text='Project name (Optional)', bg=pw.Config.SCIPION_BG_COLOR, bd=0)
416
+ labelName.grid(row=2, column=0, sticky='nw', padx=5, pady=5)
417
+ entryName = tk.Entry(content, bg='white', width=20, textvariable=self.projName, font=self.font)
418
+ entryName.grid(row=2, column=1, sticky='nw', padx=5, pady=5)
419
+
420
+ # Path to search for raw data and restore broken links.
421
+ labelSearchLocation = tk.Label(content, text="Raw files location (Optional)", bg=pw.Config.SCIPION_BG_COLOR, bd=0)
422
+ labelSearchLocation.grid(row=3, column=0, sticky='nw', padx=5, pady=5)
423
+
424
+ self.entrySearchLocation = tk.Entry(content, bg='white', width=40,
425
+ textvariable=self.searchLocation, font=self.font)
426
+ self.entrySearchLocation.grid(row=3, column=1, sticky='nw', padx=5, pady=5)
427
+ self.btnSearch = IconButton(content, 'Browse', Icon.ACTION_BROWSE,
428
+ highlightthickness=0, command=self._browseSearchLocation)
429
+ self.btnSearch.grid(row=3, column=2, sticky='e', padx=5, pady=5)
430
+ btnSearchHelp = IconButton(content, Message.LABEL_BUTTON_HELP, Icon.ACTION_HELP, highlightthickness=0,
431
+ command=lambda: self.showInfo(
432
+ 'Optional: Folder where raw files, binaries (movies, micrographs,..) can be found. Used to repair broken links.'))
433
+ btnSearchHelp.grid(row=3, column=3, sticky='e', padx=2, pady=2)
434
+
435
+ self.initial_focus = entryName
436
+ self.initial_focus.focus()
437
+ btnCheck.select()
438
+
439
+ btnFrame = tk.Frame(content)
440
+ btnFrame.columnconfigure(0, weight=1)
441
+ btnFrame.grid(row=4, column=0, sticky='sew', padx=5, pady=(0, 5), columnspan=2)
442
+ btnFrame.config(bg=pw.Config.SCIPION_BG_COLOR)
443
+
444
+ # Create buttons
445
+ btnSelect = HotButton(btnFrame, 'Import', Icon.BUTTON_SELECT, command=self._select)
446
+ btnSelect.grid(row=0, column=0, sticky='e', padx=5, pady=5)
447
+ btnCancel = Button(btnFrame, 'Cancel', Icon.BUTTON_CANCEL, command=self.close)
448
+ btnCancel.grid(row=0, column=1, sticky='e', padx=5, pady=5)
449
+
450
+ def _browseProjectLocation(self, e=None):
451
+ self._browsePath(self.projLocation)
452
+
453
+ def _browseSearchLocation(self, e=None):
454
+ self._browsePath(self.searchLocation)
455
+
456
+ def _browsePath(self, location):
457
+ def onSelect(obj):
458
+ location.set(obj.getPath())
459
+
460
+ v = location.get().strip()
461
+ path = None
462
+ if v:
463
+ v = os.path.dirname(v)
464
+ if os.path.exists(v):
465
+ path = v
466
+ if not path:
467
+ path = self.projectsPath
468
+
469
+ browser = FileBrowserWindow("Browsing",
470
+ self, path=path,
471
+ onSelect=onSelect,
472
+ onlyFolders=True)
473
+ browser.show()
474
+
475
+ def _select(self):
476
+ projName = self.projName.get().strip()
477
+ projLocation = self.projLocation.get().strip()
478
+ copyFiles = self.tkCheckVar.get() != 0
479
+ searchLocation = self.searchLocation.get().strip()
480
+ manager = Manager()
481
+
482
+ # If project name is empty we will use the same name as the source
483
+ if not projName:
484
+ projName = os.path.basename(projLocation)
485
+
486
+ errorMessage = ''
487
+
488
+ # Validate that project location is not empty
489
+ if not projLocation:
490
+ errorMessage = "Project location is empty\n"
491
+
492
+ # Validate that project location exists
493
+ elif not os.path.exists(projLocation):
494
+ errorMessage += "Project location does not exist\n"
495
+
496
+ # Validate that project location is a directory
497
+ elif not os.path.isdir(projLocation):
498
+ errorMessage += "Project location is not a directory\n"
499
+ # Validate that the project location is a scipion project folder
500
+ elif not os.path.exists(os.path.join(projLocation, Project.getDbName())):
501
+ errorMessage += "Project location doesn't look like a scipion folder\n"
502
+
503
+ # Validate that there isn't already a project with the same name
504
+ if manager.hasProject(projName):
505
+ errorMessage += "Project [%s] already exists\n" % projName
506
+
507
+ # Validate that search location exists
508
+ if searchLocation:
509
+ if not os.path.exists(searchLocation):
510
+ errorMessage += "Raw files location does not exist\n"
511
+ # Validate that search location is a directory
512
+ elif not os.path.isdir(searchLocation):
513
+ errorMessage += "Raw files location is not a directory\n"
514
+
515
+ if errorMessage:
516
+ showError("Validation error", errorMessage, self.root)
517
+ else:
518
+ self.parent.importProject(projLocation, copyFiles, projName, searchLocation)
519
+ self.close()