Doesn't do anything useful on its own.
"""
fields = ()
- hidden_fields = ()
- visible_fields = ()
+ view_list_fields = ()
+ view_display_fields = ()
- def __init__(self, model=None, view_list=None, view_display=None, parent=None):
- super(BaseController, self).__init__(parent)
+ def __init__(self, model=None, view_list=None, view_display=None, parent=None, views=None):
+ super(BaseController, self).__init__(parent=parent)
+
+ self.views = views
# Find out base name.
classname = self.__class__.__name__
- self.base_name = (
+ self.basename = (
classname[:-10] if classname.endswith('Controller')
else classname)
- self.base_name = self.base_name[0].lower() + self.base_name[1:]
+ self.basename = self.basename[0].lower() + self.basename[1:]
if model:
# We're given an existing model.
else:
# Initialize a new model.
self.model = QtSql.QSqlTableModel(parent)
- self.model.setTable(self.base_name + 's')
+ self.model.setTable(self.basename + 's')
# Create model header from fields list.
for i, field in enumerate(self.fields):
self.view_list = view_list
else:
# Get view list from the parent.
- self.view_list = getattr(parent, self.base_name + 'ViewList')
+ self.view_list = getattr(views, self.basename + 'ViewList')
self.view_list.setModel(self.model)
# Hide fields not meant for display.
for i, field in enumerate(self.fields):
- if (field in self.hidden_fields or
- field not in self.visible_fields):
+ if field not in self.view_list_fields:
self.view_list.setColumnHidden(i, True)
# Stretch headers to fill all available width.
self.view_display = view_display
else:
# Get view display from the parent.
- self.view_display = getattr(parent, self.base_name + 'ViewDisplay')
+ self.view_display = QtGui.QDataWidgetMapper(parent)
+ #getattr(parent, self.basename + 'ViewDisplay')
self.view_display.setModel(self.model)
+ # If view_display_fields is not send, display all fields except
+ # the first one that is usually the ID.
+ display_fields = self.view_display_fields or self.fields[1:]
+ for i, field in enumerate(self.fields):
+ if field in display_fields:
+ field_name = self.basename + ''.join(
+ word.capitalize() for word in field.split(' '))
+ self.view_display.addMapping(
+ getattr(views, field_name), i)
+
# Register signals for this controller.
for sender, signal, receiver in self.getSignalsData():
QtCore.QObject.connect(sender, QtCore.SIGNAL(signal), receiver)
"""
Default signals built from controller's base name.
"""
- parent = self.parent()
-
return (
- (getattr(parent, self.base_name + 'Add'), 'clicked()', self.add),
- (getattr(parent, self.base_name + 'ViewList'),
+ (getattr(self.views, self.basename + 'Add'), 'clicked()', self.add),
+ (getattr(self.views, self.basename + 'ViewList'),
'currentRowChanged(int)', self.select),
- (getattr(parent, self.base_name + 'Save'), 'clicked()',
+ (getattr(self.views, self.basename + 'Save'), 'clicked()',
self.save),
)
def add(self):
"""
- TODO: Default implementation.
+ Add new connection.
"""
- return NotImplemented
+ #name_template = 'New connection'
+
+ num_rows = self.model.rowCount()
+ self.model.insertRows(num_rows, 1)
+ self.view_list.selectRow(num_rows)
+ getattr(self.parent(), self.basename + 'Add').setEnabled(False)
+
+ #self.parent.ui.connectionName.setText('New connection')
+ #self.parent.ui.connectionName.setFocus()
+ #self.parent.ui.connectionName.selectAll()
+ #self.parent.ui.connectionLocalIpAddress.clear()
+ #self.parent.ui.connectionLocalPort.clear()
+ #self.parent.ui.connectionFreeswitchIpAddress.clear()
+ #self.parent.ui.connectionFreeswitchPort.clear()
def save(self):
"""
fields = (
'ID', 'Name', 'Local IP Address', 'Local Port',
'Freeswitch IP Address', 'Freeswitch Port')
- visible_fields = ('Name', 'Freeswitch IP Address', 'Freeswitch Port')
+ view_list_fields = ('Name', 'Freeswitch IP Address', 'Freeswitch Port')
def select(self, row):
"""
This creates a new connection with bound data copied from another one.
"""
- def add(self):
- """
- Add new connection.
- """
- self.currentConnection = None
-
- name_template = 'New connection [{0:02}]'
- for i in xrange(1, 100):
- name = name_template.format(i)
- connection_exists = False
- for connection in self.connections:
- if connection.name == name:
- connection_exists = True
- break
-
- if not connection_exists:
- break
-
- self.parent.ui.connectionName.setText('New connection')
- self.parent.ui.connectionName.setFocus()
- self.parent.ui.connectionName.selectAll()
- self.parent.ui.connectionLocalIpAddress.clear()
- self.parent.ui.connectionLocalPort.clear()
- self.parent.ui.connectionFreeswitchIpAddress.clear()
- self.parent.ui.connectionFreeswitchPort.clear()
-
def save(self):
"""
Save new or existing connection.
-# Copyright (c) Stas Shtin, 2010
+# -*- coding: utf-8 -*-
-# This file is part of IPyPBX.
+# Form implementation generated from reading ui file '../ui/layout.ui'
+#
+# Created: Fri Apr 9 17:29:46 2010
+# by: PyQt4 UI code generator 4.7.2
+#
+# WARNING! All changes made in this file will be lost!
-# IPyPBX is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+from PyQt4 import QtCore, QtGui
-# IPyPBX is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with IPyPBX. If not, see <http://www.gnu.org/licenses/>.
-
-from PyQt4 import QtCore, QtGui, QtSql
-
-
-class ConnectionDataMapper(QtGui.QDataWidgetMapper):
- def add(self):
- model = self.model()
- model.insertRows(1, model.rowCount())
-
-
-class MainWindow(QtGui.QMainWindow):
- """
- Main GUI window.
- """
- def __init__(self, parent=None):
- super(MainWindow, self).__init__(parent)
-
- # Tweak layout.
- self.setObjectName("MainWindow")
- self.resize(800, 400)
- self.centralwidget = QtGui.QWidget(self)
+class Ui_MainWindow(object):
+ def setupUi(self, MainWindow):
+ MainWindow.setObjectName("MainWindow")
+ MainWindow.resize(800, 400)
+ self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
-
- # Add tab widget
self.tabWidget = QtGui.QTabWidget(self.centralwidget)
self.tabWidget.setGeometry(QtCore.QRect(-2, -1, 811, 491))
self.tabWidget.setMinimumSize(QtCore.QSize(800, 480))
self.tabWidget.setObjectName("tabWidget")
-
- # Connections tab definition.
self.connectionsTab = QtGui.QWidget()
self.connectionsTab.setObjectName("connectionsTab")
self.layoutWidget = QtGui.QWidget(self.connectionsTab)
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtGui.QGridLayout(self.layoutWidget)
self.gridLayout.setObjectName("gridLayout")
- self.connectionViewDisplay = ConnectionDataMapper()
- #self.formLayout_7 = QtGui.QFormLayout()
- #self.formLayout_7.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
- #self.formLayout_7.setObjectName("formLayout_7")
- #self.label_5 = QtGui.QLabel(self.layoutWidget)
- #self.label_5.setObjectName("label_5")
- #self.formLayout_7.setWidget(0, QtGui.QFormLayout.LabelRole, self.label_5)
- #self.connectionName = QtGui.QLineEdit(self.layoutWidget)
- #self.connectionName.setMaxLength(100)
- #self.connectionName.setObjectName("connectionName")
- #self.formLayout_7.setWidget(0, QtGui.QFormLayout.FieldRole, self.connectionName)
- #self.connectionLocalIpAddress = QtGui.QLineEdit(self.layoutWidget)
- #self.connectionLocalIpAddress.setInputMethodHints(QtCore.Qt.ImhNone)
- #self.connectionLocalIpAddress.setObjectName("connectionLocalIpAddress")
- #self.formLayout_7.setWidget(1, QtGui.QFormLayout.FieldRole, self.connectionLocalIpAddress)
- #self.label_11 = QtGui.QLabel(self.layoutWidget)
- #self.label_11.setObjectName("label_11")
- #self.formLayout_7.setWidget(2, QtGui.QFormLayout.LabelRole, self.label_11)
- #self.connectionLocalPort = QtGui.QLineEdit(self.layoutWidget)
- #self.connectionLocalPort.setObjectName("connectionLocalPort")
- #self.formLayout_7.setWidget(2, QtGui.QFormLayout.FieldRole, self.connectionLocalPort)
- #self.label_13 = QtGui.QLabel(self.layoutWidget)
- #self.label_13.setObjectName("label_13")
- #self.formLayout_7.setWidget(4, QtGui.QFormLayout.LabelRole, self.label_13)
- #self.connectionFreeswitchPort = QtGui.QLineEdit(self.layoutWidget)
- #self.connectionFreeswitchPort.setObjectName("connectionFreeswitchPort")
- #self.formLayout_7.setWidget(4, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchPort)
- #self.label_12 = QtGui.QLabel(self.layoutWidget)
- #self.label_12.setObjectName("label_12")
- #self.formLayout_7.setWidget(1, QtGui.QFormLayout.LabelRole, self.label_12)
- #self.connectionFreeswitchIpAddress = QtGui.QLineEdit(self.layoutWidget)
- #self.connectionFreeswitchIpAddress.setObjectName("connectionFreeswitchIpAddress")
- #self.formLayout_7.setWidget(3, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchIpAddress)
- #self.label_14 = QtGui.QLabel(self.layoutWidget)
- #self.label_14.setObjectName("label_14")
- #self.formLayout_7.setWidget(3, QtGui.QFormLayout.LabelRole, self.label_14)
- #self.gridLayout.addLayout(self.formLayout_7, 0, 1, 1, 1)
+ self.formLayout_7 = QtGui.QFormLayout()
+ self.formLayout_7.setFieldGrowthPolicy(QtGui.QFormLayout.AllNonFixedFieldsGrow)
+ self.formLayout_7.setObjectName("formLayout_7")
+ self.label_5 = QtGui.QLabel(self.layoutWidget)
+ self.label_5.setObjectName("label_5")
+ self.formLayout_7.setWidget(0, QtGui.QFormLayout.LabelRole, self.label_5)
+ self.connectionName = QtGui.QLineEdit(self.layoutWidget)
+ self.connectionName.setMaxLength(100)
+ self.connectionName.setObjectName("connectionName")
+ self.formLayout_7.setWidget(0, QtGui.QFormLayout.FieldRole, self.connectionName)
+ self.connectionLocalIpAddress = QtGui.QLineEdit(self.layoutWidget)
+ self.connectionLocalIpAddress.setInputMethodHints(QtCore.Qt.ImhNone)
+ self.connectionLocalIpAddress.setObjectName("connectionLocalIpAddress")
+ self.formLayout_7.setWidget(1, QtGui.QFormLayout.FieldRole, self.connectionLocalIpAddress)
+ self.label_11 = QtGui.QLabel(self.layoutWidget)
+ self.label_11.setObjectName("label_11")
+ self.formLayout_7.setWidget(2, QtGui.QFormLayout.LabelRole, self.label_11)
+ self.connectionLocalPort = QtGui.QLineEdit(self.layoutWidget)
+ self.connectionLocalPort.setObjectName("connectionLocalPort")
+ self.formLayout_7.setWidget(2, QtGui.QFormLayout.FieldRole, self.connectionLocalPort)
+ self.label_13 = QtGui.QLabel(self.layoutWidget)
+ self.label_13.setObjectName("label_13")
+ self.formLayout_7.setWidget(4, QtGui.QFormLayout.LabelRole, self.label_13)
+ self.connectionFreeswitchPort = QtGui.QLineEdit(self.layoutWidget)
+ self.connectionFreeswitchPort.setObjectName("connectionFreeswitchPort")
+ self.formLayout_7.setWidget(4, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchPort)
+ self.label_12 = QtGui.QLabel(self.layoutWidget)
+ self.label_12.setObjectName("label_12")
+ self.formLayout_7.setWidget(1, QtGui.QFormLayout.LabelRole, self.label_12)
+ self.connectionFreeswitchIpAddress = QtGui.QLineEdit(self.layoutWidget)
+ self.connectionFreeswitchIpAddress.setObjectName("connectionFreeswitchIpAddress")
+ self.formLayout_7.setWidget(3, QtGui.QFormLayout.FieldRole, self.connectionFreeswitchIpAddress)
+ self.label_14 = QtGui.QLabel(self.layoutWidget)
+ self.label_14.setObjectName("label_14")
+ self.formLayout_7.setWidget(3, QtGui.QFormLayout.LabelRole, self.label_14)
+ self.gridLayout.addLayout(self.formLayout_7, 0, 1, 1, 1)
self.connectionAdd = QtGui.QPushButton(self.layoutWidget)
self.connectionAdd.setObjectName("connectionAdd")
self.gridLayout.addWidget(self.connectionAdd, 1, 0, 1, 1)
self.formLayout_4.setWidget(3, QtGui.QFormLayout.FieldRole, self.extensionEndpoint)
self.gridLayout_4.addLayout(self.formLayout_4, 0, 1, 1, 1)
self.tabWidget.addTab(self.extensionsTab, "")
- self.setCentralWidget(self.centralwidget)
+ MainWindow.setCentralWidget(self.centralwidget)
- self.retranslateUi()
+ self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
- QtCore.QMetaObject.connectSlotsByName(self)
-
- def retranslateUi(self):
- locale = QtCore.QLocale.system().name()
- translator = QtCore.QTranslator()
-
- if translator.load("ipypbx_%s" % locale.toLower(), "ipypbx/locale"):
- QtGui.QApplication.installTranslator(translator)
+ QtCore.QMetaObject.connectSlotsByName(MainWindow)
- self.setWindowTitle(
- QtGui.QApplication.translate(
- "MainWindow", "IPyPBX", None, QtGui.QApplication.UnicodeUTF8))
- #self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Name", None, QtGui.QApplication.UnicodeUTF8))
- #self.label_11.setText(QtGui.QApplication.translate("MainWindow", "Local Port", None, QtGui.QApplication.UnicodeUTF8))
- #self.label_13.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch Port", None, QtGui.QApplication.UnicodeUTF8))
- #self.label_12.setText(QtGui.QApplication.translate("MainWindow", "Local IP address", None, QtGui.QApplication.UnicodeUTF8))
- #self.label_14.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch IP Address", None, QtGui.QApplication.UnicodeUTF8))
+ def retranslateUi(self, MainWindow):
+ MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "IPyPBX", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_5.setText(QtGui.QApplication.translate("MainWindow", "Name", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_11.setText(QtGui.QApplication.translate("MainWindow", "Local Port", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_13.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch Port", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_12.setText(QtGui.QApplication.translate("MainWindow", "Local IP address", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_14.setText(QtGui.QApplication.translate("MainWindow", "Freeswitch IP Address", None, QtGui.QApplication.UnicodeUTF8))
self.connectionAdd.setText(QtGui.QApplication.translate("MainWindow", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.connectionSave.setText(QtGui.QApplication.translate("MainWindow", "Save", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.connectionsTab), QtGui.QApplication.translate("MainWindow", "Connections", None, QtGui.QApplication.UnicodeUTF8))