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

Last change on this file since c027106e was c027106e, checked in by wojciech, 8 years ago

Fixed help button accidently disabled with the previous commit

  • Property mode set to 100644
File size: 3.5 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_RADIOBUTTON, self.on_radio, id=button.GetId())
44            boxsizer.Add(button, 0, 0)
45
46        fit_hsizer = wx.StaticBoxSizer(static_box1, orient=wx.VERTICAL)
47        fit_hsizer.Add(boxsizer, 0, wx.ALL, 5)
48
49        self.panel1.SetSizer(fit_hsizer)
50
51        self.vbox = wx.BoxSizer(wx.VERTICAL)
52        self.vbox.Add(self.panel1, 0, wx.ALL, 10)
53
54        accept_btn = wx.Button(self, wx.ID_OK)
55        accept_btn.SetToolTipString("Accept OpenCL settings")
56
57        help_btn = wx.Button(self, wx.ID_HELP, 'Help')
58        help_btn.SetToolTipString("Help on the GPU options")
59
60        self.Bind(wx.EVT_BUTTON, self.on_accept, accept_btn)
61        self.Bind(wx.EVT_BUTTON, self.on_help, help_btn)
62        self.Bind(wx.EVT_CLOSE, self.on_close)
63
64        btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
65        btn_sizer.Add((10, 20), 1) # stretchable whitespace
66        btn_sizer.Add(accept_btn, 0)
67        btn_sizer.Add((10, 20), 0) # non-stretchable whitespace
68        btn_sizer.Add(help_btn, 0)
69
70        # Add the button sizer to the main sizer.
71        self.vbox.Add(btn_sizer, 0, wx.EXPAND|wx.ALL, 10)
72
73        self.SetSizer(self.vbox)
74        self.vbox.Fit(self)
75
76        self.Centre()
77
78    def _get_clinfo(self):
79        clinfo = []
80
81        try:
82            import pyopencl as cl
83            for platform in cl.get_platforms():
84                for device in platform.get_devices():
85                    clinfo.append(device.name)
86        except ImportError:
87            warnings.warn("pyopencl import failed. Please check installation")
88
89        clinfo.append("No OpenCL")
90        return clinfo
91
92    def on_radio(self, event):
93        """
94        Action triggered when button is selected
95        :param event:
96        :return:
97        """
98
99        import sasmodels
100        button = event.GetEventObject()
101        os.environ["SAS_OPENCL"] = self.option_button[button.Name]
102        sasmodels.kernelcl.ENV = None
103        #Need to reload sasmodels.core module to account SAS_OPENCL = "None"
104        reload(sasmodels.core)
105
106    def on_accept(self, event):
107        """
108        Close window on accpetance
109        """
110        event.Skip()
111
112    def on_help(self, event):
113        """
114        Provide help on opencl options.
115        """
116        TreeLocation = "user/gpu_computations.html"
117        anchor = "#device-selection"
118        DocumentationWindow(self, -1,
119                            TreeLocation, anchor, "OpenCL Options Help")
120
121    def on_close(self, event):
122        """
123        Close window
124        """
125        event.Skip()
Note: See TracBrowser for help on using the repository browser.