forked from monash-merc/cvl-fabric-launcher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
siteListDialog.py
148 lines (128 loc) · 5.46 KB
/
siteListDialog.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import wx
import sys
from wx.lib.agw import ultimatelistctrl as ULC
class newSiteDialog(wx.Dialog):
def __init__(self,siteList=None,*args,**kwargs):
super(newSiteDialog,self).__init__(*args,**kwargs)
self.SetSizer(wx.BoxSizer(wx.VERTICAL))
t = wx.StaticText(self,wx.ID_ANY,label='Name')
self.GetSizer().Add(t)
self.nametctrl=wx.TextCtrl(self,wx.ID_ANY,size=(400,-1))
self.GetSizer().Add(self.nametctrl,flag=wx.EXPAND)
t = wx.StaticText(self,wx.ID_ANY,label='URL')
self.GetSizer().Add(t)
self.urltctrl=wx.TextCtrl(self,wx.ID_ANY,size=(400,-1))
self.GetSizer().Add(self.urltctrl,flag=wx.EXPAND)
p=wx.Panel(self)
s=wx.BoxSizer(wx.HORIZONTAL)
p.SetSizer(s)
self.GetSizer().Add(p)
b=wx.Button(p,wx.ID_OK,label='OK')
b.Bind(wx.EVT_BUTTON,self.onClose)
s.Add(b,flag=wx.ALL,border=5)
b=wx.Button(p,wx.ID_CANCEL,label='Cancel')
b.Bind(wx.EVT_BUTTON,self.onClose)
s.Add(b,flag=wx.ALL,border=5)
self.GetSizer().Fit(self)
def getSite(self):
return self.urltctrl.GetValue()
def getName(self):
return self.nametctrl.GetValue()
def onClose(self,evt):
self.EndModal(evt.GetEventObject().GetId())
class siteListDialog(wx.Dialog):
def __init__(self,siteList=None,newSites=[],*args,**kwargs):
super(siteListDialog,self).__init__(*args,**kwargs)
mainSizer=wx.BoxSizer(wx.VERTICAL)
self.SetSizer(mainSizer)
t=wx.StaticText(self,wx.ID_ANY,label="Available Sites")
mainSizer.Add(t,flag=wx.ALL,border=5)
self.siteList=ULC.UltimateListCtrl(self,wx.ID_ANY,agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
self.siteList.InsertColumn(0,"Name")
self.siteList.InsertColumn(1,"URL")
self.siteList.InsertColumn(2,"Active")
i=0
for s in siteList:
self.siteList.InsertStringItem(i,"%s"%s['name'])
self.siteList.SetStringItem(i,1,"%s"%s['url'])
cb=wx.CheckBox(self.siteList)
cb.SetValue(s['enabled'])
self.siteList.SetItemWindow(i,col=2,wnd=cb)
i=i+1
urls=[]
for s in siteList:
urls.append(s['url'])
for s in newSites:
if s['url'] not in urls:
self.siteList.InsertStringItem(i,"%s"%s['name'])
self.siteList.SetStringItem(i,1,"%s"%s['url'])
cb=wx.CheckBox(self.siteList)
if s.has_key('enabled'):
cb.SetValue(s['enabled'])
else:
cb.SetValue(False)
self.siteList.SetItemWindow(i,col=2,wnd=cb)
i=i+1
self.siteList.SetColumnWidth(0,wx.LIST_AUTOSIZE)
self.siteList.SetColumnWidth(1,wx.LIST_AUTOSIZE)
self.siteList.SetColumnWidth(2,wx.LIST_AUTOSIZE_USEHEADER)
w=0
for i in range(0,self.siteList.GetColumnCount()):
w=w+self.siteList.GetColumnWidth(i)
# For some reason, even when I carefully calculate the column widths, on windows its still too small
if sys.platform.startswith('win'):
w=w+50
self.siteList.SetMinSize((w,200))
self.siteList.SetColumnWidth(1,-3)
mainSizer.Add(self.siteList,flag=wx.EXPAND,proportion=1)
self.siteList.Bind(ULC.EVT_LIST_ITEM_SELECTED,self.onItemSelected)
p=wx.Panel(self,wx.ID_ANY)
s=wx.BoxSizer(wx.HORIZONTAL)
s.Add((1,-1),proportion=1,flag=wx.EXPAND)
b=wx.Button(p,id=wx.ID_NEW,label="New")
s.Add(b,flag=wx.ALL|wx.ALIGN_RIGHT,border=5)
b.Bind(wx.EVT_BUTTON,self.onNew)
b=wx.Button(p,id=wx.ID_DELETE,label="Delete")
s.Add(b,flag=wx.ALL|wx.ALIGN_RIGHT,border=5)
b.Bind(wx.EVT_BUTTON,self.onDelete)
b=wx.Button(p,id=wx.ID_CANCEL,label="Cancel")
s.Add(b,flag=wx.ALL|wx.ALIGN_RIGHT,border=5)
b.Bind(wx.EVT_BUTTON,self.onCancel)
b=wx.Button(p,id=wx.ID_OK,label="OK")
s.Add(b,flag=wx.ALL|wx.ALIGN_RIGHT,border=5)
b.Bind(wx.EVT_BUTTON,self.onClose)
p.SetSizer(s)
mainSizer.Add(p,proportion=0,flag=wx.EXPAND)
self.GetSizer().Fit(self)
self.Refresh()
self.Update()
def onItemSelected(self,evt):
itemNumber=self.siteList.GetFirstSelected()
cb=self.siteList.GetItemWindow(itemNumber,2)
cb.SetValue(not cb.IsChecked())
def onNew(self,evt):
dlg=newSiteDialog(parent=self)
r=dlg.ShowModal()
if r==wx.ID_OK:
idx=self.siteList.GetItemCount()
self.siteList.InsertStringItem(idx,dlg.getName())
self.siteList.SetStringItem(idx,1,dlg.getSite())
cb=wx.CheckBox(self.siteList)
cb.SetValue(True)
self.siteList.SetItemWindow(idx,col=2,wnd=cb)
def onDelete(self,evt):
i=self.siteList.GetFirstSelected()
if i >=0:
self.siteList.DeleteItem(i)
def onClose(self,evt):
self.EndModal(evt.GetEventObject().GetId())
def onCancel(self,evt):
self.EndModal(evt.GetEventObject().GetId())
def getList(self):
r=[]
for i in range(0,self.siteList.GetItemCount()):
name=self.siteList.GetItem(i,0)
url=self.siteList.GetItem(i,1)
ri={'name':name.GetText(),'url':url.GetText(),'enabled':self.siteList.GetItemWindow(i,2).GetValue()}
r.append(ri)
return r