Re: [Tutor] Plugin system - how to manage plugin files?

2010-07-28 Thread Scott Nelson
On Wed, Jul 28, 2010 at 10:07 AM, Mac Ryan  wrote:

> Hi everybody,
>
>
Mac,

I don't know if this is exactly what you are after, but I created a
poor-man's plugin system by simply putting .py files into the same directory
as my app and naming them like _plugin.py  Each of these .py "plugins",
had to define a class named "Plugin" that had some set of expected methods
and properties (ex: initialize(), run(), etc.).  Then, when my app started
up, it simply got a list of all the "*_plugin.py" files in the current
directory, dynamically imported the files using "my_module =
__import__(name)" and then I could do whatever I wanted with that module
using "my_module", such as instantiate an object for each module's "Plugin"
class, etc.

Actually, here's a snippet of code I had lying around that I slapped
together a few years ago to remind myself of how I did this.  I can't
promise this is 100% tested, but it should give you an idea.

http://pastebin.com/UtVp6J9j

Also, you might want to look at this discussion:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/ba8d361516403fdf/

Best of luck!

-Scott
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PyWin32 - Library of functions to interact with windows?

2009-10-14 Thread Scott Nelson
If I may chime in...

As Alan said, pywin is basically a thin wrapper around the Win32 API.  The
Win32 API is very complex.  Thus pywin is, by necessity, also very complex.
There is documentation for pywin, but it is very minimal as you've probably
noticed.  If you are a *very* bold beginner with lots of patience, the best
documentation for pywin is actually the documentation for the Win32 API
itself found on Microsoft's "MSDN Library" website [1].  Navigating and
using this documentation requires a knowledge of the Windows architecture
and C programming. Once you find what you want in the MSDN documentation,
you can usually find the same function in pywin.  Again, this is not going
to be easy if you are a beginner (it is difficult even for more experienced
programmers), but I wanted to let you know the info is out there.  If you
want to dive into Win32 programming and learn the basics, the books Alan
mentioned are good.  But again, Win32 programming is pretty low-level
and complex.  There is usually an easier way to do most things you need to
do.  Especially if you want to create GUI's in Python, don't start with
pywin and Win32.  Use EasyGUI, Tkinter, or wxPython (in order of easiest to
most powerful)

Now, back to your specific task.  To clarify, I'm assuming you want to color
the text that shows up in Window's console when you do "print" from Python,
correct?  It *is* possible to color console text with Python and pywin.
But, it is tricky and not obvious.  I've been wondering how to do this
myself and I recently found some C code on the web [2] that does this and I
translated that into to Python and pywin.  It can be done in about 4 lines
of Python.

To get you started, here is the link [3] to the MSDN documentation that
tells you what you need to know about coloring text in a Windows console
window (what Python's print command uses).  Then, it is up to you to
translate this into Python and pywin.  The link [2] could also help.  If you
are up for a challenge, give it a shot.  If you get stuck or it takes too
long, write back and I/we can nudge you in the right direction with a code
snippet.

(While writing this email, I also discovered that you can control the cursor
position in a win32 console with pywin!  Fun!)

Best of luck, and feel free to ask for more help!

-Scott

[1] - http://msdn.microsoft.com/en-us/library/default.aspx
[2] - http://www.dreamincode.net/forums/showtopic23272.htm
[3] - http://msdn.microsoft.com/en-us/library/ms682088(VS.85).aspx
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] PyWin32 - Library of functions to interact with windows?

2009-11-03 Thread Scott Nelson
Scott Nelson  wrote:
>
>  It *is* possible to color console text with Python and pywin.  But, it is
> tricky and not obvious.  I've been wondering how to do this myself and I
> recently found some C code on the web [2] that does this and I translated
> that into to Python and pywin.  It can be done in about 4 lines of Python.
>

For the sake of posterity (and the archives), I figured I'd list the "4
lines of Python" I mentioned above:


import win32console
handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE)
print 'blue text'


Beginning with this snippet, there are a number of other things you can do,
such as set the cursor position (handle.SetConsoleCursorPosition) and get
the properties of the console itself (handle.GetConsoleScreenBufferInfo).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is URL to online Python interpreter?

2009-12-18 Thread Scott Nelson
>
> On Thu, Dec 17, 2009 at 09:32:44PM -0800, Benjamin Castillo wrote:
> > What is URL to online Python interpreter?
>

 There is also http://codepad.org/ which also supports lots of languages
(Python, Ruby, Perl, PHP, C/C++...).  Pretty slick.  You can also use it as
a public pastebin (this link will expire eventually)
http://codepad.org/YCrMADrc.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] win32gui, SetForegroundWindow() and setting focus

2008-03-16 Thread Scott Nelson
Greetings all...

I'm looking to use the win32api and win32gui modules to do a bit of
Windows tinkering (win2k) and I've hit a snag.

I'd like to programmatically set which window has the focus.  But
win32gui.SetForegroundWindow(hwnd) seems to be what I'm looking for,
but, it isn't working quite as I expect meaning I probably have a bad
assumption.

SetForegroundWindow() works like a charm in simple cases from the
command line.  However, when I enumerate all top level windows and try
to set each one as the foreground window in turn, it gets thru 1-2
windows out of the 8-10 I have open before giving me this:

Traceback (most recent call last):
  File "D:\_code\python\apps\WinTests.py", line 25, in ?
cycle_foreground()
  File "D:\_code\python\apps\WinTests.py", line 20, in cycle_foreground
win32gui.SetForegroundWindow(handle)
pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available')

What am I doing wrong in this case?  Can my app "give away" its own
focus but can't force a different app's window with focus to "give
away" its focus?  Is there any other way to accomplish this?  I've
attempted using a mix of SetFocus(), BringWindowToTop(), and
EnableWindow() but couldn't find the magic combo.

I've attached my test script.  Run it as "WinTests cycle" to attempt
to cycle the focus through all top level windows and see the traceback
above.  Run it as "WinTests 12345" to set focus the window with hwnd
of 12345.  Run it as "WinTests" to get a list of all top level windows
and their hwnd's.

I've tried reading the very-sparse win32 docs provided with
ActiveState's PythonWin, I've read a bit on the win32 API on MSDN and
I've googled around a bit, and haven't found much.

Thanks for making this a great list, all...

-Scott
import win32gui
import time
import sys
import win32con

def win_enum_callback(hwnd, results):
if win32gui.IsWindowVisible(hwnd) and win32gui.GetWindowText(hwnd) != '':
results.append(hwnd)

def print_list():
handles = []
win32gui.EnumWindows(win_enum_callback, handles)
print '\n'.join(['%d\t%s' % (h, win32gui.GetWindowText(h)) for h in 
handles])

def cycle_foreground():
handles = []
win32gui.EnumWindows(win_enum_callback, handles)
for handle in handles:
print handle, win32gui.GetWindowText(handle)
win32gui.SetForegroundWindow(handle)
time.sleep(2.0)
   
if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == 'cycle':
cycle_foreground()
sys.exit(0)

if len(sys.argv) == 2:
win32gui.SetForegroundWindow(int(sys.argv[1]))
else:
print_list()

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Which Python Script Editor of Choice?

2008-04-03 Thread Scott Nelson
>
> Komodo also often gets props from the "IDE People" I've known.


 To throw another one into the mix, ActiveState has a free/open source
version of its Komodo IDE called "Komodo Edit".  I downloaded it and played
with it for a few minutes awhile ago.  Seems pretty slick.  Anyone have any
first hand experience with this one?  It also supports more than just Python
(also does Perl, PHP, Ruby, Rails, etc.)
http://www.activestate.com/Products/komodo_ide/komodo_edit.mhtml

(FWIW, most of the time, I use PythonWin to edit code and a command prompt
to run scripts)

> Btw, if people know of good IDE's other than PIDA that are free, run on
windows and linux and allow use of VIM as the editor, please let me know.

Looking at Komodo Edit's page, it supports Win/Mac/Linux, has "Vi
emulation", and is free (not crippled in any way that I know of.  It just
has a smaller feature set when compared to the full Komodo).
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Providing Solutions for all the Common Questions

2008-10-21 Thread Scott Nelson
To throw out an idea...

http://www.showmedo.com/ is a site that believes that learning-by-watching
is a very effective way to teach people new skills.  So, they host lots of
(user-generated) screencasts (usually 5-10 minutes) that show people how to
do things.  Because the site is Python focused, there are 350+ videos on
learning Python (150+ beginner oriented vids).  Would it be helpful to take
the most common questions and create screencasts that demonstre the answers
to common questions, post them to ShowMeDo and get a collection of links
togeher?  Just a thought...
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Print to std output with color

2011-01-26 Thread Scott Nelson
Curses is one way to go.  Another is to use the PyWin32 module discussed in
this thread:

http://thread.gmane.org/gmane.comp.python.tutor/58450/focus=58454

Basically, here's a snippet of code that can get you started.  This requires
that you have the PyWin32 module installed (already installed by default if
you use ActiveState's Python distribution for Windows).  Using PyWin32 isn't
for the faint of heart, but it does work.

import win32console
handle = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
handle.SetConsoleTextAttribute(win32console.FOREGROUND_BLUE)
print 'blue text'

On Wed, Jan 26, 2011 at 11:10 AM, Karim  wrote:

>
> Hello all,
>
> Is there a simple way to print with color to stdout like the unix/linux
> example below:
>
> *print( '^[[1;31mThis is a warning!^[[0m' )
>
> where  <=> ^[
>
> *I see thing with curses module. But is there an more simple object in
> other module to do the trick?
> Kind of *decorate_output( mode=WARNING, 'This is a warning!')*
>
> Regards
> Karim
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Print to std output with color

2011-01-26 Thread Scott Nelson
>
> Curses is one way to go.  Another is to use the PyWin32 module discussed in
> this thread:
>

I just realized I was assuming you were on Windows.  If you are on another
OS, the code I posted will obviously not work for you as it is specific to
Windows.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What's the keyword for the Python creed?

2011-09-15 Thread Scott Nelson
On Thu, Sep 15, 2011 at 1:19 PM, Richard D. Moores wrote:

> You know, at the interactive prompt you enter some Monty Python word
> that I can't remember, and you get a small list of pithy pythonic
> advice such as "explicit is better than implicit", etc.
>

import this

You can also do...

import antigravity

...for another Pythonic easter egg...  Though I think this one requires
Python 3?  2.7?  Can't remember.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to print a string in desired colour

2012-02-12 Thread Scott Nelson
On Sun, Feb 12, 2012 at 6:47 AM, Debashish Saha  wrote:

> suppose i want to print 'hello world' in color blue.so what to do?
>
>
There was a similar thread awhile ago.  Unfortunately the answer isn't an
easy one.  It depends on what operating system you use.  Here's a link to
the old thread: http://comments.gmane.org/gmane.comp.python.tutor/67743
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor