1import sys
2from PyQt4.QtGui import *
3from PyQt4.QtCore import *
4
5def window():
6 app = QApplication(sys.argv)
7 w = QWidget()
8 b = QPushButton(w)
9 b.setText("Show message!")
10
11 b.move(50,50)
12 b.clicked.connect(showdialog)
13 w.setWindowTitle("PyQt Dialog demo")
14 w.show()
15 sys.exit(app.exec_())
16
17def showdialog():
18 msg = QMessageBox()
19 msg.setIcon(QMessageBox.Information)
20
21 msg.setText("This is a message box")
22 msg.setInformativeText("This is additional information")
23 msg.setWindowTitle("MessageBox demo")
24 msg.setDetailedText("The details are as follows:")
25 msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
26 msg.buttonClicked.connect(msgbtn)
27
28 retval = msg.exec_()
29 print "value of pressed message box button:", retval
30
31def msgbtn(i):
32 print "Button pressed is:",i.text()
33
34if __name__ == '__main__':
35 window()
1def open_database(self, filename=''):
2 """ This function opens a database and set this on the UI """
3
4 # If not filename provide, then open dialog to select
5 if self.created:
6 QMessageBox.information(self,
7 self.tr("Information"),
8 self.tr("You may only have one database"
9 " open at time."))
10 DEBUG("Ya existe una base de datos abierta")
11 return
12 if not filename:
13 if self.__last_open_folder is None:
14 directory = os.path.expanduser("~")
15 else:
16 directory = self.__last_open_folder
17 filter_ = settings.SUPPORTED_FILES.split(';;')[0]
18 filename, _ = QFileDialog.getOpenFileName(self,
19 self.tr("Open Database"),
20 directory,
21 filter_)
22 # If is canceled, return
23 if not filename:
24 return
25
26 # Remember the folder
27 self.__last_open_folder = file_manager.get_path(filename)
28
29 DEBUG("Abriendo la base de datos: '{}'".format(filename))
30
31 # If filename provide
32 try:
33 # Read pdb file
34 pfile_object = pfile.File(filename)
35 db_data = pfile_object.read()
36 # Create a dict to manipulate data more easy
37 db_data = self.__sanitize_data(db_data)
38 except Exception as reason:
39 QMessageBox.information(self,
40 self.tr("The file couldn't be open"),
41 str(reason))
42 CRITICAL("Error al intentar abrir el archivo: {}".format(reason))
43 return
44
45 # Create a database container widget
46 db_container = database_container.DatabaseContainer()
47
48 try:
49 db_container.create_database(db_data)
50 except Exception as reason:
51 QMessageBox.information(self,
52 self.tr("Error"),
53 str(reason))
54 CRITICAL("Error al crear la base de datos: {}".format(reason))
55 return
56
57 # Set the PFile object to the new database
58 db_container.pfile = pfile_object
59 # Add data base container to stacked
60 self.add_widget(db_container)
61 # Database name
62 db_name = file_manager.get_basename(filename)
63 # Update title with the new database name, and enable some actions
64 pireal = Pireal.get_service("pireal")
65 pireal.change_title(db_name)
66 pireal.set_enabled_db_actions(True)
67 pireal.set_enabled_relation_actions(True)
68 # Add to recent databases
69 self.recent_databases = filename
70 self.created = True
71