| 2 |
|
|
| 3 |
# $Id$ |
# $Id$ |
| 4 |
# $Log$ |
# $Log$ |
| 5 |
|
# Revision 1.10 2004/09/21 18:11:05 xabbu |
| 6 |
|
# + started work on the final tree Controll to display contenttypes and their items |
| 7 |
|
# |
| 8 |
|
# Revision 1.9 2004/09/17 20:51:24 xabbu |
| 9 |
|
# + function initTreeList() will init a TreeList |
| 10 |
|
# + function loadContent(contentkey) moved from FraggleListFrame |
| 11 |
|
# |
| 12 |
|
# Revision 1.8 2004/09/17 09:46:30 xabbu |
| 13 |
|
# U function OnUpdateButtonButton items will be added in the correct order now |
| 14 |
|
# |
| 15 |
|
# Revision 1.7 2004/09/15 22:31:27 xabbu |
| 16 |
|
# + in function OnUpdateButtonButton call to fraggleSync replaced with syncTopics |
| 17 |
|
# + topics are being recieved from the server now |
| 18 |
|
# |
| 19 |
|
# Revision 1.6 2004/08/31 02:25:34 joko |
| 20 |
|
# U removed FraggleTopicDetailFrame in favor of FraggleItemFrame and FraggleListFrame |
| 21 |
|
# U now clearing topicListBox before updating it |
| 22 |
|
# |
| 23 |
|
# Revision 1.5 2004/08/30 13:06:16 joko |
| 24 |
|
# U now gets config via self.engine |
| 25 |
|
# |
| 26 |
|
# Revision 1.4 2004/08/27 21:14:02 xabbu |
| 27 |
|
# TopicDetails can now be closed. |
| 28 |
|
# GUI change on Preferences Dialog in order to prepare multiple server profiles. |
| 29 |
|
# Small bugfixes to get the new topic windows working on posix platform. |
| 30 |
|
# |
| 31 |
|
# Revision 1.3 2004/08/27 04:47:35 joko |
| 32 |
|
# instance of FraggleEngine now available in self.engine |
| 33 |
|
# added event handler "OnTopicListBoxListboxDclick" and logic to open "FraggleTopicDetailFrame"s |
| 34 |
|
# |
| 35 |
# Revision 1.2 2004/08/27 03:13:50 joko |
# Revision 1.2 2004/08/27 03:13:50 joko |
| 36 |
# added listbox for topics and button for update/sync |
# added listbox for topics and button for update/sync |
| 37 |
# |
# |
| 42 |
from wxPython.wx import * |
from wxPython.wx import * |
| 43 |
from wxPython.stc import * |
from wxPython.stc import * |
| 44 |
|
|
| 45 |
def create(parent, config): |
import FraggleItemFrame |
| 46 |
return FraggleTopicFrame(parent, config) |
import FraggleListFrame |
| 47 |
|
|
| 48 |
|
def create(parent): |
| 49 |
|
return FraggleTopicFrame(parent) |
| 50 |
|
|
| 51 |
[wxID_FRAGGLETOPICFRAME, wxID_FRAGGLETOPICFRAMETOPICLISTBOX, |
[wxID_FRAGGLETOPICFRAME, wxID_FRAGGLETOPICFRAMETOPICLISTBOX, |
| 52 |
wxID_FRAGGLETOPICFRAMEUPDATEBUTTON, |
wxID_FRAGGLETOPICFRAMETREECTRL1, wxID_FRAGGLETOPICFRAMEUPDATEBUTTON, |
| 53 |
] = map(lambda _init_ctrls: wxNewId(), range(3)) |
] = map(lambda _init_ctrls: wxNewId(), range(4)) |
| 54 |
|
|
| 55 |
class FraggleTopicFrame(wxMDIChildFrame): |
class FraggleTopicFrame(wxMDIChildFrame): |
| 56 |
def _init_ctrls(self, prnt): |
def _init_ctrls(self, prnt): |
| 57 |
# generated method, don't edit |
# generated method, don't edit |
| 58 |
wxMDIChildFrame.__init__(self, id=wxID_FRAGGLETOPICFRAME, name='', |
wxMDIChildFrame.__init__(self, id=wxID_FRAGGLETOPICFRAME, name='', |
| 59 |
parent=prnt, pos=wxPoint(352, 280), size=wxSize(177, 219), |
parent=prnt, pos=wxPoint(494, 328), size=wxSize(424, 219), |
| 60 |
style=wxSIMPLE_BORDER | wxDEFAULT_FRAME_STYLE, title='Topics') |
style=wxSIMPLE_BORDER | wxDEFAULT_FRAME_STYLE, title='Topics') |
| 61 |
self.SetClientSize(wxSize(169, 192)) |
self.SetClientSize(wxSize(416, 192)) |
| 62 |
|
|
| 63 |
self.updateButton = wxButton(id=wxID_FRAGGLETOPICFRAMEUPDATEBUTTON, |
self.updateButton = wxButton(id=wxID_FRAGGLETOPICFRAMEUPDATEBUTTON, |
| 64 |
label=u'&Update', name=u'updateButton', parent=self, |
label=u'&Update', name=u'updateButton', parent=self, |
| 69 |
self.topicListBox = wxListBox(choices=[], |
self.topicListBox = wxListBox(choices=[], |
| 70 |
id=wxID_FRAGGLETOPICFRAMETOPICLISTBOX, name=u'topicListBox', |
id=wxID_FRAGGLETOPICFRAMETOPICLISTBOX, name=u'topicListBox', |
| 71 |
parent=self, pos=wxPoint(0, 0), size=wxSize(168, 168), style=0) |
parent=self, pos=wxPoint(0, 0), size=wxSize(168, 168), style=0) |
| 72 |
|
EVT_LISTBOX_DCLICK(self.topicListBox, |
| 73 |
|
wxID_FRAGGLETOPICFRAMETOPICLISTBOX, |
| 74 |
|
self.OnTopicListBoxListboxDclick) |
| 75 |
|
|
| 76 |
|
self.treeCtrl1 = wxTreeCtrl(id=wxID_FRAGGLETOPICFRAMETREECTRL1, |
| 77 |
|
name='treeCtrl1', parent=self, pos=wxPoint(176, 0), |
| 78 |
|
size=wxSize(160, 168), style=wxTR_HAS_BUTTONS) |
| 79 |
|
self.treeCtrl1.Enable(True) |
| 80 |
|
EVT_LEFT_DCLICK(self.treeCtrl1, self.OnTreeCtrl1LeftDclick) |
| 81 |
|
|
| 82 |
def __init__(self, parent, config): |
def __init__(self, parent): |
| 83 |
self.config = config |
self.parent = parent |
| 84 |
|
|
| 85 |
|
# render widgets |
| 86 |
self._init_ctrls(parent) |
self._init_ctrls(parent) |
| 87 |
|
|
| 88 |
|
# get engine-instance (singleton) |
| 89 |
|
import __main__ |
| 90 |
|
self.engine = __main__.engine |
| 91 |
|
|
| 92 |
def OnUpdateButtonButton(self, event): |
def OnUpdateButtonButton(self, event): |
| 93 |
#event.Skip() |
#event.Skip() |
| 94 |
import __main__ |
self.engine.syncTopics() |
| 95 |
engine = __main__.engine |
topics = self.engine.getTopics() |
| 96 |
# todo: make fraggleEngine read config on its own |
#print topics |
| 97 |
engine.fraggleSync(self.config) |
self.topicListBox.Clear() |
| 98 |
topics = engine.getTopics() |
self.treeCtrl1.Clear() |
| 99 |
i = 0 |
i = 0 |
| 100 |
for topic in topics: |
for topic in topics: |
| 101 |
self.topicListBox.Append(topic['name'], i) |
self.topicListBox.Append(topics[str(i)], i) |
| 102 |
i = i + 1 |
i = i + 1 |
| 103 |
|
self.initTreeList() |
| 104 |
|
|
| 105 |
|
def initTreeList(self): |
| 106 |
|
topics = self.engine.getTopics() |
| 107 |
|
i = 0 |
| 108 |
|
self.treeItems = {} |
| 109 |
|
self.rootItem = self.treeCtrl1.AddRoot('Root') |
| 110 |
|
self.treeItems[topics[str(i)]] = {} |
| 111 |
|
for topic in topics: |
| 112 |
|
self.treeItems[topics[str(i)]] = self.treeCtrl1.AppendItem(self.rootItem, topics[str(i)]) |
| 113 |
|
self.load_content(topics[str(i)]) |
| 114 |
|
i = i + 1 |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
def load_content(self,contentkey): |
| 118 |
|
self.payload = self.engine.listItems(contentkey) |
| 119 |
|
self.columns = self.payload['2'] |
| 120 |
|
topics = self.engine.getTopics() |
| 121 |
|
|
| 122 |
|
entries = self.payload['1'] |
| 123 |
|
itemid = 0 |
| 124 |
|
columnlist = self.columns |
| 125 |
|
for entry in entries: |
| 126 |
|
data = entries[entry] |
| 127 |
|
itemData = wxTreeItemData() |
| 128 |
|
itemData.SetData(data) |
| 129 |
|
#print columnlist |
| 130 |
|
#columnlist.pop() |
| 131 |
|
if entries[entry]['1'] == '1': |
| 132 |
|
self.treeCtrl1.AppendItem(self.treeItems[contentkey], |
| 133 |
|
str(entries[entry]['2']+' - English'), |
| 134 |
|
-1, |
| 135 |
|
-1, |
| 136 |
|
itemData) |
| 137 |
|
elif entries[entry]['1'] == '2': |
| 138 |
|
self.treeCtrl1.AppendItem(self.treeItems[contentkey], |
| 139 |
|
str(entries[entry]['2']+' - Deutsch'), |
| 140 |
|
-1, |
| 141 |
|
-1, |
| 142 |
|
itemData) |
| 143 |
|
#print self.treeItems |
| 144 |
|
itemid += 1 |
| 145 |
|
|
| 146 |
|
def OnTopicListBoxListboxDclick(self, event): |
| 147 |
|
#event.Skip() |
| 148 |
|
#print event |
| 149 |
|
|
| 150 |
|
# get "ClientData" of current selected entry from widget |
| 151 |
|
sel = self.topicListBox.GetSelection() |
| 152 |
|
seldata = self.topicListBox.GetClientData(sel) |
| 153 |
|
|
| 154 |
|
# determine if to activate an existing window or if to create a new one |
| 155 |
|
win = self.parent.FindWindowByName(str(seldata)) |
| 156 |
|
if win: |
| 157 |
|
win.Raise() |
| 158 |
|
win.SetFocus() |
| 159 |
|
return |
| 160 |
|
|
| 161 |
|
# resolve associated topic entry |
| 162 |
|
topics = self.engine.getTopics() |
| 163 |
|
title = topics[str(seldata)] |
| 164 |
|
#print title |
| 165 |
|
print topics |
| 166 |
|
|
| 167 |
|
frame = FraggleListFrame.create(self.parent) |
| 168 |
|
frame.SetName(str(seldata)) |
| 169 |
|
frame.SetTitle(title) |
| 170 |
|
|
| 171 |
|
# calculate new position (right beside the TopicFrame (us)) |
| 172 |
|
pos = self.GetPosition() + wxPoint(self.GetSize().GetWidth() + 5, 0) |
| 173 |
|
frame.Move(pos) |
| 174 |
|
self.parent.Fit() |
| 175 |
|
|
| 176 |
|
frame.load_content(topics[str(seldata)]) |
| 177 |
|
|
| 178 |
|
def OnTreeCtrl1LeftDclick(self, event): |
| 179 |
|
sel = self.treeCtrl1.GetSelection() |
| 180 |
|
selitem = self.treeCtrl1.GetItemData(sel) |
| 181 |
|
seldata = selitem.GetData() |
| 182 |
|
selparent = self.treeCtrl1.GetItemParent(sel) |
| 183 |
|
seltype = self.treeCtrl1.GetItemText(selparent) |
| 184 |
|
self.engine.modules.Dispatch(seldata,seltype) |
| 185 |
|
event.Skip() |
| 186 |
|
|
| 187 |
|
|