I use the library (tcltk) in R to make the GUI. Code to create a button is :
tt <- tktoplevel()
button.widget <- tkbutton(tt, text = "", command = function())
I want the existing button on the GUI has an icon. How is the code to add the icon in the button using the library (tcltk) in R?
Use the tkimage.create function to create a Tcl-level representation of an image file. Note that there are some limitations on image formats and I believe GIF is the easiest to work with. Then, you specify the image as the image argument to tkbutton. Here's an example using, an Example.gif from Wikipedia:
library("tcltk")
img <- tclVar()
tclimg <- tkimage.create("photo", img, file = "Example.gif")
tt <- tktoplevel()
button.widget <- tkbutton(tt, text = "Click me!", image = tclimg, compound = "top",
command = function() tkmessageBox(message = "Hello!"))
tkgrid(button.widget)
You can control the relative placement of the image and text on the button using the compound argument:
"none" (display only the image if present, otherwise the text; the default)
"text" (text only)
"image" (image only)
"center" (text in center of image)
"top" (image above text)
"left" (image left of text)
"bottom" (image below text)
"right" (image right of text)
Related
In a word document, I want single spaced footnotes while the body of the document is 1.5 spaced.
No matter what I try, the footnote spacing stays at 1.15 spacing instead of single spacing.
I've tried changing the style of the footnote and changing the padding around each line of the footnote (treating each as a different paragraph). Styles don't seem to work on footnotes and changing the padding to zero still left the default 1.15 space between each "paragraph."
My current code:
footnote1 = Footnote()
footnote1 = addParagraph( footnote1,
value = pot("footnote text",
textProperties(font.size = 10, font.family = "Arial"))
)
doc <- addParagraph( doc,
value = "\tparagraph text" +
pot("addfootnotehere.", footnote = footnote1 ) +
"more text.",
stylename = "NormalLeft",
bookmark = "paragraph1"
)
Your problem may be fixed if you used your own created template instead of the default doc <- docx().
Set up a template with the spacing required, save it, then call the newly created template with:
doc <- docx(template = 'D:/docs/template/my_corporate_template.docx')
then addFootnote should read your template sizing without auto correcting.
I have a quick question. I have written an app that I run on shinyapps.io. Part of the page generates a graph, through ggplot2, that I offer users the ability to download.
When exporting the file, the image is stretched right to the borders of the overall png size. My titles, x/y axis titles and the legend are all right against the edge of the frame.
Is there any quick way to either center the image by scaling it inwards from the frame of the page, or add padding and/or margins to the entire graph image?
Here is my export code:
output$downloadPlot <- downloadHandler(
filename = function() { paste(input$get.id," _Chart", '.png', sep='') },
content = function(file) {
device <- function(..., width, height) grDevices::png(..., width = width, height = height, res = 300, units = "in")
ggsave(file, plot = p(), device = device,scale=1.95)
}
)
Thank you in advance!
How can I change the default font and its size from a menu in a GUI I'm creating using Tcltk? The example below has only one menu called 'File', but in my GUI, It will have more than that. So all of them have to be re-sized. Is there any way to do that for my entire GUI?
Thank you in advance!
require(tcltk)
readCsv <- function(){
myval <- tkgetOpenFile()
mydata <- read.csv(paste(as.character(myval), collapse = " "))
assign("myData", mydata, envir = .GlobalEnv)
}
tt <- tktoplevel()
topMenu <- tkmenu(tt)
tkconfigure(tt, menu = topMenu)
fileMenu <- tkmenu(topMenu, tearoff = FALSE)
tkadd(fileMenu, "command", label = "Quit", command = function() tkdestroy(tt))
tkadd(fileMenu, "command", label = "Load", command = function() readCsv())
tkadd(topMenu, "cascade", label = "File", menu = fileMenu)
tkfocus(tt)
The default font for menus is a named font; TkMenuFont on most platforms (and menu on OSX, where you really shouldn't change it). This is usually mapped to the correct system default font for menus. However, if you do want to change it, you're still recommended to use a named font (which is what is used in a font object in R TclTk) following the pattern on this page except that you're applying the font to a menu widget instead of a label.
# Example to show how to do it
fontMenu <- tkfont.create(family="times",size=24,weight="bold",slant="italic")
fileMenu <- tkmenu(topMenu, tearoff = FALSE, font = fontMenu)
The only platform where you shouldn't do this at all is OSX, where menus work rather differently (except at the script level; there's a lot of differences being hidden under the covers!)
Yes, using the option database.
See this question for an example showing the option database for use with a button, but works the same for menus:
https://stackoverflow.com/questions/20960107/is-there-a-way-to-have-a-global-style-for-button-in-tcl
I want to position a gtkButton on top of a gtkImage. I do this putting both inside a gtkFixed container. The problem now is that the button's tooltip is not shown anymore, when there is an image in the background. Without the image it works fine. How can I get the tooltip to be shown?
I am an R programmer so the below code is R-Gtk binding style, but should still convey the idea:
library(RGtk2)
w = gtkWindow()
image = gtkImage(file="tmp_1.png")
btn = gtkButton("Test")
gtkWidgetSetTooltipText(btn, "test")
fx = gtkFixed()
gtkFixedPut(fx, image, 10, 10)
gtkFixedPut(fx, btn, 10,10)
gtkContainerAdd(w, fx)
gtkWidgetShowAll(w)
Any ideas?
TIA.
You should use GtkOverlay widget. You add your GtkImage widget as main child of the overlay and the button with gtk_overlay_add_overlay.
That should work, and that's the preferred way of doing it.
Basically, I (think I ) need to know how to assign borderContent to a cObject, when it is a typolink parameter.
To tell the whole story: I'm using perfect lightbox, and I want it to open the lightbox when a text is clicked, and display the images that are in a single content element in the border section.
Looking through the manual, i found this code:
page.20 = TEXT
page.20.value = Open an image in a lightbox
page.20.typolink {
title = This is my caption
parameter.cObject = IMG_RESOURCE
parameter.cObject = fileadmin/image2.jpg
parameter.cObject.file.maxW = 600
parameter.cObject.file.maxH = 600
ATagParams = rel="lightbox[mySet]"
}
which is working fine. But I don't want the path to be hard set, but the content to be loaded from the border section, as I said. But if I try the following:
page.20 = TEXT
page.20.value = Open an image in a lightbox
page.20.typolink {
title = This is my caption
parameter.cObject = IMG_RESOURCE
parameter.cObject < styles.content.getBorder
parameter.cObject.file.maxW = 600
parameter.cObject.file.maxH = 600
ATagParams = rel="lightbox[mySet]"
}
the link is gone.
So I GUESS I'm assigning the content wrong. Somebody knows the answer?
Thanks!
(If of any help, I use automaketemplate..)
Assigning styles.content.getBorder will just assign the full content elements from the border column. This will not get you anywhere.
You will need to manually load the content elements from the border column, of course this can be done with TypoScript. It should be something like this:
page.20 = TEXT
page.20 {
value = Open an image in a lightbox
typolink {
ATagParams = rel="lightbox[mySet]"
title = This will be the title attribute
parameter.cObject = CONTENT
parameter.cObject {
table = tt_content
select {
pidInList = this
where = colPos = 3
}
renderObj = IMG_RESOURCE
renderObj.file {
import = uploads/pics
import.field = image
import.listNum = 0
width = 600
height = 600
}
}
}
}
Basically this will load all content elements on the border position from the current page. Render the first image in the list of images and return you the resource.