Я пытаюсь создавать апплеты для Linux mint. Я впервые занимаюсь созданием приложений, раньше я был веб-разработчиком, поэтому у меня есть представление о JavaScript. На данный момент я создал очень простой апплет с пунктом контекстного меню под названием «Настроить...».
Постановка проблемы:
Приложение St.bin несколько загружено и работающий. Но CSS не загружается должным образом. Позвольте мне представить вам полный класс этого окна настройки контекстного меню
Код: Выделить всё
const St = imports.gi.St;
const Clutter = imports.gi.Clutter;
const Main = imports.ui.main;
const Gio = imports.gi.Gio;
const Gdk = imports.gi.Gdk;
class ConfigureContextMenuWindow {
//Initializer
constructor(metadata) {
this.metadata = metadata
this.path = metadata.path
this.window = new St.Bin({
style_class: "config-window",
reactive: true,
visible: false,
x_align: Clutter.ActorAlign.CENTER,
y_align: Clutter.ActorAlign.CENTER,
});
// this.window.set_style("background-color: yellow; padding: 20px;");
this.layout = new St.BoxLayout({
vertical: true,
style_class: "config-window-content",
});
const titleLabel = new St.Label({ text: "Theme Configuration" });
this.layout.add_child(titleLabel);
const closeButton = new St.Button({
label: "Close",
style_class: "config-window-button",
});
// closeButton.set_style("background-color: red; color: white;");
closeButton.connect("clicked", () => this.hide());
this.layout.add_child(closeButton);
this.window.set_child(this.layout);
Main.uiGroup.add_child(this.window);
this._loadCSS();
}
_loadCSS() {
const file = Gio.File.new_for_path(`${this.path}/ui/configureContextMenuWindowStyle.css`);
const content = file.load_contents(null)[1].toString();
const cssProvider = new Gtk.CssProvider();
cssProvider.load_from_data(content, content.length, null);
Gtk.StyleContext.add_provider_for_screen(
Gdk.Screen.get_default(),
cssProvider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
}
// Show the window
show() {
this.window.visible = true;
}
// Hide the window
hide() {
this.window.visible = false;
}
}
// Export the class
module.exports = ConfigureContextMenuWindow;
Код: Выделить всё
/* Style for the entire config window */
.config-window {
background-color: yellow;
border-radius: 10px;
padding: 20px;
width: 300px;
height: 200px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
/* Style for the close button */
.config-window-button {
background-color: red;
color: white;
border-radius: 5px;
padding: 10px;
margin-top: 20px;
cursor: pointer;
}
/* Style for the title label */
.config-window-content {
padding: 10px;
font-size: 16px;
text-align: center;
}
Я добавил файл configureContextMenuWindowStyle.css в его путь.
Я пробовал связать файл CSS с помощью Gdk и Джо
Что ожидалось:
Ожидали, что к этому окну будут применены стили, но оно не было обновлено.
Возникшие проблемы:
В Melange я получаю сообщение об ошибке, что ширина не определена
но метод set_style работает правильно.
Любая помощь будет очень признательна
Подробнее здесь: https://stackoverflow.com/questions/792 ... innamon-22
Мобильная версия