@@ -329,78 +329,88 @@ def show_project_dialog():
329329 # Work with Cinema json file
330330 import json
331331 db_directory = None
332- if show_project_dialog ():
333- # Actions when continuing work with the current project
334- dialogDirOfProjectDB = wx .DirDialog (
335- None ,
336- message = f"Select directory containing project data - { DATA_CSV_FILENAME } " , # Dialog title
337- defaultPath = "" , # Initial directory (empty = current)
338- style = wx .DD_DEFAULT_STYLE # Dialog style
339- )
340- if dialogDirOfProjectDB .ShowModal () == wx .ID_OK :
341- db_directory = dialogDirOfProjectDB .GetPath ()
342- dialogDirOfProjectDB .Destroy ()
343- else :
344- dialogDirOfProjectDB .Destroy ()
345- return
346- file_path = os .path .join (db_directory , DATA_CSV_FILENAME )
347-
348- else :
349- # Actions when creating a new project
350- json_path = os .path .join (selected_dir , DB_JSON_FILENAME )
351-
352- dlg = wx .Dialog (G2frame , title = "New Cinema:D-S Project Parameters" , size = (400 , 200 ))
353- panel = wx .Panel (dlg )
354- main_sizer = wx .BoxSizer (wx .VERTICAL )
355-
356- # Flexible grid layout (2 columns, 2 rows, 5px spacing)
357- grid_sizer = wx .FlexGridSizer (2 , 2 , 5 , 5 )
358- grid_sizer .AddGrowableCol (1 )
359-
360- # Project name field
361- name_label = wx .StaticText (panel , label = "Project Name:" )
362- name_ctrl = wx .TextCtrl (panel , value = "GSAS-II Cinema Export" )
363- grid_sizer .Add (name_label , 0 , wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_LEFT )
364- grid_sizer .Add (name_ctrl , 1 , wx .EXPAND | wx .ALIGN_LEFT )
365-
366- # Database directory field
367- dir_label = wx .StaticText (panel , label = "DB Directory: data/..." )
368- dir_ctrl = wx .TextCtrl (panel , value = "g2db.cdb" )
369- grid_sizer .Add (dir_label , 0 , wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_LEFT )
370- grid_sizer .Add (dir_ctrl , 1 , wx .EXPAND | wx .ALIGN_LEFT )
371-
372- main_sizer .Add (grid_sizer , 0 , wx .EXPAND | wx .ALL , 10 )
373-
374- # Buttons
375- btn_sizer = wx .BoxSizer (wx .HORIZONTAL )
376- btn_sizer .AddStretchSpacer (1 )
377- btn_ok = wx .Button (panel , wx .ID_OK , "OK" )
378- btn_cancel = wx .Button (panel , wx .ID_CANCEL , "Cancel" )
379- btn_sizer .Add (btn_ok , 0 , wx .RIGHT , 10 )
380- btn_sizer .Add (btn_cancel , 0 )
381- btn_sizer .AddStretchSpacer (1 )
382- main_sizer .Add (btn_sizer , 0 , wx .EXPAND | wx .ALL , 10 )
383-
384- panel .SetSizer (main_sizer )
385-
386- dlg .Layout ()
387- dlg .Centre ()
388- dlg .CenterOnParent ()
389-
390- if dlg .ShowModal () == wx .ID_OK :
391- project_name = name_ctrl .GetValue ()
392- db_directory = os .path .join ("data" , dir_ctrl .GetValue ())
393- dlg .Destroy ()
332+ Repeat = True
333+ while Repeat :
334+ Repeat = False
335+ if show_project_dialog ():
336+ # Actions when continuing work with a previous project
337+ import glob
338+ f1 = os .path .join ('data' ,'*' ,DATA_CSV_FILENAME )
339+ choices = [os .path .split (i )[0 ] for i in glob .glob (f1 ,root_dir = selected_dir )]
340+ dlg = G2G .G2SingleChoiceDialog (G2frame ,
341+ 'Select previously used location' ,
342+ 'Select directory' ,choices )
343+ dlg .CenterOnParent ()
344+ if dlg .ShowModal () == wx .ID_OK :
345+ val = choices [dlg .GetSelection ()]
346+ db_directory = os .path .join (selected_dir ,val )
347+ dlg .Destroy ()
348+ else :
349+ dlg .Destroy ()
350+ return
351+ file_path = os .path .join (db_directory , DATA_CSV_FILENAME )
394352
395- try :
396- os .makedirs (os .path .join (selected_dir ,db_directory ), exist_ok = True )
397- except OSError as e :
398- print (f"Directory creation failed: { e } " )
399- wx .MessageBox (f"Failed to create directory: { e } " , "Error" , wx .OK | wx .ICON_ERROR )
400- return # Terminate execution if directory creation failed
401353 else :
402- dlg .Destroy ()
403- return
354+ # Actions when creating a new project
355+ json_path = os .path .join (selected_dir , DB_JSON_FILENAME )
356+
357+ dlg = wx .Dialog (G2frame , title = "New Cinema:D-S Project" , size = (400 , 200 ))
358+ panel = wx .Panel (dlg )
359+ main_sizer = wx .BoxSizer (wx .VERTICAL )
360+
361+ # Flexible grid layout (2 columns, 2 rows, 5px spacing)
362+ grid_sizer = wx .FlexGridSizer (2 , 2 , 5 , 5 )
363+ grid_sizer .AddGrowableCol (1 )
364+
365+ # Project name field
366+ name_label = wx .StaticText (panel , label = "Project Name:" )
367+ name_ctrl = wx .TextCtrl (panel , value = "GSAS-II Cinema Export" )
368+ grid_sizer .Add (name_label , 0 , wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_LEFT )
369+ grid_sizer .Add (name_ctrl , 1 , wx .EXPAND | wx .ALIGN_LEFT )
370+
371+ # Database directory field
372+ dir_label = wx .StaticText (panel , label = "DB Directory: data/..." )
373+ dir_ctrl = wx .TextCtrl (panel , value = "g2db.cdb" )
374+ grid_sizer .Add (dir_label , 0 , wx .ALIGN_CENTER_VERTICAL | wx .ALIGN_LEFT )
375+ grid_sizer .Add (dir_ctrl , 1 , wx .EXPAND | wx .ALIGN_LEFT )
376+
377+ main_sizer .Add (grid_sizer , 0 , wx .EXPAND | wx .ALL , 10 )
378+
379+ # Buttons
380+ btn_sizer = wx .BoxSizer (wx .HORIZONTAL )
381+ btn_sizer .AddStretchSpacer (1 )
382+ btn_ok = wx .Button (panel , wx .ID_OK , "OK" )
383+ btn_ok .SetDefault ()
384+ btn_cancel = wx .Button (panel , wx .ID_CANCEL , "Cancel" )
385+ btn_sizer .Add (btn_ok , 0 , wx .RIGHT , 10 )
386+ btn_sizer .Add (btn_cancel , 0 )
387+ btn_sizer .AddStretchSpacer (1 )
388+ main_sizer .Add (btn_sizer , 0 , wx .EXPAND | wx .ALL , 10 )
389+
390+ panel .SetSizer (main_sizer )
391+ main_sizer .Fit (dlg )
392+ dlg .CenterOnParent ()
393+
394+ if dlg .ShowModal () == wx .ID_OK :
395+ project_name = name_ctrl .GetValue ()
396+ db_directory = os .path .join ("data" , dir_ctrl .GetValue ())
397+ dlg .Destroy ()
398+ new_loc = os .path .join (selected_dir ,db_directory )
399+ if os .path .exists (new_loc ):
400+ G2G .G2MessageBox (G2frame ,
401+ f'This file has already been created, specify a new DB directory or reuse { dir_ctrl .GetValue ()} ' ,
402+ 'In use' )
403+ Repeat = True
404+ continue
405+ try :
406+ os .makedirs (new_loc , exist_ok = True )
407+ except OSError as e :
408+ print (f"Directory creation failed: { e } " )
409+ wx .MessageBox (f"Failed to create directory: { e } " , "Error" , wx .OK | wx .ICON_ERROR )
410+ return # Terminate execution if directory creation failed
411+ else :
412+ dlg .Destroy ()
413+ return
404414
405415 try :
406416 with open (json_path , 'r' , encoding = 'utf-8' ) as fil :
0 commit comments