D类、OOP和GTKd笔记本
我试图使用下面第二个类(MyNewClass)中的gtkd将一页附加到gtk笔记本。笔记本是在第一个类的主窗口中创建的,由第二个类调用。该程序编译良好,但当我打开该程序时,gtk主窗口除测试仪框外为空D类、OOP和GTKd笔记本,d,gtkd,D,Gtkd,我试图使用下面第二个类(MyNewClass)中的gtkd将一页附加到gtk笔记本。笔记本是在第一个类的主窗口中创建的,由第二个类调用。该程序编译良好,但当我打开该程序时,gtk主窗口除测试仪框外为空 import gtk.Box; import gtk.Button; import gtk.Grid; import gtk.Label; import gtk.MainWindow; import gtk.Main; import gtk.Notebook; class main_window
import gtk.Box;
import gtk.Button;
import gtk.Grid;
import gtk.Label;
import gtk.MainWindow;
import gtk.Main;
import gtk.Notebook;
class main_window : MainWindow
{
Notebook notebook;
this()
{
super("MyProg");
setDefaultSize(600,100);
//Here is the creation of the notebook
this.notebook=new Notebook;
Box tester=new Box(Orientation.VERTICAL, 1);
notebook.appendPage(tester, new Label("test")); //This works fine from this class
Grid grid=new Grid();
grid.setColumnSpacing(12); //establish the main grid
grid.setRowSpacing(3);
grid.attach(notebook, 0,0,1,9);
add(grid);
showAll();
}
}
class MyNewClass : main_window
{
this()
{
File MFile = File("file.txt", "r");
Grid MGrid;
int row=0;
int col=0; //Set the column and row number for the gtk grid.
string[] list;
string i;
float p;
Label MLabel;
while(!MFile.eof)
{
if (match(line, `\[\[`)){
MGrid=new Grid();
MGrid.setColumnSpacing(12);
MGrid.setRowSpacing(3);
row=0;
line=replace(line, regex(r"(\[)", "g"), "");
line=replace(line, regex(r"(\])", "g"), "");
//I HAVE USED A TEST WRITELN HERE TO MAKE SURE THE FUNCTION IS CALLED.
//Below is the notebook append that fails. When I test it from the first class above, I can append. When I call it here, it compiles but nothing is done.
Box MBox=new Box(Orientation.VERTICAL, 1);
MBox.add(MGrid);
super.notebook.appendPage(MBox, new Label(line));//
}
}
}
void main(string[] args)
{
Main.init(args);
new main_window;
new M;
Main.run();
}
虽然代码没有编译,但是页面没有显示的原因是您需要调用
MBox.show()
来显示框
Box MBox = new Box(Orientation.VERTICAL, 1);
MBox.add(MGrid);
super.notebook.appendPage(MBox, new Label(line));
MBox.show();
您还可以在容器小部件上调用showAll
,以显示所有子部件。在您的例子中,这是笔记本,包含笔记本的网格或主窗口。因此,您可以在循环之后添加notebook.showAll()
,以实现相同的效果
另一方面,您可能希望遵循D风格来编写D代码:。如果您提供最少的可编译代码,我们将更容易提供帮助。没问题。它已被更改为具有更完整的代码。