10
10
We have a menu containing two items. Each item accepts a file name, one hides the file
11
11
and the other deletes it. Both items have an undo option.
12
12
Each item is a MenuItem class that accepts the corresponding command as input and executes
13
- it's execute` method when it is pressed.
13
+ it's ` execute` method when it is pressed.
14
14
15
15
*TL;DR
16
16
Object oriented implementation of callback functions.
@@ -54,20 +54,21 @@ class DeleteFileCommand:
54
54
"""
55
55
A command to delete a file given its name
56
56
"""
57
+ _deleted_files_path = 'trash'
57
58
58
59
def __init__ (self ):
59
60
# an array of deleted files, to undo them as needed
60
61
self ._deleted_files = []
61
62
62
63
# create a directory to store deleted files
63
- if not os .path .exists ('bin' ):
64
- os .makedirs ('bin' )
64
+ if not os .path .exists (self . _deleted_files_path ):
65
+ os .makedirs (self . _deleted_files_path )
65
66
66
67
def execute (self , filename ):
67
68
if os .path .isfile (filename ):
68
69
print (f'deleting { filename } ' )
69
70
70
- os .rename (filename , f'bin /{ filename } ' )
71
+ os .rename (filename , f'{ self . _deleted_files_path } /{ filename } ' )
71
72
self ._deleted_files .append (filename )
72
73
else :
73
74
print (f'{ filename } dose not exists to delete' )
@@ -78,7 +79,7 @@ def undo(self):
78
79
79
80
print (f'un-deleting { filename } ' )
80
81
81
- os .rename (f'bin /{ filename } ' , filename )
82
+ os .rename (f'{ self . _deleted_files_path } /{ filename } ' , filename )
82
83
83
84
84
85
class MenuItem :
0 commit comments