source: sasview/src/sas/sasgui/perspectives/fitting/gpu_options.py @ 6b59bb3

Last change on this file since 6b59bb3 was 6b59bb3, checked in by wojciech, 7 years ago

Setting dialog to unmodal

  • Property mode set to 100644
File size: 3.7 KB
Line 
1'''
2Created on Nov 29, 2016
3
4@author: wpotrzebowski
5'''
6
7import os
8import warnings
9
10import wx
11import wx.richtext
12import wx.lib.hyperlink
13
14from sas.sasgui.guiframe.documentation_window import DocumentationWindow
15
16class GpuOptions(wx.Dialog):
17    """
18    "Acknowledgement" Dialog Box
19
20    Shows the current method for acknowledging SasView in
21    scholarly publications.
22
23    """
24
25    def __init__(self, *args, **kwds):
26
27        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
28        wx.Dialog.__init__(self, *args, **kwds)
29
30        clinfo = self._get_clinfo()
31
32        self.panel1 = wx.Panel(self, -1)
33        static_box1 = wx.StaticBox(self.panel1, -1, "Available OpenCL Options:")
34
35        boxsizer = wx.BoxSizer(orient=wx.VERTICAL)
36        self.option_button = {}
37        for index, clopt in enumerate(clinfo):
38            button = wx.RadioButton(self.panel1, -1, label=clopt, name=clopt)
39            if clopt != "No OpenCL":
40                self.option_button[clopt] = str(index)
41            else:
42                self.option_button[clopt] = "None"
43            self.Bind(wx.EVT_LEFT_DOWN, self.on_radio_default, id=button.GetId())
44            self.Bind(wx.EVT_RADIOBUTTON, self.on_radio, id=button.GetId())
45            boxsizer.Add(button, 0, 0)
46
47        fit_hsizer = wx.StaticBoxSizer(static_box1, orient=wx.VERTICAL)
48        fit_hsizer.Add(boxsizer, 0, wx.ALL, 5)
49
50        self.panel1.SetSizer(fit_hsizer)
51
52        self.vbox = wx.BoxSizer(wx.VERTICAL)
53        self.vbox.Add(self.panel1, 0, wx.ALL, 10)
54
55        accept_btn = wx.Button(self, wx.ID_OK)
56        accept_btn.SetToolTipString("Accept OpenCL settings")
57
58        help_btn = wx.Button(self, wx.ID_HELP, 'Help')
59        help_btn.SetToolTipString("Help on the GPU options")
60
61        self.Bind(wx.EVT_BUTTON, self.on_accept, accept_btn)
62        self.Bind(wx.EVT_BUTTON, self.on_help, help_btn)
63        self.Bind(wx.EVT_CLOSE, self.on_close)
64
65        btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
66        btn_sizer.Add((10, 20), 1) # stretchable whitespace
67        btn_sizer.Add(accept_btn, 0)
68        btn_sizer.Add((10, 20), 0) # non-stretchable whitespace
69        btn_sizer.Add(help_btn, 0)
70
71        # Add the button sizer to the main sizer.
72        self.vbox.Add(btn_sizer, 0, wx.EXPAND|wx.ALL, 10)
73
74        self.SetSizer(self.vbox)
75        self.vbox.Fit(self)
76
77        self.Centre()
78
79    def _get_clinfo(self):
80        clinfo = []
81
82        try:
83            import pyopencl as cl
84            for platform in cl.get_platforms():
85                for device in platform.get_devices():
86                    clinfo.append(device.name)
87        except ImportError:
88            warnings.warn("pyopencl import failed. Please check installation")
89
90        clinfo.append("No OpenCL")
91        return clinfo
92
93    def on_radio_default(self, event):
94        event.GetEventObject().SetValue(not event.GetEventObject().GetValue())
95
96    def on_radio(self, event):
97        """
98        Action triggered when button is selected
99        :param event:
100        :return:
101        """
102
103        import sasmodels
104        button = event.GetEventObject()
105        os.environ["SAS_OPENCL"] = self.option_button[button.Name]
106        sasmodels.kernelcl.ENV = None
107        #Need to reload sasmodels.core module to account SAS_OPENCL = "None"
108        reload(sasmodels.core)
109
110    def on_accept(self, event):
111        """
112        Close window on accpetance
113        """
114        event.Skip()
115
116    def on_help(self, event):
117        """
118        Provide help on opencl options.
119        """
120        TreeLocation = "user/gpu_computations.html"
121        anchor = "#device-selection"
122        DocumentationWindow(self, -1,
123                            TreeLocation, anchor, "OpenCL Options Help")
124
125    def on_close(self, event):
126        """
127        Close window
128        """
129        event.Skip()
Note: See TracBrowser for help on using the repository browser.