1
1
# -*- coding: utf-8 -*-
2
2
"""The tutorial of straditize
3
3
4
- This module contains a guided tour through straditize"""
4
+ This module contains a guided tour to get started with straditize
5
+
6
+ **Disclaimer**
7
+
8
+ Copyright (C) 2018-2019 Philipp S. Sommer
9
+
10
+ This program is free software: you can redistribute it and/or modify
11
+ it under the terms of the GNU General Public License as published by
12
+ the Free Software Foundation, either version 3 of the License, or
13
+ (at your option) any later version.
14
+
15
+ This program is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU General Public License for more details.
19
+
20
+ You should have received a copy of the GNU General Public License
21
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
22
+ """
5
23
import os .path as osp
6
24
import shutil
7
25
import glob
16
34
17
35
18
36
class TutorialDocs (UrlHelp , DockMixin ):
37
+ """A documentation viewer for the tutorial docs
38
+
39
+ This viewer is accessible through the :attr:`Tutorial.tutorial_docs`
40
+ attribute and shows the :attr:`~TutorialPage.src_file` for the
41
+ tutorial :attr:`~Tutorial.pages`"""
19
42
20
43
dock_position = QtCore .Qt .RightDockWidgetArea
21
44
@@ -54,6 +77,16 @@ class TutorialNavigation(QtWidgets.QWidget):
54
77
current_step = 0
55
78
56
79
def __init__ (self , nsteps , validate , * args , ** kwargs ):
80
+ """
81
+ Parameters
82
+ ----------
83
+ nsteps: int
84
+ The total number of steps in the :class:`Tutorial`
85
+ validate: callable
86
+ A callable that takes the :attr:`current_step` as an argument and
87
+ returns a :class:`bool` whether the current step is valid and
88
+ finished, or not
89
+ """
57
90
super ().__init__ (* args , ** kwargs )
58
91
self .enabled = True
59
92
self .nsteps = nsteps
@@ -108,13 +141,20 @@ def __init__(self, nsteps, validate, *args, **kwargs):
108
141
self .btn_info .clicked .connect (self .show_info )
109
142
110
143
def setEnabled (self , enable ):
144
+ """Enable or disable the navigation buttons
145
+
146
+ Parameters
147
+ ----------
148
+ enable: bool
149
+ Whether to enable or disable the buttons"""
111
150
for w in [self .btn_prev , self .btn_next , self .btn_skip , self .btn_info ]:
112
151
w .setEnabled (enable )
113
152
if enable :
114
153
self .maybe_enable_widgets ()
115
154
self .enabled = enable
116
155
117
156
def maybe_enable_widgets (self ):
157
+ """Enable the buttons based on the :attr:`current_step`"""
118
158
i = self .current_step
119
159
if i == 0 :
120
160
self .btn_next .setEnabled (True )
@@ -131,12 +171,20 @@ def maybe_enable_widgets(self):
131
171
self .btn_prev .setEnabled (i > 0 )
132
172
133
173
def show_info (self ):
174
+ """Trigger the :attr:`step_changed` signal with the current step"""
134
175
self .step_changed .emit (self .current_step , self .current_step )
135
176
136
177
def display_hint (self ):
178
+ """Trigger the :attr:`hint_requested` signal with the current step"""
137
179
self .hint_requested .emit (self .current_step )
138
180
139
181
def set_current_step (self , i ):
182
+ """Change the :attr:`current_step`
183
+
184
+ Parameters
185
+ ----------
186
+ i: int
187
+ The :attr:`current_step` to switch to"""
140
188
self .current_step = i
141
189
self .progress_bar .setValue (i )
142
190
self .btn_next .setText ('Next' )
@@ -152,6 +200,7 @@ def set_current_step(self, i):
152
200
self .maybe_enable_widgets ()
153
201
154
202
def goto_next_step (self ):
203
+ """Increase the :attr:`current_step` by one"""
155
204
if self .validate (self .current_step ):
156
205
if self .current_step <= self .nsteps :
157
206
self .set_current_step (self .current_step + 1 )
@@ -161,11 +210,14 @@ def goto_next_step(self):
161
210
self .set_current_step (self .current_step )
162
211
163
212
def goto_prev_step (self ):
213
+ """Decrease the :attr:`current_step` by one"""
164
214
if self .current_step > 0 :
165
215
self .set_current_step (self .current_step - 1 )
166
216
self .step_changed .emit (self .current_step + 1 , self .current_step )
167
217
168
218
def skip (self ):
219
+ """Skip the :attr:`current_step` and emit the :attr:`skipped` signal
220
+ """
169
221
self .skipped .emit (self .current_step )
170
222
self .goto_next_step ()
171
223
@@ -176,17 +228,29 @@ class TutorialPage(object):
176
228
Subclasses show implement the :meth:`show_hint` method and the
177
229
:meth:`is_finished` property"""
178
230
231
+ #: The source directory for the docs
179
232
src_dir = osp .join (osp .dirname (__file__ ), 'beginner' )
180
233
234
+ #: The basename of the stratigraphic diagram image for this tutorial
181
235
src_base = 'beginner-tutorial.png'
182
236
237
+ #: The complete path to the of the stratigraphic diagram image for this
238
+ #: tutorial
183
239
src_file = osp .join (src_dir , src_base )
184
240
185
241
#: str. The tooltip that has been shown. This attribute is mainly for
186
242
#: testing purposes
187
243
_last_tooltip_shown = None
188
244
189
245
def __init__ (self , filename , tutorial ):
246
+ """
247
+ Parameters
248
+ ----------
249
+ filename: str
250
+ The basename (without ending) of the RST file corresponding to this
251
+ tutorial page
252
+ tutorial: Tutorial
253
+ The tutorial instance"""
190
254
self .filename = filename
191
255
self .tutorial = tutorial
192
256
self .straditizer_widgets = self .tutorial .straditizer_widgets
@@ -229,6 +293,8 @@ def lock_viewer(self, lock):
229
293
pass
230
294
231
295
def show (self ):
296
+ """Show the page and browse the :attr:`filename` in the tutorial docs
297
+ """
232
298
try :
233
299
self .lock_viewer (False )
234
300
self .tutorial .tutorial_docs .browse (self .filename )
@@ -309,14 +375,27 @@ class Tutorial(StraditizerControlBase, TutorialPage):
309
375
310
376
@property
311
377
def current_page (self ):
378
+ """The current page of the tutorial (corresponding to the
379
+ :attr:`TutorialNavigation.current_step`)"""
312
380
return self .pages [self .navigation .current_step ]
313
381
314
382
@property
315
383
def load_image_step (self ):
384
+ """The number of the page that loads the diagram image (i.e. the index
385
+ of the :class:`LoadImage` instance in the :attr:`pages` attribute"""
316
386
return next (
317
387
(i for i , p in enumerate (self .pages ) if isinstance (p , LoadImage )),
318
388
1 )
319
389
390
+ #: A list of the :class:`TutorialPages` for this tutorial
391
+ pages = []
392
+
393
+ #: A :class:`TutorialDocs` to display the RST-files of the tutorial
394
+ tutorial_docs = None
395
+
396
+ #: A :class:`TutorialNavigation` to navigate through the tutorial
397
+ navigation = None
398
+
320
399
def __init__ (self , straditizer_widgets ):
321
400
from psyplot_gui .main import mainwindow
322
401
self .init_straditizercontrol (straditizer_widgets )
@@ -374,6 +453,8 @@ def show(self):
374
453
self .tutorial_docs .show_rst (rst , name , files = files )
375
454
376
455
def setup_tutorial_pages (self ):
456
+ """Setup the :attr:`pages` attribute and initialize the tutorial pages
457
+ """
377
458
self .pages = [
378
459
self ,
379
460
ControlIntro ('beginner-tutorial-control' , self ),
@@ -402,6 +483,12 @@ def refresh(self):
402
483
self .navigation .set_current_step (self .load_image_step )
403
484
404
485
def _get_tutorial_stradi (self ):
486
+ """Get the straditizer for this tutorial
487
+
488
+ Returns
489
+ -------
490
+ straditize.straditizer.Straditizer
491
+ The straditizer for this tutorial or None if it is closed"""
405
492
src_file = self .src_base
406
493
get_attr = self .straditizer_widgets .get_attr
407
494
for stradi in self .straditizer_widgets ._straditizers :
@@ -424,15 +511,50 @@ def close(self):
424
511
del self .pages
425
512
426
513
def goto_page (self , old , new ):
514
+ """Go to another page
515
+
516
+ Parameters
517
+ ----------
518
+ old: int
519
+ The index of the old page in the :attr:`pages` attribute that is
520
+ subject to be deactivated (see :meth:`TutorialPage.deactivate`)
521
+ new: int
522
+ The index of the new page in the :attr:`pages` attribute that is
523
+ subject to be activated (see :meth:`TutorialPage.activate`)
524
+
525
+ See Also
526
+ --------
527
+ TutorialPage.activate
528
+ TutorialPage.deactivate"""
427
529
self .pages [old ].deactivate ()
428
530
page = self .pages [new ]
429
531
page .show ()
430
532
page .activate ()
431
533
432
534
def skip_page (self , i ):
535
+ """Skip a tutorial page
536
+
537
+ Parameters
538
+ ----------
539
+ i: int
540
+ The index of the page in the :attr:`pages` attribute
541
+
542
+ See Also
543
+ --------
544
+ TutorialPage.skip"""
433
545
self .pages [i ].skip ()
434
546
435
547
def display_hint (self , i ):
548
+ """Display the hint for a tutorial page
549
+
550
+ Parameters
551
+ ----------
552
+ i: int
553
+ The index of the page in the :attr:`pages` attribute
554
+
555
+ See Also
556
+ --------
557
+ TutorialPage.hint"""
436
558
stradi = self ._get_tutorial_stradi ()
437
559
if stradi is None and i > self .load_image_step :
438
560
self .navigation .set_current_step (self .load_image_step )
@@ -444,6 +566,20 @@ def display_hint(self, i):
444
566
self .pages [i ].hint ()
445
567
446
568
def validate_page (self , i , silent = False ):
569
+ """Validate a tutorial page
570
+
571
+ Parameters
572
+ ----------
573
+ i: int
574
+ The index of the page in the :attr:`pages` attribute
575
+ silent: bool
576
+ If True, and the page is not yet finished (see
577
+ :attr:`TutorialPage.is_finished`), the hint is displayed
578
+
579
+ Returns
580
+ -------
581
+ bool
582
+ True, if the page :attr:`~TutorialPage.is_finished`"""
447
583
ret = self .pages [i ].is_finished
448
584
if not silent and not ret :
449
585
self .navigation .display_hint ()
@@ -773,6 +909,7 @@ class ColumnNames(TutorialPage):
773
909
774
910
select_names_button_clicked = False
775
911
912
+ #: The column names in the diagram
776
913
column_names = [
777
914
'Pinus' , 'Juniperus' , 'Quercus ilex-type' , 'Chenopodiaceae' ]
778
915
0 commit comments