[英]hiding a widget from a thread starting in a different tab FLTK
I've come across some weird behaviour in FLTK and am trying to work out how to solve it. 我遇到了FLTK中的一些奇怪行为,并且正在尝试找出解决方法。 Essentially I have this format in main:
本质上我主要有这种格式:
int main(){
Fl::lock(); //will be doing multithreading
win= new Fl_Double_Window(0.5*(Fl::w()-w),0.5*(Fl::h()-h),w,h, "Program");
win->begin();
Fl_Tabs* oo = new Fl_Tabs(10,20,win->w()-20,win->h()-140);
{Fl_Group* a = new Fl_Group(20, 40, oo->w(),oo->h(), "Send to ");
Fl_Box* control_box= Fl_Box(x,y,w,h,"Comparison Test");
Fl_Button* button = Fl_Button(x,y,w,h,"run");
button->callback((Fl_Callback*) run_cb);
a->end();
}
{Fl_Group* b = new Fl_Group(20, 40, oo->w(),oo->h(), "");
Fl_Box* box= Fl_Box(x,y,w,h,"Warning");
box->hide();
//user does something here which causes box to box->show(); displaying warning
b->end();
}
oo->end();
win->end();
return Fl::run();
}
//functions
void run_cb(Fl_Widget* widget,void* data){
fl_create_thread(thread1,calculate,NULL);
}
void* calculate(void* data){
//do some calculations
Fl::lock();
//update some data structures
Fl::unlock();
//PROBLEM IS HERE<--------------------
}
Now, my problem is that at this "<-----------" location I want to then hide the warning box which is in tab b. 现在,我的问题是我想在此“ <-----------”位置然后隐藏选项卡b中的警告框。
Everything I try whether it be Fl::awake()
, Fl::awake(&check_from_thread)
where check_fom_thread is the appropriate function (containing every permutation of box->hide()
Fl::check()
, Fl::flush()
etc.)to be run in the parent (GUI) thread, or box->hide() in the thread , inside or outside the lock unlock pair, before and after an Fl::awake() call (again inside or outside the lock unlock pair) fails to get the functionality right which is: 我尝试的一切都是
Fl::awake()
, Fl::awake(&check_from_thread)
,其中check_fom_thread是合适的函数(包含box- box->hide()
每个排列Fl::check()
, Fl::flush()
等)在Fl :: awake()调用之前和之后(再次在锁的内部或外部)在父(GUI)线程中或在锁解锁对内或外的线程中运行box-> hide()。锁定解锁对)无法正确使用以下功能:
The warning box is shown, I switch to the first tab, I press the button which runs the callback and then thread, but before it finishes I switch back to the second tab where I expect the warning box to disappear upon completion of the threaded function call. 显示警告框,我切换到第一个选项卡,按下运行回调的按钮,然后执行线程,但是在完成操作之前,我切换回第二个选项卡,我希望警告选项在完成线程功能后消失呼叫。 BUT it doesn't get hidden.
但是它不会被隐藏。 However, if, after the thread has finished, I then switch to tab a then back to tab b it then is becomes hidden.
但是,如果在线程完成之后,然后我切换到选项卡a,然后又切换回选项卡b,则它变为隐藏状态。
On the other hand if instead of hiding 'box' in tab b, I hide 'control_box' in tab a, pretty much every permutation I described above works fine. 另一方面,如果我不是在选项卡b中隐藏“ box”,而是在选项卡a中隐藏“ control_box”,那么我上面描述的每个排列几乎都可以正常工作。
I have no idea why it would be doing this. 我不知道为什么会这么做。
Does anyone have any ideas? 有人有什么想法吗?
I thought it might be because under the hood Fl_Tabs is using ->hide() and ->show() meaning there might be some overriding of widget properties, but this doesn't make sense because if I switch to tab b before the thread which hides 'box' ends, at the time of the update tab b is shown as is widget 'box', but box fails to hide. 我认为这可能是因为Fl_Tabs在后台使用-> hide()和-> show()意味着可能覆盖了小部件属性,但这没有意义,因为如果我在线程之前切换到选项卡b隐藏“盒子”的地方,在更新选项卡b时显示为小部件“盒子”,但是盒子无法隐藏。 But the same situation applies when a thread run from a ends up hiding 'control_box' at the time of the update: tab a is shown as is 'control_box' but that situation works.
但是,当在更新时从头开始运行的线程最终隐藏“ control_box”时,情况也是如此:选项卡a显示为“ control_box”,但这种情况有效。 Tearing my hair out!...
撕开我的头发!
I have no idea why the above happens, but a way that was supposed to work (calling the redraw() method associated with the parent widget of the box I wanted to hide) didn't, but finally what did was calling redraw() on the overall parent window. 我不知道为什么会发生上述情况,但是这种方法应该起作用(调用与我要隐藏的框的父窗口小部件相关联的redraw()方法)却没有,但是最后调用了redraw()在整个父窗口上。 Not particularly elegant, but it does the job.
虽然不是特别优雅,但确实可以做到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.