[thotkeeper] r156 committed - For issue #44 ("Add ability to attach images with captions to...

2 views
Skip to first unread message

thotk...@googlecode.com

unread,
Sep 24, 2012, 3:48:37 PM9/24/12
to thotkee...@googlegroups.com
Revision: 156
Author: cmpi...@gmail.com
Date: Mon Sep 24 12:48:20 2012
Log: For issue #44 ("Add ability to attach images with captions to
entries"), add some initial working UI (the ability to list the
attachments).

* lib/tk_data.py
(TKEntryAttachment.__init__): Drop 'content_type' in favor of 'filename'.
(TKEntryAttachment.get_content_type): Remove.
(TKEntryAttachment.get_filename): New.
(TKEntry.TKJ_TAG_FILENAME): New.
(TKEntry._valid_parents): Add mapping for TKJ_TAG_FILENAME.
(TKEntry.startElement): Add handling for <attachments> and <filename>.
(TKEntry.endElement): Add handling for </filename>. Tweak handling
of </attachment> to use filename rather than content-type now.
(TKEntry.unparse_data): Write <filename>, and don't write the
"content_type" attribute of <attachment>.

* lib/tk_main.py
(ThotKeeper.OnInit): Record 'attachments_id' convenience variable.
(ThotKeeper._SetEntryFormDate): Build out the attachments list
report.
(ThotKeeper._DebugMessage): New helper function.

* lib/tk_resources.xrc
Replace static text panel with report-style ListBox of attachments.

http://code.google.com/p/thotkeeper/source/detail?r=156

Modified:
/trunk/lib/tk_data.py
/trunk/lib/tk_main.py
/trunk/lib/tk_resources.xrc

=======================================
--- /trunk/lib/tk_data.py Fri Sep 21 12:47:50 2012
+++ /trunk/lib/tk_data.py Mon Sep 24 12:48:20 2012
@@ -52,19 +52,19 @@


class TKEntryAttachment:
- def __init__(self, description='', content_type=None, data=None):
+ def __init__(self, description='', filename=None, data=None):
self.description = description
- self.content_type = content_type
+ self.filename = filename
self.data = data

+ def get_data(self):
+ return self.data
+
def get_description(self):
return self.description

- def get_content_type(self):
- return self.content_type
-
- def get_data(self):
- return self.data
+ def get_filename(self):
+ return self.filename

class TKEntry:
def __init__(self, author='', subject='', text='',
@@ -386,8 +386,9 @@
</tags>
<text>CDATA</text>
<attachments>
- <attachment content-type="T">>
+ <attachment>
<description>CDATA</description>
+ <filename>CDATA</filename>
<data>base64(DATA)</data>
</attachment>
...
@@ -407,6 +408,7 @@
TKJ_TAG_DIARY = 'diary'
TKJ_TAG_ENTRIES = 'entries'
TKJ_TAG_ENTRY = 'entry'
+ TKJ_TAG_FILENAME = 'filename'
TKJ_TAG_SUBJECT = 'subject'
TKJ_TAG_TAG = 'tag'
TKJ_TAG_TAGS = 'tags'
@@ -421,6 +423,7 @@
TKJ_TAG_DIARY : [ ],
TKJ_TAG_ENTRIES : [ TKJ_TAG_DIARY ],
TKJ_TAG_ENTRY : [ TKJ_TAG_ENTRIES ],
+ TKJ_TAG_FILENAME : [ TKJ_TAG_ATTACHMENT ],
TKJ_TAG_SUBJECT : [ TKJ_TAG_ENTRY ],
TKJ_TAG_TAG : [ TKJ_TAG_TAGS ],
TKJ_TAG_TAGS : [ TKJ_TAG_ENTRY ],
@@ -482,13 +485,15 @@
self.buffer = ''
elif name == self.TKJ_TAG_TAGS:
self.cur_entry['tags'] = []
+ elif name == self.TKJ_TAG_ATTACHMENTS:
+ self.cur_entry['attachments'] = []
elif name == self.TKJ_TAG_ATTACHMENT:
self.cur_attachment = dict(attrs)
- self.cur_entry['attachments'] = []
elif name == self.TKJ_TAG_SUBJECT \
or name == self.TKJ_TAG_TAG \
or name == self.TKJ_TAG_TEXT \
or name == self.TKJ_TAG_DESC \
+ or name == self.TKJ_TAG_FILENAME \
or name == self.TKJ_TAG_DATA:
self.buffer = ''

@@ -531,9 +536,12 @@
elif name == self.TKJ_TAG_DATA:
self.cur_attachment['data'] = base64.decodestring(self.buffer)
self.buffer = None
+ elif name == self.TKJ_TAG_FILENAME:
+ self.cur_attachment['filename'] = self.buffer
+ self.buffer = None
elif name == self.TKJ_TAG_ATTACHMENT:
attachment =
TKEntryAttachment(self.cur_attachment['description'],
-
self.cur_attachment['content_type'],
+ self.cur_attachment['filename'],
self.cur_attachment['data'])
self.cur_entry['attachments'].append(attachment)
self.cur_attachment = None
@@ -587,10 +595,11 @@
if len(attachments):
fp.write(' <attachments>\n')
for attachment in attachments:
- fp.write(' <attachment content_type="%s">\n'
- %
(attachment.get_content_type().encode('utf8')))
+ fp.write(' <attachment>\n')
fp.write(' <description>%s</description>\n'
% (attachment.get_description().encode('utf8')))
+ fp.write(' <filename>%s</filename>\n'
+ % (attachment.get_filename().encode('utf8')))
fp.write(' <data>%s</data>\n'
% (base64.encodestring(attachment.get_data())))
fp.write(' </attachment>\n')
=======================================
--- /trunk/lib/tk_main.py Sat Aug 21 08:11:23 2010
+++ /trunk/lib/tk_main.py Mon Sep 24 12:48:20 2012
@@ -568,6 +568,7 @@
self.subject_id = self.resources.GetXRCID('TKEntrySubject')
self.tags_id = self.resources.GetXRCID('TKEntryTags')
self.text_id = self.resources.GetXRCID('TKEntryText')
+ self.attachments_id = self.resources.GetXRCID("TKEntryAttachments")
self.file_new_id = self.resources.GetXRCID('TKMenuFileNew')
self.file_open_id = self.resources.GetXRCID('TKMenuFileOpen')
self.file_save_id = self.resources.GetXRCID('TKMenuFileSave')
@@ -915,17 +916,35 @@
else:
self.frame.FindWindowById(self.next_id).Enable(False)
self.frame.FindWindowById(self.date_id).SetLabel(label)
- text = subject = author = tags = ''
+ text = subject = author = tags = attachments = ''
entry = self.entries.get_entry(year, month, day, id)
if entry is not None:
text = entry.get_text()
author = entry.get_author()
subject = entry.get_subject()
tags = ', '.join(entry.get_tags() or [])
+ attachments = entry.get_attachments()
self.frame.FindWindowById(self.author_id).SetValue(author)
self.frame.FindWindowById(self.subject_id).SetValue(subject)
self.frame.FindWindowById(self.text_id).SetValue(text)
self.frame.FindWindowById(self.tags_id).SetValue(tags)
+
+ attachments_list = self.frame.FindWindowById(self.attachments_id)
+ attachments_list.ClearAll()
+ frame_width, xxx = self.frame.GetSizeTuple()
+ attachments_list.InsertColumn(0, "Description",
+ width=int(frame_width * 0.4))
+ attachments_list.InsertColumn(1, "Filename",
+ width=int(frame_width * 0.3))
+ if attachments:
+ attachments.reverse()
+ for attachment in attachments:
+ list_item = wx.ListItem()
+ idx = attachments_list.InsertItem(list_item)
+ attachments_list.SetStringItem(idx, 0,
+
attachment.get_description())
+ attachments_list.SetStringItem(idx, 1,
+ attachment.get_filename())
self._NotifyEntryLoaded(entry and True or False)

def _NotifyEntryLoaded(self, is_loaded=True):
@@ -1538,6 +1557,14 @@
return
self._SetEntryFormDate(data.year, data.month, data.day, data.id)

+ ### -----------------------------------------------------------------
+ ### Debugging Stuff
+ ### -----------------------------------------------------------------
+
+ def _DebugMessage(self, msg):
+ wx.MessageBox(msg, "DEBUG MESSAGE",
+ wx.OK | wx.ICON_ERROR, self.frame)
+ return

def main():
file = None
=======================================
--- /trunk/lib/tk_resources.xrc Fri Sep 21 08:59:17 2012
+++ /trunk/lib/tk_resources.xrc Mon Sep 24 12:48:20 2012
@@ -343,16 +343,15 @@
<object class="wxPanel">
<object class="wxFlexGridSizer">
<cols>1</cols>
- <rows>2</rows>
+ <rows>1</rows>
<growablecols>0</growablecols>
<growablerows>0</growablerows>
- <growablerows>1</growablerows>
<object class="sizeritem">
- <object class="wxStaticText">
- <label>This feature is not yet
implemented.</label>
+ <object class="wxListCtrl"
name="TKEntryAttachments">
+ <style>wxLC_REPORT|wxLC_SINGLE_SEL</style>
</object>
<flag>wxALL|wxEXPAND</flag>
- <border>20</border>
+ <border>5</border>
</object>
</object>
</object>
Reply all
Reply to author
Forward
0 new messages