add widget to QMessageBox pyqt5 code example
Example: pyqt5 qmessagebox information example
def open_database(self, filename=''):
""" This function opens a database and set this on the UI """
if self.created:
QMessageBox.information(self,
self.tr("Information"),
self.tr("You may only have one database"
" open at time."))
DEBUG("Ya existe una base de datos abierta")
return
if not filename:
if self.__last_open_folder is None:
directory = os.path.expanduser("~")
else:
directory = self.__last_open_folder
filter_ = settings.SUPPORTED_FILES.split(';;')[0]
filename, _ = QFileDialog.getOpenFileName(self,
self.tr("Open Database"),
directory,
filter_)
if not filename:
return
self.__last_open_folder = file_manager.get_path(filename)
DEBUG("Abriendo la base de datos: '{}'".format(filename))
try:
pfile_object = pfile.File(filename)
db_data = pfile_object.read()
db_data = self.__sanitize_data(db_data)
except Exception as reason:
QMessageBox.information(self,
self.tr("The file couldn't be open"),
str(reason))
CRITICAL("Error al intentar abrir el archivo: {}".format(reason))
return
db_container = database_container.DatabaseContainer()
try:
db_container.create_database(db_data)
except Exception as reason:
QMessageBox.information(self,
self.tr("Error"),
str(reason))
CRITICAL("Error al crear la base de datos: {}".format(reason))
return
db_container.pfile = pfile_object
self.add_widget(db_container)
db_name = file_manager.get_basename(filename)
pireal = Pireal.get_service("pireal")
pireal.change_title(db_name)
pireal.set_enabled_db_actions(True)
pireal.set_enabled_relation_actions(True)
self.recent_databases = filename
self.created = True