本文整理汇总了Python中viewer.Viewer.document方法的典型用法代码示例。如果您正苦于以下问题:Python Viewer.document方法的具体用法?Python Viewer.document怎么用?Python Viewer.document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viewer.Viewer
的用法示例。
在下文中一共展示了Viewer.document方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AttachmentAdder
# 需要导入模块: from viewer import Viewer [as 别名]
# 或者: from viewer.Viewer import document [as 别名]
class AttachmentAdder(Peer):
Add = Pillow.In
def __init__(self, room, directAdd=True):
Peer.__init__(self, room)
self._viewer = Viewer(room, self._setID, '_id')
self._directAdd = directAdd
self._id = None
self._catch(AttachmentAdder.In.Add, self._add)
def _setID(self, value):
self._id = value
@defer.inlineCallbacks
def _add(self, pillow, feather):
if self._id != None:
dialog = QtGui.QFileDialog()
dialog.setDirectory(QtCore.QDir.homePath())
dialog.setFileMode(QtGui.QFileDialog.ExistingFiles)
if dialog.exec_():
fileNames = dialog.selectedFiles()
from twisted.internet import threads
import os.path, mimetypes
if self._directAdd and self._viewer.document().database() != None:
import copy
doc = copy.deepcopy(self._viewer.document()._data)
db = self._viewer.document().database()
else:
doc = db = None
for f in fileNames:
content = yield threads.deferToThread(self.__readFile, f)
name = os.path.basename(f)
if self._directAdd and db is not None:
(t, encoding) = mimetypes.guess_type(name)
if t != None:
yield db.put_attachment(doc, name, content, t)
else:
yield db.put_attachment(doc, name, content)
else:
self._viewer.document().setAttachment(name, content)
def __readFile(self, f):
return open(f, "rb").read()