Technoblog

concerning latter-day magic

   Dec 11

Adding Python Script to Notepad++

Keywords: Solved, Python Script plug-in won’t load, unknown exception

I’m not sure why this has to be so complicated, but I’ve had to go through it a couple of times in the last couple of weeks.  One thing is for sure:  I have Windows 7, 64 bit, and installing the Python Script plug-in via the Notepad++ plug-in manager doesn’t work.

Remedy:

1.  Navigate to npppythonscript.sourceforge.net/ and click the download link on the left-side menu.  Do not believe the lie that the plugin manager is the easiest way.  On the ensuing page, go to the downloads, not the MSI.

2.  On this page, select the most recent version, then select the FULL zip version.  Download.

3. Be sure Notepad++ is not running. Unzip it into the Notepad++ directory, typically c:\Program Files (x86)\Notepad++.  If you do it right you will have the the python27.dll in the Notepad++ directory, and only one plugins subdirectory, not one nested in another.

4.  To Test, in Notepad++ go Main Menu >> Plugins >> Python Script >> Show Console.

    • If you’ve done it right, you will get this in the upper console window that pops up:
Python 2.7.6-notepad++ r2 (default, Apr 21 2014, 19:26:54) [MSC v.1600 32 bit (Intel)]
Initialisation took 140ms
Ready.
>>>
    • If not, you will see this only:
>>>

 Thanks.  Why again was this important? In other words, why do I want Python Script in Notepad++

So you can insert dates and times the way you want. A number of folks have written it up (like here), but once you have added python, there’s no end to the magic you can do.  Watch this space in the future about regular expressions deployed in Notepad++ via Python.

 

 


   Dec 02

C# WPF WTF you’ve got to be kidding me; v4.5.AssemblyAttributes.cs’ could not be found

So I’m building a proof-of-concept two-window C# WPF project.  I build the windows, call one from the other, and I get this:

Error 1 Source file 'C:\Users\dholoman\AppData\Local\Temp\.NETFramework,Version=
 \\rori\dholoman$\Visual Studio 2013\Projects\WpfApplication2\WpfApplication2\CSC

Googling up the a solution here, the satirical rogue correctly suggests:

<!-- somewhere after the Import of Microsoft.somelanguage.targets -->
<Target Name="GenerateTargetFrameworkMonikerAttribute" />

So you add this, and it works.  Questions:

  • What does “GenerateTargetFrameworkMonikerAttribute” even mean?  How on earth was it discovered?
  • Why is this necessary?  Can’t the thing work out-of-the-box?
  • How would I have ever become unstuck in the pre-Internet days?

Golly!


   Nov 28

WPF C# Show Second Window

I don’t really see why it is so danged difficult to find someone articulating this out in how-to land; hopefully this post will help.

How do I activate a second window from my initial window?

1)Assuming you already have the first window, create the second.  I seem to have named mine “Window1″.  Clever.

2) Here it is, attached to a button click:

 private void btnNew_Click(object sender, RoutedEventArgs e)
 {
 
 Window winVarAddContact = new MyNet.Window1();
 winVarAddContact.Show();
 }

Enjoy.


   Nov 28

Phoenix. How I did it.

So I am trying to locate the right platform to develop a project; maybe two.  I am vacillating between python (open source, cross platform) and Microsoft WPF ($$, but I do have licensing through work).  For the moment, I am pursuing both.

I would love a Delphi-like development environment;  for the moment it looks like that will have to wait.  It is interesting to read through the options and note how many have initiatives have shipwrecked, presumably on the shores of complexity.

I am interested in drag and drop, so I thought wxPython would offer the best chance of success, based on limited research (tkinter apparently requires at least one extra package), so I got read to pursue that, until I found that it has to match your Python.  I opted a few weeks back for Python 3; wxPython is only available for Python 2.  This whole Python 2/3 thing makes me particularly crazy to begin with.

But I’m not embracing 2.  3 is some 16 years old now; this is ridiculous.  And, wxPython for 3 is well underway; you can get a dev copy (doesn’t say alpha or beta).  That’s where I’m headed.

Enter the void of effective documentation for the whole Python-o-sphere.  If you don’t know how to get around, you don’t know.  If you do know, apparently you lose all interest in writing about it.

First, I did something entirely superfluous [1].  You can skip that.

Then, I did this. Don’t skip:

C:\Users\dholoman>python -m pip install --pre -f http://wxpython.org/Phoenix/sna
pshot-builds/ wxPython_Phoenix
Downloading/unpacking wxPython-Phoenix
 http://wxpython.org/Phoenix/snapshot-builds/ uses an insecure transport scheme
 (http). Consider using https if wxpython.org has it available
Installing collected packages: wxPython-Phoenix
Successfully installed wxPython-Phoenix
Cleaning up...

C:\Users\dholoman> 

Q: What is the -m for?

“you can specify any module in Python’s search path this way, not just files in the current directory. ” source

It all worked fine so far.  I made up my “hello world” equivalent and am ready to move on to the next thing.

 

____

[1] Since the Phoenix stuff was stored as a wheel (I looked up what a .whl extension is), I thought I would need wheel.  So, based on little Googling, I did this:

C:\Users\dholoman>python -m pip install wheel
 Downloading/unpacking wheel
 Installing collected packages: wheel
 Successfully installed wheel
 Cleaning up...
C:\Users\dholoman>

Successful but ineffective:  it gives me the ability to make a wheel now.  Have to look into that one day.


   Sep 18

SOLVED: HTC One USB File System Problem

Folks, this is a marketing problem rather than a technical problem.  You plug in the phone with the USB cable, and you get this:

HTC1  You don’t want the HTC Sync Manager, you only want the ability to navigate the devce with a Windows Explorer interface.  So you click ‘Open folder to view files’ and expect the best.  But instead, you get:

 

 

 

 

 

 

 

 

HTC2This.  Yikes!  Can’t navigate to your pictures or whatever that way.  Don’t get mad and frustrated like I did.  It took a trip to the Sprint store for me to find out this:

 

 

 

 

 

HTC3The desired interface was there all along, I just stopped looking for it when I say the Sync manager entry in the place where removable drives usually appear.  But at the END of the drive list, there is an additional mapped drive.  If you click on HTCONE, you will get full navigation to the files on the device, which is what I wanted.  Hope this helps.

 


   Sep 09

Concerning the satisfaction of building a lasting tool, and Quickbooks IIF imports

They say that architects and get a great amount of satisfaction from their work because years later they can ride by a building that they built to get the sense of accomplishment each time.  As a system developer, it’s also possible to get that same sort of positive reinforcement, but sometimes your work isn’t in plain view.

I have designed and built several high profile websites and systems that deliver some measure of this kind of satisfaction.  Better still, however, for whatever reason, is the satisfaction that comes when you find out your client is still using that same system or utility that you wrote for them 10 or 15 years ago.  I’ve been fortunate enough (or old enough) to have experienced this a couple of times.  One involved a small FTP program that simplified file transmission for a not-very-sophisticated client base back in the dawn of the Internet age.  Another was a utility that allowed a water testing laboratory to transfer data from their commercial operations sytem to their home-grown accounting system.

A weak or so ago, an old client called and asked if I can make a modification to a program that initially wrote for them over 10 years ago and have not touched in at least five.  It is a utility that allows data extracted from their financial products operation into their accounting system which is Quickbooks.  For all these years, this client has been importing invoices into Quickbooks using my utility, and designating the invoices to be marked in Quickbooks for printing.  What they wanted to add was for the invoices to be similarly marked for transmission via e-mail as well.

Developers that have ever tried to implement the import/export capabilities of Quickbooks using the Intuit interchange format (IIF) file standard quickly learn that the Quickbooks/Intuit organization really does not want you to be able to create interfaces such that data can be passed freely in and out of Quickbooks.  They have grudgingly provided this perfectly obtuse mechanism and have purposefully under-documented it.  The documentation has never been anything remotely approaching adequate, and it has not been updated in years.  More disturbing still, however, is the fact that apparently useful posts found using a Google or similar search are mysteriously missing from the Quickbooks/Intuit forums.  I can’t tell you how many times I’ve done a Google up what appears to be a slam dunk solution to determine the correct method of executing a specific IIF task only to find that the article in question was no longer available.

If they really cared about their clients and wanted you to be able to get data in and out of their program, they would adopt a normal standard such as XML.  They would thoroughly document the interface, and keep the documentation updated.  The documentation would be thorough and exhaustive and well organized.  None of these things are true of the existing documentation.  What they do instead is hoard their treasure like some kind of jealous troll.  I hope it works out for them in the long run.

So anyway, it took me a long time to find out what should have been a trivial fact; then I had to experiment to find the correct way to apply it.  Recall that I was trying to determine how to designate on the invoice that an e-mail copy of the invoice should be sent.  I did find it.  It is TOSEND.  Use this information with my compliments.

And if you have happened onto this post with the thought of writing an IIF interface, I suggest hiring out for it (like to me!).  It is a frustrating and steep learning curve.


   Sep 07

Rosetta Code, Learning, and Scripting Languages These Days

If you have never checked out Rosetta Code, you should.  It says it’s a programming chrestomathy (a word I had to look up): a collection of code snippets that show, for a given task, how it is achieved in a variety of different programming languages.  You can use it as a proxy for a nerd meter, I expect:  the degree to which you find it interesting is how big of nerd you are.

Or how big of a professional programmer.  Or maybe how big of an interested intellectual.  Checking out how to do the same task in 66 languages to me is fascinating, and many of the tasks there a progamming pearls that developers have been kicking around for years, and thus serves a something of a definitive reference.

The Walk A Directory task, for example, shows pretty plainly that for all the hoopla about Java, it isn’t all that compact, but still a lot more compact than C.  Python showed as pretty compact; Ruby more compact still.  Perl:  still terse but effective after all these years.

I thought I might use a little programming task like this to get a little more familiar with a comparatively recent scripting language, so I tried Ruby.  Now mind you, I didn’t try very hard, but I did get put off pretty quickly about hit-and-miss the documentation was.  I retreated to python, which I’ve used a bit before, but I’m still a long way from expressing myself effortlessly with it.

Which got me to thinking about how we get ourselves going in a programming environment these days:  we learn by Google.  You don’t get out a manual and wade through the basics; you just start, and Google up potential answers anytime you get stuck.  I’m not sure if this approach is better or worse; but in my experience it isn’t any quicker.  Like with Ruby, I found that the explanations I found for a particular issue might have solved that the issue with that particular command, but didn’t get me any closer to understanding the Ruby paradigm, if there is one.  After the retreat to python, for all its intended purpose of being object-perl, I was dramatically surprised that the method to cast something to a string is the same as it was in BASIC (no, I don’t mean Visual Basic).

So why don’t we toddle down to Borders and peruse the technical books to get a feel for the paradigm?  Because it isn’t there anymore (but not by any fault of mine), and Barnes and Noble is a poor substitute.

The Rosetta Code site is a little light on how it came to be, and why, and who is behind it (probably because it is a product of developers and not marketing people).  There are a number of projects being pursued open-source/contribute style.  I hope the initiative endures and prospers.

I did complete my python script to traverse a directory structure and crank out the results to a CSV file.  The purpose is to give the results to my networking guys so they can generate more space on our drives by archiving the big-old stuff first.

Enjoy:

import fnmatch
import os
import sys
import time

rootPath = 'c:\Lexmark'
pattern = '*.*'

f = open("out.csv", 'w')
for root, dirs, files in os.walk(rootPath):
  for filename in fnmatch.filter(files, pattern):
    f.write( '"' + os.path.join(root, filename) + '",' + str(os.path.getsize(os.path.join(root, filename))) +
',"' + time.asctime(time.localtime(os.path.getctime(os.path.join(root, filename)))) +
'",' + str(os.path.getctime(os.path.join(root, filename))) + '\n')

f.close()