Home Download Buy Blog Forum Support

Printing from sublime

Re: Printing from sublime

Postby agibsonsw on Mon Nov 19, 2012 7:24 pm

If someone could spend a few minutes to confirm that my feature works (or doesn't..) for osx or linux, that would be nice :)

First, ensure your printer is shared;
Clone, or download and copy, the files to a folder named QuickPrint in your Packages area; re-start ST, then right-click an open view and choose QuickPrint. If it doesn't print can you look in the Console (Ctrl ' (apostrophe, or possibly back-tick)) and note any error message(s) that appears there.

Thanks in anticipation. Andy.
Last edited by agibsonsw on Mon Nov 19, 2012 11:07 pm, edited 2 times in total.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Printing from sublime

Postby bbarrill on Mon Nov 19, 2012 10:37 pm

I just tried out the QuickPrint feature in OSX 10.7.5 with Sublime Text 2.0.1, Build 2217, and it doesn't work for me.

I downloaded the zip of QuickPrint from Github, unzipped it and copied the 6 files into a folder called QuickPrint in my Sublime Text 2 packages folder. I restarted ST, and now I see a "QuickPrint" option when I right-click, but it's greyed out. No error message shows up in the console (because I can't click the greyed-out QuickPrint option). Is there anything further I can try to make it work?

Also, the command to pull up the console is ctrl+backtick `, not ctrl+apostrophe ', correct? Nothing happens when I type ctrl+apostrophe in ST.
bbarrill
 
Posts: 9
Joined: Mon Nov 19, 2012 10:29 pm

Re: Printing from sublime

Postby agibsonsw on Mon Nov 19, 2012 10:58 pm

@bbarrill Thank you very much for taking a look at this.

You can view the console from the View menu, Show Console. (Control apostrophe works for me on Windows, but I notice the menu command suggests Ctrl back-tick.)

IMPORTANT: Have you shared your printer..? I mentioned this in a previous post, but forgot to mention it in my most recent one, Doh!

If you can let the know the error message that appears in the console that would great (as I'm unable to test this otherwise). Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Printing from sublime

Postby bbarrill on Mon Nov 19, 2012 11:09 pm

I do have printer sharing turned on (although this doesn't seem to affect anything; I tried it both ways). Here's what I find when I start up ST and look at the console:

Reloading plugin /Users/bb/Library/Application Support/Sublime Text 2/Packages/QuickPrint/QuickPrint.py
Traceback (most recent call last):
File "./sublime_plugin.py", line 62, in reload_plugin
File "./QuickPrint.py", line 8, in <module>
os.environ['COMPUTERNAME'])
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: 'COMPUTERNAME'
plugin init time: 0.041403
loading bindings
loading pointer bindings
found 1 files for base name Default.sublime-theme
theme loaded
app ready
pre session restore time: 0.158148
using gamma: 2 (err: 6.9282)
startup cache, total files: 94 cache hits: 94
startup time: 0.261773 (package setup was not run)
loaded 837 snippets


Hope this helps.
bbarrill
 
Posts: 9
Joined: Mon Nov 19, 2012 10:29 pm

Re: Printing from sublime

Postby agibsonsw on Mon Nov 19, 2012 11:18 pm

Ah, it doesn't like

os.environ['COMPUTERNAME']

If you open the QuickPrint.sublime-settings file can you uncomment/add the setting:

"comp_name": "YOURCOMPUTERNAME",

replacing it with your computer name please. You should restart ST before trying the print.

If this doesn't work you could edit the following line(s) temporarily in QuickPrint.py, as they are not needed for OSX:

Code: Select all
COMPUTER = sublime.load_settings(PACKAGE_SETTINGS).get("comp_name", \
    "DUMMYTEXT")


Thank you for taking the time. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Printing from sublime

Postby agibsonsw on Mon Nov 19, 2012 11:32 pm

I think I need to revise the code to use socket and socket.gethostname() to make it cross-platform (os.environ['COMPUTERNAME'] seems to depend on Windows).

Code: Select all
import sublime, sublime_plugin
import socket, os, subprocess, tempfile, sys
...
COMPUTER = sublime.load_settings(PACKAGE_SETTINGS).get("comp_name", \
    socket.gethostname())


I'll update this while awaiting your response. ta, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Printing from sublime

Postby bbarrill on Mon Nov 19, 2012 11:46 pm

Ok, so I opened the settings file and removed the "//" at the beginning of the line so that it is not commented out, and I changed the name "ANDYCOMPAQ" to my computer's name. Then I quit and restarted ST, but it still gave the same error message as before when it tried to load the plugin.

Then I also tried editing the two lines in quickprint.py to what you wrote. Now something different happens! ST starts without an error and appears to load the plugin successfully, but now when I try to use the QuickPrint feature, I get the following error:

Traceback (most recent call last):
File "./sublime_plugin.py", line 339, in run_
File "./QuickPrint.py", line 132, in run
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 470, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory


I should note that probably unlike most ST users, I'm a biologist, not a computer programmer (I use ST for basic DNA sequence analysis/cleanup), so I appreciate your easy-to-follow instructions. :)
bbarrill
 
Posts: 9
Joined: Mon Nov 19, 2012 10:29 pm

Re: Printing from sublime

Postby bbarrill on Mon Nov 19, 2012 11:55 pm

I have now also tried your updated version that uses the socket command. Now it loads the plugin without errors, but when I try to print, it still gives the "No such file or directory" error I posted a moment ago.
bbarrill
 
Posts: 9
Joined: Mon Nov 19, 2012 10:29 pm

Re: Printing from sublime

Postby agibsonsw on Tue Nov 20, 2012 12:03 am

Thanks for sticking with me!

Can you add as line 131:

print(vw_filename)

- it needs to be aligned with the subprocess statement that follows it.

When you exit and try to print again, when viewing the Console it should show the name of the file it is trying to print.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Printing from sublime

Postby agibsonsw on Tue Nov 20, 2012 12:09 am

It might require 'lpr' rather than 'lp', at line 132:

subprocess.call("lpr " + vw_filename)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

PreviousNext

Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot] and 18 guests