forked from esitarski/CrossMgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixCategories.py
57 lines (46 loc) · 1.54 KB
/
FixCategories.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import wx
import Model
def FixCategories( choice, iSelection = None, doSyncCategories = True ):
choice.InvalidateBestSize()
choice.SetSize(choice.GetBestSize())
race = Model.race
if race and doSyncCategories and getattr(race, 'syncCategories', True):
iSelection = getattr( race, 'modelCategory', 0 )
items = choice.GetItems()
if iSelection is not None and iSelection < len(items):
choice.SetSelection( iSelection or 0 )
categories = race.getCategories( startWaveOnly=False ) if race else []
newItems = [(' ' if c.catType == Model.Category.CatComponent else '') + c.fullname for c in categories]
newItems.insert( 0, _('All') )
categories.insert( 0, None )
if items == newItems:
return categories[choice.GetSelection()]
catNameCur = None
if items:
catNameCur = items[choice.GetSelection()]
choice.Clear()
choice.AppendItems( newItems )
iNew = 0
if catNameCur is not None:
for i, fullname in enumerate(newItems):
if catNameCur == fullname:
iNew = i
break
choice.SetSelection( iNew )
return categories[choice.GetSelection()]
def SetCategory( choice, cat ):
if FixCategories(choice) != cat:
if cat is None:
choice.SetSelection( 0 )
else:
for i, item in enumerate(choice.GetItems()):
if item.strip() == cat.fullname:
choice.SetSelection( i )
break
if __name__ == '__main__':
app = wx.App(False)
mainWin = wx.Frame(None,title="CrossMan", size=(600,400))
choice = wx.Choice(mainWin)
FixCategories( choice )
mainWin.Show()
app.MainLoop()