Esempio n. 1
0
 def __init__(self,
              admin=None,
              parent=None,
              create_inline=False,
              direction='onetomany',
              field_name='onetomany',
              column_width=None,
              proxy=None,
              rows=5,
              **kw):
     CustomEditor.__init__(self, parent, column_width=column_width)
     self.setObjectName(field_name)
     layout = QtWidgets.QHBoxLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     #
     # Setup table
     #
     from camelot.view.controls.tableview import AdminTableWidget
     from camelot.view.proxy.collection_proxy import CollectionProxy
     # parent set by layout manager
     table = AdminTableWidget(admin, self)
     table.setObjectName('table')
     layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
     self.setSizePolicy(QtGui.QSizePolicy.Expanding,
                        QtGui.QSizePolicy.Expanding)
     self.setMinimumHeight((self._font_height + 5) * rows)
     table.verticalHeader().sectionClicked.connect(self.trigger_list_action)
     model = (proxy or CollectionProxy)(admin)
     table.setModel(model)
     register.register(model, table)
     self.admin = admin
     self.direction = direction
     self.create_inline = create_inline
     layout.addWidget(table)
     self.setLayout(layout)
     self._new_message = None
     self.gui_context = ListActionGuiContext()
     self.gui_context.view = self
     self.gui_context.admin = self.admin
     self.gui_context.item_view = table
     post(self.admin.get_related_toolbar_actions,
          self.set_right_toolbar_actions,
          args=(Qt.RightToolBarArea, self.direction))
     post(self.get_columns, self.set_columns)
Esempio n. 2
0
 def __init__(self,
              admin=None,
              parent=None,
              create_inline=False,
              direction='onetomany',
              field_name='onetomany',
              **kw):
     CustomEditor.__init__(self, parent)
     self.setObjectName(field_name)
     layout = QtGui.QHBoxLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     #
     # Setup table
     #
     from camelot.view.controls.tableview import AdminTableWidget
     # parent set by layout manager
     table = AdminTableWidget(admin, self)
     table.setObjectName('table')
     rowHeight = QtGui.QFontMetrics(self.font()).height() + 5
     layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
     self.setSizePolicy(QtGui.QSizePolicy.Expanding,
                        QtGui.QSizePolicy.Expanding)
     self.setMinimumHeight(rowHeight * 5)
     table.verticalHeader().sectionClicked.connect(self.trigger_list_action)
     self.admin = admin
     self.direction = direction
     self.create_inline = create_inline
     layout.addWidget(table)
     self.setLayout(layout)
     self.model = None
     self._new_message = None
     self.gui_context = ListActionGuiContext()
     self.gui_context.view = self
     self.gui_context.admin = self.admin
     self.gui_context.item_view = table
     post(self.admin.get_related_toolbar_actions,
          self.set_right_toolbar_actions,
          args=(Qt.RightToolBarArea, self.direction))
Esempio n. 3
0
 def __init__( self,
               admin = None,
               parent = None,
               create_inline = False,
               direction = 'onetomany',
               field_name = 'onetomany',
               **kw ):
     CustomEditor.__init__( self, parent )
     self.setObjectName( field_name )
     layout = QtGui.QHBoxLayout()
     layout.setContentsMargins( 0, 0, 0, 0 )
     #
     # Setup table
     #
     from camelot.view.controls.tableview import AdminTableWidget
     # parent set by layout manager
     table = AdminTableWidget(admin, self)
     table.setObjectName('table')
     rowHeight = QtGui.QFontMetrics( self.font() ).height() + 5
     layout.setSizeConstraint( QtGui.QLayout.SetNoConstraint )
     self.setSizePolicy( QtGui.QSizePolicy.Expanding,
                         QtGui.QSizePolicy.Expanding )
     self.setMinimumHeight( rowHeight*5 )
     table.verticalHeader().sectionClicked.connect(
         self.trigger_list_action
     )
     self.admin = admin
     self.direction = direction
     self.create_inline = create_inline
     layout.addWidget( table )
     self.setLayout( layout )
     self.model = None
     self._new_message = None
     self.gui_context = ListActionGuiContext()
     self.gui_context.view = self
     self.gui_context.admin = self.admin
     self.gui_context.item_view = table
     post( self.admin.get_related_toolbar_actions, 
           self.set_right_toolbar_actions,
           args = (Qt.RightToolBarArea, self.direction ) )
Esempio n. 4
0
class One2ManyEditor(CustomEditor, WideEditor):
    """
    :param admin: the Admin interface for the objects on the one side of the
    relation

    :param create_inline: if False, then a new entity will be created within a
    new window, if True, it will be created inline

    after creating the editor, set_value needs to be called to set the
    actual data to the editor
    """
        
    def __init__( self,
                  admin = None,
                  parent = None,
                  create_inline = False,
                  direction = 'onetomany',
                  field_name = 'onetomany',
                  **kw ):
        CustomEditor.__init__( self, parent )
        self.setObjectName( field_name )
        layout = QtGui.QHBoxLayout()
        layout.setContentsMargins( 0, 0, 0, 0 )
        #
        # Setup table
        #
        from camelot.view.controls.tableview import AdminTableWidget
        # parent set by layout manager
        table = AdminTableWidget(admin, self)
        table.setObjectName('table')
        rowHeight = QtGui.QFontMetrics( self.font() ).height() + 5
        layout.setSizeConstraint( QtGui.QLayout.SetNoConstraint )
        self.setSizePolicy( QtGui.QSizePolicy.Expanding,
                            QtGui.QSizePolicy.Expanding )
        self.setMinimumHeight( rowHeight*5 )
        table.verticalHeader().sectionClicked.connect(
            self.trigger_list_action
        )
        self.admin = admin
        self.direction = direction
        self.create_inline = create_inline
        layout.addWidget( table )
        self.setLayout( layout )
        self.model = None
        self._new_message = None
        self.gui_context = ListActionGuiContext()
        self.gui_context.view = self
        self.gui_context.admin = self.admin
        self.gui_context.item_view = table
        post( self.admin.get_related_toolbar_actions, 
              self.set_right_toolbar_actions,
              args = (Qt.RightToolBarArea, self.direction ) )

    @QtCore.pyqtSlot( object )
    def set_right_toolbar_actions( self, toolbar_actions ):
        if toolbar_actions != None:
            toolbar = QtGui.QToolBar( self )
            toolbar.setOrientation( Qt.Vertical )
            for action in toolbar_actions:
                qaction = action.render( self.gui_context, toolbar )
                qaction.triggered.connect( self.action_triggered )
                toolbar.addAction( qaction )
            self.layout().addWidget( toolbar )
            # set field attributes might have been called before the
            # toolbar was created
            self.update_action_status()

    @QtCore.pyqtSlot( bool )
    def action_triggered( self, _checked = False ):
        action_action = self.sender()
        action_action.action.gui_run( self.gui_context )

    def set_field_attributes( self, **kwargs ):
        self.gui_context.field_attributes = kwargs
        self.update_action_status()
        
    def update_action_status( self ):
        toolbar = self.findChild( QtGui.QToolBar )
        if toolbar:
            model_context = self.gui_context.create_model_context()
            for qaction in toolbar.actions():
                post( qaction.action.get_state,
                      qaction.set_state,
                      args = ( model_context, ) )
                
    @QtCore.pyqtSlot( object )
    def update_delegates( self, *args ):
        table = self.findChild(QtGui.QWidget, 'table')
        if self.model and table:
            delegate = self.model.getItemDelegate()
            if delegate:
                table.setItemDelegate( delegate )
                for i in range( self.model.columnCount() ):
                    txtwidth = self.model.headerData( i, Qt.Horizontal, Qt.SizeHintRole ).toSize().width()
                    table.setColumnWidth( i, txtwidth )

    def set_value( self, model ):
        model = CustomEditor.set_value( self, model )
        table = self.findChild(QtGui.QWidget, 'table')
        if table and model and model != self.model:
            self.model = model
            table.setModel( model )
            register.register( self.model, table )
            model_context = self.gui_context.create_model_context()
            for toolbar in self.findChildren( QtGui.QToolBar ):
                for qaction in toolbar.actions():
                    post( qaction.action.get_state,
                          qaction.set_state,
                          args = ( model_context, ) )
            post( model._extend_cache, self.update_delegates )

    def activate_editor( self, number_of_rows ):
        assert object_thread( self )
#        return
# Activating this code can cause segfaults
# see ticket 765 in web issues
#
# The segfault seems no longer there after disabling the
# editor before setting a new model, but the code below
# seems to have no effect.
        table = self.findChild(QtGui.QWidget, 'table')
        if table:
            index = self.model.index( max(0, number_of_rows-1), 0 )
            table.scrollToBottom()
            table.setCurrentIndex( index )
            table.edit( index )

    @QtCore.pyqtSlot( int )
    def trigger_list_action( self, index ):
        table = self.findChild(QtGui.QWidget, 'table')
        # close the editor to prevent certain Qt crashes
        table.close_editor()
        if self.admin.list_action:
            self.admin.list_action.gui_run( self.gui_context )
Esempio n. 5
0
    def __init__(self,
                 parent=None,
                 width=50,
                 height=40,
                 dpi=50,
                 field_name='chart',
                 **kwargs):
        from matplotlib.figure import Figure
        from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
        super(ChartEditor, self).__init__(parent)
        AbstractCustomEditor.__init__(self)
        self.setObjectName(field_name)

        chart_frame = QtWidgets.QFrame(self)
        chart_frame.setFrameShape(self.Box)
        chart_frame.setContentsMargins(1, 1, 1, 1)
        chart_frame_layout = QtWidgets.QHBoxLayout()
        chart_frame_layout.setContentsMargins(0, 0, 0, 0)
        chart_frame.setLayout(chart_frame_layout)

        # find out background color, because using a transparent
        # figure fails when the window is resized: the background
        # is not redrawn
        # need to do str() else matplotlib gets confused by the qstring
        # bgcolorrgb = str(self.palette().background().color().name())
        self.fig = Figure(
            figsize=(width, height),
            dpi=dpi,
            facecolor='#ffffff',
        )
        layout = QtWidgets.QHBoxLayout()
        self.canvas = FigureCanvas(self.fig)
        chart_frame_layout.addWidget(self.canvas)
        layout.addWidget(chart_frame)
        button_layout = QtWidgets.QVBoxLayout()
        button_layout.setSpacing(0)

        icon = Icon(
            'tango/16x16/actions/document-print-preview.png').getQIcon()
        button_layout.addStretch()

        print_button = QtWidgets.QToolButton()
        print_button.setIcon(icon)
        print_button.setAutoRaise(True)
        print_button.setToolTip(_('Print Preview'))
        print_button.clicked.connect(self.print_preview)
        button_layout.addWidget(print_button)

        icon = Icon('tango/16x16/actions/edit-copy.png').getQIcon()
        copy_button = QtWidgets.QToolButton()
        copy_button.setIcon(icon)
        copy_button.setAutoRaise(True)
        copy_button.setToolTip(_('Copy to clipboard'))
        copy_button.clicked.connect(self.copy_to_clipboard)
        button_layout.addWidget(copy_button)

        layout.addLayout(button_layout)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)
        self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                  QtGui.QSizePolicy.Expanding)
        self.canvas.installEventFilter(self)
        self.show_fullscreen_signal.connect(self.show_fullscreen)
        self.canvas.updateGeometry()
        self._litebox = None
        self.gui_context = ListActionGuiContext()
Esempio n. 6
0
class One2ManyEditor(CustomEditor, WideEditor):
    """
    :param admin: the Admin interface for the objects on the one side of the
    relation

    :param create_inline: if False, then a new entity will be created within a
    new window, if True, it will be created inline

    :param proxy: the proxy class to use to present the data in the list or
        the query to the table view

    :param column_width: the width of the editor in number of characters

    :param rows: minimum number of rows visible

    after creating the editor, set_value needs to be called to set the
    actual data to the editor
    """
    def __init__(self,
                 admin=None,
                 parent=None,
                 create_inline=False,
                 direction='onetomany',
                 field_name='onetomany',
                 column_width=None,
                 proxy=None,
                 rows=5,
                 **kw):
        CustomEditor.__init__(self, parent, column_width=column_width)
        self.setObjectName(field_name)
        layout = QtWidgets.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        #
        # Setup table
        #
        from camelot.view.controls.tableview import AdminTableWidget
        from camelot.view.proxy.collection_proxy import CollectionProxy
        # parent set by layout manager
        table = AdminTableWidget(admin, self)
        table.setObjectName('table')
        layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
        self.setSizePolicy(QtGui.QSizePolicy.Expanding,
                           QtGui.QSizePolicy.Expanding)
        self.setMinimumHeight((self._font_height + 5) * rows)
        table.verticalHeader().sectionClicked.connect(self.trigger_list_action)
        model = (proxy or CollectionProxy)(admin)
        table.setModel(model)
        register.register(model, table)
        self.admin = admin
        self.direction = direction
        self.create_inline = create_inline
        layout.addWidget(table)
        self.setLayout(layout)
        self._new_message = None
        self.gui_context = ListActionGuiContext()
        self.gui_context.view = self
        self.gui_context.admin = self.admin
        self.gui_context.item_view = table
        post(self.admin.get_related_toolbar_actions,
             self.set_right_toolbar_actions,
             args=(Qt.RightToolBarArea, self.direction))
        post(self.get_columns, self.set_columns)

    @QtCore.qt_slot(object)
    def set_right_toolbar_actions(self, toolbar_actions):
        if toolbar_actions is not None:
            toolbar = QtWidgets.QToolBar(self)
            toolbar.setOrientation(Qt.Vertical)
            for action in toolbar_actions:
                qaction = action.render(self.gui_context, toolbar)
                if isinstance(qaction, QtWidgets.QWidget):
                    toolbar.addWidget(qaction)
                else:
                    qaction.triggered.connect(self.action_triggered)
                    toolbar.addAction(qaction)
            self.layout().addWidget(toolbar)
            # set field attributes might have been called before the
            # toolbar was created
            self.update_action_status()

    @QtCore.qt_slot(bool)
    def action_triggered(self, _checked=False):
        action_action = self.sender()
        action_action.action.gui_run(self.gui_context)

    def set_field_attributes(self, **kwargs):
        super(One2ManyEditor, self).set_field_attributes(**kwargs)
        self.gui_context.field_attributes = kwargs
        self.update_action_status()

    def get_columns(self):
        return self.admin.get_columns()

    def update_action_status(self):
        toolbar = self.findChild(QtWidgets.QToolBar)
        if toolbar:
            model_context = self.gui_context.create_model_context()
            for qaction in toolbar.actions():
                if isinstance(qaction, ActionAction):
                    post(qaction.action.get_state,
                         qaction.set_state,
                         args=(model_context, ))

    def get_model(self):
        """
        :return: a :class:`QtGui.QAbstractItemModel` or `None`
        """
        table = self.findChild(QtWidgets.QWidget, 'table')
        if table is not None:
            return table.model()

    @QtCore.qt_slot(object)
    def set_columns(self, columns):
        from ..delegates.delegatemanager import DelegateManager
        table = self.findChild(QtWidgets.QWidget, 'table')
        if table is not None:
            delegate = DelegateManager(columns, parent=self)
            table.setItemDelegate(delegate)
            model = table.model()
            if model is not None:
                model.set_columns(columns)
                for i in range(model.columnCount()):
                    txtwidth = variant_to_py(
                        model.headerData(i, Qt.Horizontal,
                                         Qt.SizeHintRole)).width()
                    table.setColumnWidth(i, txtwidth)

    def set_value(self, collection):
        collection = CustomEditor.set_value(self, collection)
        model = self.get_model()
        if model is not None:
            # even if the collection 'is' the same object as the current
            # one, still need to set it, since the content of the collection
            # might have changed.
            model.set_value(collection)
            model_context = self.gui_context.create_model_context()
            for toolbar in self.findChildren(QtWidgets.QToolBar):
                for qaction in toolbar.actions():
                    post(qaction.action.get_state,
                         qaction.set_state,
                         args=(model_context, ))
            #post( model._extend_cache, self.update_delegates )

    def activate_editor(self, number_of_rows):
        assert object_thread(self)
        #        return
        # Activating this code can cause segfaults
        # see ticket 765 in web issues
        #
        # The segfault seems no longer there after disabling the
        # editor before setting a new model, but the code below
        # seems to have no effect.
        table = self.findChild(QtWidgets.QWidget, 'table')
        if table is not None:
            index = table.model().index(max(0, number_of_rows - 1), 0)
            table.scrollToBottom()
            table.setCurrentIndex(index)
            table.edit(index)

    @QtCore.qt_slot(int)
    def trigger_list_action(self, index):
        table = self.findChild(QtWidgets.QWidget, 'table')
        # close the editor to prevent certain Qt crashes
        table.close_editor()
        if self.admin.list_action:
            self.admin.list_action.gui_run(self.gui_context)
Esempio n. 7
0
class One2ManyEditor(CustomEditor, WideEditor):
    """
    :param admin: the Admin interface for the objects on the one side of the
    relation

    :param create_inline: if False, then a new entity will be created within a
    new window, if True, it will be created inline

    after creating the editor, set_value needs to be called to set the
    actual data to the editor
    """
    def __init__(self,
                 admin=None,
                 parent=None,
                 create_inline=False,
                 direction='onetomany',
                 field_name='onetomany',
                 **kw):
        CustomEditor.__init__(self, parent)
        self.setObjectName(field_name)
        layout = QtGui.QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        #
        # Setup table
        #
        from camelot.view.controls.tableview import AdminTableWidget
        # parent set by layout manager
        table = AdminTableWidget(admin, self)
        table.setObjectName('table')
        rowHeight = QtGui.QFontMetrics(self.font()).height() + 5
        layout.setSizeConstraint(QtGui.QLayout.SetNoConstraint)
        self.setSizePolicy(QtGui.QSizePolicy.Expanding,
                           QtGui.QSizePolicy.Expanding)
        self.setMinimumHeight(rowHeight * 5)
        table.verticalHeader().sectionClicked.connect(self.trigger_list_action)
        self.admin = admin
        self.direction = direction
        self.create_inline = create_inline
        layout.addWidget(table)
        self.setLayout(layout)
        self.model = None
        self._new_message = None
        self.gui_context = ListActionGuiContext()
        self.gui_context.view = self
        self.gui_context.admin = self.admin
        self.gui_context.item_view = table
        post(self.admin.get_related_toolbar_actions,
             self.set_right_toolbar_actions,
             args=(Qt.RightToolBarArea, self.direction))

    @QtCore.pyqtSlot(object)
    def set_right_toolbar_actions(self, toolbar_actions):
        if toolbar_actions != None:
            toolbar = QtGui.QToolBar(self)
            toolbar.setOrientation(Qt.Vertical)
            for action in toolbar_actions:
                qaction = action.render(self.gui_context, toolbar)
                qaction.triggered.connect(self.action_triggered)
                toolbar.addAction(qaction)
            self.layout().addWidget(toolbar)
            # set field attributes might have been called before the
            # toolbar was created
            self.update_action_status()

    @QtCore.pyqtSlot(bool)
    def action_triggered(self, _checked=False):
        action_action = self.sender()
        action_action.action.gui_run(self.gui_context)

    def set_field_attributes(self, **kwargs):
        self.gui_context.field_attributes = kwargs
        self.update_action_status()

    def update_action_status(self):
        toolbar = self.findChild(QtGui.QToolBar)
        if toolbar:
            model_context = self.gui_context.create_model_context()
            for qaction in toolbar.actions():
                post(qaction.action.get_state,
                     qaction.set_state,
                     args=(model_context, ))

    @QtCore.pyqtSlot(object)
    def update_delegates(self, *args):
        table = self.findChild(QtGui.QWidget, 'table')
        if self.model and table:
            delegate = self.model.getItemDelegate()
            if delegate:
                table.setItemDelegate(delegate)
                for i in range(self.model.columnCount()):
                    txtwidth = self.model.headerData(
                        i, Qt.Horizontal, Qt.SizeHintRole).toSize().width()
                    table.setColumnWidth(i, txtwidth)

    def set_value(self, model):
        model = CustomEditor.set_value(self, model)
        table = self.findChild(QtGui.QWidget, 'table')
        if table and model and model != self.model:
            self.model = model
            table.setModel(model)
            register.register(self.model, table)
            model_context = self.gui_context.create_model_context()
            for toolbar in self.findChildren(QtGui.QToolBar):
                for qaction in toolbar.actions():
                    post(qaction.action.get_state,
                         qaction.set_state,
                         args=(model_context, ))
            post(model._extend_cache, self.update_delegates)

    def activate_editor(self, number_of_rows):
        assert object_thread(self)
        #        return
        # Activating this code can cause segfaults
        # see ticket 765 in web issues
        #
        # The segfault seems no longer there after disabling the
        # editor before setting a new model, but the code below
        # seems to have no effect.
        table = self.findChild(QtGui.QWidget, 'table')
        if table:
            index = self.model.index(max(0, number_of_rows - 1), 0)
            table.scrollToBottom()
            table.setCurrentIndex(index)
            table.edit(index)

    @QtCore.pyqtSlot(int)
    def trigger_list_action(self, index):
        table = self.findChild(QtGui.QWidget, 'table')
        # close the editor to prevent certain Qt crashes
        table.close_editor()
        if self.admin.list_action:
            self.admin.list_action.gui_run(self.gui_context)