How to add a response to a button with Gtkmm - c++

I am trying to add a response to a button in a Gtk::Dialog but I don't know why it does not work I try to type this :
button_quit(Gtk::Stock::QUIT, Gtk::RESPONSE_CLOSE)
but it does not work. Also, I tried to do with an other way like this :
button_quit.signal_clicked().connect([]() {Gtk::Main::quit();});
but when I clicked on the button I have this error :
(code:7199): Gtk-CRITICAL **: gtk_main_quit: assertion 'main_loops != NULL' failed
So if you know how to solve this it will be very helpful for me.
Thank you.

Use add_button.
Gtk::Dialog dialog;
auto button = dialog.add_button("Ok", Gtk::RESPONSE_CLOSE);
dialog.signal_response().connect([&](int response_id)
{
std::cout<<response_id<<std::endl;
});

Related

ember delete record, not able to delete after first attempt

I have a workflow in which I have to delete a record, but in case back-end throws any error then I show an error dialog with a close button on it. The user can close that error dialog and go back to the main screen where he can again submit the action for deleting the record. But I am getting the following error when I try to click on delete for the second time:
Attempted to handle event deleteRecord while in state root.deleted.inFlight
Can someone guide me what can be the potential issue?
My code for reference:
File: component.js
let person = this.get('person') -> this is the model
person.destroyRecord().then(() => {
// if success, show success message
this.showSuccessModel();
}, (error) => {
// show error message in a dialog, with close button
this.showErrorModel();
});
When user clicks on close button, and when he click on delete action again, then I am getting the error above.
I was able to fix the issue, in case of errors, I was using rollBackAttributes() function on the model object as suggested by ember documentation but just realized I also have to do:
model.send('becameInvalid'), as otherwise just rolling back Attributes does not work. So, my working code will look something like this:
let person = this.get('person') -> this is the model
person.destroyRecord().then(() => {
// if success, show success message
this.showSuccessModel();
}, (error) => {
// show error message in a dialog, with close button
if(person.get('hasDirtyAttributes') {
person.send('becameInvalid');
person.rollBackAttributes();
}
this.showErrorModel();
});

Gtk Widget add_child fails with error

I am trying to create a custom Gtk text entry. The basic idea is to put a button inside of a text entry. Here is a shortened version of my full code:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
builder = Gtk.Builder()
button = Gtk.Button('button')
entry = Gtk.Entry()
entry.add_child(builder, button, "button")
The button does not get shown and it fails with the error:
(pygtk_foobar.py:26622): Gtk-CRITICAL **: gtk_buildable_add_child:
assertion 'iface->add_child != NULL' failed
Any suggestions?
A GtkEntry widget is not a GtkContainer, and thus it cannot have child widgets added or removed to it.
Only widgets that inherit from the GtkContainer class can have children in GTK+.
If you want to put a button next to a text entry, you should pack both widgets into a container like GtkBox, e.g.:
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=2)
entry = Gtk.Entry()
button = Gtk.Button(label='button', hexpand=True)
box.add(entry)
box.add(button)
box.show_all()
This will create a box with an entry and a button.

Accept a Popup using Phantomjs with Selenium

I am using python 2.7, Selenium, and PhantomJs.
When I click the sign in button in my script it goes to a new page and a popup appears that I must accept.
Here is the code I am trying to use. I got it from here
How can I handle an alert with GhostDriver via Python?
sign_in.click()
js = 'window.alert = function(message) { lastAlert = message; }'
driver.execute_script("%s" % js)
driver.execute_script("return lastAlert")
Here is the error that I get:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message:
{"errorMessage":"Can't find variable: lastAlert","request":{"hea
ders":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"95","Content-Type
":"application/json;charset=UTF-8","Host":"127.0.0.1:56712","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","metho
d":"POST","post":"{\"sessionId\":
\"3832e2c0-4902-11e6-b766-0d7f487d0794\", \"args\": [], \"script\":
\"return lastAlert
\"}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":
"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","q
ueryKey":{},"chunks":["execute"]},"urlOriginal":"/session/3832e2c0-4902-11e6-b766-0d7f487d0794/execute"}}
Screenshot: available via screen
I am not very experienced with javascript and a point in the right direction would be useful.
Here is the Behat step that I'm using:
/**
* This step overrides windows.confirm and basically accepts it before it is displayed.
*
* #When /^(?:|I )bypass the popup$/
*/
public function bypassPopup() {
$function = "
var realConfirm=window.confirm;
window.confirm=function(){
window.confirm=realConfirm;
return true;
};
";
$session = $this->getSession();
$session->executeScript($function);
}
You place it before you click on the button and when you click your popup will be accepted automatically.
In this case, only the first popup will be accepted.

How can I verify if the checkbox is checked or not in Qt?

The following code is supposed to set the text of nameLine form to this box is unchecked when the QCheckBox instance checkbox has state Unchecked.
Here is the my checkbox instance declaration:
QCheckBox *checkbox = new QCheckBox("paid with cash!", this);
checkbox->setCheckState(Qt::Unchecked);
and here is the logic so far:
if(checkbox->checkState(Qt::Unchecked))
{
nameLine->setText("the box is unchecked");
}
This code does not compile. The resulting error is the following:
C:\Qt\5.1.1\mingw48_32\examples\widgets\tutorials\addressbook\part1\voruskra.cpp:144: error: no matching function for call to 'QCheckBox::checkState(Qt::CheckState)'
if(checkbox->checkState(Qt::Unchecked))
^
Can you tell me what I am doing wrong?
Unless you are using a tristate checkbox, you can simply if (checkbox->isChecked())
This property is inherited way back in QAbstractButton. If it is a tristate checkbox, you will have to use checkState() as suggested in the other answer.
I think checkState doesn't take any argument. Try if(checkbox->checkState() == Qt::Unchecked)
maybe you can try like this?
QCheckBox *checkbox = new QCheckBox("paid with cash!", this);
checkbox->setChecked(false);
then for if command..
if(!checkbox->isChecked)
{
nameLine->setText("the box is unchecked");
}

Xcode6.1 Swift If error

I am making a To do list app and well I need to create a delete button so when the self (user) swipes the task to the left a red button will say delete.
So well I started to create the code imported from UITableViewDataSource and well the code I am trying to use is if(editingStyle) == UITableViewCellEditingStyle.Delete) and well when I put it into the code, the code throws back a error saying (!) Expected '{' after 'if' condition.
So is there anyway to get round this because I have tried to but a { after if but loads more errors come back!
Replace those 3 lines with these 4. You have a parenthesis error and a bracket error.
if (editingStyle == UITableViewCellEditingStyle.Delete) {
taskMgr.tasks.removeAtIndex(indexPath.row)
}
tblTasks.reloadData()
Also, make sure that you've properly set your UITableView dataSource and delegate. You can do this in IB or you can do this by replacing your existing viewDidLoad with:
override func viewDidLoad() {
super.viewDidLoad()
tblTasks.delegate = self
tblTasks.datasource = self
}