1 | """ElementGUI: class defn. for element GUIs |
---|
2 | Copyright: 2008, Robert B. Von Dreele & Brian H. Toby (Argonne National Laboratory) |
---|
3 | """ |
---|
4 | ########### SVN repository information ################### |
---|
5 | # $Date: 2012-01-24 14:31:27 -0600 (Tue, 24 Jan 2012) $ |
---|
6 | # $Author: vondreele & toby $ |
---|
7 | # $Revision: 456 $ |
---|
8 | # $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/GSASIIElemGUI.py $ |
---|
9 | # $Id: GSASIIElemGUI.py 456 2012-01-24 20:31:27Z toby $ |
---|
10 | ########### SVN repository information ################### |
---|
11 | import wx |
---|
12 | import os |
---|
13 | import wx.lib.colourselect as wscs |
---|
14 | class PickElement(wx.Dialog): |
---|
15 | "Makes periodic table widget for picking element - caller maintains element list" |
---|
16 | Elem=None |
---|
17 | def _init_ctrls(self, prnt,oneOnly): |
---|
18 | wx.Dialog.__init__(self, id=-1, name='PickElement', |
---|
19 | parent=prnt, pos=wx.DefaultPosition, |
---|
20 | style=wx.DEFAULT_DIALOG_STYLE, title='Pick Element') |
---|
21 | import ElementTable as ET |
---|
22 | self.butWid = 55 |
---|
23 | if 'nt' in os.name: |
---|
24 | self.butWid = 40 |
---|
25 | self.SetClientSize(wx.Size(50+18*self.butWid, 250)) |
---|
26 | |
---|
27 | i=0 |
---|
28 | for E in ET.ElTable: |
---|
29 | if oneOnly: |
---|
30 | color=E[4] |
---|
31 | else: |
---|
32 | color=E[6] |
---|
33 | PickElement.ElButton(self,name=E[0], |
---|
34 | pos=wx.Point(E[1]*self.butWid+25,E[2]*24+24),tip=E[3],color=color,oneOnly=oneOnly) |
---|
35 | i+=1 |
---|
36 | |
---|
37 | def __init__(self, parent,oneOnly=False): |
---|
38 | self._init_ctrls(parent,oneOnly) |
---|
39 | |
---|
40 | def ElButton(self, name, pos, tip, color, oneOnly): |
---|
41 | Black = wx.Colour(0,0,0) |
---|
42 | if oneOnly: |
---|
43 | El = wscs.ColourSelect(label=name[0], parent=self,colour=color, |
---|
44 | pos=pos, size=wx.Size(self.butWid,23), style=wx.RAISED_BORDER) |
---|
45 | El.Bind(wx.EVT_BUTTON, self.OnElButton) |
---|
46 | else: |
---|
47 | El = wx.ComboBox(choices=name, parent=self, pos=pos, size=wx.Size(self.butWid,23), |
---|
48 | style=wx.CB_READONLY, value=name[0]) |
---|
49 | El.Bind(wx.EVT_COMBOBOX,self.OnElButton) |
---|
50 | |
---|
51 | El.SetBackgroundColour(color) |
---|
52 | El.SetToolTipString(tip) |
---|
53 | |
---|
54 | def OnElButton(self, event): |
---|
55 | El = event.GetEventObject().GetValue() |
---|
56 | self.Elem = El |
---|
57 | self.EndModal(wx.ID_OK) |
---|
58 | |
---|
59 | class DeleteElement(wx.Dialog): |
---|
60 | "Delete element from selected set widget" |
---|
61 | def _init_ctrls(self, parent,choice): |
---|
62 | l = len(choice)-1 |
---|
63 | wx.Dialog.__init__(self, id=-1, name='Delete', parent=parent, |
---|
64 | pos=wx.DefaultPosition, size=wx.Size(max(128,64+l*24), 87), |
---|
65 | style=wx.DEFAULT_DIALOG_STYLE, title='Delete Element') |
---|
66 | self.Show(True) |
---|
67 | self.SetAutoLayout(True) |
---|
68 | self.SetHelpText('Select element to delete') |
---|
69 | self.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) |
---|
70 | |
---|
71 | i = 0 |
---|
72 | Elem = [] |
---|
73 | for Elem in choice: |
---|
74 | self.ElButton(id=-1,name=Elem,pos=wx.Point(16+i*24, 16)) |
---|
75 | i+=1 |
---|
76 | |
---|
77 | def __init__(self, parent,choice): |
---|
78 | DeleteElement.El = ' ' |
---|
79 | self._init_ctrls(parent,choice) |
---|
80 | |
---|
81 | def ElButton(self, id, name, pos): |
---|
82 | White = wx.Colour(255, 255, 255) |
---|
83 | El = wscs.ColourSelect(label=name, parent=self, colour = White, |
---|
84 | pos=pos, size=wx.Size(24, 23), style=wx.RAISED_BORDER) |
---|
85 | El.Bind(wx.EVT_BUTTON, self.OnDeleteButton) |
---|
86 | |
---|
87 | def OnDeleteButton(self, event): |
---|
88 | DeleteElement.El=event.GetEventObject().GetLabel() |
---|
89 | self.EndModal(wx.ID_OK) |
---|
90 | |
---|
91 | def GetDeleteElement(self): |
---|
92 | return DeleteElement.El |
---|
93 | |
---|
94 | |
---|