@@ -43,6 +43,10 @@ def __init__(self, parent):
43
43
self .SetTitle (_APP_NAME + " - " + _APP_VERSION )
44
44
45
45
self .Bind (wx .EVT_SIZE , self .OnSize )
46
+
47
+ self .bomSortCol = - 1
48
+ self .bomSortAscending = True
49
+ self .nonBomSortAscending = False
46
50
47
51
def OnSize (self , event ):
48
52
size = self .GetClientSize ()
@@ -76,4 +80,79 @@ def OnSize(self, event):
76
80
if event is not None :
77
81
event .Skip ()
78
82
83
+ def OnBOMGridLabelClicked (self , event ):
84
+ if event .Col <= 1 :
85
+ if self .bomSortCol == event .Col :
86
+ self .bomSortAscending = not self .bomSortAscending
87
+ else :
88
+ self .bomSortCol = event .Col
89
+
90
+ rows = self .bomGrid .GetNumberRows () - 1 # Ignore the empty final row
91
+ cols = self .bomGrid .GetNumberCols ()
92
+
93
+ def compareVals (col , ascending , val1 , val2 ):
94
+ if col == 0 and ascending :
95
+ if val1 [0 ] == val2 [0 ]: # If the Qty is equal, sort on ascending PROD_ID
96
+ return (val1 [1 ] < val2 [1 ])
97
+ return (int (val1 [0 ]) < int (val2 [0 ]))
98
+ elif col == 0 and not ascending :
99
+ if val1 [0 ] == val2 [0 ]: # If the Qty is equal, sort on ascending PROD_ID
100
+ return (val1 [1 ] < val2 [1 ])
101
+ return (int (val1 [0 ]) > int (val2 [0 ]))
102
+ elif col == 1 and ascending :
103
+ return (val1 [1 ] < val2 [1 ])
104
+ elif col == 1 and not ascending :
105
+ return (val1 [1 ] > val2 [1 ])
106
+ return False
107
+
108
+ for row1 in range (rows ):
109
+ for row2 in range (rows ):
110
+ cells1 = []
111
+ cells2 = []
112
+ for col in range (cols ):
113
+ cells1 .append (self .bomGrid .GetCellValue (row1 , col ))
114
+ cells2 .append (self .bomGrid .GetCellValue (row2 , col ))
115
+ background1 = self .bomGrid .GetCellBackgroundColour (row1 , 1 )
116
+ background2 = self .bomGrid .GetCellBackgroundColour (row2 , 1 )
117
+ if compareVals (self .bomSortCol , self .bomSortAscending , cells1 , cells2 ):
118
+ for col in range (cols ):
119
+ self .bomGrid .SetCellValue (row1 , col , cells2 [col ])
120
+ self .bomGrid .SetCellValue (row2 , col , cells1 [col ])
121
+ self .bomGrid .SetCellBackgroundColour (row1 , 1 , background2 )
122
+ self .bomGrid .SetCellBackgroundColour (row2 , 1 , background1 )
123
+
124
+ self .bomGrid .Refresh ()
125
+
126
+ def OnNonBOMGridLabelClicked (self , event ):
127
+ if event .Col == 0 :
128
+ self .nonBomSortAscending = not self .nonBomSortAscending
129
+
130
+ rows = self .nonBomGrid .GetNumberRows () - 1 # Ignore the empty final row
131
+ cols = self .nonBomGrid .GetNumberCols ()
132
+
133
+ def compareVals (ascending , val1 , val2 ):
134
+ if ascending :
135
+ return (int (val1 [0 ]) < int (val2 [0 ]))
136
+ return (int (val1 [0 ]) > int (val2 [0 ]))
137
+
138
+ for row1 in range (rows ):
139
+ for row2 in range (rows ):
140
+ cells1 = []
141
+ cells2 = []
142
+ for col in range (cols ):
143
+ cells1 .append (self .nonBomGrid .GetCellValue (row1 , col ))
144
+ cells2 .append (self .nonBomGrid .GetCellValue (row2 , col ))
145
+ if compareVals (self .nonBomSortAscending , cells1 , cells2 ):
146
+ for col in range (cols ):
147
+ self .nonBomGrid .SetCellValue (row1 , col , cells2 [col ])
148
+ self .nonBomGrid .SetCellValue (row2 , col , cells1 [col ])
149
+
150
+ self .nonBomGrid .Refresh ()
151
+
152
+ def OnShowEvent (self , event ):
153
+ self .bomGrid .Refresh () # This may help the cell background color?
154
+
155
+
156
+
157
+
79
158
0 commit comments