本文整理汇总了Python中View.View.show方法的典型用法代码示例。如果您正苦于以下问题:Python View.show方法的具体用法?Python View.show怎么用?Python View.show使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类View.View
的用法示例。
在下文中一共展示了View.show方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from View import View [as 别名]
# 或者: from View.View import show [as 别名]
def main(args) :
"""Fonction principal qui va nous lancer notre annuaire"""
#bdd = sqlite3.connect('Bdd/patron.db')
app=QApplication(args)
control = Control()
model = Model(control)
fenetre = View(control);
fenetre.show();
#bdd.close()
return app.exec_()
示例2: __init__
# 需要导入模块: from View import View [as 别名]
# 或者: from View.View import show [as 别名]
class Control:
"""Control Class: Commands the View and the Model, and deals with interactions between them."""
def __init__(self, app):
"""Constructor of Control"""
self.view = View(self, "Phone Book", app)
self.view.show()
self.model = Model()
def exportCSV(self):
"""Export contacts into a CSV file"""
fileDialog = QtWidgets.QFileDialog.getSaveFileName(self.view,
"Save File",
"untitled",
"CSV files (*.csv);;All Files (*)")
fileName = str(fileDialog).partition('\'')[2].split('\'')[0]
if not (fileName is ""):
with open(fileName, "wb") as file:
file.write(str(self.model.exportCSV()).encode('Latin-1'))
QtWidgets.QMessageBox.information(self.view,
"Save succeeded",
"The file has been successfully saved in the folder : " + fileName,
QtWidgets.QMessageBox.Close)
self.view.isModified = False
else:
QtWidgets.QMessageBox.information(self.view, "Save failed", "The file has not been saved.")
def importCSV(self):
"""Import contacts from a CSV file"""
fileDialog = QtWidgets.QFileDialog.getOpenFileName(self.view, "Open File", None, "CSV Files (*.csv)")
fileName = str(fileDialog).partition('\'')[2].split('\'')[0]
if not (fileName is ""):
if not self.model.listContact:
answer = QtWidgets.QMessageBox.No
else:
answer = QtWidgets.QMessageBox.question(self.view, "Death or life choice !?",
"Would you like to append the contacts to your actual list?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
if answer == QtWidgets.QMessageBox.No:
self.clearAll()
with open(fileName, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for nbLine, row in enumerate(reader):
tempElement = QtWidgets.QTreeWidgetItem()
if nbLine != 0:
for index, word in enumerate(row):
tempElement.setText(index, word)
self.registerContact(tempElement.clone())
QtWidgets.QMessageBox.information(self.view,
"Open succeeded",
"The file has been successfully opened in the folder : " + fileName,
QtWidgets.QMessageBox.Close)
else:
QtWidgets.QMessageBox.information(self.view, "Open failed", "The file has not been opened.")
def registerContact(self, newElement, oldElement = None):
"""Register contacts in Model before adding them to the View"""
if self.model.registerContact(newElement.clone(), oldElement):
if oldElement is not None:
self.view.tableOfContact.takeTopLevelItem(self.view.indexOfCurrentElement())
self.view.tableOfContact.addTopLevelItem(self.model.buffer)
self.view.tableOfContact.setCurrentItem(self.model.buffer)
def eraseContact(self, item):
"""Erase contacts in model and by doing so, authorized the View to delete it too"""
if self.model.listContact:
if not self.model.eraseContact(item):
return False
else:
return True
else:
return False
def searchContact(self, strContact):
"""Search the text entered by the user among the list of contacts in model"""
if self.model.listContact:
newListContact = self.model.searchContact(strContact)
if newListContact:
# Erase contacts in the view before inserting the ones among
# the new list containing the searched contacts:
size = int(self.view.tableOfContact.topLevelItemCount())
if size != 0:
for index in reversed(range(size)):
self.view.tableOfContact.takeTopLevelItem(index)
for contact in newListContact:
self.view.tableOfContact.addTopLevelItem(contact)
def clearAll(self):
"""Erase all contacts from the Model and the View"""
size = int(self.view.tableOfContact.topLevelItemCount())
if size != 0:
for index in reversed(range(size)):
self.model.eraseContact(index)
self.view.tableOfContact.takeTopLevelItem(index)