I am using Leaflet-routing-machine,
I added the error control to my map like this :
L.Routing.errorControl(this.control).addTo(map);
for style I used this :
.leaflet-routing-error {
width: 320px;
background-color: rgb(238, 153, 164);
padding-top: 4px;
transition: all 0.2s ease;
box-sizing: border-box;
}
this is what I got :
Ididn't find a lot of explanations about. Have anyone know how to customise this more, change language, hide/show... ?
After reading this source code
you can redefine the header and the fromat message function
L.Routing.errorControl(control, {
header: 'Routing error',
formatMessage(error) {
if (error.status < 0) {
return 'Calculating the route caused an error. Technical description follows: <code><pre>' +
error.message + '</pre></code';
} else {
return 'The route could not be calculated. ' +
error.message;
}
}
}).addTo(map);
I believe that in your control you can redefine this two options
also you may be able to use the leaflet element with classes leaflet-bar leaflet-routing-error and inject more html code on it as they do to create the alert
var L = require('leaflet');
onAdd: function() {
var header,
message;
this._element = L.DomUtil.create('div', 'leaflet-bar leaflet-routing-error');
this._element.style.visibility = 'hidden';
header = L.DomUtil.create('h3', null, this._element);
message = L.DomUtil.create('span', null, this._element);
header.innerHTML = this.options.header;
return this._element;
}
so retrieving the div of class or id leaflet-routing-error and injecting on it your desired html component template should be fine
I have the following code that works fine to set background and foreground colors for a GtkTextview:
static void
setColor(GtkWidget * widget) {
auto style_context = gtk_widget_get_style_context (widget);
gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_VIEW );
auto css_provider = gtk_css_provider_new();
GError *error=NULL;
auto data = g_strdup_printf("\
* {\
background-color: black;\
color: white;\
}\
*:selected {\
background-color: blue;\
color: yellow;\
}\
");
gtk_css_provider_load_from_data (css_provider, data, -1, &error);
g_free(data);
if (error){
ERROR("gtk_css_provider_load_from_data: %s\n", error->message);
g_error_free(error);
return;
}
gtk_style_context_add_provider (style_context,
GTK_STYLE_PROVIDER(css_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
The result is that both normal and selected text color have black background and white foreground.
Why doesn't the selected text appear in yellow/blue?
Any pointer to an example file would be much appreciated.
Figured it out. The lack of any tutorials or example led me search the gtk source code for answers. A very complete css file is in the Adwaita theme (gtk-contained.css). From looking through that and a bit of experimenting, the following code will set the foreground and background colors for normal and selected text as specified.
auto data = g_strdup_printf("\
textview text {\
background-color: black;\
color: white;\
}\
.view text selection {\
background-color: blue;\
color: yellow;\
}\
");
The main problem was using the "*". In that same file there is a comment which reads "Wildcards ar bad and troublesome, use them with car, or better, just don't. Everytime a wildcard is used a kitten dies, painfully."
I'm using glade3 to develop a simple app on windows. The official reference manual seems out of date, so I use the gtk-function to create the Listview and put the MySQL-Query result under the field rows. Need help about create the listview by glade3 not by the codes.
Thanks anymore!
My code:
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
#include "mysql.h"
#define HOST "localhost"
#define USERNAME "root"
#define PASSWORD ""
#define DATABASE "student"
enum ListCols
{
LIST_NUM,
LIST_NAME,
LIST_CHECKED,
LIST_CNT
};
int main (int argc, char *argv[])
{
GtkWidget* win;
GtkWidget* vbox ;
GtkWidget* statusbar ;
GtkTreeView* tree;
GtkTreeView* list;
GtkTreeStore* tree_store;
GtkListStore* list_store;
GtkTreeIter iter;
GtkTreeIter iter_child;
GtkCellRenderer* renderer;
GtkTreeViewColumn* column;
GtkTreeSelection* select;
MYSQL my_connection;
MYSQL_RES *res_ptr;
MYSQL_FIELD *field;
MYSQL_ROW result_row;
int res;
int row, col;
int i, j;
char * sql = "select * from person;";
gtk_init (&argc, &argv);
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (win), "QueryData");
gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
gtk_widget_set_size_request(win, 480, 480);
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_add (GTK_CONTAINER (win), vbox);
list = gtk_tree_view_new();
list_store = gtk_list_store_new(LIST_CNT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_BOOLEAN);
mysql_init(&my_connection);
if (mysql_real_connect(&my_connection, HOST, USERNAME, PASSWORD,DATABASE, 0, NULL, CLIENT_FOUND_ROWS))
{
printf("Query data successfully!\n");
mysql_query(&my_connection, "set names utf8");
res = mysql_query(&my_connection, sql);
if (res)
{
printf("Error: mysql_query !\n");
mysql_close(&my_connection);
}
else
{
res_ptr = mysql_store_result(&my_connection);
if (res_ptr)
{
col = mysql_num_fields(res_ptr);
row = mysql_num_rows(res_ptr) + 1;
printf("%d lines queried\n", row);
for (i = 0; field = mysql_fetch_field(res_ptr); i++)
printf("%s ", field->name);
printf("\n");
for (i = 1; i < row; i++)
{
result_row = mysql_fetch_row(res_ptr);
gtk_list_store_append(list_store, &iter);
gtk_list_store_set(list_store, &iter,
LIST_NUM, result_row[0],
LIST_NAME, result_row[2],
LIST_CHECKED, FALSE, -1);
}
}
mysql_close(&my_connection);
}
}
else
printf("Fail to query data!\n");
for (int k = 0; k < 3; k++)
gtk_tree_view_set_model(list, list_store);
g_object_unref(list_store);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Name", renderer,
"text", LIST_NUM, NULL);
column = gtk_tree_view_append_column(list, column);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Age", renderer,
"text", LIST_NAME, NULL);
column = gtk_tree_view_append_column(list, column);
renderer = gtk_cell_renderer_toggle_new();
column = gtk_tree_view_column_new_with_attributes("PersonInfo", renderer,
"active", LIST_CHECKED, NULL);
column = gtk_tree_view_append_column(list, column);
gtk_box_pack_start(vbox, list, TRUE, TRUE, 1);
g_signal_connect (win, "destroy", gtk_main_quit, NULL);
gtk_widget_show_all (win);
gtk_main ();
return 0;
}
First of all you have to create a container to hold the treeview. If your using a grid, you can use a ScrolledWindow for example. In this example I just put it directly in the window container. Drag the TreeView on the window container:
Then a dialog asks you for the corresponding treestore:
Press on the pen and paper icon to open another dialog. Then press on "new".
This will get you back to the first dialog, with the newly created TreeStore already filled into the field. You can just press "Create":
Then you can start creating columns for the TreeStore. I created on for the Name (gchararray) and one for the Age (gint):
After that you can add data to the TreeStore:
Finally you still have to add columns to the TreeView. That is done by clicking on the TreeView --> click edit --> go to Hierarchy tab --> Add as many columns as you need.
Don't forget to also load the liststore from the Glade file, otherwise your data will not be present, when you run the program from the code.
Let's say you already have a container and you want to add a tree view into it.
To do that, you look at the "Control and Display" category of widgets, and locate "tree view". If you can't find it, or can't identify the icon, try hovering each icon until you find it.
Click on the icon, then click on the container that you wish to add it to. This will immediately cause a dialog box to occur, asking you to link it with a tree model. You can click the pencil icon, then click "New" to create a list store.
Alternatively, you can create a list store or tree store first. In the widget selection side panel, look under "Miscellaneous". (Between "Composite Widgets" and "Deprecated".) Locate list store or tree store, and click on it to create it. Now if you create the tree view (using the method above), you can choose this tree store / list store as your model.
According to the gtk documentation you can create a combobox with:
GtkWidget * gtk_combo_box_new ()
GtkWidget * gtk_combo_box_new_with_entry ()
GtkWidget * gtk_combo_box_new_with_model ()
GtkWidget * gtk_combo_box_new_with_model_and_entry ()
GtkWidget * gtk_combo_box_new_with_area ()
GtkWidget * gtk_combo_box_new_with_area_and_entry ()
I have found a lot of examples for the gtk_combo_box_new_with_model but I can't find anything related to the use of gtk_combo_box_new_with_area .
The langage used doesn't matter.
something like (pygobject):
from gi.repository import Gtk
area = Gtk.CellAreaBox()
combo = Gtk.ComboBox.new_with_area(area=area)
cell = Gtk.CellRendererText()
area.pack_start(cell, True, True, True)
you can add more CellRenderers to the box (which is a Gtk.Box) and do whatever you need to do with those.
I'm using Vala with GTK+ and now I'm trying to add custom CSS to specified widget.
I can add fe. backgroudn to GtkWidget but not for #sidebar
#sidebar { //It doesn't work
color: white;
}
GtkWindow { // It works
background-color: red;
}
I'm adding class to widget like that:
sidebar = new Gtk.Label("Hello");
sidebar.set_name("sidebar");
And it's changes color to GtkWindow, but not for this label.
Any ideas?
I haven't programmed in Vala, but you should add class to StyleContext.
This is in C
sidebar = gtk_label_new ("Hello');
gtk_style_context_add_class ( gtk_widget_get_style_context ("mysidebar"), sidebar);
Also, style "sidebar", is already defined in GtkStyle. You should change the "sidebar" in CSS into something else (sidebar is used by views, toolbar etc)
But if you persist, the syntax should be:
.mysidebar {
#anything
}