Difference between revisions of "Python Smart ClipBoard"

From OpenCircuits
Jump to navigation Jump to search
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
  
  
= '''The following is junk, will transform in a bit an this message will go''' =
+
= Goal/Purpose =
 
  
 +
This Python program (clip_board.py) is an application to enhance the windows ( unix ?? ) clipboard
 +
by adding the ability to it to:
  
 +
*Transform keyboard contents, referred to as "Transforms".
 +
*Insert predefined elements into the clipboard, referred to as "Snippets".
 +
*Open example files in a configerable editor or ide, referred to as "Snips". -- This really does not involve the clipboard, but is a sort of high powered version of snippets
 +
*Interpret copied text as commands or directions to the system to carry out some action specified in the clipboard contents, for example, browse to some website.
 +
*The program is easily modified by adding transforms, snips, or snippets, this may require some python programming.
  
  
 +
*The program does not have a clipboard history as I, so far, have not found that useful.  There are a lot of other apps with this feature.
  
  
= Goal/Purpose =
+
For a quick overview on use once installed see the GUI documentation at: '''[[ClipBoard GUI]]'''  That page will also link to the 4 areas of operation:
 +
* [[Clipboard Transformations]] 
 +
* [[Clipboard Snippets]] 
 +
* [[Clipboard Snips]] 
 +
* [[Clipboard Commands]] 
  
This program (clip_board.py) is an application to enhance the windows ( unix ?? ) clipboard
 
by adding the ability to it to:
 
 
*Transform keyboard contents.
 
*Insert predefined elements into the clipboard.
 
*Interpret copied text as commands or directions to the system to carry out some action specified in the clipboard contents for example browse to some website.
 
 
See the GUI at [[TBD]]
 
 
   
 
   
 +
== Status ==
 +
This program is up and running most of the functions seem to work well, major problem is that I keep adding details to the functionality, I use the program partly as an opportunity to explore Python.  Making improvements from time to time for my projects.  Code at GitHub, see [[https://github.com/russ-hensel/python_smart_terminal Code at GitHub]]  I think the major problem with the code is that I am still making a fairly large number of changes/enhancements.  As a result I am breaking things.  New versions are uploaded at various milestones, they are not carefully checked.  Email me if there are problems.  [[http://www.opencircuits.com/User:Russ_hensel Russ Hensel]]
  
== Status ==
 
This program is up and running.  Making improvements from time to time for my projects.  Code at GitHub, see [[https://github.com/russ-hensel/python_smart_terminal Code at GitHub]]
 
 
== Code ==
 
== Code ==
 
 
Code at GitHub, see [[https://github.com/russ-hensel/smart_clipboard/tree/master Code at GitHub]]   
 
Code at GitHub, see [[https://github.com/russ-hensel/smart_clipboard/tree/master Code at GitHub]]   
 
  
 
This is an article started by Russ Hensel, see "http://www.opencircuits.com/index.php?title=Russ_hensel#About My Articles" About My Articles for a bit of info.
 
This is an article started by Russ Hensel, see "http://www.opencircuits.com/index.php?title=Russ_hensel#About My Articles" About My Articles for a bit of info.
Line 73: Line 74:
 
As a programmer and general computer hacker I often need to make simple but time consuming changes to text or recall easily forgotten text, a couple of examples:
 
As a programmer and general computer hacker I often need to make simple but time consuming changes to text or recall easily forgotten text, a couple of examples:
  
* In a wiki you can hide text with a bit of special markup:  it uses <  and > and --- and !  I cannot show it because it hides itself.  But in any case I often forget exactly
+
* In a wiki you can hide text with a bit of special markup:  it uses <  and > and --- and !  I often forget exactly
 
what it looks like, and in any case it is a pain to type.  If I click on "wiki hidden" in the clipboard app then the text is put in the clipboard and I can paste in the wiki.
 
what it looks like, and in any case it is a pain to type.  If I click on "wiki hidden" in the clipboard app then the text is put in the clipboard and I can paste in the wiki.
  
* In a similar way a wiki has a big messy way of setting up a table.  "wiki table" put a whole example in my clipboard for pasting.
+
<pre>
 +
<!-----------
 +
this cannot bee seen
 +
------------->
 +
</pre>
 +
 
 +
* In a similar way a wiki has a big messy way of setting up a table.  "wiki table" puts a whole example in my clipboard for pasting.
  
 
* Many programmers like file names without spaces.  A transformation function in the clipboard will take the text in the clipboard, remove the spaces and put it back in the clipboard.
 
* Many programmers like file names without spaces.  A transformation function in the clipboard will take the text in the clipboard, remove the spaces and put it back in the clipboard.
  
* Some tasks like opening text files or url can be made easy from text you store, for this a prefix is used.  To open a text file:
+
* Some tasks like opening text files or url can be made easy from text you store, for this a prefix is used.  To open a text file copy from a place you have stored it:
 
+
<pre>
 +
  *>text  some_file.txt
 +
</pre>
  
 +
Then pressing the <*cmd> button will open the file in your chosen text editor.  In a similar way;
 
<pre>
 
<pre>
  <!-----------
+
  *>url http://www.opencircuits.com/Main_Page
this cannot bee seen
 
------------->
 
 
</pre>
 
</pre>
  
+
Will open the main page of Open Circuits in your chosen browser.
<!-----------
 
this cannot bee seen
 
------------->
 
 
 
 
 
  
 
   
 
   
So what are the features?
+
What are some other features?
  
 
* Free open source
 
* Free open source
Line 112: Line 115:
 
== My Environment/Your Environment ==
 
== My Environment/Your Environment ==
  
The program has a better chance of running if your environment is not too much different from mine.  The most important is that it is Python 2.7 or compatible.  '''No now Pyton 3.6'''
+
The program has a better chance of running if your environment is not too much different from mine.  The most important is that it is Python 3.6 or higher
 
    
 
    
 
Before you begin to install you should know a bit about the environment that I have used to build, test and run the terminal. If your environment differs too much you may have trouble getting it to run.
 
Before you begin to install you should know a bit about the environment that I have used to build, test and run the terminal. If your environment differs too much you may have trouble getting it to run.
Line 120: Line 123:
 
== Download ==
 
== Download ==
  
Code at GitHub, see [[https://github.com/russ-hensel/python_smart_terminal Code at GitHub]] ( it is Python and you can run directly from the source ) Email me if you have issues ( use this link [[User:Russ_hensel]] ).
+
Code at GitHub, see [[https://github.com/russ-hensel/smart_clipboard/tree/master Code at GitHub]] ( it is Python and you can run directly from the source ) Email me if you have issues ( use this link [[User:Russ_hensel]] ).
 
You will get a zip file, unzip it and you should get:
 
You will get a zip file, unzip it and you should get:
  
 
+
<pre>
 
     .... whatever --|
 
     .... whatever --|
 
                     |
 
                     |
                     |-- smart_terminal --| -> all code required to run the application ( not sure if smart_terminal or python_smart_terminal or nothing is top level name, just put it in some well named place )
+
                     |-- clipboard    -----> all code required to run the application ( not sure if smart_terminal or python_smart_terminal or nothing is top level name, just put it in some well named place )
                                           |    some logs from my running of the code may or may not be present, these will be deleted as they creep in, when you run the program you will
+
                                            
                                          |    get your own log files ... all typically named xxx.py_log
+
                                        | -- images -> image files, mostly screen shots, icons... or what ever, not important for the code.
                                          | -- images -> image files, mostly screen shots, icons... or what ever, not important for the code.
+
                                         
                                          | -- sounds -> wav files used for the deer me extension, my attempt to scare deer.
+
                                        | -- wiki_etc -> various files documenting program, including at least some of the material from this wiki  
                                          | -- wiki_etc -> various files documenting program, including at least some of the material from this wiki  
+
 
 +
                                        | -- example_snips -> files used as snip ( not snippet ) examples. ( You can relocate in your setup but this makes the downloaded app in the new_user_mode work. )
 +
 
 +
                                        | -- snipsand -> files containg links to the smip files and the snippet files.  ( You can relocate in your setup but this makes the downloaded app in the new_user_mode work. )
 +
 
 +
</pre>
  
 
Put them in your system making "....whatever" anything convenient for your Python ( that is move the files to where you keep your Python source ).   
 
Put them in your system making "....whatever" anything convenient for your Python ( that is move the files to where you keep your Python source ).   
Line 139: Line 147:
 
== Run ==
 
== Run ==
  
Run it until it stops complaining about dependencies ( in the console ), after that ( and perhaps even before ) the GUI should come up.  You are installed.
+
Run it ( smart_clipboard.com ) until it stops complaining about dependencies ( in the console ), after that ( and perhaps even before ) the GUI should come up.  You are installed.
  
I have run the program on both Windows 10 and Rasperian on a RPi.  It should work in most OS's.  Let me know about issues.
+
I have run the program on both Windows 10 but not Linux or Rasperian on a RPi.  It should may in most OS's, this depends on how well pyclip a library I use works on these OS.  Let me know about issues.
  
Some parts of the program think that mySql is available.  It should run fine without it ( there will be a message or two in the console ), untill you try to use the database then it is not so gracious.  Straight ahead use as a terminal does not use the database.
+
I may list dependencies, one almost for sure is pyperclip.
  
 
= Configure to Run =
 
= Configure to Run =
Line 149: Line 157:
 
== Basic ==
 
== Basic ==
  
Basic configuration of comm parameters like port, baud rate .... is all done in a file called parameters.py.  It seemed easier to simply use a Python text file instead of some other format like an ini file.  Pretty much all the file does is set instance variables in itself.  It is used by the program controller ( smart_terminal.SmartTerminal ) to create an instance of Parameters and then the values can be used.  Save the original ( parameters.py, maybe I will include a backup maybe not ) in case you mess it up too much.
+
Basic configuration is all done in a file called parameters.py.  It seemed easier to simply use a Python text file instead of some other format like an ini file.  Pretty much all the file does is set instance variables in itself.  It is used by the program controller ( clip_board.App ) to create an instance of Parameters and then the values can be used.  Save the original ( parameters.py, maybe I will include a backup maybe not ) in case you mess it up too much.
  
 
I have made yet another pass to clean up and comment the code in parameters.  Let me know if you have issues.  You should understand some values are being phased out but may still have some implementation and some may be coming in and have little or no implementation.  The comments should let you identify these situations.
 
I have made yet another pass to clean up and comment the code in parameters.  Let me know if you have issues.  You should understand some values are being phased out but may still have some implementation and some may be coming in and have little or no implementation.  The comments should let you identify these situations.
Line 157: Line 165:
 
All the com port values are defined in pretty much one place, find it ( say search on "baud" ) an change it to what you need.
 
All the com port values are defined in pretty much one place, find it ( say search on "baud" ) an change it to what you need.
  
== Command Line Arguments ==
+
[[Clipboard Configuration]]
 
 
If you run with the command line parameters=paramaters_b then after the regular parameters file runs, then the system looks for parameters_b.py and uses that to override values that you might want to tweak ( or completely redo.  There are two examples in the directory follow the pattern in them and you should be fine ).
 
 
 
This can be especially useful if you want to run two copies connected to different ports and possibly running in different modes.  In this case it is also nice to change ( its in parameters ) the '''icon''' and '''color''' for each instance of the program.  You can write or use the little bat file to start them ( although this leaves a dos console hanging around )  Command line arguments can also be placed in shortcuts.  In either case they may take some tweaking to run in/from your file locations.
 
 
 
The above mostly applies to Windows, but the program run fine with Linux ( including the Raspberry Pi ) and I suppose the Mac.  Of course the .bat file and shortcuts will not work, but similar facilities exist in the other OSs.
 
  
 
== Running It ==
 
== Running It ==
  
When you run it it should open a windows a lot like the picture [[Smart Terminal GUI]].  Errors may show up in your Python console or the log file ( look in parameters.py for the name of the log file, typically self.pylogging_fn      = "smart_terminal.py_log" ).  The most likely errors will point to missing Python modules like pyserial.  You should install with pip ( or conda if using Spyder ).  Let me know how it goes.
+
When you run it it should open a windows a lot like the picture [[ClipBoard GUI].  Errors may show up in your Python console or the log file ( look in parameters.py for the name of the log file, typically self.pylogging_fn      = "smart_terminal.py_log" ).  The most likely errors will point to missing Python modules like pyperclip.  You should install with pip ( or conda if using Spyder ).  Let me know how it goes.
  
Normally the terminal does not open the com port until you press the <Open> button.  The parameters are displayed in the GUI if you do not like them ( for example when you press the <open> button the port open status changes to "open failed", not the desired "open" ) you can shutdown, edit parameters.py and restart.  There is a simpler way.
+
Setting up for your system editor:
  
 
*First configure parameters.py to know the name of a text editor on your system. For mine this is one of:  
 
*First configure parameters.py to know the name of a text editor on your system. For mine this is one of:  
Line 187: Line 189:
  
  
..... more here soon ......
+
..... more here soon perhaps ......
 +
 
 +
 
 +
 
 +
== Debugging ==
 +
 
 +
There are several application outputs that may be useful for debugging.
 +
 
 +
* Watch the GUI
 +
* Check the Python console.
 +
* Look at the python log file ( use the GUI button <Edit Log> ( specify your editor in parameters.py first ) or use your editor on the default name of the log file, by default: clipboard.py_log.
 +
 
 +
Most issues will probably be missing libraries, parameters.py issues, or just bugs in my code (email me ).
  
 
= Notes on the Code =
 
= Notes on the Code =
  
In some ways I am proud of the code, it was sometimes a slog, and I had to learn a lot of Python to get it going. On the other hand it kind of sucks, it has lots of dead code, ass backwards was of doing things, poor naming...... There is also a good bit of code on features that I am adding, but that is unfinished.  Until I loose interest in it it will probably improve.  However, adding features is more part of the life of a programmer than polishing old features; making something better that seems good enough is not always the priority it should be.  If you do not like it, mostly keep it to yourself unless it is accompanied by an offer to improve it.  I do not need ideas, I need time.  That said if you think you have a helpful comment contact me, my page will tell you how: [[User:Russ_hensel]]
+
Code quality is uneven some dates back a long time ago, some has ideas I tried, but now do not like. There is too much dead code, ass backwards was of doing things, poor naming...... There is also a good bit of code on features that I am adding, but that is unfinished.  Until I loose interest in it it will probably improve.  However, adding features is more part of the life of a programmer than polishing old features; making something better that seems good enough is not always the priority it should be.  If you do not like it, mostly keep it to yourself unless it is accompanied by an offer to improve it.  I do not need ideas, I need time.  That said if you think you have a helpful comment contact me, my page will tell you how: [[User:Russ_hensel]]
  
 
= Design =
 
= Design =
Line 197: Line 211:
 
Description of the design, and a bit to help you figure out what the files do ( for .py files also see the top of file ).
 
Description of the design, and a bit to help you figure out what the files do ( for .py files also see the top of file ).
  
see: [[Python Smart Terminal Technical]]
+
see:  
 +
*[[Python Clipboard Design]]
 +
*[[Python Desk Top Applications]]
  
 
= Customizing/Extending =
 
= Customizing/Extending =
Line 207: Line 223:
 
*Click on the category '''ClipBoard''' below ( and perhaps the others as well )
 
*Click on the category '''ClipBoard''' below ( and perhaps the others as well )
 
   
 
   
*[[Writing You Own Extensions to ClipBoard]]
 
 
   
 
   
 
*[[ClipBoard GUI]]   
 
*[[ClipBoard GUI]]   
 +
*[[ClipBoard Help File]]
 
*[[Python Desk Top Applications]]     
 
*[[Python Desk Top Applications]]     
 
   
 
   

Revision as of 14:11, 20 March 2020


Goal/Purpose

This Python program (clip_board.py) is an application to enhance the windows ( unix ?? ) clipboard by adding the ability to it to:

  • Transform keyboard contents, referred to as "Transforms".
  • Insert predefined elements into the clipboard, referred to as "Snippets".
  • Open example files in a configerable editor or ide, referred to as "Snips". -- This really does not involve the clipboard, but is a sort of high powered version of snippets
  • Interpret copied text as commands or directions to the system to carry out some action specified in the clipboard contents, for example, browse to some website.
  • The program is easily modified by adding transforms, snips, or snippets, this may require some python programming.


  • The program does not have a clipboard history as I, so far, have not found that useful. There are a lot of other apps with this feature.


For a quick overview on use once installed see the GUI documentation at: ClipBoard GUI That page will also link to the 4 areas of operation:


Status

This program is up and running most of the functions seem to work well, major problem is that I keep adding details to the functionality, I use the program partly as an opportunity to explore Python. Making improvements from time to time for my projects. Code at GitHub, see [Code at GitHub] I think the major problem with the code is that I am still making a fairly large number of changes/enhancements. As a result I am breaking things. New versions are uploaded at various milestones, they are not carefully checked. Email me if there are problems. [Russ Hensel]

Code

Code at GitHub, see [Code at GitHub]

This is an article started by Russ Hensel, see "http://www.opencircuits.com/index.php?title=Russ_hensel#About My Articles" About My Articles for a bit of info.

Who should use this program and How:

Who What How
Person with little programming experience, no interest in Python. Looking for download and install. Probably should use another program. Not well suited to use this, I do not plan to fix this.
Likely a programmer or other user who frequently needs to transform text or insert standard snippets in text. Run the basic program. Customize in fairly minor ways. Edit the parameter file to configure the program.
Modest Python experience, same needs as above. Modify all over the place, add/delete functionality. Program should be well documented with an API, sample extensions. Code changes localized ( now ) to one class plus the parameter file.

What/Why

As a programmer and general computer hacker I often need to make simple but time consuming changes to text or recall easily forgotten text, a couple of examples:

  • In a wiki you can hide text with a bit of special markup: it uses < and > and --- and ! I often forget exactly

what it looks like, and in any case it is a pain to type. If I click on "wiki hidden" in the clipboard app then the text is put in the clipboard and I can paste in the wiki.

 <!-----------
 this cannot bee seen
 ------------->
  • In a similar way a wiki has a big messy way of setting up a table. "wiki table" puts a whole example in my clipboard for pasting.
  • Many programmers like file names without spaces. A transformation function in the clipboard will take the text in the clipboard, remove the spaces and put it back in the clipboard.
  • Some tasks like opening text files or url can be made easy from text you store, for this a prefix is used. To open a text file copy from a place you have stored it:
   *>text  some_file.txt

Then pressing the <*cmd> button will open the file in your chosen text editor. In a similar way;

   *>url  http://www.opencircuits.com/Main_Page

Will open the main page of Open Circuits in your chosen browser.


What are some other features?

  • Free open source
  • Runs across OSs Linux ( inc Raspberry Pi ), Mac or Windows
  • Python
  • Parameter file for wide range of modifications of program behavior.
  • Uses standard Python logging class.

What would you like to see in the program or documentation? Email me.

Installation

This program is intended for those who at least occasionally develop in Python. I expect that they already run some things in Python and will just add this as an additional project. There is no install program you just download the files, place where you keep your projects and run. A bit more later in this section.

My Environment/Your Environment

The program has a better chance of running if your environment is not too much different from mine. The most important is that it is Python 3.6 or higher

Before you begin to install you should know a bit about the environment that I have used to build, test and run the terminal. If your environment differs too much you may have trouble getting it to run.

I run Python mostly using the install that comes with Anaconda Spyder and often use the IDE it installs. This is not necessary, it is just an nice install that downloads a lot of stuff that technical folks find useful. I have use conda and pip to add to this install and do not know offhand all that is in it. You can look at the include statements to get some idea of what you might need to add. Or you can just keep running it and add the packages it complains about.

Download

Code at GitHub, see [Code at GitHub] ( it is Python and you can run directly from the source ) Email me if you have issues ( use this link User:Russ_hensel ). You will get a zip file, unzip it and you should get:

     .... whatever --|
                     |
                     |-- clipboard    -----> all code required to run the application ( not sure if smart_terminal or python_smart_terminal or nothing is top level name, just put it in some well named place )
                                          
                                        | -- images -> image files, mostly screen shots, icons... or what ever, not important for the code.
                                           
                                        | -- wiki_etc -> various files documenting program, including at least some of the material from this wiki 

                                        | -- example_snips -> files used as snip ( not snippet ) examples. ( You can relocate in your setup but this makes the downloaded app in the new_user_mode work. )

                                        | -- snipsand -> files containg links to the smip files and the snippet files.  ( You can relocate in your setup but this makes the downloaded app in the new_user_mode work. )

Put them in your system making "....whatever" anything convenient for your Python ( that is move the files to where you keep your Python source ).

Note that there may be a certain amount of left over, dead code, in the directory I am cleaning out bit by bit, someday it may be nice and neat. For now if you want to tinker look at the design info below first.

Run

Run it ( smart_clipboard.com ) until it stops complaining about dependencies ( in the console ), after that ( and perhaps even before ) the GUI should come up. You are installed.

I have run the program on both Windows 10 but not Linux or Rasperian on a RPi. It should may in most OS's, this depends on how well pyclip a library I use works on these OS. Let me know about issues.

I may list dependencies, one almost for sure is pyperclip.

Configure to Run

Basic

Basic configuration is all done in a file called parameters.py. It seemed easier to simply use a Python text file instead of some other format like an ini file. Pretty much all the file does is set instance variables in itself. It is used by the program controller ( clip_board.App ) to create an instance of Parameters and then the values can be used. Save the original ( parameters.py, maybe I will include a backup maybe not ) in case you mess it up too much.

I have made yet another pass to clean up and comment the code in parameters. Let me know if you have issues. You should understand some values are being phased out but may still have some implementation and some may be coming in and have little or no implementation. The comments should let you identify these situations.

Parameters starts out with some "meta" parameters. These are defined early in the creation of the objects and may effect other values. In any case you can always define a value twice, the last one always wins. The most important meta parameter is mode, you should not change it from self.mode = "Terminal" unless you understand the implications or do not mind going on a ride.

All the com port values are defined in pretty much one place, find it ( say search on "baud" ) an change it to what you need.

Clipboard Configuration

Running It

When you run it it should open a windows a lot like the picture [[ClipBoard GUI]. Errors may show up in your Python console or the log file ( look in parameters.py for the name of the log file, typically self.pylogging_fn = "smart_terminal.py_log" ). The most likely errors will point to missing Python modules like pyperclip. You should install with pip ( or conda if using Spyder ). Let me know how it goes.

Setting up for your system editor:

  • First configure parameters.py to know the name of a text editor on your system. For mine this is one of:

self.ex_editor   =  r"leafpad"    # linux and pi

self.ex_editor   =  r"D:\apps\Notepad++\notepad++.exe" # for windows.  

It is set up to auto switch between the two os to make copying the whole program back and forth between the windows and linux a bit easier.

  • Now when you run it the button <Edit Parms> should let you edit the parameters.py file. Edit it and save.
  • Hit the <Restart> button. In a flash the program should restart with the new parameters.


..... more here soon perhaps ......


Debugging

There are several application outputs that may be useful for debugging.

  • Watch the GUI
  • Check the Python console.
  • Look at the python log file ( use the GUI button <Edit Log> ( specify your editor in parameters.py first ) or use your editor on the default name of the log file, by default: clipboard.py_log.

Most issues will probably be missing libraries, parameters.py issues, or just bugs in my code (email me ).

Notes on the Code

Code quality is uneven some dates back a long time ago, some has ideas I tried, but now do not like. There is too much dead code, ass backwards was of doing things, poor naming...... There is also a good bit of code on features that I am adding, but that is unfinished. Until I loose interest in it it will probably improve. However, adding features is more part of the life of a programmer than polishing old features; making something better that seems good enough is not always the priority it should be. If you do not like it, mostly keep it to yourself unless it is accompanied by an offer to improve it. I do not need ideas, I need time. That said if you think you have a helpful comment contact me, my page will tell you how: User:Russ_hensel

Design

Description of the design, and a bit to help you figure out what the files do ( for .py files also see the top of file ).

see:

Customizing/Extending

Simple customization may be done simply by changing the parameter file, see: Smart Terminal Parameter Examples If you want to add code that can be done by messing with any of the source code ( not recommended ) or by programming an extension, see: Python Smart Terminal Technical and Writing You Own Extensions to SmartTerminal

Additional Info

  • Click on the category ClipBoard below ( and perhaps the others as well )