代码拉取完成,页面将自动刷新
/* Wrapper functions for and interface to Tcl/Tk. Thanks to Python!
Tk4cpp provides classes which allow the display, positioning and
control of widgets. Toplevel widgets are Tk and Toplevel. Other
widgets are Frame, Label, Entry, Text, Canvas, Button, Radiobutton,
Checkbutton, Scale, Listbox, Scrollbar, OptionMenu, Spinbox
LabelFrame and PanedWindow.
Widgets are positioned with one of the geometry managers Place, Pack
or Grid. These managers can be called with methods place, pack, grid
available in every Widget.
Actions are bound to events by resources (e.g. keyword argument
command) or with the method bind.
Example (Hello, World):
#include "tk4cpp.hpp"
using namespace tk4cpp::constants;
int main()
{
tk4cpp::initialize();
auto tk = tk4cpp::Tk(NULL);
auto frame = tk4cpp::Frame(tk, "-relief", RIDGE, "-borderwidth", S(2));
frame.pack("-fill", BOTH, "-expand", S(1));
auto label = tk4cpp::Label(frame, "-text", "Hello, World");
label.pack("-fill", X, "-expand", S(1));
auto button = tk4cpp::Button(frame,"-text","Exit","-command",S(tk.destroy));
button.pack("-side", Bottom);
tk.mainloop();
tk4cpp::finalize();
return 0;
}
*/
#ifndef TK4CPP_HEADER
#define TK4CPP_HEADER
#include "tk4cpp.constants.hpp"
#include "tk4cpp._tk4cpp.hpp"
#define LAMBDA (std::vector<_tk4cpp::Object>&argv)->_tk4cpp::Object
namespace tk4cpp {
using sint = _tk4cpp::sint;
using uint = _tk4cpp::uint;
using TkApp = _tk4cpp::TkApp;
using Object = _tk4cpp::Object;
using Id = _tk4cpp::Id;
using _Func = _tk4cpp::_Func;
using Func = _tk4cpp::Func;
template <class... Us>
std::vector<Object> readargs(Us... a);
using RuntimeError = _tk4cpp::RuntimeError;
class Tk;
class Misc;
static bool _support_default_root = true;
static Misc* _default_root = NULL;
/* Inhibit setting of default root window.
Call this function to inhibit that the first instance of
Tk is used for windows without an explicit parent window.
*/
void NoDefaultRoot();
Misc* _get_default_root(std::string what = "");
static uint _varnum = 0;
/* Internal class. Stores function to call when some user
defined Tcl function is called e.g. after an event occurred. */
class CallWrapper {
public:
Func func;
Func subst;
Misc* widget;
// Store FUNC, SUBST and WIDGET as members.
CallWrapper(Func func, Func subst, Misc* widget);
// Apply first function SUBST to arguments, than FUNC.
Object operator()(std::vector<_tk4cpp::Object> args);
};
/* Class to define value holders for e.g. buttons.
Subclasses StringVar, IntVar, DoubleVar, BooleanVar are specializations
that constrain the type of the value returned from get(). */
class Variable {
public:
static std::string _default;
Tk* _root = NULL;
TkApp* _tk = NULL;
std::string _name;
std::vector<std::string> _tclCommands;
/* Construct a variable
MASTER can be given as master widget.
VALUE is an optional value (defaults to "")
NAME is an optional Tcl name (defaults to PY_VARnum).
If NAME matches an existing variable and VALUE is omitted
then the existing value is retained.
*/
Variable(Misc* master, Object value = {}, std::string name = "");
// Unset the variable in Tcl.
~Variable();
// Return the name of the variable in Tcl.
operator std::string();
// Set the variable to VALUE.
void set(Object value);
void initialize(Object value);
// Return value of variable.
Object get();
std::string _register(Func callback);
/* Define a trace callback for the variable.
Mode is one of "read", "write", "unset", or a list or tuple of
such strings.
Callback must be a function which is called when the variable is
read, written or unset.
Return the name of the callback. */
std::string trace_add(std::string mode, Func callback);
/* Delete the trace callback for a variable.
Mode is one of "read", "write", "unset" or a list or tuple of
such strings. Must be same as were specified in trace_add().
cbname is the name of the callback returned from trace_add(). */
void trace_remove(std::string mode, std::string cbname);
// Return all trace callback information.
void trace_info();
};
/* Internal class.
Base class which defines methods common for interior widgets. */
class Misc {
public:
TkApp* tk;
// used for generating child widget names
int _last_child_ids = -1;
// XXX font command?
std::vector<std::string> _tclCommands;
Id _w;
/* Internal function.
Delete all Tcl commands created for this widget in the Tcl interpreter. */
void destroy() {
if (this->_tclCommands.size() != 0) {
for (const std::string& name : this->_tclCommands) {
this->tk->deletecommand(name);
}
this->_tclCommands = {};
}
}
/* Internal function.
Delete the Tcl command provided in NAME. */
void deletecommand(std::string name) {
this->deletecommand(name);
for (uint i = 0; i < this->_tclCommands.size(); i++) {
if (this->_tclCommands[i] == name) {
this->_tclCommands.erase(this->_tclCommands.begin() + i);
}
}
}
/* Set Tcl internal variable, whether the look and feel
should adhere to Motif.
A parameter of 1 means adhere to Motif (e.g. no color
change if mouse passes over slider). */
bool tk_strictMotif() {
return this->tk->boolean_fromobj(this->tk->call({ "set","tk_strictMotif" }));
}
/* Set Tcl internal variable, whether the look and feel
should adhere to Motif.
Returns the set value. */
bool tk_strictMotif(bool boolean) {
return this->tk->boolean_fromobj(this->tk->call({ "set","tk_strictMotif",std::to_string(boolean)}));
}
// Change the color scheme to light brown as used in Tk 3.6 and before.
void tk_bisque() {
this->tk->call({ "tk_bisque" });
}
/* Set a new color scheme for all widget elements.
A single color as argument will cause that all colors of Tk
widget elements are derived from this.
Alternatively several keyword parameters and its associated
colors can be given. The following keywords are valid:
activeBackground, foreground, selectColor,
activeForeground, highlightBackground, selectBackground,
background, highlightColor, selectForeground,
disabledForeground, insertBackground, troughColor. */
template <class ... Us>
void tk_setPalette(Us... args) {
std::vector<Object> v;
v = { "tk_setPalette" };
std::vector<Object> argv = readargs(args...);;
for (const auto& i : argv) v.push_back(i);
this->tk->call(v);
}
/* Wait until the variable is modified.
A parameter of type IntVar, StringVar, DoubleVar or
BooleanVar must be given. */
void wait_variable(std::string name = "CPP_VAR") {
this->tk->call({ "tkwait","variable",name });
}
void waitvar(std::string name = "CPP_VAR") {
wait_variable(name);
}
// XXX b/w compat
// Wait until this is destroyed.
void wait_window() {
this->tk->call({ "tkwait","window",std::string(this->_w) });
}
// Wait until a WIDGET is destroyed.
void wait_window(Misc* window) {
this->tk->call({ "tkwait","window",std::string(window->_w) });
}
/* Wait until the visibility of this changes
(e.g. this appears). */
void wait_visibility() {
this->tk->call({ "tkwait","window",std::string(this->_w) });
}
/* Wait until the visibility of a WIDGET changes
(e.g. it appears). */
void wait_visibility(Misc* window) {
this->tk->call({ "tkwait","window",std::string(window->_w) });
}
// Set Tcl variable NAME to VALUE.
void setvar(std::string name = "CPP_VAR", Object value = "1") {
this->tk->setvar(name, value);
}
// Return value of Tcl variable NAME.
Object getvar(std::string name = "CPP_VAR") {
return this->tk->getvar(name);
}
};
class Tk : public Misc {
public:
template <class ... Us>
Tk(Misc* tk, Us... args) {
this->tk = tk->tk;
this->_w = this->tk->newid();
std::vector<Object> v;
v = { "toplevel", std::string(this->_w) };
std::vector<Object> argv = readargs(args...);
for (const auto& i : argv) v.push_back(i);
this->tk->call(v);
}
};
class Toplevel : public Misc {
public:
template <class ... Us>
Toplevel(Misc* tk, Us... args) {
this->tk = tk->tk;
this->_w = this->tk->newid();
std::vector<Object> v;
v = { "toplevel", std::string(this->_w) };
std::vector<Object> argv = readargs(args...);
for (const auto& i : argv) v.push_back(i);
this->tk->call(v);
}
};
}
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。