Have created a Gtk "calculator" that has a spreadsheet-like element (similar to and partially based on GtkSheet/GtkExtra). It is capable of, amongst other things, using the usual Ctrl-X/C and Ctrl-V to Cut/Copy/Paste data/strings within itself, and also across to other apps, such as Excel/OpenOffice etc (i.e. in both directions) using GtkClipboard elements.
For example, it can also perform Cut/Copy/Past of ranges (though via a different route, and this in not in Python) discussed in this SO posting.
However, when an Excel, OpenOffice, etc cell contains a formula (and displays the formula's value ... eg. formula in cell =1+2, displays 3), copying the Cell into the proprietary Gtk-Spreadsheet via GtkClipboard only pastes/contains the "display value" (not the formula).
How does one get GtkClipboard to pass the formula instead? Does this require some GDKAtom specification, is it necessary to use gtk_clipboard_request_text() vs. _request_content() etc. and work through the "(Gtk) target", or ???
P.S. Copying, say, an Excel cell (with formula) to, say, an OpenOffice cell works correctly in that OO will contain the formula and display the result (though we cannot be certain if the formula is contained in the OS's clipboard, or if OO et al. are doing something extra). Is it presumptuous to imagine that GtkClipboard should be able to do it as well ... ?
UPDATE: Since the Original Post (OP), we have followed-up with some testing to further assess our "intuition" that perhaps the GtkClipboard or the Windows clipboard, or some combination therein, may not be capable of directly passing spreadsheet formulas (or "full" Cell contents) via Cut/Copy/Paste (CCP). Here are some results:
1) We tried to look at the OO, POI, etc source code to see how they do it, but it's much too big. We tried to look at GNumerics source code, but from our perspective, it uses a coding style that is much too difficult (at least for us) to follow.
2) So, we performed a few additional test to see if we could determine at least the possibility of relying on the OS/GtkClipboard. During these tests we also "kept an eye" on the Windows clipboard via clipbrd.exe (the Windows clipboard viewer (WCV)):
a) As before, when CCP from Excel to OO (and both apps are simultaneous running), everything is passed.
Though, WCV only shows the display value, not the formula or any other property of the cell (e.g. colours, etc)[Note: WCV can pass some colours etc if an image format is used, but not the explicit Cell "contents/formulas/properties" etc]. This is a bit worrying for Gtk, as it implies the passing of the formula etc is not actually via the (basic OS) clipboard.
b) When CCP in reverse, from OO to Excel (with both apps running), it does NOT work, only the display value is passed (no formula's, properties, etc).
Again, a bit worrying with respect to (wrt) GtkClipboard possibilities.
c) When the Copy is performed from Excel, but before OO is launched, and then Excel is closed, and the Paste after OO launched, it does NOT work for formula's etc, only the display value.
Again, a bit worrying wrt GtkClipboard possibilities.
d) Skipping some details to avoid diluting this point, our sense is that the (only) "successful" CCP (from Excel to OO while both are running) is somehow performed with some combination of OO accessing the OfficeClipoard (c.f. the Win clipboard, which Gtk has access to) and/or using some ODBC/OLE or whatever direct internal connection to Excel to effect the passing of the full Cell contents. That the CCP does not work in reverse (i.e. OO -> Excel), or only when both are running, also supports this contention.
Although these tests/results do not in themselves decisively prove that the OS/GtkClipboard is not actually usable for CCP of "full" Cell/Range contents, they are highly suggestive of that. However, for all we know, there may be some GtkClipboard (GdkAtom etc) settings that might permit access to other (e.g. Office) clipboards, but we can't find any info on this.
Similarly, it would be useful to know if anybody has succeeded in CCP'ing these sort of things in a Unix/Linux environment with Gtk (we are testing via a couple different MingW setups on Win, but the Win and Office clipboards seem to have some difference under Gtk compared to under Linux).
... as such, we would be grateful to anybody with actual knowledge on the subject at least to confirm whether or not the Win/GtkClipboard strategy is a waste of time, and if not, any hints for implementation would be much appreciated.
OK, sussed it, found (an) answer to our own question:
It is possible to CCP Cells/Ranges from Excel to a GTK entity via GtkClipoard.
... having said so, the Gtk side documentation is almost non-existent, and essentially requires a huge amount of trial and error.
... to confuse matters exponentially, the documentation/discussions regarding the Win OS clipboard, and the actual mechanism Excel uses (which is actually via attaching items to the OS clipboard via various machinations of the OfficeClipboard, OLEClipboard, iDatatObjects, etc.) is, indeed, overwhelmingly documented and creates a hugely expensive distraction.
The entire key to the matter does lie in the Gtk/Gdk "Atoms", "Targets" etc. as speculated/enquired in the OP.
One solution (with CAVEATS):
1) Use either gtk_clipboard_request_targets() or gtk_clipboard_request_contents() to obtain a list of the "Targets" that the "owner" of CCP'd material on the clipboard can support (i.e. convert into). gtk_clipboard_request_contents() can do this is it is given gdk_atom_intern("TARGETS") as its "target".
This process can be used to produce the list of targets from which to choose to convert into. For example, in a test case copying an Excel Cell with a formula, colours, grid etc, the "available targets" lists that the "owner" (e.g. Excel) will support was:
"DataObject"
"Biff8"
"Biff5"
"Biff4"
"Biff3"
"Biff"
"Wk1"
"XML Spreadsheet"
"HTML Format"
"UTF8_STRING"
"Csv"
"Rich Text Format"
"Embed Source"
"Native"
"OwnerLink"
"Object Descriptor"
"Link Source"
"Link Source Descriptor"
"Link"
"ObjectLink"
"Ole Private Data"
"image/bmp"
CAVEAT: we tested a number of these "targets" for conversion inside Gtk following CCP from Excel, but some of them produced "empty/faulty" 'GtkSelectionData'.
Some worked to various extents, depending on what "you" actually want. For example, the Target "UTF8_STRING" brought just the "display text/value" (e.g. of the Excel-side formula was "=1+2", which displayed as "3", then this Target provides Gtk with "3".
To demonstrate that the "full splendour" of the Cell "object" can be brought into Gtk, the Target "XML Spreadsheet" was used to CCP a Cell with formula, colours, etc from Excel, into Gtk, and inside Gtk it produced a variable (Data_Alloc) with the "value" of:
GtkClipboardContntReceivedFuncX Data_Alloc = <?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s25">
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
<Font ss:FontName="Bauhaus 93" x:Family="Decorative" ss:Size="12"/>
<Interior ss:Color="#CCFFFF" ss:Pattern="Solid"/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1">
<Row ss:Height="18.75">
<Cell ss:StyleID="s25" ss:Formula="=1+2"><Data ss:Type="Number">3</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
<< GtkClipboardContntReceivedFuncX - Exit
Clearly, all the crucial information was passed into Gtk, and then its just a matter of parsing the "data" to whatever is required in the Gtk app. For example, to CCP the Excel formula to Gtk (instead of the "value"), just parse the 6th line from the bottom where it has Formula = "=1+2"
... whoo hoo :)
Unfortunately, the "XML Spreadsheet" may not be sufficiently robust for all cases (e.g. it seems to have difficulty CPP'ing anything with Cell references e.g. "= 1+B1" gives it trouble (see ** note below), and which may be Gtk version, Excel version, etc issues). So one or another of the other "targets" may be required, and some of which are rather complex (e.g. any of the BIFF's).
** Note: Some of the Targets/conversion actually create an entire spreadsheet based on the Cell/Range that was CCP'd. Thus, in the case of sending a single Cell with a formula, and using the "XML Spreadsheet" Target/conversion in Gtk, the "result" is an "entire single cell spreadsheet" (as can be seen in the XML example above). Since many of these conversions convert "A1" style cell referencing to "(relative) RC" referencing, any dependencies that lie "outside" of the Range/Cell that was CCP'd and converted into an "entire clipboard (XML) spreadsheet" would not include the "outside cells", and then the RC referencing is referencing "nothing", so it cannot convert the formula correctly/at all.
... again, there is much going on here, and much depends on OS, Excel, Gtk etc versions and protocols.
So I have some formatting rule to follow, such as :
Space on each side of operator (*, =, +, %, etc)
No space at the end of a line
No more than 80 chars per line
Is there a way to highlight in red line containing formating error?
The eclipse auto-formating tool is no good because either :
It will change to many line (old code not written by me)
or it won't (only my code)
Because I must follow some "colorfull" guideline :
You must change formating error relative to operators in old code but nothing else
Your code must be correctly formated.
Any ideas?
Thanks
You can select which lines of code you want to format. The Eclipse formatting tool doesn't have to run across the entire file. To do this: select the lines you want to format, then press Ctrl-Shift-F.
You could try using the Eclipse Checkstyle Plugin.
You'll need to configure it with just the rules that you need (the default configuration is very strict, so create a new one with just the rules you care about).
This will highlight all lines with formatting issues. I don't think it's possible to ignore old code using the plugin.
Talk to whoever created that coding guideline. It does not make sense in the long run, because editing code in Eclipse will always apply all current formatting rules (which violates that guideline) or none, if you disable the formatter (which leads to you writing bad code).
If there is really no way around that guideline, then you should split your workflow into 2 phases: Reformat all existing code one time to fulfill that operator guideline. You may use any tool you like, even just a regular expression search and replace might be fine.
After that has been done, configure Eclipse to auto-format only changed lines, but always apply all formattings to each changed line. There is no good reason to not re-format the other 75 characters in an existing line of code, if you already touched 5 characters of it.
I've got an app config file that contains two types of templated variables. The first set will be populated at build time by some powershell scripts. The second remain within the config file but are used at runtime.
So, under source control, the file might look like:
<property name="$($settings.elementName)" value="${valueThatIsSubstitutedAtRuntime}" />
After a build I'd like it to be:
<property name="settingFromPosh" value="${valueThatIsSubstitutedAtRuntime}" />
But unfortunately it's coming out as
<property name="settingFromPosh" value="" />
I'm using the a slightly modified version of the templating method described in Powershell for Developers. Basically, I'm using populating a ScriptBlock with the variables to substitute, reading the template and calling Invoke-Expression with the template content. The script it successfully substituting values it can find but also wiping out any it can't.
I'm reluctant to use regex token replacements because I want the full power of ps within the template. Also, I prefer not to introduce different variable tokens for the values I don't want populated during the build.
Is there a way to leave variables in place that can't be substituted or perhaps escape them so they're ignore?
Put your string in single-quotes so that PowerShell doesn't try to expand any variables in it e.g.:
<property name="$($settings.elementName)" value='${valueThatIsSubstitutedAtRuntime}' />
Then you can use $ExecutionContext.InvokeCommand.ExpandString(...) to expand the string at runtime e.g.:
$foo = 'bar'
$str = '$foo'
$ExecutionContext.InvokeCommand.ExpandString($str)
Are you sure this:
"${valueThatIsSubstitutedAtRuntime}"
shouldn't be:
&{valueThatIsSubstitutedAtRuntime}
That first one is the syntax for a braced variable. I think it's looking for a variable named "whatever is between the braces" (and not finding it, so it returns a null string). If it's a script block, I'd think you'd want to invoke it.
I use this to set my maximum line width to 80:
org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.lineSplit=80
Let's face it, Eclipse's formatter is not strict.
It has a very high success rate, and format things very nicely indeed, but it is not 100% strict, sometimes it leaves lines > 80 characters and so it is useless for a project that just lints and refuses code not strictly matching the 80 columns limit and requires Eclipse code auto-formatting.
These 2 things, Eclipse-based formatting and lint, can only really work together when the success rate is 100%. If not, even changing the code by hand triggers a "reformat/reflow" on save and the check-in bombs and refuses the commit.
I cannot disable the formatting on the client and I cannot circumvent the linting.
Is there any way at all to just make the wonderful Eclipse formatter 100% strict? Something like "considerTheLimitSeriously=true"?
Notice: it's eminently "unstrict" in lines with method signatures, but not only.
Sorry, there's no way to make the formatter 100% strict when it comes to line splitting. According to JLS 3.8. Identifiers:
An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.
So it's possible that some lines cannot be split without causing a compile error.
The best you can do is set the formatting as strict as possible, then look at specific lines in your code to see where this is failing. On the Eclipse main menu go to Window > Preferences, then go to the Java > Code Style > Formatter tab, then click Edit. There you'll find a Line Wrapping tab where you can customize the line wrapping rules.
Usually I pipe my log through a lot of greps to remove the "noise" before i open it in an editor.
I think it should be possible to do this filtering inside an editor (Especially Emacs)
Is this what chainsaw is doing? For log4j format only or more general?
(It is the only logfile viewer tool I can find)
How do you guys do it?
(I think UNIX grep syntax would be easiest for me)
Chainsaw does support both positive and negative filter matching. You can define positive and negative matches based on the logger tree (right click on nodes for the options), and you can define positive-match expressions in the 'refine focus' field, and negative-match expressions using the 'ignore' option below the logger tree. There is a tutorial available from the help menu which describes the expression syntax.
Chainsaw has had a lot of new features added since the last official release. The developer snapshot (including a reworked configuration screen) is available here:
http://people.apache.org/~sdeboy
Chainsaw doesn't just work with log4j. There are 'receivers' available that make it work with log4net, java.util.logging, log4php and others.
You can also process any regularly formatted text file using a VFSLogFilePatternReceiver (use the 'process a log file' option to configure Chainsaw to define one). There are some pre-defined log formats in the configuration dialog that act as example formats - tweak one to match your format. The JavaDoc provides more information: http://logging.apache.org/chainsaw/apidocs/org/apache/log4j/chainsaw/vfs/VFSLogFilePatternReceiver.html
If the greps are the same, you can simply code a script to do all that work for you (e.g. vimscript for vi). That way, you don't have to repeat all the tasks while leaving the logs intact for further investigation.
You're right on chainsaw and log4j - it's a logging viewer with different capabilities, e.g. a filter mechanism. However, I am unsure, if you are able to have multiple filters activated simultaneously.
Yes, you should try Chainsaw first.. it does support various ways of getting your logs.
Necroposting: I created a mode for Emacs that is specifically targeted at Log4j-like logs, but supports many more formats, especially if you customize it for yourself.
Features:
Colorization (just customize faces if that's too much)
Interactive filtering in the same buffer:
by level
by logger name
by thread
by message
easy narrowing
edit all currently set filters at once
A few log-specific movement commands
Copy (with M-w) only visible text, goes well with filtering (this is customizable)