Home Download Buy Blog Forum Support

Help getting the default sublime modules loaded

Help getting the default sublime modules loaded

Postby GrantSP on Thu Sep 05, 2013 5:21 am

I am really new to Sublime and Python but I really wanted to get in and see what I can do with this software.
So, having used the WinMerge package in ST2 and now using ST3, I thought I could port it over to the newest version since it is very basic (only about 30 lines).

I managed to fix it, sort of, it works 66% of the time, and I am now trying to figure out why it won't do exactly the same as the ST2 version.

Well now I can't figure out why I keep getting:
Traceback (most recent call last):
File "C:\Users\Grant\AppData\Roaming\Sublime Text 3\Packages\WinMerge\WinMerge.py", line 1, in <module>
import sublime, sublime_plugin
ImportError: No module named sublime

Why aren't the sublime and sublime_plugin modules being imported?
GrantSP
 
Posts: 39
Joined: Sat Aug 31, 2013 5:11 am

Re: Help getting the default sublime modules loaded

Postby skuroda on Sat Sep 07, 2013 8:23 am

Not really sure, but if you could post all of the code, rather than just the error, it might be easier to help.
skuroda
 
Posts: 677
Joined: Fri Oct 05, 2012 8:11 am

Re: Help getting the default sublime modules loaded

Postby GrantSP on Sun Sep 08, 2013 12:58 am

Thank you for the reply, I was beginning to think no one would look at it.

The error is not specific to the task I mentioned, the WinMerge port, as it occurs with every plugin I look at that imports the Sublime Text modules.

I can't see how to get the functions that those modules detail to be included in an examination of the running code.
I can code a simple Python program and 'Build' it and see the console report its progress including errors. But even though the directory with the modules is in my 'PATH' the Python 'Build' won't or can't see what/where they are.
GrantSP
 
Posts: 39
Joined: Sat Aug 31, 2013 5:11 am

Re: Help getting the default sublime modules loaded

Postby skuroda on Sun Sep 08, 2013 4:30 am

Are you trying to "build" these outside of ST?
skuroda
 
Posts: 677
Joined: Fri Oct 05, 2012 8:11 am

Re: Help getting the default sublime modules loaded

Postby GrantSP on Mon Sep 09, 2013 4:30 am

No, not outside but within using the Ctrl-B build command.

However, I have realised my mistake.
What I should be doing is running the "view.run_command('winmerge')" to check for errors in the code.

I am now following a tutorial by WBond on creating a plugin so as to become more conversant with this great piece of software.

But, perhaps I may push you for some further assistance?

I'm trying to figure out the correct EventListener method to use to select two files for comparison.
The existing plugin just used on_activated but in version 3 it is not working as expected.

eg. If I load 2 files one at a time from the sidebar and invoke the compare command only the topmost file is loaded and the 2nd selection criteria is empty.
If I then either Ctrl-tab or mouseclick on the 1st file the compare works. I assume that the buffers are not filled until these events take place.
This also happens with layouts of 2 or more columns or even with other windows. The 2 files must have been selected consecutively by either a mouseclick or key combo to bring them to the fore.

What I would like to know is do the other methods like on_new or on_load behave better for this role.
ie. If I load from the sidebar or using the Windows shell extension "Open with Sublime Text" 2 files they will be 'in the buffer' and then used as criteria for comparison?

Ideally I would like to have the second way checked first and then if an on_activated has taken place with one of the files the original code with on_activated is called.

It's not a big problem, more of an exercise in learning for me.

Thanks
GrantSP
 
Posts: 39
Joined: Sat Aug 31, 2013 5:11 am

Re: Help getting the default sublime modules loaded

Postby skuroda on Mon Sep 09, 2013 6:58 am

Glad you figured out the original issue. It depends what you want to do. Yes, you could use "on_new" or "on_load". The benefit of using on_activated is it's easy to determine what the last two files are. Though, you could argue on_new/on_load lets you manage it the same way. That is, you just need to know what the last two files you opened are. I'm relatively certain that on_load and on_new will be called, regardless of how they are opened. However, whereas on_activated is only called once, these listeners will only be called once. Well maybe on_load will be called more often if there are modifications outside of ST, I'm not sure. Perhaps you could put some logic in to store recent "on_activated" entries, in addition to "on_load/on_new" entries. Then, when you run the command, you can choose.

An enhancement you might consider making (if you are trying to learn more about the API or get more experience doing some Python) is adding some quick panel prompts. For example, you could present a quick panel with 2 entries. The first being an "ok" selection along with the current files. The second would lead to a secondary prompt so you may select alternate files. This would give you some indication of the actual files being used, rather than having to remember what the last files you worked with were.

As a final note, I believe this plugin would fail if one of the activated files didn't exist on disk (it wouldn't have a file name). Well, at least the version that came up from my google search.

I meant to mention this before, but having no response can mean multiple things. It is possible that no one looked at it. It is also possible that people are unsure on how to answer. As always, try to give as much detail as possible. You may also want to create a post on stackoverflow. That has the benefit of having notifications. Though I would guess that fewer ST users browse that tag compared to the users on the forum. SO does have the benefit of giving some sort of notification when a response has been made. Up to you though.
skuroda
 
Posts: 677
Joined: Fri Oct 05, 2012 8:11 am

Re: Help getting the default sublime modules loaded

Postby GrantSP on Tue Sep 10, 2013 2:30 am

Thank you very much.

I will look at that suggestion about choosing the files, though as my coding skills are still very rusty, it may take some time.

If the version you found was the WinMerge plugin, I have forked off that and made a version 3 compatible update on GitHub to play around with. As I said in the OP, since it was only 30 odd lines I figured I could handle that.
Everything is working as I would expect, except for this failure to find the 2nd file at times. I never experienced that when I used Sublime Text 2 and the plugin, although that was only for a few weeks before I decided on going for version 3. Why get used to a new programme that will be redundant shortly? So here I am with version 3 and absolutely loving it. How can I not have seen this before?

Again, Thanks.
GrantSP
 
Posts: 39
Joined: Sat Aug 31, 2013 5:11 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 10 guests