-3

当小部件之一处于焦点时,按钮“G”、“H”工作,但“F”不工作。

我的代码:

# -*- coding: UTF-8 -*-
import numpy
from galry import *

class MyPaintManager(PlotPaintManager):
    def initialize(self):
        self.add_visual(PlotVisual, x=self.parent.x, y=self.parent.y, color='b')

class MyBindings_manager(Bindings):
    def initialize_default(self):
        super(MyBindings_manager, self).initialize_default()
        self.set_fullscreen()
        self.set('KeyPress', 'Fullscreen', key='F')

class MyWidget(GalryWidget):
    def initialize(self, x, y):
        self.activate_grid = True
        self.show_grid = True
        self.is_fullscreen = True
        self.x = x
        self.y = y

        self.set_companion_classes(
            paint_manager=MyPaintManager,
            interaction_manager=PlotInteractionManager,
#           binding_manager=MyBindings_manager
            )
        self.initialize_companion_classes()

class Window(QtGui.QWidget):
    def __init__(self):
        super(Window, self).__init__()
        self.initUI()

    def initUI(self):
        layout = QtGui.QGridLayout(self)
        sampleRate = 30000.
        channelCount = 20
        data = np.random.normal(size=1000000)
        newData = data.reshape(channelCount,-1, order='F')

        for channelNum in range(channelCount):
            count = len(newData[channelNum])
            x = np.linspace(0, count / sampleRate, count)
            graph = MyWidget(x=x, y=newData[channelNum])
            layout.addWidget(graph, channelNum % 4, channelNum / 4)
        self.setLayout(layout)
        self.show()

if __name__ == '__main__':
    show_window(Window)

当我取消注释此行时

binding_manager=MyBindings_manager

我收到错误:

TypeError: __init__() takes exactly 1 argument (2 given)

我究竟做错了什么?

4

1 回答 1

0

BindingsManager应该是 type PlotBindings,并且不需要设置为伴随类。

https://github.com/klusta-team/klustaviewa/blob/master/klustaviewa/views/traceview.py为例,看看它是如何完成的。

Galry 已经过时,现在已被Vispy取代,因此它不是构建新应用程序的最佳库选择!

于 2015-06-03T17:16:26.340 回答