I've created a Rich Edit control (1.0) from MFC as below:
m_hRichEditWnd = ::CreateWindow(_T("RichEdit"), csWindowName, ES_MULTILINE|ES_READONLY, 0, 0, 200, 200, NULL, 0, 0, 0);
I've read text into that control from a file. The file is a multipage .txt document with ascii control characters for page breaks. When I print from the Rich Edit control, I do not get the page breaks. They are printed out as characters. Is there any way to get those page breaks?
I'm printing out from the control using methods similar to those described here http://msdn.microsoft.com/en-us/library/windows/desktop/bb787875(v=vs.85).aspx
So something I left out was that I wasn't actually printing out to a physical printer but to a .ps file. That .ps file was then getting converted by ghost script to a pdf which did not register the page breaks. I believe this is due to the fact that the edit control does not actually SHOW page breaks inside it - and the way the print command works is almost like a graphic blit to a print device. The page break isn't "on screen" so it doesn't make it to the .ps file. That's a theory.
The only solution I found was to parse the information going into the CRichEditControl for form feed characters. Load up all characters up to the form feed character, print that to the file, then use the EndPage() function to manually force the form feed. Continue on in that way until there are not more form feed characters. Then make sure you print out any remaining characters after the last form feed.
Related
I have an issue with getting the contents of a tkinter text box. If I paste information into it from Excel (for example), it always adds an empty line at the bottom. I would like to remove that line automatically. This is what I use to get the contents:
contents = inputText.get(1.0, "end-1c")
for line in contents.split("\n"):
line = line.strip()
I initially added a '[:-1]' on the end of that, which works, but only on text that is pasted into the text box. If you type text in manually, then obviously there's no trailing '\n' on the end, so it ends up removing the last character that was typed. Not good!
How can I get it to remove (or ignore) the trailing empty lines? The 'line = line.strip()' in the code further down seems to have no effect.
Thanks, Chris.
Your problem isn't with getting the text, your problem is that pasting seems to add more than you expect. To get text, regardless of how it ended up in the widget, you should use .get("1.0", "end-1c"). There is simply no way to know at the time you are getting the contents of the widget if any extra newlines came from the user directly or from a paste operation. To tkinter, text is text no matter how it was entered.
The only solution is to adjust the paste binding, and even that is problematic because I don't think tkinter has any way of knowing if the clipboard contents are from excel, or from some other source.
If all you really want is to ignore all trailing blank lines, call strip() on the data before calling split("\n")
Textbox was always inserts a blank line at the end. The problem was compounded when editing textbox and yet another blank line was inserted. However during edit you could remove blank lines so you can't use "end-1c" all the time.
The trick was to remove 1 or more extra blank lines after editing:
# Rebuild lyrics from textbox
self.work_lyrics_score = \
self.lyrics_score_box.get('1.0', tk.END)
while self.work_lyrics_score.endswith('\n\n'):
# Drop last blank line which textbox automatically inserts.
# User may have manually deleted during edit so don't always assume
self.work_lyrics_score = self.work_lyrics_score[:-1]
Note however this is with Linux. For Windows you might need something like:
while self.work_lyrics_score.endswith('\n\r\n\r'):
# Drop last blank line which textbox automatically inserts.
# User may have manually deleted during edit so don't always assume
self.work_lyrics_score = self.work_lyrics_score[:-2]
Or whatever the the control code is for DOS/Windows LF/CR (Line Feed / Carriage Return) typewriter days style is.
This is maybe a weird request but hear me out:
I have a huge database at my shop containing product codes, like 87 445 G 6 which I need to check for availability on a supplier's website. The problem is, the supplier's website consists of a web form in which I have to enter the code without spaces, so imagine that I have to manually delete spaces every time I paste a code or write it manually without.
I can't edit the database from which I copy the codes.
I wonder if some sort of plugin, script, or trick can be used directly in browser on the supplier's web form, or some software to modify how the windows clipboard works, maybe some option to copy text without spaces. Using Windows XP.
The OP has probably moved on, but for anyone else looking here, my approach was to tackle this from the windows clipboard side.
For background: I keep a list of my credit card info in Keepass. Sometimes (poorly coded) shopping cart checkout forms don't like spaces in between card numbers. I like storing them with spaces since it's easier to read off that way.
There's various Windows clipboard utilites out there, but it took me a while to find one that could do some processing on the clipboard contents and pasting it out - Clipboard Help and Spell
The program has a way to "save" a bunch of text transformations, and even assign the action to a hotkey.
For reference, my "Find and Replace" action is to find "\s" (without quotes) and leave the Replace textbox empty. "\s" will match whitespace character.
Use the javascript console
You could use the javascript console for your browser to edit the textarea after you paste.
Using Google Chrome (or Firefox)
Paste your text in the text area.
Right click the text area and click Inspect Element
Look at the id for the element
Now switch to the console view
then run these lines (making sure to replace with 'the-id' with your id)
var my_text_area = document.getElementById('the-id'); // Put your id in here
my_text_area.value = my_text_area.value.replace(/ /g,"") // Deletes just spaces
It's even simpler if you have access to jQuery:
$('#the-id').val($('#the-id').val().replace(/ /g, ""))
The replace function is simply using regular expressions to convert spaces to nothing. If you want to replace all whitespace (including newlines) you would use .replace(/\s/g,"").
For firefox, the names are the same but the UI is a little bit different.
Use greasemonkey
You can either write a greasemonkey plugin or try to find one that fits your needs.
We have a text box which is in fact an instance of the standard native Windows edit control used to enter text. The control was created using CreateWindowsEx without the ES_AUTOHSCROLL flag specified. It implies that word wrapping for entered text is used automatically.
Our goal is to fix the control's width and increase the height of the control automatically as the number of text lines is increased to show all them. An example: by default, the text box is empty. The user starts typing, and as soon as the end of the first line is reached, the text box automatically increases its height by one text line so the last word is put into the beginning of the second line due to word wrap.
How to gain this? Our development environment is VB6, but any WinAPI-based code is also welcome.
I am trying to set up a (USB) Motorola Symbol DS6708 barcode scanner to scan QR code encoded with some contact information onto a text file.
When scanning in a barcode, the expected text is displayed on in the text file. When it is finished reading it in all the text is selected and deleted.
If it hit ctr+z, the text is undeleted and displayed in the file.
The desired result is in this format:
Name
Title
Company
Phone
ect
I'm not really sure where to start with debugging this. I am assuming that there is some characters being read in at the end that doing the equivalent of ctrl+a and delete.
EDIT
I tried scanning using the 123Scan2 from Motorolo, and this was the result:
<STX> <STX> <STX>318315647 <ETX> <LF>NAME<ETX> <ETX>LNAME<ETX> <LF>TITLE <ETX>
<LF>COMPANY <ETX>
<LF>ADDRESS <ETX> <LF>ADDRESS <ETX> <LF>CITY<ETX>, <ETX>ST<ETX> <ETX>12345<ETX> <LF>USA <ETX>
<LF>PHONE <ETX> <LF>PHONE <ETX>
<LF>EMAIL <ETX> <LF> <LF> <LF> <LF> <LF> <SUB> <CR>
EDIT
I attempted to set console application with C# and read in the input with Console.Read() or Console.ReadLine(), but the input actually caused the application to stop running, and then the input text was written into the text of the Program.cs file on Visual Studio.
The simple console app:
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Debug.WriteLine("start");
int result;
while ((result = Console.Read()) != 0)
{
Console.WriteLine("{0} = {1}", result, (char)result);
}
}
}
I'm not really sure where to start with debugging this. I am assuming
that there is some characters being read in at the end that doing the
equivalent of ctrl+a and delete.
I attempted to set console application with C# and read in the input
with Console.Read() or Console.ReadLine(), but the input actually
caused the application to stop running, and then the input text was
written into the text of the class on Visual Studio.
I would bet that the data contain an EOF char (Ctrl+Z). All text devices (like console I/O) use this as an end signal, and it is still supported in modern OSes, although little known these days. And of course it is documented.
When it is finished reading it in all the text is selected and
deleted. If it hit ctr+z, the text is undeleted and displayed in the
file.
You probably want to say, that the text is shown in the editor, and selected/deleted from the editor. A file can't hardly display anything on it's own, it just contains something. By the way, the fact that EOF is Ctrl+Z and your editor's undo is also Ctrl+Z is pure coincidence.
As you don't show any code, it's hard to say anything about it. I'd probably do a Read() loop and store everything useful I get in a suitable place, for example in a file :-) This data are then to be processed in a second step.
PS: This related question may also be helpful.
I haven't played with barcode scanners for a while but this sounds to me that either the barcode you are scanning contains the control codes to do Ctrl-A and Del or that the scanner is programmed in that way.
To the host PC a barcode scanner basically appears like a keyboard. If you can type it, the barcode scanner can deliver it, including all Ctrl / Shift / Alt shortcuts.
If you have the scanner from new you should have a sheet of barcodes that allow you to program it up and affect its behavior. Have a look for a full reset barcode and see if that improves things.
You might want to try their sdk downloaded here. tell me if it still deletes the file in the textbox of the form.
If it isn't deleted, it might be better to add an export to a text file button.
Dim ProcessProperties As New ProcessStartInfo()
ProcessProperties.FileName = "notepad.exe"
ProcessProperties.Arguments = "/p c:/doc.txt" 'command line arguments ''
''ProcessProperties.WindowStyle = ProcessWindowStyle.Maximized
Dim myProcess As Process = Process.Start(ProcessProperties)
when printing using the code above i have "doc.txt" printed. I don't want the file name to appear when printing is over
It is not possible to pass an argument through command line to notepad to hide the header, the only parameter accepted for the /P argument is the file name. (See link)
The only way to hide the header from printing is by opening notepad and going to File->Page Setup, and changing the header command. (See link)
If it is really needed to print using a process, you can try searching for third party editing tools which support printing arguments.
Another way is to implement functionality for printing the text file, see this Stackoverflow article (Link)
You will have to configure the header and footer options of Notepad in order to prevent or override the file name appearing on the print page. This can be done by simulating user input to bring up the Page Setup dialog and clear the header and footer.
There are a number of ways to send user input (mouse and/or keyboard). For starters you could look at these two:
Windows Input Simulator
Application and Global Mouse and Keyboard Hooks .Net Libary in C#