I created a menu using:
fileMenu = wx.Menu()
fileMenu.Append(ID_NEW, "&New\tCtrl+N", "Creates a new file")
I can access New by clicking it on the menu or by clicking Ctrl+N.
My question is: What is the & stand for?
if I delete it everything is still working. However all guides still use it and none of them explain what is the purpose of it.
I've read also here:
http://wxpython.org/Phoenix/docs/html/MenuItem.html#MenuItem.SetItemLabel
"An accelerator key can be specified using the ampersand & character ... Optionally you can specify also an accelerator string appending a tab character \t followed by a valid key combination"
So according to this there is no need to use & if I use \t.
can someone confirm if my conclusion is correct? I just can't figure why I always see both... there has to be a reason why everyone are using it this way.
The & characters in menu titles indicate an accelerator that you can press while the menu is open to quickly access the item. This only works when the menu is open and focused. You'll see the underscored character in the item title as a mnemonic. Same applies to the top level menu entry as well, such as 'File' or 'Edit': by standard WIMP convention you can open said menu using Alt-F (if F is the accelerator for File) and then just as quickly press 'C' if there is an accelerator for C in that menu. Quick and very little known these days.
The \t means a tab in traditional context and in menu items it will make a global shortcut in your frame that you can press without the menu being active.
The shortcut letter following & will be accessible only from the menu.
The \tCtrl+N is available from the entire app, and the short-cut is displayed next to the menu item.
Related
Guys I am using Spyder ide, but when I go to modify a certain thing in any line it selects the letter and starts typing above it and deletes the already written code rather than spacing and typing, any solution?
I would try to hit the Insert key on your keyboard first and see if it toggles between the Insert mode and the Overtype mode:
overtype mode, in which the cursor, when typing, overwrites any text that is present in the current location; and
insert mode, where the cursor inserts a character at its current position, forcing all characters past it one position further.
The insert/overtype mode toggling is not global for the computer or
even for a single application but rather local to the text input
window in which the Insert key was pressed.
Does anyone know how to make it so that Jupyter Notebook doesn't show me this prompt every time I select Heading option? I've created a jupyter_notebook_config.py file, but I didn't see an option to turn it off. I like to use headings often to break up my code and keep better documentation, but I find it annoying to constantly click OK every time.
The warning is not that headings are gone, it is that heading cells don't exist anymore. All text cells are markdown now, and you create headings by prefixing the line with a number of # symbols to indicate the heading level. When you see this dialog, it is not creating a heading cell; it is creating a markdown cell with the right number of # characters.
The way to avoid the warning is to create markdown cells and add the # characters yourself.
To not get a prompt you can just:
enter your text in the cell
hit esc to enter command mode
press 1,2,3,4,5 or 6 keys for getting a heading(1-6) respectively
simultaneously press (shift + return/enter)
I can't spy on CheckListBox object (I think Delphi) in a window frame with AutoIt. It can't see anything in the area. I need to get the list of items from the area and possibly select one the items.
I am using python and robotframework.
I also tried using ControlListView:
self.get_autoit().ControlListView("Setup - XXXXX", "Select the XXXX", "[CLASS:TNewCheckListBox; INSTANCE:1]", "GetText")
But it throws:
com_error: (-2147352561, 'Parameter not optional.', None, None)
The error seems to be an issue with pywinauto.
Anyway I can not get the list of items from this annoying object.
The result from autoit spy is in screenshot:
Can anyone please suggest a good way to access the list of items in this unidentified area?
I can see the inside items from inspect.exe:
Please see the detailed answer from Vasily in the comments. However to summarize:
In the original question, I was trying to get the list of items from CheckListBox using pyautoit however as it was not working. So, as suggested by Vasily, I used pywinauto (another automation tool) in UIA mode and following worked for me:
self.Wizard = Application(backend="uia").connect(title = self.installerTitle) #connect the application
self.Wizard.InstallerDialog.TreeView.wait('visible', timeout=150) #wait for tree view to load
items = self.Wizard.InstallerDialog.TreeView.children() #get the children of tree view
for item in items: #iterate through items, radio button in this case
if item.window_text() == "item_name_to_select":
item.click_input() #click radio button if the text is what we are looking for
return
print "no item found with name: item_name_to_select"
The most helpful trick was to use print_control_identifiers() method in pywinauto to get the identifiers of the control. Also the inspect.exe in uia mode helped in identifying the objects.
Motivation: I was going around assigning parameters read in from a config file to variables in a function like so:
john = my_quest
terry = my_fav_color
eric = airspeed
ni = swallow_type
...
when I realized this was going to be a lot of parameters to pass. I thus decided I'd put these parameters in a nice dictionary, grail, e.g. grail['my_quest'] so that the only thing I needed to pass to the function was grail.
Question: Is there a simple way in Sublime (or Notepad++, Spyder, Pycharm, etc.) to paste grails['variable'] around those variables in one step, instead of needing to paste the front and back seperately? (I know about multiple cursors in Sublime, that does help, but I'd love to find a "highlight-variable-and-hit-ctrl-meta-shift-\" and it's done.)
Based on examples you provided, this is a simple task solvable using standard regex find/replace.
So in Notepad++, record this macro (for recording control examine Macro menu):
Press Ctrl+H to open Find/Replace dialog
Find what: = (.*)$
Replace with: = grail['\1']
Choose Regular Expression and press Replace All
If you finish recording the macro and you choose to save it, shortcut key is requested. Assign your favorite ctrl-meta-shift-\ and you are done.
I'm experimenting with wxPython,
I have a tabbed interface (notebook) and each tab is basically a file list view (yes, I'm trying to make a file manager)
The file list inherits from wx.ListCtrl, and the tabbed interface inherits from wx.Notebook
I'm just starting .. and I had it so double clicking on a folder will cd into that folder, but I want to also change the title of the tab.
How do I do that?
I have the object that represents the file list and the title I want to set it to,
[ EDIT Notebook.SetPageText() takes a number, so I can't pass the tab object directly to it ]
my current approach is to cycle through the tabs until one of them matches my tab:
for tab_id in range(self.GetPageCount()):
if self.GetPage(tab_id) == tab:
self.SetPageText(tab_id, title)
break
This seems rather naive though, isn't there a smarter approach?
I don't know wxPython, but I assume it wraps all the methods of the C++ classes.
There is wxNotebook::GetSelection() which returns wxNOT_FOUND or the index of the selected page, which can then be used to call wxNotebook::SetPageText().
Or use wxNotebook::GetPage() with this index to check whether it is equal to tab.
I think doing something like this helps :
notebook.get_tab_label(notebook.get_nth_page(your_page_number)).set_text("Your text")
If you want to have a reference to the current tab always, you must connect the "switch-page" signal, and save the page in a variable.
As .GetPage returns a wx.Window, I think tab.Label = title should work.