本文整理匯總了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)