1 |
#Boa:MDIChild:FraggleTopicFrame |
2 |
|
3 |
# $Id: FraggleTopicFrame.py,v 1.3 2004/08/27 04:47:35 joko Exp $ |
4 |
# $Log: FraggleTopicFrame.py,v $ |
5 |
# Revision 1.3 2004/08/27 04:47:35 joko |
6 |
# instance of FraggleEngine now available in self.engine |
7 |
# added event handler "OnTopicListBoxListboxDclick" and logic to open "FraggleTopicDetailFrame"s |
8 |
# |
9 |
# Revision 1.2 2004/08/27 03:13:50 joko |
10 |
# added listbox for topics and button for update/sync |
11 |
# |
12 |
# Revision 1.1 2004/08/26 17:23:30 joko |
13 |
# initial commit |
14 |
# |
15 |
|
16 |
from wxPython.wx import * |
17 |
from wxPython.stc import * |
18 |
|
19 |
import FraggleTopicDetailFrame |
20 |
|
21 |
def create(parent, config): |
22 |
return FraggleTopicFrame(parent, config) |
23 |
|
24 |
[wxID_FRAGGLETOPICFRAME, wxID_FRAGGLETOPICFRAMETOPICLISTBOX, |
25 |
wxID_FRAGGLETOPICFRAMEUPDATEBUTTON, |
26 |
] = map(lambda _init_ctrls: wxNewId(), range(3)) |
27 |
|
28 |
class FraggleTopicFrame(wxMDIChildFrame): |
29 |
def _init_ctrls(self, prnt): |
30 |
# generated method, don't edit |
31 |
wxMDIChildFrame.__init__(self, id=wxID_FRAGGLETOPICFRAME, name='', |
32 |
parent=prnt, pos=wxPoint(494, 328), size=wxSize(169, 192), |
33 |
style=wxSIMPLE_BORDER | wxDEFAULT_FRAME_STYLE, title='Topics') |
34 |
self._init_utils() |
35 |
self.SetClientSize(wxSize(169, 192)) |
36 |
|
37 |
self.updateButton = wxButton(id=wxID_FRAGGLETOPICFRAMEUPDATEBUTTON, |
38 |
label=u'&Update', name=u'updateButton', parent=self, |
39 |
pos=wxPoint(0, 168), size=wxSize(168, 23), style=0) |
40 |
EVT_BUTTON(self.updateButton, wxID_FRAGGLETOPICFRAMEUPDATEBUTTON, |
41 |
self.OnUpdateButtonButton) |
42 |
|
43 |
self.topicListBox = wxListBox(choices=[], |
44 |
id=wxID_FRAGGLETOPICFRAMETOPICLISTBOX, name=u'topicListBox', |
45 |
parent=self, pos=wxPoint(0, 0), size=wxSize(168, 168), style=0) |
46 |
EVT_LISTBOX_DCLICK(self.topicListBox, |
47 |
wxID_FRAGGLETOPICFRAMETOPICLISTBOX, |
48 |
self.OnTopicListBoxListboxDclick) |
49 |
|
50 |
def _init_utils(self): |
51 |
# generated method, don't edit |
52 |
pass |
53 |
|
54 |
def __init__(self, parent, config): |
55 |
self.parent = parent |
56 |
self.config = config |
57 |
self._init_ctrls(parent) |
58 |
import __main__ |
59 |
self.engine = __main__.engine |
60 |
|
61 |
def OnUpdateButtonButton(self, event): |
62 |
#event.Skip() |
63 |
# todo: make fraggleEngine read config on its own |
64 |
self.engine.fraggleSync(self.config) |
65 |
topics = self.engine.getTopics() |
66 |
i = 0 |
67 |
for topic in topics: |
68 |
self.topicListBox.Append(topic['name'], i) |
69 |
i = i + 1 |
70 |
|
71 |
def OnTopicListBoxListboxDclick(self, event): |
72 |
#event.Skip() |
73 |
#print event |
74 |
|
75 |
# get "ClientData" of current selected entry from widget |
76 |
sel = self.topicListBox.GetSelection() |
77 |
seldata = self.topicListBox.GetClientData(sel) |
78 |
|
79 |
# determine if to activate an existing window or if to create a new one |
80 |
win = self.parent.FindWindowByName(str(seldata)) |
81 |
if win: |
82 |
win.Raise() |
83 |
win.SetFocus() |
84 |
return |
85 |
|
86 |
# resolve associated topic entry |
87 |
topics = self.engine.getTopics() |
88 |
title = topics[seldata]['name'] |
89 |
|
90 |
frame = FraggleTopicDetailFrame.create(self.parent) |
91 |
frame.SetName(str(seldata)) |
92 |
frame.SetTitle(title) |
93 |
|
94 |
# calculate new position (right beside the TopicFrame (us)) |
95 |
pos = self.GetPosition() + wxPoint(self.GetSize().GetWidth() + 5, 0) |
96 |
frame.Move(pos) |
97 |
self.parent.Fit() |
98 |
|
99 |
|
100 |
|