Sikuli ide special caracters :, \ doesn' t pass through - sikuli

I am using Sikuli ide,
I want to do a very simple type("1440144711350.png", "C:\tests\exportDest.csv")
But it doesn' t seems to work, when i run it, i got errors, what' s the problem may be coming from ?
Thanks

From your code, I suppose you are trying to find or open a file from the windows explorer, or something similar.
The type function simulates the Standard US keyboard, can be tricky if you do not have one. Have a look to SikuliX documentation on the function type. You certainly then have to prefer the method paste
The second issue you certainly encounter is linked to the backslash that is interpreted in your string (for example \t is interpreted as tab). you have to escape them with a \\
To verify it: simply paste (Ctrl+V) in atext editor after running your script can provide you an idea what sikuli tried to paste...
paste("1440144711350.png", "C:\\tests\\exportDest.csv")
if needed you can simply press the enter key afterwards as following:
paste("1440144711350.png", "C:\\tests\\exportDest.csv")
type(Key.ENTER)

Related

Why is the type() function not executed in this script?

I am new to Sikulix and I am running into a problem.
I am trying to follow a tutorial, but the type() function does not seem to work.
I am working on a windows 10 machine 64bit, with sikulix 1.1.3 IDE.
Below is an image of my simple script in which I try to start the calculator in windows.
Both clicks are executed, but the type is not. It also doesn't show up in the log screen:
Is this a bug or am I missing something?
Put a wait(1) right after the click
And do
type("Calc")
type(Key.ENTER)
The issue you're having is your type statement: type("calc" + Key.ENTER)
This should be avoided.
You could try type("calc", Key.ENTER) but I'm unsure if this works. Hope this helps!
I think this is a bug in 1.1.3.
I am running 1.1.0 on a 64 bit Windows 10 PC and this code worked fine for me. I have never had issues concatenating a Key with a String because in Sikuli most of the key constants are actually String values including Key.ENTER documented here.
Maybe try:
wait(image)
type(image, "calc" + Key.ENTER)
Using type this way will click the image and then type whatever is in the second parameter.
Side note for #Michell Monarch:
type("calc", Key.ENTER) will search for the text "calc" on the screen, click it, and then press enter

Can we make use of syntax highlighting feature to remove all comments from a source file in SublimeText?

I have a bunch of source files written in different languages, and I would like to strip all comments from the source files.
While writing regex is certainly an option, depending on the input files, I may have to handle cases where the character to denote comment appears inside string literals. There is also the need to maintain a list of regex for different languages.
The syntax highlighting seems to do quite a good job at highlighting the comments, but there doesn't seem to be any command to remove all comments in the Command Palette.
Is there any way to leverage the syntax highlighting feature in SublimeText to remove all comments from source files in different languages?
Based on nhahtdh's answer, the following plugin should work for both Sublime Text 2 and 3
import sublime_plugin
class RemoveCommentsCommand(sublime_plugin.TextCommand):
def run(self, edit):
comments = self.view.find_by_selector('comment')
for region in reversed(comments):
self.view.erase(edit, region)
Create a new file with Python syntax, and paste the code above into it. Save the file in your Packages/User directory (accessible via Preferences -> Browse Packages...) as remove_comments.py. You can now either run the plugin via the console, or bind a key combination to it. To run via the console, just type
view.run_command('remove_comments')
in the console, and all the comments in the current view will be deleted.
To bind a key combination, open Preferences -> Key Bindings-User and add the following (surround it with square brackets [] if the file is empty):
{ "keys": ["ctrl+alt+shift+r"], "command": "remove_comments" }
Save the file, and you can now hit CtrlAltShiftR (or whatever key combination you choose) and all comments in the current file will be deleted.
Assumption
We will make use of the syntax highlighting rules in Sublime Text to remove all comments, so the method below works only if the syntax highlighting works correctly for the language of your source file.
For most languages, the syntax highlighting rules do quite a good job at recognizing the comments. However, it would be best if you take another look at your files to see if there is any anomaly in syntax highlighting.
The current method only works for Sublime Text 2.
Solution
Open the Console via View > Show Console or the key combination Ctrl+`
Copy and paste the following commands line by line:
e = view.begin_edit()
len([view.erase(e, r) for r in reversed(view.find_by_selector('comment'))])
view.end_edit(e)
After the last command, the edit will be applied and all comments will be removed.

Set syntax for a specific file name in Sublime Text 2/3

I have a program that uses a file called user.cfg to get its user defined configuration settings. The odd thing is that they chose the syntax for this file to be Tcl (it's not odd that it is Tcl, it's odd they chose the .cfg extension instead of .tcl). So, when I open this file in Sublime Text, it doesn't know what syntax highlighting scheme to choose.
What I would like to do is set the syntax highlighting for user.cfg to Tcl, but not all .cfg files to Tcl.
I have seen this question which is very similar to mine, except in that case the special file name had no extension so Sublime Text knew to assign Ruby highlighting to only that one file. Unfortunately, I have an extension so the solution given there will not work for me.
Is there any known way to get Sublime Text base a highlighting scheme on the full filename?
Take a look at the ApplySyntax plugin.
The previous answer is completely true; however, I thought it would be better to have it here all in one place rather than going on another webpage to find the list of procedure to apply it
Sublime text 3
This is found here
Ensure Package Control is installed. Instructions are found here.
In Sublime Text, press Ctrl+Shift+P (Win, Linux) or Cmd+Shift+P (macOS) to bring up the quick panel and start typing Package Control: Install Package.
Select the command and it will show a list of installable plugins.
Start typing ApplySyntax; when you see it, select it.
Restart to be sure everything is loaded proper.
Enjoy!

igraph for python

I'm thoroughly confused about how to read/write into igraph's Python module. What I'm trying right now is:
g = igraph.read("football.gml")
g.write_svg("football.svg", g.layout_circle() )
I have a football.gml file, and this code runs and writes a file called football.svg. But when I try to open it using InkScape, I get an error message saying the file cannot be loaded. Is this the correct way to write the code? What could be going wrong?
The write_svg function is sort of deprecated; it was meant only as a quick hack to allow SVG exports from igraph even if you don't have the Cairo module for Python. It has not been maintained for a while so it could be the case that you hit a bug.
If you have the Cairo module for Python (on most Linux systems, you can simply install it from an appropriate package), you can simply do this:
igraph.plot(g, "football.svg", layout="circle")
This would use Cairo's SVG renderer, which is likely to generate the correct result. If you cannot install the Cairo module for Python for some reason, please file a bug report on https://bugs.launchpad.net/igraph so we can look into this.
(Even better, please file a bug report even if you managed to make it work using igraph.plot).
Couple years late, but maybe this will be helpful to somebody.
The write_svg function seems not to escape ampersands correctly. Texas A&M has an ampersand in its label -- InkScape is probably confused because it sees & rather than &. Just open football.svg in a text editor to fix that, and you should be golden!

Syntax highlighting when pasting into emails

Im in the situation that I often send small codesnippets and xml-snippets to coworkers and partners via my outlook.
Has anyone got a good idea or tool that I can use to have my pastes syntaxhighlighted before I paste them into an email.
I was thinking of an intermediate paste to "$fancytool" and then I would have something to copy that will htmlified so I can copy paste it into the "compose email" window.
Edit-More-info:
Im pasting from windows within a VMWare virtual Machine, it might be eclipse, xmlspy, logfiles and other programs
Even-more-info:
I've seen this link how to do it from Vim. Unfortunately it seldom from vim im copying Code, and my email machine hasnt got any vim. The vmware machines has gvim, but I was hoping for an easier way that pasting to vim, saving to file, opening in internetexplorer and then copy/paste
Late but I can give an answer that works.
You need 2 things
putty
access to some Unix server (With vim)
In putty options, Under window → selection , turn the check box on for
Paste in to clipboard in RTF as well as plain text.
Log on to the server using putty.
start vim by typing vim
Paste your text (for example XML ) in to vim.
enter command mode (of vim by pressing ESC) and type
:set syn=xml.
Syntax highlighting kicks in.
Copy the text using mouse and paste it into your email.
5 years too late, sorry, but I've a much simpler solution than the accepted answer.
Use this online tool: http://tohtml.com/
copy the preview from your browser window and just paste into Word or Outlook.
Vim (or GVim) will output your code as formatted HTML. Then as long as your email is using an HTML format you can copy and paste it in.
Just an update on this matter, if you're on Windows, you can install Notepad++ (which is one of the best windows editors anyway), it comes out of the box with a plugin for this: "Copy text with Syntax Highlighting", when you select some text and right click on it.
If you just want the Add-In here it is.
If you want to know how it is done, here is an article on how to write the Add-In.
Comment: svrist mentioned a code paste site with syntax highlighting. Try http://codepad.org/
(don't have enough mojo to comment yet)
This link led me to SciTE.
Looks like SciTE has a Copy to RTF feature:
Edit(vmware upgrade):
But it looks like I am pretty much lost when I use vmware because I cant transfer rtf clipboard items to the vmware host. And I cant install software on the vmware host.
Maybe a paste-site with syntax highlighting?
If you're on Windows, Visual Studio does this automatically. At least it does for me, using Visual Studio 2005 on XP and copy/pasting to both MS Word and Lotus Notes
HeidiSQL does this for sql queries, and the syntax highlighting choices they made are quite readable. However, this will only work for sql queries, not other code. I like Notepad++ for Windows-based systems, and here are some instructions for Notepad++. Several people mentioned VIM for unix/shell environment.
For gVim (Windows), I defined this function and a convenience mapping:
function! HlCopy() range
exec a:firstline.','.a:lastline.'TOhtml'
normal yG
q!
!start /min powershell "Get-Clipboard | Set-Clipboard -AsHtml"
redraw
endfun
vmap Y :call HlCopy()<CR>
How to use?
Enter visual mode with v or by selecting text with left mouse. Then copy the current selection as raw text with y or highlighted text with Y.
Pass range directly (without visual mode): :1,3call HlCopy().
If you are lazy like me, you can set additional options for TOhtml in that function. I have this in my vimrc:
function! HlCopy() range
let g:html_font = "Consolas"
let g:html_number_lines = 0
exec a:firstline.','.a:lastline.'TOhtml'
normal yG
q!
!start /min powershell "Get-Clipboard | Set-Clipboard -AsHtml"
redraw
endfun
vmap Y :call HlCopy()<CR>