Extjs 4.2中的自定义组件的多个实例(Multiple Instances of Custom Component in Extjs 4.2)
我有一个名为“Teilgewerke”的网格面板。 我可以使用它作为面板的一个项目
{ xtype:'panel', layout: { type: 'hbox', align: 'stretch' }, items:[ { //xtype: 'teilgewerkegrid', id:'feinplanungPanelTeilgewerkeGrid', flex: 2 }, { xtype: 'panel', flex: 1 } ] }
但是现在当我尝试在另一个面板中使用它时,它会抛出以下错误:
Uncaught TypeError: Cannot read property 'isComponent' of undefined
我发现这个问题在指向完全相同的问题的Stackoverflow。 我尝试了上述链接中给出的解决方案,将项目放置为
initComponent: function() { this.items = [ { xtype:'panel', flex: 5, border: false, padding: '0 20 0 20', items:[ { xtype: 'text', text: 'Teilgewerke für Aufbau an beteiligte Gruppen senden.', } ] }, Ext.create('PfalzkomApp.view.TeilgewerkeGrid', { padding: '0 20 0 20', id:'aufbauTabTeilgewerkeGrid', flex: 90 }), { xtype: 'panel', border: false, padding: '0 20 0 20', flex: 5 } ] this.callParent(); }
但我仍有同样的问题。 有人可以指出我的错误吗?
I have a grid panel named "Teilgewerke". I am able to use it as an item of a panel like
{ xtype:'panel', layout: { type: 'hbox', align: 'stretch' }, items:[ { //xtype: 'teilgewerkegrid', id:'feinplanungPanelTeilgewerkeGrid', flex: 2 }, { xtype: 'panel', flex: 1 } ] }
But now when I try to use it inside another panel, it throws following error:
Uncaught TypeError: Cannot read property 'isComponent' of undefined
I found this question on Stackoverflow which is pointing to exact same problem. I tried the solution given in above link, by putting items as
initComponent: function() { this.items = [ { xtype:'panel', flex: 5, border: false, padding: '0 20 0 20', items:[ { xtype: 'text', text: 'Teilgewerke für Aufbau an beteiligte Gruppen senden.', } ] }, Ext.create('PfalzkomApp.view.TeilgewerkeGrid', { padding: '0 20 0 20', id:'aufbauTabTeilgewerkeGrid', flex: 90 }), { xtype: 'panel', border: false, padding: '0 20 0 20', flex: 5 } ] this.callParent(); }
But I still have same issue. Can someone point out my mistake?
原文:https://stackoverflow.com/questions/33823075
最满意答案
首先,我建议你采用面向对象的方法来分割每个组件的行为。
通过这种方式,您将拥有一个类App,您可以在其中初始化应用程序的主要组件:
class App(tk.Tk): def __init__(self,parent): Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): ... ... # Menubar self.menubar = MyMenuBar(self) # Filemenu self.filemenu = MyFileMenu(self, menubar) # Plot self.plot = MyPlot(self, menubar) # The rest for all the other components ... def get_import_filename(self): # Ask the child for the filename and return it return self.filemenu.get_filename()
然后定义每个对象:
class MyPlot(tk.Menu): def __init__(self, parent, menubar): tk.Menu.__init__(self, menubar, tearoff=0) self.parent = parent self.initialize() def initialize(self): self.add_command(label="Plot My CSV File", command= self.popupgraph) def popupgraph(self): # Ask the parent for the filename filename = self.parent.get_import_filename() # Do whatever with the filename...like open a file class MyFileMenu(tk.Menu): def __init__(self, parent, menubar): tk.Menu.__init__(self, menubar, tearoff=0) self.parent = parent self.initialize() def initialize(self): self.add_command(label="Import a CSV File", command = file_opener) def file_opener(self): # Your file opener function goes here ... # At the end, save the imported file: self.filename = filename def get_filename(self): return self.filename
最后,主要运行它:
def main(): app = App(None) app.title('Auto login') app.mainloop() if __name__ == "__main__": main()
First of all, I would suggest you take an Object Oriented approach to split each component behaviour.
This way, you would have a class App, where you would initialise the main components of the app:
class App(tk.Tk): def __init__(self,parent): Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): ... ... # Menubar self.menubar = MyMenuBar(self) # Filemenu self.filemenu = MyFileMenu(self, menubar) # Plot self.plot = MyPlot(self, menubar) # The rest for all the other components ... def get_import_filename(self): # Ask the child for the filename and return it return self.filemenu.get_filename()
And then define every of your objects:
class MyPlot(tk.Menu): def __init__(self, parent, menubar): tk.Menu.__init__(self, menubar, tearoff=0) self.parent = parent self.initialize() def initialize(self): self.add_command(label="Plot My CSV File", command= self.popupgraph) def popupgraph(self): # Ask the parent for the filename filename = self.parent.get_import_filename() # Do whatever with the filename...like open a file class MyFileMenu(tk.Menu): def __init__(self, parent, menubar): tk.Menu.__init__(self, menubar, tearoff=0) self.parent = parent self.initialize() def initialize(self): self.add_command(label="Import a CSV File", command = file_opener) def file_opener(self): # Your file opener function goes here ... # At the end, save the imported file: self.filename = filename def get_filename(self): return self.filename
Finally, have the main to run it:
def main(): app = App(None) app.title('Auto login') app.mainloop() if __name__ == "__main__": main()
相关问答
更多-
Perl / Tk菜单栏怪癖(Perl/Tk menubar quirks)[2023-08-24]
这是因为&menu_file('n')是调用子例程的语法( 更多细节 )。 相反,你必须这样做: $mw->bind('' => sub{menu_file('n')}); 或者像这样: $mw->bind(' ' => [\&menu_file, 'n']); That's because &menu_file('n') is syntax for invoking a subroutine (more details). Instead, you have ... -
您无法在Windows或OSX上更改菜单栏的颜色。 有可能在linux上的一些窗口管理器上,虽然我不确定。 原因是菜单栏是使用不由tkinter管理的本机小部件绘制的,因此您只能使用平台允许的内容。 You cannot change the color of the menubar on Windows or OSX. It might be possible on some window managers on linux, though I don't know for certain. The re ...
-
在添加任何小部件之前先添加菜单栏 import wx import wx.grid as gridlib class ScrollbarFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY,"Grid with Popup Menu") self.layout_file = {'ID':[1,5,5],'NAME':[6,12],'STATE':[13 ...
-
如果您在谈论根窗口的menu属性时获得的本地菜单栏,则不能。 您可以使用框架和一个或多个menubutton创建自己的菜单栏,其行为有点像菜单栏,并将其置于底部。 You can't, if you're talking about the native menubar you get when you set the menu attribute of the root window. You can create your own menubar that behaves a little bit li ...
-
您可以使用方法MenuItem.addActionListener(ActionListener)将实现ActionListener接口的类的对象添加到菜单项,如下所示: menuItem.addActionListener(actionListener); You can add an object of a class that implements the ActionListener interface to the menu item by using the method MenuItem.a ...
-
MenuBar没有显示(MenuBar is not showing)[2022-10-02]
问题是菜单的高度高于应用程序的高度。 所以它正在显示但它已经离开了屏幕。 我猜测逻辑是,如果弹出菜单的任何部分不在屏幕上,则菜单栏必须沿着应用程序的底部放置,因此弹出菜单应显示在菜单栏上方而不是下方。 解决方法是让屏幕更高(我看到Firebug,因此它不是典型的高度)。 我可以检查弹出窗口的高度,并将其与应用程序的高度进行比较,并手动将弹出的垂直位置设置为正确的位置。 我没有尝试解决它超出这一点,因为用户可能不会在这么短的高度使用该应用程序。 The problem was the height of th ... -
此处描述了类似的问题: 如何指定打开URL的按钮? 一种可能的方案: public class MyMenuBar extends MenuBar { ResourceReference rr; public MyMenuBar() { Resource pdf = new FileResource(new File("C:/temp/temp.pdf")); setResource("help", pdf); rr = ResourceR ...
-
首先,我建议你采用面向对象的方法来分割每个组件的行为。 通过这种方式,您将拥有一个类App,您可以在其中初始化应用程序的主要组件: class App(tk.Tk): def __init__(self,parent): Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): ... ... ...
-
在Qt中制作自定义菜单栏(Making a custom menubar in Qt)[2023-12-18]
您可以将非本机QMenuBar放置在布局中,就像任何其他窗口小部件一样。 下面是一个示例应用程序。 #include#include #include int main(int argc, char **argv) { QApplication app(argc, argv); QWidget window; QVBoxLayout layout(&window); QMenuBar menu ... -
关于菜单栏应用中的面板在激活时不是最前面的(about panel in menubar application is not frontmost when activated)[2022-04-20]
NSApplication *app = [NSApplication sharedApplication]; [app activateIgnoringOtherApps:YES]; [NSApp orderFrontStandardAboutPanel:sender]; 请尝试上面的代码。 NSApplication *app = [NSApplication sharedApplication]; [app activateIgnoringOtherApps:YES]; [NSApp orderFr ...