How do I get a GtkComboBox(Text) to hexpand within a GtkToolItem? - gtk

I'm trying to embed a GtkComboBoxText in a GtkToolbar (think URL entry) through a GtkToolItem. It's the most important part of the toolbar, so I'd like it to take as much space as is available.
I've tried setting hexpand to true at many various levels of the container chain, from toolbar to GtkComboBoxText (example below) to embedded GtkEntry and GtkCellAreaBox though every intermediate container I could find a handle to.
Highlighting with the inspector, it looks like the toolbar is ok with taking all the horizontal space, but not the toolitem, no matter what it contains. But that's guesswork.
(my code's Haskell, gi-gtk-3.0.37, dynamically linked to gtk3.22.30, but I don't suppose that changes anything)
main :: IO ()
main = do
Gtk.init Nothing
win <- new Gtk.Window [ #title := "win" ]
on win #destroy Gtk.mainQuit
vbox <- new Gtk.Box [ #orientation := Gtk.OrientationVertical ]
#add win vbox
hbox <- new Gtk.Box [ #orientation := Gtk.OrientationHorizontal ]
#add vbox hbox
f1 <- new Gtk.Label [ #label := "filler 1" ]
#add hbox f1
cb1 <- new Gtk.ComboBoxText [ #hexpand := True ]
#add hbox cb1
f2 <- new Gtk.Label [ #label := "filler 2" ]
#add hbox f2
tb <- new Gtk.Toolbar []
#add vbox tb
f3 <- new Gtk.ToolButton [ #label := "filler 3" ]
#add tb f3
tbi <- new Gtk.ToolItem [ #hexpand := True ]
#add tb tbi
cb2 <- new Gtk.ComboBoxText [ #hexpand := True ]
#add tbi cb2
f4 <- new Gtk.ToolButton [ #label := "filler 4" ]
#add tb f4
#showAll win
Gtk.main
I'm aiming for results similar between the hbox (above) and the toolbar (below).
Is this kind of behavior possible? Am I using GtkToolbar wrong?

Related

htmlTable in Rmd - conversion to Word docx

I have the following Rmd file, which produces an html file, which I then copy-paste into a docx file (for collaborators). Here are things I'd like to know how to do with the tables, but I can't find answers in the vignettes here:
A. I want to know how to remove the blank column that gets inserted in Word in between Cgroup 1 and Cgroup 2.
B. I want to know how to set the width of the column with the row names ("1st row",...)
C. How can I change the font and font size? I tried following this but it doesn't work to have output: word_document with htmlTable()
D. To ease the conversion to Word, is there a way to specify page breaks? Landscape orientation?
Thank you so much!
---
title: "Example"
output:
Gmisc::docx_document:
fig_caption: TRUE
force_captions: TRUE
---
Results
=======
```{r, echo = FALSE}
library(htmlTable)
library(Gmisc)
library(knitr)
mx <-
matrix(ncol=6, nrow=8)
rownames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:8, "th")),
"row")
colnames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:6, "th")),
"hdr")
for (nr in 1:nrow(mx)){
for (nc in 1:ncol(mx)){
mx[nr, nc] <-
paste0(nr, ":", nc)
}
}
htmlTable(mx,
cgroup = c("Cgroup 1", "Cgroup 2"),
n.cgroup = c(2,4))
```
The styling seemed to be off for the row names and it is now fixed in version 1.10.1 that you can download using the devtools package: devtools::install_github("gforge/htmlTable", ref="develop")
Regarding the styling the function allows almost any CSS-style you could image. Unfortunately it requires copy-pasting into Word and this functionality hasn't been Microsofts highest priority. You can easily adapt you example to accomodate the requiered changes using the css.cell:
library(htmlTable)
library(knitr)
mx <-
matrix(ncol=6, nrow=8)
rownames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:8, "th")),
"row")
colnames(mx) <- paste(c("1st", "2nd",
"3rd",
paste0(4:6, "th")),
"hdr")
for (nr in 1:nrow(mx)){
for (nc in 1:ncol(mx)){
mx[nr, nc] <-
paste0(nr, ":", nc)
}
}
css.cell = rep("font-size: 1.5em;", times = ncol(mx) + 1)
css.cell[1] = "width: 4cm; font-size: 2em;"
htmlTable(mx,
css.cell=css.cell,
css.cgroup = "color: red",
css.table = "color: blue",
cgroup = c("Cgroup 1", "Cgroup 2"),
n.cgroup = c(2,4))
There is no way to remove the empty column generated by cgroups. This was required for the table to look nice and is a conscious design choice.
Regarding page-breaks I doubt there is any elegant way for doing that. An alternative could possibly be the ReporteRs package. I haven't used it myself but it's closer integrated with Word and could possibly be a solution.

Toggle between keyboard shortcuts with AutoHotKey

I am trying to map a key to toggle between two different shortcuts. The purpose is to easily switch between desktops in Windows 10 (instead of having to press three buttons)
What I am trying is:
toggle := false
½:: Toggle = false ? ( ^#Right, Toggle := true ) : ( ^#Left, Toggle := false )
She script runs without errors, but it does not work.
Can someone give me a hint?
It should be send ^#Right, but you cannot put extra commands into the ternary operator. You may only specify a value to be stored into toggle (as shown here).
Toggle = false ? ... has to be Toggle := false ? ..., for the right-hand side is an expression, not a string.
Try
%::
toggle := !toggle
if(toggle)
send ^#{Right}
else
send ^#{Left}
return
I personally can't think of a more compact way of doing it, which you obviously want to achieve.
If you want to toggle with more then two [Keyboard Shortcuts] toggle's,
you can use this AHK code.
Example1.ahk
; [+ = Shift] [! = Alt] [^ = Ctrl] [# = Win]
#SingleInstance ignore
a := 1
; If you want to toggle with more the two toggle's you can use this code.
;a = 1 => send {^#Right}
;a = 2 => send {^#Left}
;a = 3 => send {????}
;click the f1 key to toggle
f1::
if (a=1)
{
Menu, Tray, Icon,c:\icons\32x32\icon1.ico,1,1 ; change tray icon
send {^#Right}
a := 2
}else{
if (a=2)
{
Menu, Tray, Icon,c:\icons\32x32\icon2.ico,1,1 ; change tray icon
send {^#Left}
a := 3
}else{
if (a=3)
{
Menu, Tray, Icon,c:\icons\32x32\icon3.ico,1,1 ; change tray icon
;send {????}
a := 1
}}}
return
esc::exitapp

AutoHotKey - How to add a click handler to a displayed program's icon in a GUI?

The examples that I've found that display a program's icon on a GUI form all seem to use a text control to indicate where the icon is to be displayed, but then send the STM_SETICON messages to actually display the image. However, the text control's event subroutine that handles mouse clicks are never get called when I click on the displayed icon. I've considered displaying a transparent graphic area over the icon with its own event subroutine, but seems like I should be able to attach the event handler directly to the icon's display area or load the icon into a graphic control with its own event handler.
Anyone know how to do either of these?
I am using AutoHotKey L (v 1.1.09.04) 64 bit on Windows 7 Pro.
Here is the code I found while searching for a way to display the icon, which I am now using.
FileName := "C:\XXXX\XXXX.exe" ; Get the icon from a program file.
Ignored := 0
;
; CopyImage into memory and scale it to size.
;
IMAGE_ICON := 1
LR_COPYFROMRESOURCE := 4
LR_COPYDELETEORG := 8
IconSize := 16 ; Icon size: X by X
ptr := ( ( A_PtrSize = 8 ) ? "ptr" : "uint" )
sfi_size := A_PtrSize + 8 + ( ( A_IsUnicode ) ? 680 : 340 )
VarSetCapacity( sfi, sfi_size )
DllCall( "Shell32\SHGetFileInfo" . ( ( A_IsUnicode ) ? "W" : "A" )
, "str", FileName
, "uint", Ignored
, ptr, &sfi
, "uint", sfi_size
, "uint", SHGFI_ICON )
hIcon := NumGet( sfi, 0 )
hicon_resized := DllCall( "CopyImage"
, ptr, hicon
, "uint", IMAGE_ICON
, "int", IconSize
, "int", IconSize
, "uint", LR_COPYFROMRESOURCE | LR_COPYDELETEORG
, ptr )
DllCall( "DestroyIcon", ptr, hicon )
STM_SETICON := 0x0170
Gui, Add, Text, x5 y8 w%IconSize% h%IconSize% hwndMyPic %SS_ICON% gClicked
SendMessage, STM_SETICON, hicon_resized, 0,, Ahk_ID %MyPic%
I want to change the icon to be embedded in my script and to also use is a the taskbar and tray icon, and I want this to all work without having to compile the script.
Could it be that you are looking for the way to change the tray icon for any running script? Here is an example where I borrow an icon from Shell32.dll:
Menu, Tray, Tip, My Application
Menu, Tray, Icon , Shell32.dll, 28, 1
By using:
menu, tray, add
You could also add to (or replace) the tray menu
A long time ago SKAN showed how to include an icon inside a script.
http://www.autohotkey.com/board/topic/31044-crazy-scripting-include-an-icon-in-your-script/
Here is what I tried:
#NoTrayIcon
IconDataHex =
( LTrim Join
0000010001002020080000000000A8080000160000002800000020000000400000000100080000000000000400
000000000000000000000000000000000000000000000080000080000000808000800000008000800080800000
C0C0C000C0DCC000F0CAA6000020400000206000002080000020A0000020C0000020E000004000000040200000
40400000406000004080000040A0000040C0000040E00000600000006020000060400000606000006080000060
A0000060C0000060E00000800000008020000080400000806000008080000080A0000080C0000080E00000A000
0000A0200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0000000C0200000C0400000C06000
00C0800000C0A00000C0C00000C0E00000E0000000E0200000E0400000E0600000E0800000E0A00000E0C00000
E0E00040000000400020004000400040006000400080004000A0004000C0004000E00040200000402020004020
400040206000402080004020A0004020C0004020E00040400000404020004040400040406000404080004040A0
004040C0004040E00040600000406020004060400040606000406080004060A0004060C0004060E00040800000
408020004080400040806000408080004080A0004080C0004080E00040A0000040A0200040A0400040A0600040
A0800040A0A00040A0C00040A0E00040C0000040C0200040C0400040C0600040C0800040C0A00040C0C00040C0
E00040E0000040E0200040E0400040E0600040E0800040E0A00040E0C00040E0E0008000000080002000800040
0080006000800080008000A0008000C0008000E00080200000802020008020400080206000802080008020A000
8020C0008020E00080400000804020008040400080406000804080008040A0008040C0008040E0008060000080
6020008060400080606000806080008060A0008060C0008060E000808000008080200080804000808060008080
80008080A0008080C0008080E00080A0000080A0200080A0400080A0600080A0800080A0A00080A0C00080A0E0
0080C0000080C0200080C0400080C0600080C0800080C0A00080C0C00080C0E00080E0000080E0200080E04000
80E0600080E0800080E0A00080E0C00080E0E000C0000000C0002000C0004000C0006000C0008000C000A000C0
00C000C000E000C0200000C0202000C0204000C0206000C0208000C020A000C020C000C020E000C0400000C040
2000C0404000C0406000C0408000C040A000C040C000C040E000C0600000C0602000C0604000C0606000C06080
00C060A000C060C000C060E000C0800000C0802000C0804000C0806000C0808000C080A000C080C000C080E000
C0A00000C0A02000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C00000C0C02000C0C04000C0
C06000C0C08000C0C0A000F0FBFF00A4A0A000808080000000FF0000FF000000FFFF00FF000000FF00FF00FFFF
0000FFFFFF00FFFFFFFFFFFFFFF607F707F6F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6
E49A525BA40708F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBE0D8D89991525BA407F6F6FFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2E8D8D8D8D8D899925B9BF707F6F6FFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFE2E8D8D8D8D0D0D8D8D899525B9BF707F6F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFE2E9D0D0D0D0D0D0
D0D0D8D8D899525BA4F708FFFFFFFFFFFFFFFFFFFFFFFFFFE2E9D092DB929191D8D0D0D0D0D8D8D8999AA4F6FF
FFFFFFFFFFFFFFFFFFFFFFE2E990DBE4E4E4DB929191D8D090D0D8D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E9
90DBE4E4E408BFE4DB929191D8D8D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E9909BE4E4E4B7BF07070807E492
91D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E99092DBDBE4F777E5BFBFBFBFBFE491D9A4F6FFFFFFFFFFFFFFFF
FFFFFFFFE2EA9092DBDBDBDBE4E4AEAEF7B67FED92D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2EA9092DBDBDBDBDB
DBDBE4E4E4F7E492D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2EA9092D2DBDBDBDBDBDBDBDBDBE4DB92D9A4F6FFFF
FFFFFFFFFFFFFFFFFFFFE2F29092D2D2DBDBDBDBDBDBDBDBDBDB9299A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2F290
92D2D2D2D2DBDBDBDBDBDBDBDB9299A4F6FFFFFFFFFFFFFFFFFFFFFFFFE3FFD192D2D2D2D2D2D2D2D2D2D2D2D2
9291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D992D2D2D2D2D2D2D2D2D2D2D2D29291A4F6FFFFFFFFFFFFFFFFFF
FFFFFF09F3D989D2D2D2D2D2D2D2D2D2D2D2D29291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D98992D2D2D2D2D2
D2D2D2D2D2929291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D9899292929292929292929292929291A4F6FFFFFF
FFFFFFFFFFFFFFFFFF0909D9499192929292929292929292929291A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB9149
4949494949494949494949499291A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB904949494949494949494949494992
91F7FFFFFFFFFFFFFFFFFFFFFFFFFFECEB90494949494949494949494949499292F7F6FFFFFFFFFFFFFFFFFFFF
FFFFECEB90494949494949494949494949498991A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB904949404040404949
49494949498991A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB90914949494949494040494949494991A4F6FFFFFFFF
FFFFFFFFFFFFFFFFECEB90909090909191919149494949499191A4F6FFFFFFFFFFFFFFFFFFFFFFFF09FFE2DAD9
D1909090909090909091919091A4F6FFFFFFFFFFFFFFFFFFFFFFFF0909EBECE2EBE2EAE2E2D9D9D0D0D0909091
F7F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0909ECECEBE3E2D9D8D9ECF6FFFFFFFFFFFFFF0000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000
)
VarSetCapacity( IconData,( nSize:=StrLen(IconDataHex)//2) )
Loop %nSize% ; MCode by Laszlo Hars: http://www.autohotkey.com/forum/viewtopic.php?t=21172
NumPut( "0x" . SubStr(IconDataHex,2*A_Index-1,2), IconData, A_Index-1, "Char" )
IconDataHex := "" ; contents needed no more
hICon := DllCall( "CreateIconFromResourceEx", UInt,&IconData+22
, UInt,NumGet(IconData,14), Int,1, UInt,0x30000, Int,32, Int,32, UInt,0 )
Gui +LastFound ; Set our GUI as LastFound window ( affects next two lines )
SendMessage, ( WM_SETICON:=0x80 ), 0, hIcon ; Set the Titlebar Icon
SendMessage, ( WM_SETICON:=0x80 ), 1, hIcon ; Set the Alt-Tab icon
PID := DllCall("GetCurrentProcessId"), VarSetCapacity( NID,444,0 ), NumPut( 444,NID )
DetectHiddenWindows, On
NumPut( WinExist( A_ScriptFullPath " ahk_class AutoHotkey ahk_pid " PID),NID,4 )
DetectHiddenWindows, Off
NumPut( 1028,NID,8 ), NumPut( 2,NID,12 ), NumPut( hIcon,NID,20 )
Menu, Tray, Icon ; Shows the default Tray icon
DllCall( "shell32\Shell_NotifyIcon", UInt,0x1, UInt,&NID ) ; and we immediately modify it.
Gui, Show, w640 h480
Return
GuiClose:
ExitApp
It opens an empty GUI but it HAS CHANGED THE tray Icon, The GUI Icon and the Alt+Tab icon.

Doxygen with Graphviz to document VHDL

I don't manage to add a graphviz (#dot) to my doxygen documented VHDL files.
Can somebody provide some example code?
I would like to add fsm graphical representation to my code.
thanks in advance
Just write the dot-file manually:
digraph FSM {
RESET -> IDLE
IDLE -> CALC [label="data_in = '1'"]
CALC -> DONE
DONE -> IDLE
}
comment with --!;
start with #dot and stop with #enddot
Example:
--! #dot
--! digraph finite_state_machine {
--! rankdir=LR;
--! size="8,5"
--! node [shape = circle];
--! S0 -> S1 [ label = "010" ]
--! S1 -> S0 [ label = "000" ]
--! S1 -> S2 [ label = "111" ]
--! S2 -> S0 [ label = "101" ]
--! }
--! #enddot

How do I update a menu after a button press in PyGTK?

I am not that familiar with PyGTK. Please see the following code. Is it possible to make it do the following?
There are two buttons, which we refer to as "generate" and "view".
The "generate" button will generate random values for variables A and B.
The "view" button will pop up a menu showing A and B.
The problem with the following code is that the "view" menu shows A and B, but the menu does not update as the user presses the "generate" button.
I ran the code with Python 2.6.6.
Please also suggest any ways that I can improve the code (formatting, style, PyGTK conventions, ...). Thank you in advance.
"""Generate values for two variables A and B."""
# ------------------------------------------------------------------------------
# Winston C. Yang
# Created 2010-12-04
# ------------------------------------------------------------------------------
# Python modules. Be alphabetical.
import random
# ------------------------------------------------------------------------------
# Other Python modules. Be alphabetical.
import gtk
import pygtk
pygtk.require("2.0")
# ------------------------------------------------------------------------------
class Generator:
"""Generate values for two variables A and B."""
def __init__(self):
# Create a dictionary in which a key is a variable name and a
# (dictionary) value is the variable value.
self.d_variable_value = {}
# ----------------------------------------------------------------------
window = gtk.Window()
window.set_title("Generate")
window.connect("destroy", self.quit_event)
# ----------------------------------------------------------------------
# Create a vertical box with two buttons.
vbox = gtk.VBox()
# Create a button to generate values for A and B.
b = gtk.Button("Generate A and B")
vbox.pack_start(b)
b.connect("clicked", self.generate_variable_values)
# Create a button to view A and B.
b = gtk.Button("View A and B")
vbox.pack_start(b)
b.connect_object("event", self.button_press, self.create_menu())
# ----------------------------------------------------------------------
window.add(vbox)
window.show_all()
# --------------------------------------------------------------------------
def quit_event(self, widget=None, event=None):
"""Quit."""
gtk.main_quit()
# --------------------------------------------------------------------------
def generate_variable_values(self, widget=None):
"""Generate values for A and B."""
self.d_variable_value = {
"A" : random.randint(0, 10),
"B" : random.randint(0, 10),
}
print "I generated " + str(self.d_variable_value)
# --------------------------------------------------------------------------
def button_press(self, widget, event):
"""button_press method."""
if event.type == gtk.gdk.BUTTON_PRESS:
widget.popup(None, None, None, event.button, event.time)
return True
return False
# --------------------------------------------------------------------------
def create_menu(self):
"""Create a menu showing A and B."""
# How can I update the menu after the user presses the
# "generate" button?
# If there are no values for A and B, generate them.
if not self.d_variable_value:
self.generate_variable_values()
# Show A and B in a menu.
menu = gtk.Menu()
for key, value in sorted(self.d_variable_value.items()):
text = key + " " + str(value)
item = gtk.MenuItem(text)
item.show()
menu.append(item)
return menu
# ------------------------------------------------------------------------------
if __name__ == "__main__":
Generator()
gtk.main()
This line b.connect_object("event", self.button_press, self.create_menu()) is connecting self.button_press to the event signal on a gtk.Menu created by self.create_menu(). This line is never executed again, so the menu is always the same.
What I did was connect the event signal for the View A and B button to the self.button_press handler, and that handler creates an updated menu every time it's run.
# ------------------------------------------------------------------------------
# Python modules. Be alphabetical.
import random
# ------------------------------------------------------------------------------
# Other Python modules. Be alphabetical.
import gtk
import pygtk
pygtk.require("2.0")
# ------------------------------------------------------------------------------
class Generator:
"""Generate values for two variables A and B."""
def __init__(self):
# Create a dictionary in which a key is a variable name and a
# (dictionary) value is the variable value.
self.d_variable_value = {}
# ----------------------------------------------------------------------
window = gtk.Window()
window.set_title("Generate")
window.connect("destroy", self.quit_event)
# ----------------------------------------------------------------------
# Create a vertical box with two buttons.
vbox = gtk.VBox()
# Create a button to generate values for A and B.
b = gtk.Button("Generate A and B")
vbox.pack_start(b)
b.connect("clicked", self.generate_variable_values)
# Create a button to view A and B.
b = gtk.Button("View A and B")
vbox.pack_start(b)
b.connect("event", self.button_press)
# ----------------------------------------------------------------------
window.add(vbox)
window.show_all()
# --------------------------------------------------------------------------
def quit_event(self, widget=None, event=None):
"""Quit."""
gtk.main_quit()
# --------------------------------------------------------------------------
def generate_variable_values(self, widget=None):
"""Generate values for A and B."""
self.d_variable_value = {
"A" : random.randint(0, 10),
"B" : random.randint(0, 10),
}
print "I generated " + str(self.d_variable_value)
# --------------------------------------------------------------------------
def button_press(self, button, event):
"""button_press method."""
if event.type == gtk.gdk.BUTTON_PRESS:
menu = self.create_menu()
menu.popup(None, None, None, event.button, event.time)
return True
return False
# --------------------------------------------------------------------------
def create_menu(self):
"""Create a menu showing A and B."""
# How can I update the menu after the user presses the
# "generate" button?
# If there are no values for A and B, generate them.
if not self.d_variable_value:
self.generate_variable_values()
# Show A and B in a menu.
menu = gtk.Menu()
print self.d_variable_value
for key, value in sorted(self.d_variable_value.items()):
text = key + " " + str(value)
item = gtk.MenuItem(text)
item.show()
menu.append(item)
return menu
# ------------------------------------------------------------------------------
if __name__ == "__main__":
Generator()
gtk.main()