From b9a360e4f40dc70986f897e8a132050af0ae4cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 22 Jul 2025 14:28:01 +0200 Subject: [PATCH] chore: rm some tk stuff --- .Rbuildignore | 2 - NAMESPACE | 4 - R/console.R | 324 ------------------------------------- R/package.R | 26 --- R/par.R | 20 +-- man/console.Rd | 34 ---- man/dot-igraph.progress.Rd | 15 -- man/dot-igraph.status.Rd | 12 -- man/igraph.console.Rd | 15 -- man/min_st_separators.Rd | 16 +- src/rinterface_extra.c | 20 ++- 11 files changed, 15 insertions(+), 473 deletions(-) delete mode 100644 R/console.R delete mode 100644 R/package.R delete mode 100644 man/console.Rd delete mode 100644 man/dot-igraph.progress.Rd delete mode 100644 man/dot-igraph.status.Rd delete mode 100644 man/igraph.console.Rd diff --git a/.Rbuildignore b/.Rbuildignore index 3e4bd8658db..c06643736e5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -62,8 +62,6 @@ ^covr$ ^src/*\.gcda$ ^src/*\.gcno$ -^man/dot-igraph.progress\.Rd$ -^man/dot-igraph.status\.Rd$ ^man/dot-extract_constructor_and_modifiers\.Rd$ ^man/dot-apply_modifiers\.Rd$ ^man/handle_vertex_type_arg\.Rd$ diff --git a/NAMESPACE b/NAMESPACE index 3b318d4395e..b05977ce1bc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -261,7 +261,6 @@ export(compose) export(connect) export(connect.neighborhood) export(consensus_tree) -export(console) export(constraint) export(contract) export(contract.vertices) @@ -501,7 +500,6 @@ export(hrg_tree) export(hub.score) export(hub_score) export(identical_graphs) -export(igraph.console) export(igraph.drl.coarsen) export(igraph.drl.coarsest) export(igraph.drl.default) @@ -950,7 +948,5 @@ importFrom(stats,runif) importFrom(stats,sd) importFrom(utils,capture.output) importFrom(utils,head) -importFrom(utils,setTxtProgressBar) importFrom(utils,tail) -importFrom(utils,txtProgressBar) useDynLib(igraph, .registration = TRUE) diff --git a/R/console.R b/R/console.R deleted file mode 100644 index 8a9eabf802d..00000000000 --- a/R/console.R +++ /dev/null @@ -1,324 +0,0 @@ -#' The igraph console -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' `igraph.console()` was renamed to [console()] to create a more -#' consistent API. -#' -#' @keywords internal -#' @export -igraph.console <- function() { - # nocov start - lifecycle::deprecate_soft("2.0.0", "igraph.console()", "console()") - console() -} # nocov end - -# IGraph R package -# Copyright (C) 2010-2012 Gabor Csardi -# 334 Harvard street, Cambridge, MA 02139 USA -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301 USA -# -################################################################### - -#' The igraph console -#' -#' The igraph console is a GUI window that shows what the currently running -#' igraph function is doing. -#' -#' The console can be started by calling the `console()` function. -#' Then it stays open, until the user closes it. -#' -#' Another way to start it to set the `verbose` igraph option to -#' \dQuote{tkconsole} via `igraph_options()`. Then the console (re)opens -#' each time an igraph function supporting it starts; to close it, set the -#' `verbose` option to another value. -#' -#' The console is written in Tcl/Tk and required the `tcltk` package. -#' -#' @return `NULL`, invisibly. -#' @author Gabor Csardi \email{csardi.gabor@@gmail.com} -#' @seealso [igraph_options()] and the `verbose` option. -#' @keywords graphs -#' @family console -#' @export -console <- function() { - oldverb <- igraph_opt("verbose") - igraph_options(verbose = "tkconsole") - pb <- .igraph.progress.tkconsole.create(oldverb) - assign(".igraph.pb", pb, envir = asNamespace("igraph")) - .igraph.progress.tkconsole.message("Console started.\n") - invisible() -} - -.igraph.pb <- NULL - -#' igraph progress -#' @param percent,message,clean Used internally by `.igraph.progress()` and `.igraph.status()` -#' @dev -.igraph.progress <- function(percent, message, clean = FALSE) { - if (clean) { - if (!is.null(.igraph.pb)) { - close(.igraph.pb) - } - return(invisible()) - } - type <- igraph_opt("verbose") - if (is.logical(type) && type) { - .igraph.progress.txt(percent, message) - } else { - switch( - type, - "tk" = .igraph.progress.tk(percent, message), - "tkconsole" = .igraph.progress.tkconsole(percent, message), - stop("Cannot interpret 'verbose' option, this should not happen") - ) - } -} - -#' igraph status -#' @inheritParams .igraph.progress -#' @dev -.igraph.status <- function(message) { - type <- igraph_opt("verbose") - if (is.logical(type) && type) { - message(message, appendLF = FALSE) - } else { - switch( - type, - "tk" = message(message, appendLF = FALSE), - "tkconsole" = .igraph.progress.tkconsole.message(message, start = TRUE), - stop("Cannot interpret 'verbose' option, this should not happen") - ) - } - 0L -} - -#' @importFrom utils txtProgressBar setTxtProgressBar -.igraph.progress.txt <- function(percent, message) { - pb <- get(".igraph.pb", asNamespace("igraph")) - if (percent == 0) { - if (!is.null(pb)) { - close(pb) - } - cat(sep = "", " ", message, "\n") - pb <- txtProgressBar(min = 0, max = 100, style = 3) - } - setTxtProgressBar(pb, percent) - if (percent == 100) { - close(pb) - pb <- NULL - } - assign(".igraph.pb", pb, envir = asNamespace("igraph")) - 0L -} - -.igraph.progress.tk <- function(percent, message) { - pb <- get(".igraph.pb", asNamespace("igraph")) - if (percent == 0) { - if (!is.null(pb)) { - close(pb) - } - pb <- tcltk::tkProgressBar( - min = 0, - max = 100, - title = message, - label = "0 %" - ) - } - tcltk::setTkProgressBar(pb, percent, label = paste(percent, "%")) - if (percent == 100) { - close(pb) - pb <- NULL - } - assign(".igraph.pb", pb, envir = asNamespace("igraph")) - 0L -} - -.igraph.progress.tkconsole <- function(percent, message) { - pb <- get(".igraph.pb", asNamespace("igraph")) - startmess <- FALSE - - ## Open the console, if it is not open - if (is.null(pb)) { - startmess <- TRUE - pb <- .igraph.progress.tkconsole.create(NA) - } - - ## Update progress bar - pb$pb$set(pb$pb$widget, percent) - tcltk::tkconfigure(pb$pb$label, text = substr(message, 1, 20)) - tcltk::tcl("update", "idletasks") - - ## Done - assign(".igraph.pb", pb, envir = asNamespace("igraph")) - if (startmess) { - .igraph.progress.tkconsole.message("Console started.\n") - } - 0L -} - -.igraph.progress.tkconsole.create <- function(oldverb) { - console <- tcltk::tktoplevel() - tcltk::tktitle(console) <- "igraph console" - - fn <- tcltk::tkfont.create(family = "courier", size = 8) - - lfr <- tcltk::tkframe(console) - image <- tcltk::tkimage.create( - "photo", - "img", - format = "gif", - file = system.file("igraph2.gif", package = "igraph") - ) - logo <- tcltk::tklabel( - lfr, - relief = "flat", - padx = 10, - pady = 10, - image = image - ) - - scr <- tcltk::tkscrollbar( - console, - repeatinterval = 5, - command = function(...) tcltk::tkyview(txt, ...) - ) - txt <- tcltk::tktext( - console, - yscrollcommand = function(...) tcltk::tkset(scr, ...), - width = 60, - height = 7, - font = fn - ) - tcltk::tkconfigure(txt, state = "disabled") - pbar <- .igraph.progress.tkconsole.pbar(console) - - bclear <- tcltk::tkbutton(lfr, text = "Clear", command = function() { - tcltk::tkconfigure(txt, state = "normal") - tcltk::tkdelete(txt, "0.0", "end") - tcltk::tkconfigure(txt, state = "disabled") - }) - bstop <- tcltk::tkbutton(lfr, text = "Stop", command = function() {}) - bclose <- tcltk::tkbutton(lfr, text = "Close", command = function() { - if (!is.na(oldverb) && igraph_opt("verbose") == "tkconsole") { - igraph_options(verbose = oldverb) - } - tcltk::tkdestroy(console) - }) - - tcltk::tkpack( - logo, - side = "top", - fill = "none", - expand = 0, - anchor = "n", - ipadx = 10, - ipady = 10 - ) - tcltk::tkpack(bclear, side = "top", fill = "x", expand = 0, padx = 10) - ## tcltk::tkpack(bstop, side="top", fill="x", expand=0, padx=10) - tcltk::tkpack(bclose, side = "top", fill = "x", expand = 0, padx = 10) - - tcltk::tkpack(lfr, side = "left", fill = "none", expand = 0, anchor = "n") - tcltk::tkpack(pbar$frame, side = "bottom", fill = "x", expand = 0) - tcltk::tkpack(scr, side = "right", fill = "y", expand = 0) - tcltk::tkpack(txt, side = "left", fill = "both", expand = 1) - - tcltk::tkbind(console, "", function() { - if (!is.na(oldverb) && igraph_opt("verbose") == "tkconsole") { - igraph_options(verbose = oldverb) - } - assign(".igraph.pb", NULL, envir = asNamespace("igraph")) - }) - - res <- list(top = console, txt = txt, pb = pbar$pb, oldverb = oldverb) - class(res) <- "igraphconsole" - res -} - -.igraph.progress.tkconsole.message <- function(message, start = FALSE) { - txt <- get(".igraph.pb", asNamespace("igraph"))$txt - if (is.null(txt)) { - if (start) { - pb <- .igraph.progress.tkconsole.create(NA) - assign(".igraph.pb", pb, envir = asNamespace("igraph")) - txt <- pb$txt - } else { - return() - } - } - tcltk::tkconfigure(txt, state = "normal") - now <- paste(sep = "", substr(date(), 5, 19), ": ") - s1 <- grepl("^ ", message) - if (!s1) { - tcltk::tkinsert(txt, "insert", now) - } - tcltk::tkinsert(txt, "insert", message) - tcltk::tksee(txt, "end") - tcltk::tkconfigure(txt, state = "disabled") - tcltk::tcl("update", "idletasks") -} - -#' @exportS3Method NULL -close.igraphconsole <- function(con, ...) { - invisible() -} - -## Much of this is from tkProgressbar - -.igraph.progress.tkconsole.pbar <- function(top) { - useText <- FALSE - have_ttk <- as.character(tcltk::tcl("info", "tclversion")) >= "8.5" - if (!have_ttk && as.character(tcltk::tclRequire("PBar")) == "FALSE") { - useText <- TRUE - } - fn <- tcltk::tkfont.create(family = "helvetica", size = 10) - frame <- tcltk::tkframe(top) - if (useText) { - .lab <- tcltk::tklabel( - frame, - text = " ", - font = fn, - anchor = "w", - padx = 20 - ) - tcltk::tkpack(.lab, side = "left", anchor = "w", padx = 5) - fn2 <- tcltk::tkfont.create(family = "helvetica", size = 12) - .vlab <- tcltk::tklabel(frame, text = "0%", font = fn2, padx = 20) - tcltk::tkpack(.vlab, side = "right") - } else { - .lab <- tcltk::tklabel(frame, text = " ", font = fn, anchor = "w", pady = 5) - tcltk::tkpack(.lab, side = "top", anchor = "w", padx = 5) - tcltk::tkpack(tcltk::tklabel(frame, text = "", font = fn), side = "bottom") - .val <- tcltk::tclVar() - pBar <- if (have_ttk) { - tcltk::ttkprogressbar(frame, length = 300, variable = .val) - } else { - tcltk::tkwidget(frame, "ProgressBar", width = 300, variable = .val) - } - tcltk::tkpack(pBar, side = "bottom", anchor = "w", padx = 5) - } - get <- function(w) { - return(tcltk::tclvalue(.val)) - } - set <- function(w, val) { - tcltk::tclvalue(.val) <<- val - } - pb <- list(widget = pBar, get = get, set = set, label = .lab) - list(frame = frame, pb = pb) -} diff --git a/R/package.R b/R/package.R deleted file mode 100644 index af9f774c97e..00000000000 --- a/R/package.R +++ /dev/null @@ -1,26 +0,0 @@ -# IGraph R package -# Copyright (C) 2005-2012 Gabor Csardi -# 334 Harvard street, Cambridge, MA 02139 USA -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301 USA -# -################################################################### - -.onAttach <- function(library, pkg) { - ## we can't do this in .onLoad - unlockBinding(".igraph.pb", asNamespace("igraph")) - invisible() -} diff --git a/R/par.R b/R/par.R index 9507dc039b3..4bee5cf934d 100644 --- a/R/par.R +++ b/R/par.R @@ -75,24 +75,8 @@ getIgraphOpt <- function(x, default = NULL) { ) igraph.pars.set.verbose <- function(verbose) { - if (is.logical(verbose)) { - .Call(R_igraph_set_verbose, verbose) - } else if (is.character(verbose)) { - if (!verbose %in% c("tk", "tkconsole")) { - cli::cli_abort("Unknown {.arg verbose} value.") - } - if (verbose %in% c("tk", "tkconsole")) { - if (!capabilities()[["X11"]]) { - cli::cli_abort("X11 not available.") - } - if (!requireNamespace("tcltk", quietly = TRUE)) { - cli::cli_abort("tcltk package not available.") - } - } - .Call(R_igraph_set_verbose, TRUE) - } else { - cli::cli_abort("{.arg verbose} should be a logical or character scalar.") - } + check_logical(verbose) + .Call(R_igraph_set_verbose, verbose) verbose } diff --git a/man/console.Rd b/man/console.Rd deleted file mode 100644 index d2280ed140e..00000000000 --- a/man/console.Rd +++ /dev/null @@ -1,34 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/console.R -\name{console} -\alias{console} -\title{The igraph console} -\usage{ -console() -} -\value{ -\code{NULL}, invisibly. -} -\description{ -The igraph console is a GUI window that shows what the currently running -igraph function is doing. -} -\details{ -The console can be started by calling the \code{console()} function. -Then it stays open, until the user closes it. - -Another way to start it to set the \code{verbose} igraph option to -\dQuote{tkconsole} via \code{igraph_options()}. Then the console (re)opens -each time an igraph function supporting it starts; to close it, set the -\code{verbose} option to another value. - -The console is written in Tcl/Tk and required the \code{tcltk} package. -} -\seealso{ -\code{\link[=igraph_options]{igraph_options()}} and the \code{verbose} option. -} -\author{ -Gabor Csardi \email{csardi.gabor@gmail.com} -} -\concept{console} -\keyword{graphs} diff --git a/man/dot-igraph.progress.Rd b/man/dot-igraph.progress.Rd deleted file mode 100644 index faf598c5c63..00000000000 --- a/man/dot-igraph.progress.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/console.R -\name{.igraph.progress} -\alias{.igraph.progress} -\title{igraph progress} -\usage{ -.igraph.progress(percent, message, clean = FALSE) -} -\arguments{ -\item{percent, message, clean}{Used internally by \code{.igraph.progress()} and \code{.igraph.status()}} -} -\description{ -igraph progress -} -\keyword{internal} diff --git a/man/dot-igraph.status.Rd b/man/dot-igraph.status.Rd deleted file mode 100644 index 2ae44620bb0..00000000000 --- a/man/dot-igraph.status.Rd +++ /dev/null @@ -1,12 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/console.R -\name{.igraph.status} -\alias{.igraph.status} -\title{igraph status} -\usage{ -.igraph.status(message) -} -\description{ -igraph status -} -\keyword{internal} diff --git a/man/igraph.console.Rd b/man/igraph.console.Rd deleted file mode 100644 index 6903d3c1bd7..00000000000 --- a/man/igraph.console.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/console.R -\name{igraph.console} -\alias{igraph.console} -\title{The igraph console} -\usage{ -igraph.console() -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -\code{igraph.console()} was renamed to \code{\link[=console]{console()}} to create a more -consistent API. -} -\keyword{internal} diff --git a/man/min_st_separators.Rd b/man/min_st_separators.Rd index 6a1924654d3..d8d56d30dc6 100644 --- a/man/min_st_separators.Rd +++ b/man/min_st_separators.Rd @@ -33,21 +33,13 @@ Note that the code below returns \verb{\{1, 3\}} despite its subset \code{{1}} b separator as well. This is because \verb{\{1, 3\}} is minimal with respect to separating vertices 2 and 4. -\if{html}{\out{
}}\preformatted{g <- make_graph(~ 0-1-2-3-4-1) +\if{html}{\out{
}}\preformatted{g <- make_graph(~ 0-1-2-3-4-1) min_st_separators(g) }\if{html}{\out{
}} -\if{html}{\out{
}}\preformatted{#> [[1]] -#> + 1/5 vertex, named: -#> [1] 1 -#> -#> [[2]] -#> + 2/5 vertices, named: -#> [1] 2 4 -#> -#> [[3]] -#> + 2/5 vertices, named: -#> [1] 1 3 +\if{html}{\out{
}}\preformatted{local_igraph_options(print.id = FALSE) +g <- make_graph(~ 0-1-2-3-4-1) +min_st_separators(g) }\if{html}{\out{
}} } diff --git a/src/rinterface_extra.c b/src/rinterface_extra.c index 461d2db0737..26b268e2aba 100644 --- a/src/rinterface_extra.c +++ b/src/rinterface_extra.c @@ -2382,11 +2382,10 @@ igraph_error_t R_igraph_progress_handler(const char *message, double percent, SEXP l3 = PROTECT(Rf_lang2(l1, l2)); SEXP rho = PROTECT(Rf_eval(l3, R_BaseEnv)); - SEXP l4 = PROTECT(Rf_install(".igraph.progress")); - SEXP l5 = PROTECT(Rf_ScalarReal(percent)); - SEXP l6 = PROTECT(Rf_ScalarString(PROTECT(Rf_mkChar(message)))); - SEXP l7 = PROTECT(Rf_lang3(l4, l5, l6)); - PROTECT(ec=Rf_eval(l7, rho)); + SEXP l4 = PROTECT(Rf_ScalarReal(percent)); + SEXP l5 = PROTECT(Rf_ScalarString(PROTECT(Rf_mkChar(message)))); + SEXP l6 = PROTECT(Rf_lang3(l3, l4, l5)); + PROTECT(ec=Rf_eval(l6, rho)); ecint=INTEGER(ec)[0]; UNPROTECT(11); @@ -2485,12 +2484,11 @@ SEXP R_igraph_finalizer(void) { SEXP l3 = PROTECT(Rf_lang2(l1, l2)); SEXP rho = PROTECT(Rf_eval(l3, R_BaseEnv)); - SEXP l4 = PROTECT(Rf_install(".igraph.progress")); - SEXP l5 = PROTECT(Rf_ScalarReal(0.0)); - SEXP l6 = PROTECT(Rf_ScalarString(PROTECT(Rf_mkChar("")))); - SEXP l7 = PROTECT(Rf_ScalarLogical(1)); - SEXP l8 = PROTECT(Rf_lang4(l4, l5, l6, l7)); - Rf_eval(l8, rho); + SEXP l4 = PROTECT(Rf_ScalarReal(0.0)); + SEXP l5 = PROTECT(Rf_ScalarString(PROTECT(Rf_mkChar("")))); + SEXP l6 = PROTECT(Rf_ScalarLogical(1)); + SEXP l7 = PROTECT(Rf_lang4(l3, l4, l5, l6)); + Rf_eval(l7, rho); UNPROTECT(11); return R_NilValue; }