示例#1
0
        for row in removals:
            new_record.remove(row)

        print new_record.count()
        for i in range(new_record.count()):
            print new_record.value(i).toString()

        return new_record


if __name__ == "__main__":
    import gettext
    gettext.install("")

    app = QtGui.QApplication([])

    from lib_openmolar.admin.connect import DemoAdminConnection
    from lib_openmolar.admin.qt4.classes import MyModel
    sc = DemoAdminConnection()
    sc.connect()

    model = MyModel(db=sc)
    model.setTable("diary_calendar")
    while True:
        dl = NewRowDialog(model)
        if dl.exec_():
            print dl.record
        else:
            break
示例#2
0
 def setModel(self):
     self.model = MyModel(self, self.connection)
示例#3
0
class DatabaseTableViewer(QtGui.QWidget):
    connection = None
    name = _("Table Viewer")

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.table_list = QtGui.QListWidget(self)
        tool_bar = QtGui.QToolBar()

        icon = QtGui.QIcon.fromTheme("document-open")
        action_import = QtGui.QAction(icon, "import from xml", self)
        action_import.setToolTip(
            "import data into the current table from an xml file")

        icon = QtGui.QIcon.fromTheme("document-save")
        action_export = QtGui.QAction(icon, "export to xml", self)
        action_export.setToolTip(
            "export data from the current table to an xml file")

        action_new_row = QtGui.QAction("New Row", self)
        action_new_row.setToolTip("add a row of data to the current table")

        tool_bar.addAction(action_new_row)
        tool_bar.addSeparator()
        tool_bar.addAction(action_import)
        tool_bar.addAction(action_export)

        self.table_view = QtGui.QTableView(self)

        #h_header = self.table_view.horizontalHeader()
        #h_header.setStretchLastSection(True)

        left_frame = QtGui.QFrame(self)
        layout = QtGui.QVBoxLayout(left_frame)
        layout.setMargin(0)
        layout.addWidget(self.table_list)
        layout.addWidget(tool_bar)

        splitter = QtGui.QSplitter(self)
        splitter.addWidget(left_frame)
        splitter.addWidget(self.table_view)

        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(splitter)
        splitter.setSizes([150, 400])

        self.table_list.itemSelectionChanged.connect(self.load_data)

        action_new_row.triggered.connect(self.new_row)
        action_import.triggered.connect(self.import_data)
        action_export.triggered.connect(self.export_data)

    def set_connection(self, connection):
        self.connection = connection
        self.load_table_choice()
        self.setModel()

    def setModel(self):
        self.model = MyModel(self, self.connection)

    def load_table_choice(self):
        self.table_list.clear()
        if not self.connection:
            return
        tables = self.connection.get_available_tables()
        tables.sort()
        if tables:
            self.table_list.addItems(tables)
            self.table_list.setCurrentRow(-1)
        else:
            self.parent().parent().emit(QtCore.SIGNAL("Query Success"),
                                        _("No Tables"))

    def advise(self, message):
        QtGui.QMessageBox.warning(self, _("error"), message)

    def new_row(self, args):
        listwidget_item = self.table_list.currentItem()
        if not listwidget_item.isSelected():
            self.advise("no table chosen")
            return

        dl = NewRowDialog(self.model)
        if dl.exec_():
            record = dl.record
            if self.model.insertRecord(-1, record):
                self.advise(_("Successful insert"))
            else:
                self.advise(u"%s<hr /><pre>%s</pre>" %
                            (_("error"), self.model.lastError().text()))
                self.model.revert()

    def export_data(self, args):
        listwidget_item = self.table_list.currentItem()
        if not listwidget_item.isSelected():
            self.advise("no table chosen")
            return
        try:
            filepath = QtGui.QFileDialog.getSaveFileName(
                None, _("save xml"), "%s.xml" % self.model.tableName(),
                _("text files ") + "(*.xml)")
            if filepath != '':
                if not re.match(".*\.xml$", filepath):
                    filepath += ".xml"
                f = open(filepath, "w")
                f.write(self.model.table_xml())
                f.close()
        except Exception, e:
            self.advise(_("File not saved") + " - %s" % e)
示例#4
0
 def setModel(self):
     self.model = MyModel(self, self.connection)
示例#5
0
class DatabaseTableViewer(QtGui.QWidget):
    connection = None
    name = _("Table Viewer")
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.table_list = QtGui.QListWidget(self)
        tool_bar = QtGui.QToolBar()

        icon = QtGui.QIcon.fromTheme("document-open")
        action_import = QtGui.QAction(icon, "import from xml", self)
        action_import.setToolTip(
            "import data into the current table from an xml file")


        icon = QtGui.QIcon.fromTheme("document-save")
        action_export = QtGui.QAction(icon, "export to xml", self)
        action_export.setToolTip(
            "export data from the current table to an xml file")

        action_new_row = QtGui.QAction("New Row", self)
        action_new_row.setToolTip(
            "add a row of data to the current table")


        tool_bar.addAction(action_new_row)
        tool_bar.addSeparator()
        tool_bar.addAction(action_import)
        tool_bar.addAction(action_export)


        self.table_view = QtGui.QTableView(self)

        #h_header = self.table_view.horizontalHeader()
        #h_header.setStretchLastSection(True)

        left_frame = QtGui.QFrame(self)
        layout = QtGui.QVBoxLayout(left_frame)
        layout.setMargin(0)
        layout.addWidget(self.table_list)
        layout.addWidget(tool_bar)

        splitter = QtGui.QSplitter(self)
        splitter.addWidget(left_frame)
        splitter.addWidget(self.table_view)

        layout = QtGui.QVBoxLayout(self)
        layout.addWidget(splitter)
        splitter.setSizes([150,400])

        self.table_list.itemSelectionChanged.connect(self.load_data)

        action_new_row.triggered.connect(self.new_row)
        action_import.triggered.connect(self.import_data)
        action_export.triggered.connect(self.export_data)

    def set_connection(self, connection):
        self.connection = connection
        self.load_table_choice()
        self.setModel()

    def setModel(self):
        self.model = MyModel(self, self.connection)

    def load_table_choice(self):
        self.table_list.clear()
        if not self.connection:
            return
        tables = self.connection.get_available_tables()
        tables.sort()
        if tables:
            self.table_list.addItems(tables)
            self.table_list.setCurrentRow(-1)
        else:
            self.parent().parent().emit(QtCore.SIGNAL("Query Success"),
                _("No Tables"))

    def advise(self, message):
        QtGui.QMessageBox.warning(self, _("error"), message)

    def new_row(self, args):
        listwidget_item = self.table_list.currentItem()
        if not listwidget_item.isSelected():
            self.advise("no table chosen")
            return

        dl = NewRowDialog(self.model)
        if dl.exec_():
            record = dl.record
            if self.model.insertRecord(-1, record):
                self.advise(_("Successful insert"))
            else:
                self.advise(u"%s<hr /><pre>%s</pre>"% (_("error"),
                    self.model.lastError().text()))
                self.model.revert()


    def export_data(self, args):
        listwidget_item = self.table_list.currentItem()
        if not listwidget_item.isSelected():
            self.advise("no table chosen")
            return
        try:
            filepath = QtGui.QFileDialog.getSaveFileName(None,
            _("save xml"),"%s.xml"% self.model.tableName(),
            _("text files ")+"(*.xml)")
            if filepath != '':
                if not re.match(".*\.xml$", filepath):
                    filepath += ".xml"
                f = open(filepath, "w")
                f.write(self.model.table_xml())
                f.close()
        except Exception, e:
            self.advise(_("File not saved")+" - %s"% e)
示例#6
0
                new_record.setValue(i, input_.text())

        for row in removals:
            new_record.remove(row)

        print new_record.count()
        for i in range(new_record.count()):
            print new_record.value(i).toString()

        return new_record

if __name__ == "__main__":
    import gettext
    gettext.install("")

    app = QtGui.QApplication([])

    from lib_openmolar.admin.connect import DemoAdminConnection
    from lib_openmolar.admin.qt4.classes import MyModel
    sc = DemoAdminConnection()
    sc.connect()

    model = MyModel(db=sc)
    model.setTable("diary_calendar")
    while True:
        dl = NewRowDialog(model)
        if dl.exec_():
            print dl.record
        else:
            break