本文整理汇总了Python中db.Database.insert_new_paste方法的典型用法代码示例。如果您正苦于以下问题:Python Database.insert_new_paste方法的具体用法?Python Database.insert_new_paste怎么用?Python Database.insert_new_paste使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.insert_new_paste方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clipboardWatcher
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import insert_new_paste [as 别名]
class clipboardWatcher(QObject):
on_server_update = pyqtSignal()
def __init__(self, qtClipboard, login_callback):
super(clipboardWatcher, self).__init__()
self.clipboard = qtClipboard
self._cur_contents = self.clipboard.text()
self.clipboard.dataChanged.connect(self.update_to_server)
self.on_server_update.connect(self.update_clipboard)
self.first_login = True
self.login_callback = login_callback
def authenticate(self, username, password):
if self.first_login:
self.db = Database(self.login_callback, self.update_from_server)
self.first_login = False
self.db.authenticate(username, password)
def update_to_server(self, replacing_paste=None):
new_contents = self.clipboard.text()
if new_contents != self._cur_contents:
self.db.insert_new_paste(new_contents)
self._cur_contents = new_contents
def update_from_server(self, latest_paste):
if latest_paste != self._cur_contents:
self._cur_contents = latest_paste
self.on_server_update.emit()
def update_clipboard(self, paste = ""):
if paste:
self.clipboard.setText(paste)
else:
self.clipboard.setText(self._cur_contents)
def get_contents(self):
return self._cur_contents
def stop(self):
if not self.first_login:
self.db.stop()