Skip to content

notepad.runMenuCommand in Hebrew  #20

Closed

Description

@Yaron10

Hello Dave,

When Notpad++ Interface Language is set to English, the following script is executed successfully.

notepad.runMenuCommand("View", "Word wrap")

However, I couldn't find a way to run that script if the Interface Language is set to Hebrew.
I've tried various ".decode('utf8')" commands, but to no avail.

Thank you for this great plugin.

Activity

  1. Yaron10 commented on Dec 20, 2014

    @Yaron10
    Author

    notepad.menuCommand(MENUCOMMAND.VIEW_WRAP)

    Works even if the Interface Language is set to Hebrew.

  2. chcg commented on Apr 22, 2018

    @chcg
    Collaborator

    @Yaron10 How is in case of Hebrew the command equivalent to

    notepad.runMenuCommand("View", "Word wrap")

    written and which direction do you use? RTL?

  3. Yaron10 commented on Apr 22, 2018

    @Yaron10
    Author

    Hello @chcg,

    Thanks for replying. I appreciate it.
    And many thanks you for your work on this plugin. 👍

    The command in Hebrew is notepad.runMenuCommand("תצוגה", "גלילת שורות").
    It works from the console but not within a script.

    I use NPP in Hebrew and the layout is RTL.


    Two related request:

    1) Could you set the console layout to LTR even if NPP layout is RTL?
    Please see this discussion (the RTL part).
    @ClaudiaFrank kindly found the relevant code (thanks again Claudia).

    • As I've mentioned in that thread, Dave uploaded PythonScript v1.1.1 without committing the changes.
      Have you committed the fix included in v1.1.1?

    2) Could you add Unicode support to the menu?
    Hebrew file-names are displayed as gibberish.

    default


    Allow me two more questions:

    1) Dave's latest official version is 1.0.8.0. Why did you start with 0.6.3.0?

    2) I've downloaded your latest PythonScript_Full_1.0.9.0.zip and replaced the DLL and the lib folder.
    from ctypes import windll, byref, wintypes, WINFUNCTYPE, Structure, sizeof in startup.py triggers an error.
    Why is that?


    Thanks also for your contribution to ComparePlugin. :)

    Best regards.

  4. Yaron10 commented on Apr 22, 2018

    @Yaron10
    Author

    Hello Claudia,

    Thanks for replying. I appreciate it.

    I'm using the DLL from the zip package.
    I've replaced python27.dll and PythonScript.dll with the new ones.

    I don't get the error now. It was certainly there a few hours ago.

    However, NPP consistently hangs when I'm using the following script.

    if RIGHT_CLICK_MODE:
    	console.hide()
    	editor.grabFocus()
    else:
    	console.show()
    

    With the following startup.py (thanks again :) ).

    # The lines up to and including sys.stderr should always come first
    # Then any errors that occur later get reported to the console
    # If you'd prefer to report errors to a file, you can do that instead here.
    import sys
    from Npp import *
    
    # Set the stderr to the normal console as early as possible, in case of early errors
    sys.stderr = console
    
    # Define a class for writing to the console in red
    class ConsoleError:
    	def __init__(self):
    		global console
    		self._console = console;
    
    	def write(self, text):
    		self._console.writeError(text);
    
    # Set the stderr to write errors in red
    sys.stderr = ConsoleError()
    
    # This imports the "normal" functions, including "help"
    import site
    
    # This sets the stdout to be the currently active document, so print "hello world",
    # will insert "hello world" at the current cursor position of the current document
    sys.stdout = editor
    
    ##################### Right-click mode and Change console output to LTR. #####################
    
    # See https://notepad-plus-plus.org/community/topic/13510/python-lua-script-detect-if-a-modifier-is-pressed-when-running-a-script.
    
    # console.write('parent:{}\n'.format(parent))
    
    from ctypes import windll, byref, wintypes, WINFUNCTYPE, Structure, sizeof
    
    WNDENUMPROC = WINFUNCTYPE(wintypes.BOOL,
                              wintypes.HWND,
                              wintypes.LPARAM)
    
    WndProcType = WINFUNCTYPE(wintypes.LONG,
                              wintypes.HWND,
                              wintypes.UINT,
                              wintypes.WPARAM,
                              wintypes.LPARAM)
    
    GWL_WNDPROC = -4
    RIGHT_CLICK_MODE = False
    
    GWL_EXSTYLE = -20
    WS_EX_LAYOUTRTL = 0x00400000
    
    class NPPchildWindows():
    
    	def EnumNPPCallback(self, hWnd, lParam):
    		curr_class = (wintypes.WCHAR * 256)()
    		windll.user32.GetClassNameW(hWnd, curr_class, 256)
    
    		if lParam == 0:
    			if curr_class.value.lower() == "toolbarwindow32":
    				self.toolbar_handle = hWnd
    				return False
    		else:
    			curr_name = (wintypes.WCHAR * 256)()
    			windll.user32.GetWindowTextW(hWnd, curr_name, 256)
    			if curr_name.value.lower() == "python script":
    				self.python_script_hwnd = hWnd
    			elif curr_class.value.lower() == "scintilla" and windll.user32.GetParent(hWnd) == self.python_script_hwnd:
    				self.python_script_sci_handle = hWnd
    				return False
    
    		return True
    
    	def __init__(self):
    		self.toolbar_handle = None
    		self.oldWndProc = None
    		self.python_script_hwnd = None
    		self.python_script_sci_handle = None
    
    		parent = windll.user32.FindWindowA("Notepad++", None)
    		windll.user32.EnumChildWindows(parent, WNDENUMPROC(self.EnumNPPCallback), 0)
    		console.show()
    		windll.user32.EnumChildWindows(parent, WNDENUMPROC(self.EnumNPPCallback), 1)
    
    	def registerRightClick(self):
    		if self.toolbar_handle:
    			self.new_wnd_proc = WndProcType(self.sciWndProc)
    			self.oldWndProc = windll.user32.SetWindowLongA(self.toolbar_handle, GWL_WNDPROC, self.new_wnd_proc)
    			console.write("Toolbar right-click mode registered.\n\n")
    
    	def sciWndProc(self, hWnd, msg, wParam, lParam):
    		global RIGHT_CLICK_MODE
    		if msg == 0x0204:		# WM_RBUTTONDOWN.
    			windll.user32.mouse_event(0x0002, 0, 0, 0, 0)	# Left down. WM_RBUTTONUP is sent although the right button is still down.
    		elif msg == 0x0205:	# WM_RBUTTONUP.
    			if RIGHT_CLICK_MODE:		# Another WM_RBUTTONUP is sent when the right button is released. Send "Left up" now.
    				windll.user32.mouse_event(0x0004, 0, 0, 0, 0)	# Left up.
    			else:	# The right button is still down.
    				RIGHT_CLICK_MODE = True
    		elif RIGHT_CLICK_MODE and msg == 0x0201:		# WM_LBUTTONDOWN.
    			RIGHT_CLICK_MODE = False
    
    		return windll.user32.CallWindowProcA (self.oldWndProc, hWnd, msg, wParam, lParam)
    
    	def consoleToLTR(self):
    		if self.python_script_sci_handle:
    			exStyle = windll.user32.GetWindowLongA(self.python_script_sci_handle, GWL_EXSTYLE)
    			exStyle = exStyle ^ WS_EX_LAYOUTRTL
    			windll.user32.SetWindowLongA(self.python_script_sci_handle, GWL_EXSTYLE, exStyle);
    			console.write("Console output changed to LTR.\n\n")
    
    _NPPchildWindows = NPPchildWindows()
    _NPPchildWindows.registerRightClick()
    _NPPchildWindows.consoleToLTR()
    
    console.hide()
    editor.grabFocus()
    

    I've added several right/left toolbar buttons (using CustomizeToolbar; executing various scripts) and they all work properly except the Show/Hide one.

    Actually, just using console.show() causes NPP to hang.
    Reverting to the original startup.py, console.show() works as expected.

    Replacing the new PythonScript.dll with the old one - the Show/Hide button works properly.


    Why do you think 1.0.9.0 was created out from 0.6.3??

    https://github.com/bruderstein/PythonScript/releases

    0.6.3 was released a few days ago and I was just wondering why those numbers were chosen when 1.0.8.0 was out a few years ago. Isn't that confusing?

    Best regards.

  5. Yaron10 commented on Apr 22, 2018

    @Yaron10
    Author

    Great. 👍
    Thank you very much.

  6. Yaron10 commented on Apr 22, 2018

    @Yaron10
    Author
    Toolbar right-click mode registered.
    
    Console output changed to LTR.
    
    Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]
    Initialisation took 47ms
    Ready.
    

    Thanks.

  7. Yaron10 commented on Apr 22, 2018

    @Yaron10
    Author

    Yes, it does.
    I've tried those combinations. :)

  8. Yaron10 commented on Apr 22, 2018

    @Yaron10
    Author

    The original zip.

  9. Yaron10 commented on Apr 22, 2018

    @Yaron10
    Author

    And it also happens with the original NPP.

  10. 26 remaining items

  11. added this to the v1.1 milestone on May 25, 2018
  12. Yaron10 commented on May 25, 2018

    @Yaron10
    Author

    Fixed 3. with 5969bb8.

    👍
    Very nice. Thank you for the quick fix.


    Don't think there is a diff between last or previous.
    ...
    I don't have any opinion on Last vs. Previous - for me, both explain the same.

    It's certainly not important but I think that Last is more commonly used in this context (e.g. Last Closed Tab).
    As you understand.

    Ellipses...

    Well... I thought the rule was that any command/button opening a new window should have an ellipses.
    The Registry Workshop developer is quite a perfectionist. An ellipses is added to both Settings and About in that app.

    default

    default

    But reading this article you seem to be right: no ellipses for Settings and About.

    This doesn't mean you should use an ellipsis whenever an action displays another window—only when additional information is required to perform the action. Consequently, any command button whose implicit verb is to "show another window" doesn't take an ellipsis, such as with the commands About, Advanced, Help (or any other command linking to a Help topic), Options, Properties, or Settings.


    Allow me another minor comment:
    I've just noticed the Configuration Dialog title is: Python Script Shortcut Configuration.
    It contains other settings as well; so wouldn't Python Script Configuration be better? Or even better - Python Script Settings?

  13. Yaron10 commented on May 25, 2018

    @Yaron10
    Author

    And Set Icon should certainly be Set Icon.... :)

  14. Yaron10 commented on May 25, 2018

    @Yaron10
    Author

    but it is nice to see that MS has the same opinion.

    Great minds think alike.

    I just ignore for the moment that Microsofts argument is totally different to mine

    I've ignored that too. :)

  15. Yaron10 commented on May 25, 2018

    @Yaron10
    Author

    such as with the commands About, Advanced, Help (or any other command linking to a Help topic), Options, Properties, or Settings.

    Well, MS VS uses Options... and Properties.... :)
    And this seems to be the convention in most good apps.

  16. Yaron10 commented on May 25, 2018

    @Yaron10
    Author

    Makes sense, doesn't it?

    Yes, it does.
    OTOH, I'm not sure the convention should be completely ignored. It's somewhat like a "proper" language vs. a common language.

    So we'll raise a toast to whatever @chcg decides to do. :)

  17. chcg commented on May 27, 2018

    @chcg
    Collaborator

    @Yaron10 See Version 1.1, if further issue arise or something from here is missing please create new ones

  18. Yaron10 commented on May 27, 2018

    @Yaron10
    Author

    Hello @chcg and @ClaudiaFrank,

    👍
    Great.
    Thank you. I appreciate your time and work.

    Should notepad.runMenuCommand("תצוגה", "עטיפת מילים") be working now? - I still get an error.
    It's actually not important as you can use notepad.menuCommand.

  19. chcg commented on May 27, 2018

    @chcg
    Collaborator

    @Yaron10 In this case it was a misunderstanding from my side. Thought just the wrong name
    גלילת שורות
    instead of
    עטיפת מילים
    caused the problem. So I will have another look at that.

    Are you using version 1.1? From my tests it looks ok from console and script I think.

    Or is your expectation that also
    notepad.runMenuCommand("View", "Word wrap")
    should work in Hebrew mode?

  20. chcg commented on May 27, 2018

    @chcg
    Collaborator

    From within a script the encoding info is needed:

    # -*- coding: utf-8 -*-
    notepad.runMenuCommand("תצוגה", "עטיפת מילים")
    
  21. Yaron10 commented on May 27, 2018

    @Yaron10
    Author

    Are you using version 1.1?

    Yes, I am.

    Or is your expectation that also
    notepad.runMenuCommand("View", "Word wrap")
    should work in Hebrew mode?

    No. :)


    # -*- coding: utf-8 -*-

    👍
    That works like a charm.

    Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions