Home Download Buy Blog Forum Support

Printing from Sublime Text 2?

Re: Printing from Sublime Text 2?

Postby Nova on Thu Nov 28, 2013 2:57 pm

qgates wrote:A simple solution is to use the Export HTML plugin together with your browser. Apart from simple, it's also pretty darned flexible, because once your printable code is in HTML/CSS you can do lots with it in <your favourite browser> before printing (ie. on the fly styling of fonts, colours, spacing, pagination, etc.).
For the above reason I really don't understand why people are so hung up on printing. Maybe I'm missing something.

I completely agree.
Futhermore, adding that I seldom print my code (or anything) ..this is really a non-issue to me.
Nova
 
Posts: 19
Joined: Tue Jul 10, 2012 9:01 am

Re: Printing from Sublime Text 2?

Postby jbjornson on Thu Nov 28, 2013 3:12 pm

TonyW wrote:
bizoo wrote:Give Export HTML plugin a try, I pretty sure is good enough for 99% of people


I must be the 1% :D

Because when I do "Export HTML | Show Export menu | Browser print: Color", my html editor starts up (NVu)

Without having looked at the source code... I suppose the plugin requires "htm(l)" file types to be associated with a browser, which is a no-go for me. Is there a way to say which process to start?

Note: I used https://github.com/facelessuser/ExportHtml - maybe there is an alternative?


Looking at the ExportHtml source code that you linked to, the last few lines of "ExportHtml.py" have the following code:
Code: Select all
        if inputs["view_open"]:
            self.view.window().open_file(the_html.name)
        else:
            # Open in web browser; check return code, if failed try webbrowser
            status = desktop.open(the_html.name, status=True)
            if not status:
                webbrowser.open(the_html.name, new=2)


So it looks like the plugin is trying to open the html file with the default application (desktop.open), but the fallback code is what you want (webbrowser.open). A simple edit of the code should give you the preferred behaviour. If editing the code is out of the question for you, then maybe you could create a new issue with the developer asking him for a setting to control this behaviour (https://github.com/facelessuser/ExportHtml/issues)?
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Printing from Sublime Text 2?

Postby TonyW on Thu Nov 28, 2013 3:22 pm

jbjornson wrote:
TonyW wrote:
bizoo wrote:Give Export HTML plugin a try, I pretty sure is good enough for 99% of people


I must be the 1% :D

Because when I do "Export HTML | Show Export menu | Browser print: Color", my html editor starts up (NVu)

Without having looked at the source code... I suppose the plugin requires "htm(l)" file types to be associated with a browser, which is a no-go for me. Is there a way to say which process to start?

Note: I used https://github.com/facelessuser/ExportHtml - maybe there is an alternative?


Looking at the ExportHtml source code that you linked to, the last few lines of "ExportHtml.py" have the following code:
Code: Select all
        if inputs["view_open"]:
            self.view.window().open_file(the_html.name)
        else:
            # Open in web browser; check return code, if failed try webbrowser
            status = desktop.open(the_html.name, status=True)
            if not status:
                webbrowser.open(the_html.name, new=2)


So it looks like the plugin is trying to open the html file with the default application (desktop.open), but the fallback code is what you want (webbrowser.open). A simple edit of the code should give you the preferred behaviour. If editing the code is out of the question for you, then maybe you could create a new issue with the developer asking him for a setting to control this behaviour (https://github.com/facelessuser/ExportHtml/issues)?


Thanks for the suggestions. After some looking around, I figured out how to edit the source and made sure only webbrowser.open is called. Unfortunately, that too opens NVu (or whatever the default application is)
TonyW
 
Posts: 15
Joined: Thu Nov 28, 2013 7:50 am

Re: Printing from Sublime Text 2?

Postby jbjornson on Thu Nov 28, 2013 3:39 pm

How about trying this instead?

Code: Select all
webbrowser.open('file://' +the_html.name, new=2)
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Printing from Sublime Text 2?

Postby jbjornson on Thu Nov 28, 2013 3:44 pm

...or maybe this:

Code: Select all
webbrowser.get("firefox").open(the_html.name, new=2)

from http://www.daniweb.com/software-development/python/threads/285581/how-do-i-call-the-default-browser-from-a-python-program.

Check here for more browser types other than firefox: http://docs.python.org/2/library/webbrowser.html
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Printing from Sublime Text 2?

Postby TonyW on Thu Nov 28, 2013 3:54 pm

jbjornson wrote:...or maybe this:

Code: Select all
webbrowser.get("firefox").open(the_html.name, new=2)

from http://www.daniweb.com/software-development/python/threads/285581/how-do-i-call-the-default-browser-from-a-python-program.

Check here for more browser types other than firefox: http://docs.python.org/2/library/webbrowser.html


Chrome (my only browser) is not on that list. Chrome support was added in Python 3.3.x apparently - but still no go.

I think I'll give up for now, and I guess this proves the point about printing as a native feature...
TonyW
 
Posts: 15
Joined: Thu Nov 28, 2013 7:50 am

Re: Printing from Sublime Text 2?

Postby jbjornson on Thu Nov 28, 2013 4:33 pm

One last try...the correct documentation link is: http://docs.python.org/3/library/webbrowser.html. Try one of the following: 'google-chrome', 'chrome', 'chromium', 'chromium-browser'
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland

Re: Printing from Sublime Text 2?

Postby TonyW on Thu Nov 28, 2013 4:38 pm

jbjornson wrote:One last try...the correct documentation link is: http://docs.python.org/3/library/webbrowser.html. Try one of the following: 'google-chrome', 'chrome', 'chromium', 'chromium-browser'


None of those works - the associated application still starts. Since Python has four (!) different chrome names, I guess this is shaky business, and my bleeding edge chrome beta isn't found under those names?
TonyW
 
Posts: 15
Joined: Thu Nov 28, 2013 7:50 am

Re: Printing from Sublime Text 2?

Postby bizoo on Thu Nov 28, 2013 4:48 pm

I suppose you are on a Windows box.
webbrowser module is next to useless for anything except the default system browser.
It search the browser name in the system path, which is not a good idea on Windows.

You can check which browser was found in the console:
Code: Select all
import webbrowser
webbrowser._browsers


Something like that must work, but not very useful:
Code: Select all
webbrowser.BackgroundBrowser('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe').open('http://www.myurl.com')


Open an issue for the Export HTML plugin, facelessuser is a nice and brilliant guy.
bizoo
 
Posts: 886
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Printing from Sublime Text 2?

Postby Opie on Fri Dec 06, 2013 7:15 pm

I'm one of "those guys" that considers integrated printing essential to their work. I really don't understand the virulence and contempt with which the people with the opposite views seem to regard this feature request.

I've been programming for 20 something years, and an essential part of the way I work is to print out and annotate my own code, and to share it with others for comment and revision. I understand that not everyone works that way, but because it is so important to the way I work, my primary editor will have that feature.

I have tried the other printing options, and they are just not "there." Print to HTML trashes programming indentation, particularly when there is a mix of spaces and tabs in the file. So I come to this forum simply to state that integrated printing is an essential feature for me, and to express my wish that it be added to Sublime 3. The developer of Sublime can do with this what he will, but I'm not going to buy the editor unless it has this feature.

If you don't care about this feature, fine. But it's important to me, because it's part of the way that I work and code.

I really, really like Sublime: it is elegant, lightweight, and has personality. But the lack of integrated printing keeps me using editors that are otherwise clunkier (Notepad++, MultiEdit, SlickEdit).
Opie
 
Posts: 1
Joined: Fri Dec 06, 2013 6:59 pm

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: Yahoo [Bot] and 25 guests