-
Notifications
You must be signed in to change notification settings - Fork 0
/
sidebar.py
90 lines (68 loc) · 2.65 KB
/
sidebar.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
import wx
from base import *
from wx.lib.pubsub import setupkwargs
from wx.lib.pubsub import setuparg1
from wx.lib.pubsub import pub
LOCATIONS = ["France","Germany","United Kingdom","Ukraine","Hong Kong","USA"]
class SidebarList(wx.ListCtrl):
""" navigate different """
def __init__(self, parent):
wx.ListCtrl.__init__(self,
parent,
style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_NO_HEADER|wx.LC_HRULES)
self.AppendColumn("Sidebar")
self.SetFont(SIDEBARFONT)
strmax = []
items = ["-----MAIN-----",
"All Configs",
"Recently Used",
"Starred",
"Command Flags",
"Preferences",
"-----Protocol-----",
"TCP",
"UDP",
"-----Locations-----"]
for item in items:
strmax.append(len(item))
self.InsertItem(self.GetItemCount(), item)
for loc in LOCATIONS:
strmax.append(len(loc))
if loc == "separator":
self.InsertItem(self.GetItemCount(), "-"*10)
continue
self.InsertItem(self.GetItemCount(), loc)
dc = wx.ScreenDC()
dc.SetFont(SIDEBARFONT)
text = "*"*max(strmax)
maxtextwidth, _ = dc.GetTextExtent(text)
# (width, height) in pixels
# print dc.GetTextExtent(text))
self.SetSize(250, -1)
self.SetColumnWidth(0, maxtextwidth)
#Bindings
self.Bind(wx.EVT_MOTION, self.OnSidebarMotion)
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSidebarListItemSelected)
def OnSidebarMotion(self, event):
pos = event.GetPosition()
row, _ = self.HitTest(pos)
if row == -1:
return
item_txt = self.GetItem(row, 0).GetText()
if "-" in item_txt:
return
self.Select(row)
def OnSidebarListItemSelected(self, event=None):
item = event.Index
if item == -1:
return
item_txt = self.GetItem(item).GetText()
pub.sendMessage("PubSubChangeMainPanel", item_txt)
class Sidebar(BasePanel):
""" navigate different """
def __init__(self, parent):
BasePanel.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
list = SidebarList(self)
sizer.Add(list, 1, wx.ALL|wx.EXPAND)
self.SetSizer(sizer)