new parameter -s textonly
[swftools.git] / wx / gui / info.py
1 import wx
2 from lib.document import PDF_INFO
3 import lib.utils as utils
4 #from wx.lib.mixins import listctrl as listmix
5
6 #class InfoList(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
7 class InfoList(wx.ListCtrl):
8     def __init__(self, parent):
9         wx.ListCtrl.__init__(self, parent,
10                                  style=wx.LC_REPORT
11                                  | wx.LC_VIRTUAL
12                                  | wx.BORDER_SUNKEN
13                                  #| wx.BORDER_NONE
14                                  #| wx.LC_EDIT_LABELS
15                                  #| wx.LC_SORT_ASCENDING
16                                  #| wx.LC_NO_HEADER
17                                  | wx.LC_VRULES
18                                  | wx.LC_HRULES
19                                  | wx.LC_SINGLE_SEL
20                              )
21         #listmix.ListCtrlAutoWidthMixin.__init__(self)
22         #self.setResizeColumn("LAST")
23
24         self.InsertColumn(0, "Property")
25         self.InsertColumn(1, "Value", wx.LIST_FORMAT_LEFT)
26         self.SetColumnWidth(0, 120)
27         self.SetColumnWidth(1, 400)
28
29         self.__data = []
30
31     def append(self, data):
32         self.__data.append(data)
33         self.SetItemCount(len(self.__data))
34         self.RefreshItem(len(self.__data)-1)
35
36     def OnGetItemText(self, item, col):
37         data_row = self.__data[item]
38         return data_row[col]
39
40     def display(self, doc):
41         self.__data = []
42         for item in PDF_INFO:
43             val = getattr(doc, item)
44             # This will be the fallback value
45             sane_val = repr(val)[1:-1]
46             # Maybe more enconding, which ones?
47             for encoding in ["utf-8", "iso-8859-15",]:
48                 try:
49                     sane_val = utils.force_unicode(val, encoding)
50                     break
51                 except utils.GPdf2SwfUnicodeDecodeError:
52                     pass
53
54             self.append([item, sane_val])
55