1 | # -*- coding: utf-8 -*- |
---|
2 | ########### SVN repository information ################### |
---|
3 | # $Date: 2013-08-29 19:47:35 +0000 (Thu, 29 Aug 2013) $ |
---|
4 | # $Author: toby $ |
---|
5 | # $Revision: 1046 $ |
---|
6 | # $URL: trunk/GSASIIElemGUI.py $ |
---|
7 | # $Id: GSASIIElemGUI.py 1046 2013-08-29 19:47:35Z toby $ |
---|
8 | ########### SVN repository information ################### |
---|
9 | ''' |
---|
10 | *GSASIIElemGUI: GUI to select and delete element lists* |
---|
11 | ------------------------------------------------------- |
---|
12 | |
---|
13 | Module to select elements from a periodic table and |
---|
14 | to delete an element from a list of selected elements. |
---|
15 | ''' |
---|
16 | """ElementGUI: class defn. for element GUIs |
---|
17 | Copyright: 2008, Robert B. Von Dreele & Brian H. Toby (Argonne National Laboratory) |
---|
18 | """ |
---|
19 | |
---|
20 | import GSASIIpath |
---|
21 | GSASIIpath.SetVersionNumber("$Revision: 1046 $") |
---|
22 | import wx |
---|
23 | import os |
---|
24 | import wx.lib.colourselect as wscs |
---|
25 | class PickElement(wx.Dialog): |
---|
26 | "Makes periodic table widget for picking element - caller maintains element list" |
---|
27 | Elem=None |
---|
28 | def _init_ctrls(self, prnt): |
---|
29 | wx.Dialog.__init__(self, id=-1, name='PickElement', |
---|
30 | parent=prnt, pos=wx.DefaultPosition, |
---|
31 | style=wx.DEFAULT_DIALOG_STYLE, title='Pick Element') |
---|
32 | import ElementTable as ET |
---|
33 | self.butWid = 60 |
---|
34 | if 'nt' in os.name: |
---|
35 | self.butWid = 40 |
---|
36 | self.SetClientSize(wx.Size(50+18*self.butWid, 250)) |
---|
37 | |
---|
38 | i=0 |
---|
39 | for E in ET.ElTable: |
---|
40 | if self.oneOnly: |
---|
41 | color=E[4] |
---|
42 | else: |
---|
43 | color=E[6] |
---|
44 | PickElement.ElButton(self,name=E[0], |
---|
45 | pos=wx.Point(E[1]*self.butWid+25,E[2]*24+24),tip=E[3],color=color) |
---|
46 | i+=1 |
---|
47 | |
---|
48 | def __init__(self, parent,oneOnly=False,ifNone=False): |
---|
49 | 'Needs a doc string' |
---|
50 | self.oneOnly = oneOnly |
---|
51 | self.ifNone = ifNone |
---|
52 | self._init_ctrls(parent) |
---|
53 | |
---|
54 | def ElButton(self, name, pos, tip, color): |
---|
55 | 'Needs a doc string' |
---|
56 | Black = wx.Colour(0,0,0) |
---|
57 | if not self.ifNone and name[0] == 'None': |
---|
58 | return |
---|
59 | if self.oneOnly: |
---|
60 | El = wscs.ColourSelect(label=name[0], parent=self,colour=color, |
---|
61 | pos=pos, size=wx.Size(self.butWid,23), style=wx.RAISED_BORDER) |
---|
62 | El.Bind(wx.EVT_BUTTON, self.OnElButton) |
---|
63 | else: |
---|
64 | butWid = self.butWid |
---|
65 | if name[0] == 'None': |
---|
66 | butWid *= 2 |
---|
67 | El = wx.ComboBox(choices=name, parent=self, pos=pos, size=wx.Size(butWid,23), |
---|
68 | style=wx.CB_READONLY, value=name[0]) |
---|
69 | El.Bind(wx.EVT_COMBOBOX,self.OnElButton) |
---|
70 | |
---|
71 | El.SetBackgroundColour(color) |
---|
72 | El.SetToolTipString(tip) |
---|
73 | |
---|
74 | def OnElButton(self, event): |
---|
75 | if self.oneOnly: |
---|
76 | El = event.GetEventObject().GetLabel() |
---|
77 | else: |
---|
78 | El = event.GetEventObject().GetValue() |
---|
79 | self.Elem = El |
---|
80 | self.EndModal(wx.ID_OK) |
---|
81 | |
---|
82 | class DeleteElement(wx.Dialog): |
---|
83 | "Delete element from selected set widget" |
---|
84 | def _init_ctrls(self, parent,choice): |
---|
85 | l = len(choice)-1 |
---|
86 | wx.Dialog.__init__(self, id=-1, name='Delete', parent=parent, |
---|
87 | pos=wx.DefaultPosition, size=wx.Size(max(128,64+l*24), 87), |
---|
88 | style=wx.DEFAULT_DIALOG_STYLE, title='Delete Element') |
---|
89 | self.Show(True) |
---|
90 | self.SetAutoLayout(True) |
---|
91 | self.SetHelpText('Select element to delete') |
---|
92 | self.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) |
---|
93 | |
---|
94 | i = 0 |
---|
95 | Elem = [] |
---|
96 | for Elem in choice: |
---|
97 | self.ElButton(id=-1,name=Elem,pos=wx.Point(16+i*24, 16)) |
---|
98 | i+=1 |
---|
99 | |
---|
100 | def __init__(self, parent,choice): |
---|
101 | DeleteElement.El = ' ' |
---|
102 | self._init_ctrls(parent,choice) |
---|
103 | |
---|
104 | def ElButton(self, id, name, pos): |
---|
105 | 'Needs a doc string' |
---|
106 | White = wx.Colour(255, 255, 255) |
---|
107 | El = wscs.ColourSelect(label=name, parent=self, colour = White, |
---|
108 | pos=pos, size=wx.Size(24, 23), style=wx.RAISED_BORDER) |
---|
109 | El.Bind(wx.EVT_BUTTON, self.OnDeleteButton) |
---|
110 | |
---|
111 | def OnDeleteButton(self, event): |
---|
112 | DeleteElement.El=event.GetEventObject().GetLabel() |
---|
113 | self.EndModal(wx.ID_OK) |
---|
114 | |
---|
115 | def GetDeleteElement(self): |
---|
116 | return DeleteElement.El |
---|
117 | |
---|
118 | |
---|