Skip to content

Commit 72ff528

Browse files
committed
adapt CIF Origin1->2 for scripting; cleanup unused vars
1 parent 70ce148 commit 72ff528

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

GSASII/GSASIIctrlGUI.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import random as ran
3232
import numpy as np
3333

34-
import matplotlib as mpl
34+
#import matplotlib as mpl
3535
try:
3636
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
3737
except ImportError:
@@ -47,7 +47,7 @@
4747
from . import GSASIIpwd as G2pwd
4848
from . import GSASIIlattice as G2lat
4949
from . import GSASIImath as G2mth
50-
from . import GSASIIstrMain as G2stMn
50+
#from . import GSASIIstrMain as G2stMn
5151
from . import GSASIImiscGUI as G2IO
5252
from .tutorialIndex import tutorialIndex
5353
if sys.version_info[0] >= 3:
@@ -5042,7 +5042,7 @@ def SetContents(self,parent):
50425042
if parent.hisNum != '*' and name.split(':')[1] != parent.hisNum: continue
50435043
if (parent.varName != ' ') and (parent.varName not in name): continue
50445044
self.varList.append(name)
5045-
oldlen = self.GetItemCount()
5045+
#oldlen = self.GetItemCount()
50465046
self.SetItemCount(len(self.varList))
50475047

50485048
def OnRowSelected(self, event, row=None):
@@ -6025,7 +6025,7 @@ def copy2clip(event):
60256025
msg += f"\n\n * For {key} use cite:\n"
60266026
msg += GetCite(key,wrap=95,indent=6)
60276027
msg += '\n\nNote that your citations are one of the strongest ways you can say thank you to the\nscientists who make their software available to you.'
6028-
res = ShowScrolledInfo(parent,msg,header='Please Cite',
6028+
ShowScrolledInfo(parent,msg,header='Please Cite',
60296029
buttonlist=[
60306030
('Close', lambda event: event.GetEventObject().GetParent().EndModal(wx.ID_OK)),
60316031
('Copy to clipboard', copy2clip),
@@ -6283,7 +6283,7 @@ def copyURL(event):
62836283
# place HTML title into window title
62846284
dlg.wv.Bind(wx.EVT_UPDATE_UI, lambda event:
62856285
dlg.SetTitle(dlg.wv.GetCurrentTitle()))
6286-
lastWebView = dlg.wv
6286+
#lastWebView = dlg.wv
62876287
sizer.Add(dlg.wv,1,wx.EXPAND)
62886288
# row of buttons & URL label on bottom of window
62896289
bsizer=wx.BoxSizer(wx.HORIZONTAL)
@@ -7349,7 +7349,7 @@ class gitVersionSelector(wx.Dialog):
73497349
from a git repository
73507350
'''
73517351
def __init__(self,parent=None):
7352-
import git
7352+
#import git
73537353
self.g2repo = GSASIIpath.openGitRepo(path2GSAS2)
73547354
self.githistory = GSASIIpath.gitHistory('hash',self.g2repo)
73557355
# patch Feb 2024: don't allow access to versions that are too old
@@ -7492,7 +7492,7 @@ def docCommit(self,commit):
74927492
74937493
:returns: a multi-line string
74947494
'''
7495-
import datetime
7495+
#import datetime
74967496
fmtdate = lambda c:"{:%d-%b-%Y %H:%M}".format(c.committed_datetime)
74977497
commit = self.g2repo.commit(commit) # converts a hash, if supplied
74987498
msg = f'git {commit.hexsha[:10]} from {fmtdate(commit)}'
@@ -9397,6 +9397,15 @@ def askQuestion(parent,question,title):
93979397
dlg.Destroy()
93989398
return ans
93999399

9400+
def haveGUI():
9401+
'''Test if there is a GUI that can be accessed
9402+
:returns: True if a GUI is available
9403+
'''
9404+
try:
9405+
return wx.App.IsMainLoopRunning()
9406+
except:
9407+
return False
9408+
94009409
#===========================================================================
94019410
def gitFetch(G2frame):
94029411
wx.BeginBusyCursor()
@@ -9832,7 +9841,7 @@ def gitSwitchMaster2Main():
98329841
98339842
See web page GSASII.github.io for information on how to install GSAS-II.
98349843
'''
9835-
res = ShowScrolledInfo(G2frame,msg,header='Please Note',
9844+
ShowScrolledInfo(G2frame,msg,header='Please Note',
98369845
height=250)
98379846
return
98389847

@@ -9941,13 +9950,13 @@ def gitSwitchMaster2Main():
99419950
if script and sys.platform.startswith('darwin'):
99429951
print(f'running {script}')
99439952
import subprocess
9944-
out = subprocess.run([sys.executable,script],cwd=GSASIIpath.path2GSAS2)
9953+
subprocess.run([sys.executable,script],cwd=GSASIIpath.path2GSAS2)
99459954
# On windows make a batch file with hard-coded paths to Python and GSAS-II
99469955
elif script and sys.platform.startswith('win'):
99479956
script = os.path.normpath(os.path.join(GSASIIpath.path2GSAS2,'install',s))
99489957
print(f'running {script!r}')
99499958
import subprocess
9950-
out = subprocess.run([sys.executable,script],cwd=GSASIIpath.path2GSAS2)
9959+
subprocess.run([sys.executable,script],cwd=GSASIIpath.path2GSAS2)
99519960
# On linux, make a desktop icon with hard-coded paths to Python and GSAS-II
99529961
elif script:
99539962
sys.argv = [script]

GSASII/imports/G2phase_CIF.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -672,23 +672,31 @@ def Reader(self,filename, ParentFrame=None, usedRanIdList=[], **unused):
672672
msg = 'This CIF uses a space group setting not compatible with GSAS-II.\n'
673673
if self.Phase['General']['SGData']['SpGrp'] in G2spc.spg2origins:
674674
msg += '\nThis is likely due to the space group being set in Origin 1 rather than 2.\n'
675-
msg += '''
675+
haveGUI = False
676+
ans = True
677+
try:
678+
from .. import GSASIIctrlGUI as G2G
679+
haveGUI = G2G.haveGUI()
680+
except Exception as err: # fails if non-interactive (no wxPython)
681+
print(err)
682+
if haveGUI:
683+
msg += '''
676684
Do you want to use Bilbao's "CIF to Standard Setting" web service to
677685
transform this into a standard setting?
678686
'''
679-
if self.Phase['General']['SGData']['SpGrp'] in G2spc.spg2origins and not centro:
680-
msg += '''
687+
if self.Phase['General']['SGData']['SpGrp'] in G2spc.spg2origins and not centro:
688+
msg += '''
681689
If you say "no" here, later, you will get the chance to apply a simple origin
682690
shift later as an alternative to the above.'''
691+
else:
692+
msg += '\nIf you say "no" here you will need to do this yourself manually.'
693+
try:
694+
ans = G2G.askQuestion(ParentFrame,msg,'xform structure?')
695+
except Exception as err: # fails if non-interactive (no wxPython)
696+
print(err)
683697
else:
684-
msg += '\nIf you say "no" here you will need to do this yourself manually.'
685-
try:
686-
from .. import GSASIIctrlGUI as G2G
687-
ans = G2G.askQuestion(ParentFrame,msg,'xform structure?')
688-
except Exception as err: # fails if non-interactive (no wxPython)
689-
print(err)
690-
print('\nCIF symops do not agree with GSAS-II, calling Bilbao "CIF to Standard Setting" web service.\n')
691-
ans = True
698+
print(msg)
699+
print('\nCIF symops do not agree with GSAS-II, calling Bilbao "CIF to Standard Setting" web service.\n')
692700
if ans:
693701
from .. import SUBGROUPS
694702
SUBGROUPS.createStdSetting(filename,self)

0 commit comments

Comments
 (0)