28 from graphics.GraphicCommons import SELECTION_DIVERGENCE, \ |
28 from graphics.GraphicCommons import SELECTION_DIVERGENCE, \ |
29 SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE |
29 SELECTION_CONVERGENCE, SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE |
30 from graphics.SFC_Objects import SFC_Divergence |
30 from graphics.SFC_Objects import SFC_Divergence |
31 from BlockPreviewDialog import BlockPreviewDialog |
31 from BlockPreviewDialog import BlockPreviewDialog |
32 |
32 |
33 #------------------------------------------------------------------------------- |
33 # ------------------------------------------------------------------------------- |
34 # Create New Divergence Dialog |
34 # Create New Divergence Dialog |
35 #------------------------------------------------------------------------------- |
35 # ------------------------------------------------------------------------------- |
36 |
36 |
37 """ |
|
38 Class that implements a dialog for defining parameters for creating a new |
|
39 divergence graphic element |
|
40 """ |
|
41 |
37 |
42 class SFCDivergenceDialog(BlockPreviewDialog): |
38 class SFCDivergenceDialog(BlockPreviewDialog): |
43 |
39 """ |
44 def __init__(self, parent, controller, tagname, poss_div_types = None): |
40 Class that implements a dialog for defining parameters for creating a new |
|
41 divergence graphic element |
|
42 """ |
|
43 |
|
44 def __init__(self, parent, controller, tagname, poss_div_types=None): |
45 """ |
45 """ |
46 Constructor |
46 Constructor |
47 @param parent: Parent wx.Window of dialog for modal |
47 @param parent: Parent wx.Window of dialog for modal |
48 @param controller: Reference to project controller |
48 @param controller: Reference to project controller |
49 @param tagname: Tagname of project POU edited |
49 @param tagname: Tagname of project POU edited |
50 @param poss_div_types: Types of divergence that will be available in the dialog window |
50 @param poss_div_types: Types of divergence that will be available in the dialog window |
51 """ |
51 """ |
52 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
52 BlockPreviewDialog.__init__(self, parent, controller, tagname, |
53 title=_('Create a new divergence or convergence')) |
53 title=_('Create a new divergence or convergence')) |
54 |
54 |
55 # Init common sizers |
55 # Init common sizers |
56 self._init_sizers(2, 0, 7, None, 2, 1) |
56 self._init_sizers(2, 0, 7, None, 2, 1) |
57 |
57 |
58 # Create label for divergence type |
58 # Create label for divergence type |
59 type_label = wx.StaticText(self, label=_('Type:')) |
59 type_label = wx.StaticText(self, label=_('Type:')) |
60 self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) |
60 self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) |
61 |
61 |
62 # Create radio buttons for selecting divergence type |
62 # Create radio buttons for selecting divergence type |
63 divergence_buttons = [ |
63 divergence_buttons = [ |
64 (SELECTION_DIVERGENCE, _('Selection Divergence')), |
64 (SELECTION_DIVERGENCE, _('Selection Divergence')), |
65 (SELECTION_CONVERGENCE, _('Selection Convergence')), |
65 (SELECTION_CONVERGENCE, _('Selection Convergence')), |
66 (SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')), |
66 (SIMULTANEOUS_DIVERGENCE, _('Simultaneous Divergence')), |
67 (SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))] |
67 (SIMULTANEOUS_CONVERGENCE, _('Simultaneous Convergence'))] |
68 poss_div_btns = [] |
68 poss_div_btns = [] |
69 if poss_div_types is not None: |
69 if poss_div_types is not None: |
70 for val in poss_div_types: |
70 for val in poss_div_types: |
71 poss_div_btns.append(divergence_buttons[val]) |
71 poss_div_btns.append(divergence_buttons[val]) |
72 else: |
72 else: |
73 poss_div_btns = divergence_buttons |
73 poss_div_btns = divergence_buttons |
74 self.TypeRadioButtons = {} |
74 self.TypeRadioButtons = {} |
75 first = True |
75 first = True |
76 focusbtn = None |
76 focusbtn = None |
77 for type, label in poss_div_btns: |
77 for type, label in poss_div_btns: |
78 radio_button = wx.RadioButton(self, label=label, |
78 radio_button = wx.RadioButton(self, label=label, |
79 style=(wx.RB_GROUP if first else 0)) |
79 style=(wx.RB_GROUP if first else 0)) |
80 radio_button.SetValue(first) |
80 radio_button.SetValue(first) |
81 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) |
81 self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) |
82 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
82 self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) |
83 self.TypeRadioButtons[type] = radio_button |
83 self.TypeRadioButtons[type] = radio_button |
84 if first: focusbtn = type |
84 if first: |
|
85 focusbtn = type |
85 first = False |
86 first = False |
86 |
87 |
87 # Create label for number of divergence sequences |
88 # Create label for number of divergence sequences |
88 sequences_label = wx.StaticText(self, |
89 sequences_label = wx.StaticText(self, |
89 label=_('Number of sequences:')) |
90 label=_('Number of sequences:')) |
90 self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW) |
91 self.LeftGridSizer.AddWindow(sequences_label, flag=wx.GROW) |
91 |
92 |
92 # Create spin control for defining number of divergence sequences |
93 # Create spin control for defining number of divergence sequences |
93 self.Sequences = wx.SpinCtrl(self, min=2, max=20, initial=2) |
94 self.Sequences = wx.SpinCtrl(self, min=2, max=20, initial=2) |
94 self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences) |
95 self.Bind(wx.EVT_SPINCTRL, self.OnSequencesChanged, self.Sequences) |
95 self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW) |
96 self.LeftGridSizer.AddWindow(self.Sequences, flag=wx.GROW) |
96 |
97 |
97 # Add preview panel and associated label to sizers |
98 # Add preview panel and associated label to sizers |
98 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
99 self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) |
99 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
100 self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) |
100 |
101 |
101 # Add buttons sizer to sizers |
102 # Add buttons sizer to sizers |
102 self.MainSizer.AddSizer(self.ButtonSizer, border=20, |
103 self.MainSizer.AddSizer( |
103 flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT) |
104 self.ButtonSizer, border=20, |
104 |
105 flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) |
|
106 |
105 self.Fit() |
107 self.Fit() |
106 |
108 |
107 # Selection divergence radio button is default control having keyboard |
109 # Selection divergence radio button is default control having keyboard |
108 # focus |
110 # focus |
109 self.TypeRadioButtons[focusbtn].SetFocus() |
111 self.TypeRadioButtons[focusbtn].SetFocus() |
110 |
112 |
111 def GetMinElementSize(self): |
113 def GetMinElementSize(self): |
112 """ |
114 """ |
113 Get minimal graphic element size |
115 Get minimal graphic element size |
114 @return: Tuple containing minimal size (width, height) or None if no |
116 @return: Tuple containing minimal size (width, height) or None if no |
115 element defined |
117 element defined |
116 """ |
118 """ |
117 return self.Element.GetMinSize(True) |
119 return self.Element.GetMinSize(True) |
118 |
120 |
119 def GetDivergenceType(self): |
121 def GetDivergenceType(self): |
120 """ |
122 """ |
121 Return type selected for SFC divergence |
123 Return type selected for SFC divergence |
122 @return: Type selected (None if not found) |
124 @return: Type selected (None if not found) |
123 """ |
125 """ |