Skip to content

Commit 27791ee

Browse files
Yuchen XiaoYuchen Xiao
authored andcommitted
chore: migrate and refactor the code
1 parent 9aa20d9 commit 27791ee

12 files changed

Lines changed: 1013 additions & 59 deletions

File tree

news/refine-batch.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: Migrate the refinement functionality.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ exclude = [] # exclude packages matching these glob patterns (empty by default)
5151
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
5252

5353
[project.scripts]
54-
diffpy-batchpdfsuite = "diffpy.batchpdfsuite.app:main"
54+
bpdfsuite = "diffpy.batchpdfsuite.batchpdfsuite_app:main"
5555

5656
[tool.setuptools.dynamic]
5757
dependencies = {file = ["requirements/pip.txt"]}

requirements/conda.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
numpy
2+
traits
3+
traitsui
4+
mayavi
5+
pyside6
6+
watchdog
7+
jinja2
8+
# FIXME: add diffpy.apps once it is released

requirements/pip.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
numpy
1+
chaco
Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,67 @@
1-
import argparse
1+
#!/usr/bin/env python
2+
##############################################################################
3+
#
4+
# diffpy.xpdfsuite by Simon J. L. Billinge group
5+
# (c) 2012 Trustees of the Columbia University
6+
# in the City of New York. All rights reserved.
7+
#
8+
# File coded by: Xiaohao Yang
9+
#
10+
# See AUTHORS.rst for a list of people who contributed.
11+
# See LICENSE.txt for license information.
12+
#
13+
##############################################################################
14+
"""Provide UI for pdfgetxgui."""
215

3-
from diffpy.batchpdfsuite.version import __version__ # noqa
16+
import sys
17+
18+
from pyface.api import ImageResource, SplashScreen
19+
from traits.etsconfig.api import ETSConfig
20+
21+
from diffpy.batchpdfsuite.batchpdfsuite_gui import BatchPDFsuiteGUI
22+
from diffpy.batchpdfsuite.help import IMAGE_DIR
23+
24+
# break if help passed to the args
25+
sysargv = sys.argv[1:]
26+
# if ('--help' in sysargv) or('-h' in sysargv):
27+
# from dpx.srxplanargui.srxconfig import SrXconfig
28+
# SrXconfig(args=sysargv)
29+
30+
ETSConfig.toolkit = "qt"
31+
32+
33+
# open splash screen
34+
def maybe_show_splash(argv):
35+
if any(aa in ("-h", "--help") for aa in argv):
36+
return None
37+
38+
try:
39+
splash = SplashScreen(
40+
image=ImageResource(str(IMAGE_DIR / "splash.png")),
41+
show_log_messages=False,
42+
)
43+
if splash is not None:
44+
splash.open()
45+
return splash
46+
except Exception:
47+
return None
48+
49+
50+
def running_under_pytest():
51+
return "pytest" in sys.modules
52+
53+
54+
splash = None
55+
if not running_under_pytest():
56+
splash = maybe_show_splash(sysargv)
457

558

659
def main():
7-
parser = argparse.ArgumentParser(
8-
prog="diffpy.batchpdfsuite",
9-
description=(
10-
"GUI for batch refinements of multiple PDF datasets\n\n"
11-
"For more information, visit: "
12-
"https://github.com/diffpy/diffpy.batchpdfsuite/"
13-
),
14-
formatter_class=argparse.RawDescriptionHelpFormatter,
15-
)
16-
17-
parser.add_argument(
18-
"--version",
19-
action="store_true",
20-
help="Show the program's version number and exit",
21-
)
22-
23-
args = parser.parse_args()
24-
25-
if args.version:
26-
print(f"diffpy.batchpdfsuite {__version__}")
27-
else:
28-
# Default behavior when no arguments are given
29-
parser.print_help()
60+
gui = BatchPDFsuiteGUI(splash=splash)
61+
gui.configure_traits(view="traits_view")
62+
return
3063

3164

3265
if __name__ == "__main__":
33-
main()
66+
sys.exit(main())
67+
# main()
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
from pyface.api import ImageResource
2+
from traits.api import Any, HasTraits, Instance
3+
from traitsui.api import Action, HGroup, InstanceEditor, Item, VGroup, View
4+
from traitsui.menu import ToolBar
5+
6+
from diffpy.batchpdfsuite.help import IMAGE_DIR
7+
from diffpy.batchpdfsuite.refinement_config import RefinementConfig
8+
from diffpy.batchpdfsuite.refinement_editor import LogDialog
9+
from diffpy.batchpdfsuite.refinement_io import (
10+
SimpleSelectFiles,
11+
SimpleSelectFolder,
12+
)
13+
14+
toolbar_settings = Action(
15+
name="settings",
16+
action="_settings",
17+
tooltip="Configure the settings for PDF refinement",
18+
image=ImageResource(str(IMAGE_DIR / "settings.png")),
19+
)
20+
toolbar_refinement_log = Action(
21+
name="log",
22+
action="_refinement_log",
23+
tooltip="Display the runtime output for PDF refinement",
24+
image=ImageResource(str(IMAGE_DIR / "log.png")),
25+
)
26+
27+
toolbar_help = Action(
28+
name="help",
29+
action="_help",
30+
tooltip="Quick start",
31+
image=ImageResource(str(IMAGE_DIR / "help.png")),
32+
)
33+
34+
toolbar = ToolBar(
35+
toolbar_settings,
36+
toolbar_refinement_log,
37+
toolbar_help,
38+
)
39+
40+
41+
class BatchPDFsuiteGUI(HasTraits):
42+
splash = Any
43+
exp_files = Instance(SimpleSelectFolder, ())
44+
phase_files = Instance(SimpleSelectFiles, ())
45+
refinement_configuration = Instance(RefinementConfig)
46+
log_dialog = Instance(LogDialog, ())
47+
48+
def __init__(self, *args, **kargs):
49+
super().__init__(*args, **kargs)
50+
self.refinement_configuration = RefinementConfig(
51+
structure_files_selector=self.phase_files,
52+
profile_folder_selector=self.exp_files,
53+
log_dialog=self.log_dialog,
54+
)
55+
if self.splash is not None:
56+
self.splash.close()
57+
58+
def _refinement_log(self):
59+
self.log_dialog.edit_traits("log_view")
60+
return
61+
62+
def _settings(self):
63+
pass
64+
65+
def _help(self):
66+
pass
67+
68+
traits_view = View(
69+
HGroup(
70+
VGroup(
71+
Item(
72+
"exp_files",
73+
style="custom",
74+
editor=InstanceEditor(view="traits_view"),
75+
show_label=False,
76+
),
77+
Item(
78+
"phase_files",
79+
style="custom",
80+
editor=InstanceEditor(view="traits_view"),
81+
show_label=False,
82+
),
83+
),
84+
Item(
85+
"refinement_configuration",
86+
style="custom",
87+
editor=InstanceEditor(view="traits_view"),
88+
show_label=False,
89+
),
90+
),
91+
toolbar=toolbar,
92+
resizable=True,
93+
title="Batch PDF Refinement Suite",
94+
width=800,
95+
height=600,
96+
)
97+
98+
# traits_view = View(
99+
# HGroup(
100+
# VGroup(
101+
# Item(
102+
# "select_exp_files",
103+
# editor=InstanceEditor(view="traits_view"),
104+
# style="custom",
105+
# width=300,
106+
# show_label=False,
107+
# ),
108+
# Item(
109+
# "select_phase_files",
110+
# editor=InstanceEditor(view="traits_view"),
111+
# style="custom",
112+
# width=300,
113+
# show_label=False,
114+
# ),
115+
# ),
116+
# Item(
117+
# "refinement_configuration",
118+
# editor=InstanceEditor(view="traits_view"),
119+
# style="custom",
120+
# show_label=False,
121+
# ),
122+
# ),
123+
# resizable=True,
124+
# title="Batch PDF Refinement Suite",
125+
# width=800,
126+
# height=600,
127+
# kind="live",
128+
# toolbar=toolbar,
129+
# )

src/diffpy/batchpdfsuite/functions.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/diffpy/batchpdfsuite/help.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pathlib import Path
2+
3+
from traits.api import HasTraits
4+
5+
# FIXME: add image dir including splash image, log icon, and help icon
6+
PACKAGE_DIR = Path(__file__).resolve().parent
7+
IMAGE_DIR = PACKAGE_DIR / "images"
8+
9+
10+
# FIXME: add quick start guide for the help button
11+
class SuiteHelp(HasTraits):
12+
pass
132 KB
Loading

0 commit comments

Comments
 (0)