Tcl/Tk: Applying theme (awdark) to an application - themes

I would like to apply the awdark theme to refresh an old apllication. Unable to apply themes using tcl awthemes https://sourceforge.net/projects/tcl-awthemes/, or even the default built in Themes like classic, vista, xpnative.
In the working code below the the "awdark" theme is being applied and I can confirm this by asking ttk::style theme use. But I dont see any changes on the styling of the GUI
lappend auto_path "C:/Root/tcl_tk/33_Dummy_Analyzer_2022/awthemes-10.4.0"
package require awdark
#
ttk::style theme use awdark
#
label .l_inst -text "Instructions: fill in the below fields and click 'Go'"
label .l_year -text "Enter the digits for year, eg 22: "
grid config .l_inst -column 0 -row 0 -columnspan 2 -sticky "w"
grid config .l_year -column 0 -row 1 -sticky "e"
#
set autofill1 22
entry .e_year -bg white -textvariable autofill1 -validate key \
-vcmd {expr {[string is digit %P] && [string length %P]<=2}} -width 20
grid config .e_year -column 1 -row 1 -sticky "e"
#
button .b_go -relief raised -overrelief ridge -borderwidth 5 -text "GO"
button .b_quit -relief raised -overrelief ridge -borderwidth 5 \
-text "Cancel and Close"
grid config .b_go -column 0 -row 8 -sticky "snew" -pady 10
grid config .b_quit -column 1 -row 8 -sticky "snew" -pady 10

You should use ttk::widget to apply a theme, for this replace :
label by ttk::label
entry by ttk::entry
button by ttk::button
Note : Be careful not all properties apply for ttk::widget

Related

Difference between FPDFAnnot_SetRect and FPDFAnnot_AppendAttachmentPoints when adding a annotation to pdf document

I'm using pdfium to add annotations to pdf files.
I opened the pdf file using Notepad++ and viewed its objects. Annotation object was present inside the Page object as follows,
3 0 obj
<</Annots[<</C[ 1 1 0]/CA 1/F 4/QuadPoints[ 0 300 300 300 0 0 300 0]/Rect[ 216.182 702.94 368.75 686.38]/Subtype/Highlight/Type/Annot>>]/Contents 4 0 R /Group<</CS/DeviceRGB/S/Transparency/Type/Group>>/MediaBox[ 0 0 612 792]/Parent 2 0 R /Resources<</ExtGState<</GS7 7 0 R /GS8 8 0 R >>/Font<</F1 5 0 R >>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/StructParents 0/Tabs/S/Type/Page>>
endobj
I used following code to add the rect and attachment points to the annotation.
FPDF_ANNOTATION highlightAnnot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_HIGHLIGHT);
FPDFAnnot_SetRect(highlightAnnot, &rect);
FPDFAnnot_AppendAttachmentPoints(highlightAnnot, &new_quadpoints);
As I understood, Attachment points are set to give the location of Highlight annotation where we want it to be. But I don't understand the purpose of setting the Rect for this annotation.
Can someone please tell the reason for using FPDFAnnot_SetRect function?
Another thing,
FPDFAnnot_SetRect defines the bounding box, while FPDFAnnot_AppendAttachmentPoints defines the actual shape. Consider a multiline highlight annotation, it has only one Rect, but several AttachmentPoints.
A Rect could be used as a "collision box" at application level so that when you click on it, you select the contained annotation. Or it can be an "updating box".
Rect is more general and only text-related annotation types have AttachmentPoints.

How do I put a stamp on the upper right corner?

I'm trying to put a stamp on the top right corner of a PDF file. I have a PS file created from Excel using driver for HP Color LaserJet 4500 printed to file.
I am using GhostScript to create a PDF.
GSWIN32C.EXE #S:\Temp\PS\Options.txt
Here is the contents of the Options.txt file:
-sDEVICE=pdfwrite -q -dSAFER -dNOPAUSE
-sOUTPUTFILE="S:\Temp\PS\Sample.pdf" -dBATCH
"S:\Temp\PS\Stamp.txt"
"S:\Temp\PS\Sample.ps"
Here is the contents of Stamp.txt modified from here:
<<
/EndPage
{
2 eq { pop false }
{
gsave
/Helvetica_Bold 15 selectfont
0 setgray
475 767 moveto
(STATE COPY) show
grestore
true
} ifelse
} bind
>> setpagedevice
The PDF is created just fine, but the stamp is causing me problems. The stamp shows very tiny on the upper left but flipped vertically.
Here is a section with the tiny stamp upper left:
Here is the stamp enlarged 800%
On a multi-page PDF I want the stamp on all pages. I understand that using the /EndPage should let me do that.
So how do I get my stamp on the upper right corner?
I assume the problem with the stamp resides in the previous transformations. So I used scale to flip the stamp upright and adjusted until I got it in the right place.
<<
/EndPage
{
2 eq { pop false }
{
gsave
/Helvetica_Bold 15 selectfont
0 setgray
10 10 scale
375 17 moveto
1 -1 scale
(STATE COPY) show
grestore
true
} ifelse
} bind
>> setpagedevice
I didn't test it but I assume using a different print driver to produce the PS file would give different results.

Scrolling two widgets using single scrollbar in TCL/TK.

I have created two tree control widgets and a scrollbar widget. Now i am trying to create a functionality where the user would have choice of using scrollbar in the sense that there will be radiobutton options which would decide which widget gets scrolled with the scrollbar. I got some idea for how to scroll two widgets together from here. But not sure how to create a switchable scrollbar. My code is below :
package require Tk
package require treectrl
namespace eval ::at::GUI {
variable Priv;
variable OptionsRB;
set Priv(treePrimary) "";
set Priv(treeSecondary) "";
set Priv(treeScrollbar) "";
if { ![info exists OptionsRB] } {
set OptionsRB(scrollTree) "LeftTree";
}
}
proc ::at::GUI::DrawGUI {} {
variable Priv;
set frm_treeFrame [ttk::labelframe .treeFrame -text "Tree Area"];
set Priv(treePrimary) [treectrl $frm_treeFrame.treePrimary]
set Priv(treeSecondary) [treectrl $frm_treeFrame.treeSecondary]
set Priv(treeScrollbar) [ttk::scrollbar $frm_treeFrame.sb_treeScroll -command "::at::GUI::yview"]
grid $Priv(treePrimary) $Priv(treeSecondary) $Priv(treeScrollbar) -sticky news;
grid columnconfigure $frm_treeFrame 0 -weight 1;
grid columnconfigure $frm_treeFrame 1 -weight 1;
grid rowconfigure $frm_treeFrame 0 -weight 1;
set frm_ST [ttk::labelframe .scrollTreeOptions -text "Scroll Option"];
set rb_leftTree [ttk::radiobutton $frm_ST.rb1 -text "Left Tree" -variable [namespace current]::OptionsRB(scrollTree) -value LeftTree -command [namespace current]::configScroll ]
set rb_rightTree [ttk::radiobutton $frm_ST.rb2 -text "Right Tree" -variable [namespace current]::OptionsRB(scrollTree) -value RightTree -command [namespace current]::configScroll ]
set rb_bothTree [ttk::radiobutton $frm_ST.rb3 -text "Both Tree" -variable [namespace current]::OptionsRB(scrollTree) -value BothTree -command [namespace current]::configScroll ]
grid $rb_leftTree -row 1 -padx {30 5} -pady 5 -sticky w
grid $rb_rightTree -row 2 -padx {30 5} -pady 5 -sticky w
grid $rb_bothTree -row 3 -padx {30 5} -pady 5 -sticky w
# Grid all the frames in main window.
grid $frm_treeFrame -sticky news;
grid $frm_ST -sticky news;
##############################
::at::GUI::CreateLemes $Priv(treePrimary)
::at::GUI::CreateLemes $Priv(treeSecondary)
foreach tree [list $Priv(treePrimary) $Priv(treeSecondary)] {
for {set i 0} {$i < 20} {incr i} {
set parent [expr {int(rand()*$i)}]
$tree item create -tag item$i -button auto
$tree item lastchild $parent item$i
$tree item text item$i name item$i
}
}
return;
}
proc ::at::GUI::CreateLemes {T} {
$T element create rect rect -fill [list blue selected]
$T element create name text
set S [$T style create nameStyle]
$T style elements $S {rect name};
$T style layout $S rect -detach yes -iexpand xy;
$T style layout $S name -detach no -iexpand xy -expand e;
$T column create -tag name -itemstyle $S -text Items
$T configure -treecolumn first;
}
proc ::at::GUI::configScroll {args} {
variable Priv;
variable OptionsRB;
if {$OptionsRB(scrollTree) eq "LeftTree"} {
#$Priv(treeSecondary) -yscrollcommand "";
$Priv(treePrimary) -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)";
} elseif {$OptionsRB(scrollTree) eq "RightTree"} {
#$Priv(treePrimary) -yscrollcommand "";
$Priv(treeSecondary) -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)";
} elseif {$OptionsRB(scrollTree) eq "BothTree"} {
$Priv(treePrimary) -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)";
$Priv(treeSecondary) -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)";
}
}
proc ::at::GUI::yset {sb args} {
uplevel [linsert $args 0 $sb set]
::at::GUI::yview moveto [lindex [$sb get] 0]
}
proc ::at::GUI::yview {args} {
variable Priv;
variable OptionsRB;
if {$OptionsRB(scrollTree) eq "LeftTree"} {
eval [linsert $args 0 $Priv(treePrimary) yview];
} elseif {$OptionsRB(scrollTree) eq "RightTree"} {
eval [linsert $args 0 $Priv(treeSecondary) yview];
} elseif {$OptionsRB(scrollTree) eq "BothTree"} {
eval [linsert $args 0 $Priv(treePrimary) yview];
eval [linsert $args 0 $Priv(treeSecondary) yview];
}
}
The thing is that whenever i try to click on the radiobuttion, i get an error saying :
bad command "-yscrollcommand": must be activate, bbox, canvasx,
canvasy, cget, collapse, column, compare, configure, contentbox,
debug, depth, dragimage, element, expand, gradient, header, identify,
index, item, marquee, notify, numcolumns, numitems, orphans, range,
scan, see, selection, state, style, theme, toggle, xview, or yview bad
command "-yscrollcommand": must be activate, bbox, canvasx, canvasy,
cget, collapse, column, compare, configure, contentbox, debug, depth,
dragimage, element, expand, gradient, header, identify, index, item,
marquee, notify, numcolumns, numitems, orphans, range, scan, see,
selection, state, style, theme, toggle, xview, or yview
while executing "$Priv(treeSecondary) -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)""
(procedure "::at::GUI::configScroll" line 10)
invoked from within "::at::GUI::configScroll"
invoked from within ".scrollTreeOptions.rb2 invoke "
invoked from within ".scrollTreeOptions.rb2 instate {pressed !disabled} { .scrollTreeOptions.rb2 state !pressed;
.scrollTreeOptions.rb2 invoke } "
(command bound to event)
But the funny part is, even though i get the error, if i move the scrollbar, it does switch between the widget and works as desired. But the error is something i am not able to understand.
This is my very first TK project so I am not sure if I am missing some crucial information. Any comments??
The error message is the key. Indeed the command contained in the Priv(treeSecondary) variable does not have a subcommand named -yscrollcommand. I think you want to use the configure subcommand to change the value of the -yscrollcommand option. Try something like:
$Priv(treeSecondary) configure -yscrollcommand "::at::GUI::yset $Priv(treeScrollbar)"

How to set a NSCalibratedRGBColorSpace ? Cocoa

I need to set a color.
In my case the color returned by a NSColorWell is NSCalibratedRGBColorSpace 0 1 0 1. If I set this color the app crashes. How can I manipulate it ?
Thanks

Change background color of ListView in VB6

I'm working with some legacy code and need to change the background color of a row (and the font color) in a ListView in VB6 based on some criteria. I need to change the color of the row when the row is selected and not selected. I can change the font color of a non-selected row via the .Foreground property but I can't change the color in any of the other scenarios.
Check out this forum post. Here's an sample from the code which colors every other row:
'\\ loop through the rows to select every other row
For i = 1 To lvwBackColour.ListItems.Count
If (lvwBackColour.ListItems(i).Index Mod 2) = 0 Then
'\\ add a tick to the checkbox
lvwBackColour.ListItems(i).Checked = True
'\\ add the colour to the picturebox
'\\ See Here (http://msdn2.microsoft.com/en-us/library/aa230480(VS.60).aspx)
'\\ for information about the Line method
picBG.Line (0, i - 1)-(1, i), &H4000FF, BF
'\\ update column four caption
lvwBackColour.ListItems(i).SubItems(3) = "Hidden column value = 1"
Else
'\\ remove the tick from the checkbox
lvwBackColour.ListItems(i).Checked = False
'\\ reset backcolour to white
picBG.Line (0, i - 1)-(1, i), &HFFFFFF, BF
'\\ reset the Column Four caption
lvwBackColour.ListItems(i).SubItems(3) = "Hidden column value = 0"
End If
Next i
'\\ set the listview to use the picturebox image
lvwBackColour.Picture = picBG.Image
Here's the link to the msdn article which talks about the Line method.
The background color of selected rows is controlled by the system. You cannot change it to anything else.
If you have to be able to change the background of the selected rows, you will need to custom draw the listview -- which, to be honest, is too much of a pain to seriously consider :)

Resources