OPENDCL (AUTOCAD): avoid exiting modeless dialog if [ENTER] is pressed - dialog

I was looking for a way to avoid exiting modeless dialogs in autocad (created by opendcl) when [ENTER] is pressed.
Any idea?
Thanks,
Dennis

I've implemented such a feature for the OpenDCL grid system. You have to activate the OnCancelClose function on your form. This is how I did it:
(defun c:MyFunction_Form1_OnCancelClose (Reason /)
;; Reason = 0 when Enter is pressed
(if (= Reason 0)
(progn
;; Shift active editing cell one row down
(setq rowAndCol(dcl_Grid_GetCurCell MyFunction_Form1_revisions))
(dcl_Grid_StartCellEdit MyFunction_Form1_revisions (1+ (car rowAndCol)) (cadr rowAndCol))
)
)
;; Reason = 1 when ESC key is pressed, or the closing button in the titlebar
;; is clicked. Hence, enter won't work to cancel the dialog
(/= Reason 1)
)

Related

Tkinter: How to bind a Shift

I'm making a menubar in Tkinter with an accelerator:
menubar = tk.Menu(window)
file_menu = tk.Menu(menubar)
menubar.add_cascade(label='File', menu=file_menu)
window.config(menu=menubar)
file_menu.add_command(label='Open resource pack', command=openPack, accelerator='Cmd+o' if IS_MAC else 'Ctrl+o')
window.bind_all('<M1-o>' if IS_MAC else '<Control-o>', openPack)
file_menu.add_command(label='Copy original pack', command=copyOriginalPack, accelerator='Shift+Cmd+c' if IS_MAC else 'Shift+Ctrl+c')
window.bind_all('<M1-C>' if IS_MAC else '<Control-C>', copyOriginalPack)
But for the Copy original pack option the key combination is Shift + Command + C. The accelerator only shows the key combination in the menubar but doesn't actually run the command, so I have to manually bind to the window.
If I remember correctly, to bind Shift + Command + C I just need to say Control+C and make the C uppercase because of Shift.
But I can't bind Shift. It works if I click the menu option, but the key combo doesn't. It works for the other option, which doesn't have Shift
I fixed it by writing <M1-Shift-c> (note the lowercase c)

AHK in MS Excel (Cell Selection Issue With Script)

I started a little script using CAPSLock key for navigation (This is only part of the code):
SetCapsLockState, AlwaysOff
CapsLock & i::
if getkeystate("alt") = 0
Send,{Up}
else
Send,+{Up}
return
CapsLock & l::
if getkeystate("alt") = 0
Send,{Right}
else
send, +{Right}
return
It works perfectly everywhere.. except in MS Excel!
When I select a range of cells the selection marquee is there but no cell reference is taken in the formula.
Ex: Summing C3:C10 turns into =sum() no cells are actually selected in the formula.
if I keep trying up and down many times.. it shows, but never consistent.
Any idea how to fix this?
Thank you in advance
The problem comes from your shift key being released between the key presses.
Like for example try pressing keys like this in Excel and you'll see you're not actually selecting cells, you're just highlighting them:
Shift Down, Up Arrow, Shift Up
Shift Down, Up Arrow, Shift Up
Shift Down, Up Arrow, Shift Up
...
So you're going to have to keep shift pressed for the whole duration of your selection making process.
Here's what I could come up with:
CapsLock::Shift
#If, GetKeyState("CapsLock", "P")
*i::
if (GetKeyState("Alt", "P"))
SendInput, {Blind}{Alt Up}{Up}
else
SendInput, {Up}
return
*l::
if (GetKeyState("Alt", "P"))
SendInput, {Blind}{Alt Up}{Right}
else
SendInput, {Down}
return
#If
Or just like this to write it a lot cleaner with a ternary:
CapsLock::Shift
#If, GetKeyState("CapsLock", "P")
*i::SendInput, % GetKeyState("Alt", "P") ? "{Blind}{Alt Up}{Up}" : "{Up}"
*l::SendInput, % GetKeyState("Alt", "P") ? "{Blind}{Alt Up}{Right}" : "{Right}"
#If
So what's happening?
First we use the simple remapping syntax(docs) to remap CapsLock to Shift.
Then we create context sensitive hotkeys for I and L with #If(docs).
The hotkeys are only triggered if the physical state of CapsLock is down.
We need the physical state, because the logical state (which is default) was remapped to shift.
The hotkeys are created with the * modifier(docs) so they fire even if Shift and/or Alt is held down.
I switched the Send commands SendInput due to it being the recommended faster and more reliable send mode(docs).
And then about {Blind}. Normally, when you just send something with a send command, it automatically releases any modifiers you may be holding. But if you use the blind send mode(docs), this doesn't happen. So Shift is still held down all the time.

Emacs and eww, open links in new window?

I configured Emacs to open new links in eww like so:
(setq browse-url-browser-function 'eww-browse-url)
Now when I click on a link, it opens in the same buffer.
I would like it to open a new window (i.e split vertically like C - x 3) and open the page in the newly created frame on the right. So that I still have the original org-mode notes on the left.
[Edit]
I hacked together something. But it only works when I activate the hotkey, not when another function opens a link.
Ideally, I want something like the below, but for whenever I open a link (e.g in helm-google).
(defun my/open-in-right-window ()
"Open the selected link on the right window plane"
(interactive)
(delete-other-windows nil)
(split-window-right nil)
(other-window 1)
(org-return nil)
)
(defun my/eww-quitAndSingleWin ()
"Quit the current browser session and activate single window mode."
(interactive)
(quit-window nil)
(delete-other-windows nil)
)
(defun my/eww-split-right ()
"Splits the Window. Moves eww to the right and underlying content on the left."
(interactive)
(split-window-right nil)
(quit-window nil)
(other-window 1)
)
(global-set-key (kbd "H-r") 'my/open-in-right-window)
(add-hook 'eww-mode-hook ;no impact.
(lambda ()
(local-set-key (kbd "s") 'my/eww-split-right)
(local-set-key (kbd "Q") 'my/eww-quitAndSingleWin)
))
It kills other windows, opens new window, switches to new window, then presses return [which is configured to open links in my config].
Further then in eww-mode a 'Q' (capital) quits the session and kills the other window so as to avoid too many open windows.
It's not the most elegant solution. I'm open to better ideas?
I had the similar issue of wanting to have multiple eww buffers open and did it by advising eww-render. You could probably put your code in there to make it always run.
(defadvice eww-render (after set-eww-buffer-name activate)
(rename-buffer (concat "*eww-" (or eww-current-title
(if (string-match "://" eww-current-url)
(substring eww-current-url (match-beginning 0))
eww-current-url)) "*") t))
While russel's answer may have been correct in the past, eww-current-title and eww-current-url has been obsoleted in favour of a buffer-local plist called eww-data.
Current eww-implementation also includes the hooks we need to plug in after a buffer is rendered, thus avoiding the need to do "messy" things like defadvice.
As per August 2015 and this Git-commit, the following elisp works for me:
(defun my-set-eww-buffer-title ()
(let* ((title (plist-get eww-data :title))
(url (plist-get eww-data :url))
(result (concat "*eww-" (or title
(if (string-match "://" url)
(substring url (match-beginning 0))
url)) "*")))
(rename-buffer result t)))
(add-hook 'eww-after-render-hook 'my-set-eww-buffer-title)
You can probably use this hook to add your desired keybindings too.

Cannot access mouse coords relative to CANVAS widget

I am working with SBCL for Linux on an AMD64 machine.
Function ANIMTEST instantiates an LTK window with a CANVAS widget. Two items, BARRIER and FOLLOWER, live in the canvas. Both spin continuously, with BARRIER at the center of the canvas and FOLLOWER intended to follow the mouse, which is not working as intended. My first attempt (see comment) resulted in absolute screen coordinates of the mouse being interpreted as relative coordinates within the canvas with no account of the offset between the two. After searching through ltk.lisp and docs, I found SCREEN-MOUSE-X/Y (Second Attempt, see comment). I feel like I am using SCREEN-MOUSE-X & -Y according to the documentation, but why is it not working?
= Note =
The file that contains ANIMTEST and the packages that support it load and run with no errors.
Functions I have defined (UCTK-BEAM, etc.) are tested and run fine.
(defun animtest ()
"Test a spinning figure in LTK"
(with-ltk ()
(let* ((cnvs (make-instance 'canvas :width 400 :height 400))
(barrier (uctk-beam 200 200 40 20))
(follower (uctk-beam 0 40 40 20))
(slp-time 50) ; in ms
(bar-theta 0)
(fol-theta 0))
(labels ((update ()
(draw barrier nil)
(draw follower nil)
(incf bar-theta (/ pi 15))
(incf fol-theta (/ pi 15))
(geo:set-theta barrier bar-theta)
(geo:set-theta follower fol-theta)
(geo:set-center follower
;== FIRST ATTEMPT ==
(cons (screen-mouse-x cnvs)
(screen-mouse-y cnvs)))
; == SECOND ATTEMPT ==
;(cons (canvasx cnvs (screen-mouse-x cnvs))
; (canvasy cnvs (screen-mouse-y cnvs))))
(after slp-time #'update)))
(pack cnvs :fill :both :expand 1)
(update)))))
Thanks in advance!
To grab the mouse position in a canvas widget, I don't call the
screen-mouse functions, but rather bind the motion and button press
events. The callback gets passed the event structure which contains
the slots event-x and event-y which are canvas coordinates. Not only
are you getting the right values directly this way, but also it is
more efficient, as you don't have to poll the mouse position - you get
updates automatically when it changes. In your case you could either
choose to update the barrier on mouse-move or alternatively, just
store the mouse coordinates in a variable you read inside your update
loop.
Although it still appears that the CANVASX/Y functions do not work as intended, LTK offers WINDOW-X/-Y to return the X and Y screen coordinates of a widget such that you can write the following to achieve the desired effect:
(cons (- (screen-mouse-x) (window-x cnvs))
(- (screen-mouse-y) (window-y cnvs)))
This assumes that the mouse cursor is on the same screen as the canvas widget named CNVS.

How to exit program with close button in XCB

Can not find any reference on how to close application by the "X" button. I'm programming using XCB and want to close the program by the "X" button. I looked and can't find anything about it. I know how to close by pressing a button. Also, by pressing the "X" button the window looks like it closes but doesn't.
I struggled on this topic some time ago as well.
Look at http://marc.info/?l=freedesktop-xcb&m=129381953404497 .
The key is to store the cookie for the WM_DELETE_WINDOW in a separate cookie...
xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(c, 0, 16, "WM_DELETE_WINDOW");
xcb_intern_atom_reply_t* reply2 = xcb_intern_atom_reply(c, cookie2, 0);
and in the event loop compare the client_message with the cookie2
case XCB_CLIENT_MESSAGE:
{
if((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply2).atom) ...
}

Resources