How to stop mousegrabber in another function - awesome-wm

I am creating a tasklist with drag and drop.
In the widget_template create_callback function I am using this code:
self:connect_signal("button::press",
function(_, lx, ly, button, mods)
capi.mousegrabber.run(
function()
return true
end, "hand")
end)
self:connect_signal("button::release",
function(_, lx, ly, button, mods)
capi.mousegrabber.stop()
end)
Mousegrabber does not stop when mouse is released and I don't understand why.

Thanks to #Emmanuel Lepage Vallee the solution I found looks like this:
self:connect_signal("button::press",
function(_, lx, ly, button, mods)
capi.mousegrabber.run(
function(mouse)
return mouse.buttons[1]
end, "hand")
end)
Mousegrabber disables any mouse events happening that's why you can't rely on button::release signal to activate another function. The only way to interact with the mouse is through the mousegrabber function mouse parameter
mouse.buttons[NUMBER] is an undocumented property which you can use. It returns true if it is pressed.

Related

How can I distinguish wheel button click event from mouse press event?

I am wondering how i can distinguish wheel click event from mouse press event. Because i want to do different handling for these two events in pyside. Currently, every time I click the wheel button, the event is catched by mousepressevent. Can anyone explain ?
Edit: I want to implement this in a subclass of
qglwidget class
From its name, the mousePressEvent is responsible for mouse clicks while the wheelEvent is for scrolling solely. The wheelEvent will not catch the wheel button click. It is how the Qt's API is designed when it comes to mouse events processing.
In order to separate which mouse button is pressed (right, wheel or left), use button property of QMouseEvent.
This is how the code would look like using C++ (I imagine it is easy to translate it to pyside)
void GLWidget::mousePressEvent(QMouseEvent *event) // redefine the mouse event
{
switch( event->button() ) {
case Qt::LeftButton:
// do stuff for left button pressed
break;
case Qt::MiddleButton:
// do stuff for wheel button pressed
break;
// ...
}
}
So, for pyside, you only need to compare the button property of event in mousePressEvent and see whether it is Qt.LeftButton , Qt.RightButton or Qt.MidButton. Hope that helps.

How to remove a window's onclick event (Pebble.js)

I am writing a Pebble app in Pebble.js which needs to run different functions when the same button is pressed at different times throughout the app.
I can easily associate a function with a button:
dispWindow.on('click', 'up', function(e) {
doSomething();
});
After doSomething runs a few times, I need to change what happens when the user clicks the "up" button in the dispWindow Window. I can add this code:
dispWindow.on('click', 'up', function(e) {
doSomethingElse();
});
However, when the user clicks the "up" button, doSomething and doSomethingElse both fire. How do I remove doSomething from the "up" button?
You can use the off event, like this:
dispWindow.off('click');
Then, call the on event again after that:
dispWindow.on('click', 'up', function(e) {
doSomethingElse();
});

Dragging event reverts before confirm

I have a calendar with drag functionality where a user can drag events to quickly update them.
After Dragging an event I ask the user if he wants to save it and then call a UpdatEvent function.
However, before the user confirms, (just as the dialog appears) the event automatically reverts back and only return to the updated position if I confirm in the dialog.
Is there a way for the event to stay in the dragged position and then either revert back or stay in the actual one?
My eventDrop looks like this:
eventDrop: function (event, delta, revertFunc) {
if (confirm("Do you wish to save the event?")) {
UpdateEvent(event.id, event.start);
}
else {
revertFunc();
}
}
At the beginning of the Eventdrop and/or Eventresize place the following:
$('#calendar').fullCalendar('updateEvent', event);

How to get Click Event of QLineEdit in Qt?

How to get Click Event of QLineEdit in Qt ?
I am not able to see any SLOT related to click in QLineEdit ?
I don't think subclassing a QLineEdit is the right choice. Why subclass if you don't need to? You could instead use event filters. Check out QObject::eventFilter.
Example:
MyClass::MyClass() :
edit(new QLineEdit(this))
{
edit->installEventFilter(this);
}
bool MyClass::eventFilter(QObject* object, QEvent* event)
{
if(object == edit && event->type() == QEvent::FocusIn) {
// bring up your custom edit
return false; // lets the event continue to the edit
}
return false;
}
You need to reimplement focusInEvent in a new class extending QLineEdit. The following links are going to help you.
http://doc.qt.io/qt-5/qwidget.html#focusInEvent
QLineEdit - focus event
How to know if a QLineEdit got focus?
QLineEdit Focus Event
Although there is no "clicked" or "entered" event. You can use the
void cursorPositionChanged(int old, int new)
Signal. It is emitted when the user clicks the lineedit (if it is enabled) and also on a few other occasions so you have to verify which of the events actually happened but I think this is still easier than subclassing or using the event listener for some applications.
I dono if this will help,
i had to call a function once a text is entered. This is how i did it.
connect(ui->passwordSetLineEdit,SIGNAL(textEdited(QString)),this,SLOT(onTextEdit(QString)));
when a text is entered textEdited signal will be emited, thus my onTextEdit function will be called.
There is no signals like clicked() for QLineEdit, but you can subclass it and emit such signal in your custom implementation of mouseReleaseEvent.
I used this solution many times
def clickable(widget): # make this function global
class Filter(QObject):
clicked = pyqtSignal()
def eventFilter(self, obj, event):
if obj == widget and event.type() == QEvent.MouseButtonRelease and obj.rect().contains(event.pos()):
self.clicked.emit()
return True
else:
return False
filter = Filter(widget)
widget.installEventFilter(filter)
return filter.clicked
clickable(self.lineedit).connect(self.test) #use this in class
def test(self):
print("lineedit pressed")
pass
Just use the Pushbutton clicked event. Change the backcolor of the Pushbutton into Transparent then remove the text of it. Lay it in front of the LineEdit then use the setfocus property of the LineEdit when the push button was clicked. That's the easiest way to get the clicked event and use it in LineEdit.. 😉

Flex - Display a panel at the point where mouse is clicked

I would like to create a component(extending from spark Panel), which upon a buttonclick should show up next to the button(something like a bubble popping up or like the small box opening up when hovering up on profile links in facebook/twitter).
I tried to create a component that implements mx.core.IToolTip and provided the methods required by the interface.
And on the toolTipCreate event, set this component as the tooltip.
This works to an extent. When I bring the mouse over the button, the panel appears as the tooltip and goes away when i move the mouse away.
What I need is, the panel should appear next to the button when click on it and should go away only when I click outside the panel or click the close button present inside the panel.
Can you please provide me your suggestions on how to proceed further?
Thanks
//on the first click...
addChild( mouseX , mouseY );
//or
component.x = mouseX;
component.y = mouseY;
//then tween alpha or make visible
component.visible = true;
//for the click outside , assuming parent is not null
if( event.currentTarget == this.stage || event.currentTarget == this.parent)
component.visible = false;

Resources