1
1
import os
2
+ import tkinter as tk
2
3
from src .common import config , utils
3
4
from src .gui .interfaces import MenuBarItem
4
5
from tkinter .filedialog import askopenfilename , asksaveasfilename
@@ -14,7 +15,14 @@ def __init__(self, parent, **kwargs):
14
15
self .add_command (label = 'Save Routine' , command = utils .async_callback (self , File ._save_routine ))
15
16
self .add_separator ()
16
17
self .add_command (label = 'Load Command Book' , command = utils .async_callback (self , File ._load_commands ))
17
- self .add_command (label = 'Load Routine' , command = utils .async_callback (self , File ._load_routine ))
18
+ self .add_command (
19
+ label = 'Load Routine' ,
20
+ command = utils .async_callback (self , File ._load_routine ),
21
+ state = tk .DISABLED
22
+ )
23
+
24
+ def enable_routine_state (self ):
25
+ self .entryconfig ('Load Routine' , state = tk .NORMAL )
18
26
19
27
@staticmethod
20
28
@utils .run_if_disabled ('\n [!] Cannot create a new routine while Auto Maple is enabled' )
@@ -30,7 +38,7 @@ def _new_routine():
30
38
@staticmethod
31
39
@utils .run_if_disabled ('\n [!] Cannot save routines while Auto Maple is enabled' )
32
40
def _save_routine ():
33
- file_path = asksaveasfilename (initialdir = os . path . join ( config . RESOURCES_DIR , 'routines' ),
41
+ file_path = asksaveasfilename (initialdir = get_routines_dir ( ),
34
42
title = 'Save routine' ,
35
43
filetypes = [('*.csv' , '*.csv' )],
36
44
defaultextension = '*.csv' )
@@ -46,7 +54,7 @@ def _load_routine():
46
54
'Would you like to proceed anyways?' ,
47
55
icon = 'warning' ):
48
56
return
49
- file_path = askopenfilename (initialdir = os . path . join ( config . RESOURCES_DIR , 'routines' ),
57
+ file_path = askopenfilename (initialdir = get_routines_dir ( ),
50
58
title = 'Select a routine' ,
51
59
filetypes = [('*.csv' , '*.csv' )])
52
60
if file_path :
@@ -66,3 +74,10 @@ def _load_commands():
66
74
filetypes = [('*.py' , '*.py' )])
67
75
if file_path :
68
76
config .bot .load_commands (file_path )
77
+
78
+
79
+ def get_routines_dir ():
80
+ target = os .path .join (config .RESOURCES_DIR , 'routines' , config .bot .module_name )
81
+ if not os .path .exists (target ):
82
+ os .makedirs (target )
83
+ return target
0 commit comments