forked from capocchi/DEVSimPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityGUI.py
More file actions
152 lines (109 loc) · 3.91 KB
/
PriorityGUI.py
File metadata and controls
152 lines (109 loc) · 3.91 KB
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
149
150
151
152
# -*- coding: utf-8 -*-
import wx
import os.path
from sys import maxsize
import DragList
class PriorityGUI(wx.Frame):
def __init__(self, parent, id, title, priorityList):
wx.Frame.__init__( self,
parent,
id,
title,
size = (350, 300),
style = wx.FRAME_NO_WINDOW_MENU|wx.DEFAULT_FRAME_STYLE|wx.CLOSE_BOX)
icon = wx.EmptyIcon() if wx.VERSION_STRING < '4.0' else wx.Icon()
icon.CopyFromBitmap(wx.Bitmap(os.path.join(ICON_PATH_16_16, "priority.png"), wx.BITMAP_TYPE_ANY))
self.SetIcon(icon)
panel = wx.Panel(self, -1)
### ------------------------------------------------------------------
#self.listCtrl = DragList.DragList(panel, style = wx.LC_ICON|wx.LC_AUTOARRANGE)
#il = wx.ImageList(16, 16, True)
#il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16, 16)))
#self.listCtrl.AssignImageList(il, wx.IMAGE_LIST_NORMAL)
self.listCtrl = DragList.DragList(panel, style = wx.LC_LIST)
# append to list
for item in priorityList:
#self.listCtrl.InsertImageStringItem(maxint,item,0)
self.listCtrl.InsertItem(100000000, item)
if wx.VERSION_STRING >= '4.0':
self.listCtrl.SetToolTipString = self.listCtrl.SetToolTip
self.listCtrl.SetToolTipString(_('Drag and drop a model in order to define its priority.'))
### id list not empty, first item is selected
if self.listCtrl.GetItemCount():
self.listCtrl.Select(0, 1)
### -------------------------------------------------------------------
hbox = wx.BoxSizer(wx.HORIZONTAL)
up_btn = wx.Button(panel, wx.ID_UP)
down_btn = wx.Button(panel, wx.ID_DOWN)
apply_btn = wx.Button(panel, wx.ID_APPLY)
up_btn.Enable(self.listCtrl.GetItemCount() != 0)
down_btn.Enable(self.listCtrl.GetItemCount() != 0)
hbox.Add(up_btn, 1)
hbox.Add(down_btn, 1)
hbox.Add(apply_btn, 1)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.listCtrl, 1, wx.EXPAND | wx.ALL , 5)
vbox.Add(hbox, 0, wx.EXPAND | wx.ALL, 5)
panel.SetSizer(vbox)
self.Bind(wx.EVT_BUTTON, self.OnApply, id=wx.ID_APPLY)
self.Bind(wx.EVT_BUTTON, self.OnUp, id=wx.ID_UP)
self.Bind(wx.EVT_BUTTON, self.OnDown, id=wx.ID_DOWN)
self.Center()
def OnApply(self, evt):
self.Close()
def GetSelectedItems(self):
""" Gets the selected items for the list control.
Selection is returned as a list of selected indices,
low to high.
"""
selection = []
index = self.listCtrl.GetFirstSelected()
if index != -1:
selection.append(index)
while len(selection) != self.listCtrl.GetSelectedItemCount():
index = self.listCtrl.GetNextSelected(index)
selection.append(index)
return selection
def OnUp(self, evt):
""" Allow up moving for selected items.
"""
for pos in self.GetSelectedItems():
item = self.listCtrl.GetItem(pos)
current_item = item
new_pos = pos-1 if pos != 0 else self.listCtrl.GetItemCount()-1
current_item.SetId(new_pos)
self.listCtrl.DeleteItem(pos)
self.listCtrl.InsertItem(item)
self.listCtrl.SetItemState(new_pos, 1, wx.LIST_STATE_SELECTED)
self.listCtrl.Select(new_pos,1)
def OnDown(self, evt):
""" Allow down moving for selected items.
"""
for pos in self.GetSelectedItems():
item = self.listCtrl.GetItem(pos)
current_item = item
new_pos = pos+1 if pos != self.listCtrl.GetItemCount()-1 else 0
current_item.SetId(new_pos)
self.listCtrl.DeleteItem(pos)
self.listCtrl.InsertItem(item)
self.listCtrl.SetItemState(new_pos, 1, wx.LIST_STATE_SELECTED)
self.listCtrl.Select(new_pos, 1)
### ------------------------------------------------------------
class TestApp(wx.App):
""" Testing application
"""
def OnInit(self):
"""
"""
import builtins
import gettext
builtins.__dict__['ICON_PATH_16_16']=os.path.join('icons','16x16')
builtins.__dict__['_'] = gettext.gettext
frame = PriorityGUI(None, -1, "Test", ['TOTO', 'TITI'])
frame.Show()
return True
def OnQuit(self, event):
self.Close()
if __name__ == '__main__':
app = TestApp(0)
app.MainLoop()