gtk4: get break screen ui running
This commit is contained in:
parent
78c9570497
commit
0f902fe052
|
@ -1,5 +1,4 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.1 -->
|
|
||||||
<!--
|
<!--
|
||||||
~ Safe Eyes is a utility to remind you to take break frequently
|
~ Safe Eyes is a utility to remind you to take break frequently
|
||||||
~ to protect your eyes from eye strain.
|
~ to protect your eyes from eye strain.
|
||||||
|
@ -20,115 +19,84 @@
|
||||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-->
|
-->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.12"/>
|
<requires lib="gtk" version="4.0"/>
|
||||||
<object class="GtkWindow" id="window_main">
|
<object class="GtkWindow" id="window_main">
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="window_position">center</property>
|
|
||||||
<property name="hide_titlebar_when_maximized">True</property>
|
|
||||||
<property name="icon_name">safeeyes</property>
|
<property name="icon_name">safeeyes</property>
|
||||||
<property name="skip_taskbar_hint">True</property>
|
<property name="decorated">0</property>
|
||||||
<property name="urgency_hint">True</property>
|
<property name="deletable">0</property>
|
||||||
<property name="focus_on_map">False</property>
|
|
||||||
<property name="decorated">False</property>
|
|
||||||
<property name="deletable">False</property>
|
|
||||||
<property name="gravity">center</property>
|
|
||||||
<signal name="delete-event" handler="on_window_delete" swapped="no"/>
|
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<property name="child">
|
||||||
<object class="GtkGrid" id="grid1">
|
<object class="GtkGrid" id="grid1">
|
||||||
<property name="visible">True</property>
|
<property name="row_homogeneous">1</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="column_homogeneous">1</property>
|
||||||
<property name="row_homogeneous">True</property>
|
|
||||||
<property name="column_homogeneous">True</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="box_center_parent">
|
<object class="GtkBox" id="box_center_parent">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="spacing">10</property>
|
<property name="spacing">10</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkGrid" id="grid_central">
|
<object class="GtkGrid" id="grid_central">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="row_spacing">10</property>
|
<property name="row_spacing">10</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="img_break">
|
<object class="GtkImage" id="img_break">
|
||||||
<property name="visible">True</property>
|
<layout>
|
||||||
<property name="can_focus">False</property>
|
<property name="column">0</property>
|
||||||
|
<property name="row">0</property>
|
||||||
|
</layout>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkGrid" id="grid_parent">
|
<object class="GtkGrid" id="grid_parent">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
<property name="valign">center</property>
|
<property name="valign">center</property>
|
||||||
<property name="hexpand">True</property>
|
<property name="hexpand">1</property>
|
||||||
<property name="row_spacing">15</property>
|
<property name="row_spacing">15</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="lbl_message">
|
<object class="GtkLabel" id="lbl_message">
|
||||||
<property name="visible">True</property>
|
<property name="label" translatable="1">Hello World</property>
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="label" translatable="yes">Hello World</property>
|
|
||||||
<property name="justify">center</property>
|
<property name="justify">center</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="lbl_message"/>
|
<class name="lbl_message"/>
|
||||||
</style>
|
</style>
|
||||||
|
<layout>
|
||||||
|
<property name="column">0</property>
|
||||||
|
<property name="row">0</property>
|
||||||
|
<property name="column-span">3</property>
|
||||||
|
</layout>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">0</property>
|
|
||||||
<property name="width">3</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkAlignment" id="alignment_button">
|
<object class="GtkLabel" id="lbl_count">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
<property name="yscale">0.20000000298023224</property>
|
<property name="label" translatable="1">00</property>
|
||||||
<child>
|
<style>
|
||||||
<object class="GtkLabel" id="lbl_count">
|
<class name="lbl_count"/>
|
||||||
<property name="visible">True</property>
|
</style>
|
||||||
<property name="can_focus">False</property>
|
<layout>
|
||||||
<property name="label" translatable="yes">00</property>
|
<property name="column">1</property>
|
||||||
<style>
|
<property name="row">2</property>
|
||||||
<class name="lbl_count"/>
|
</layout>
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="left_attach">1</property>
|
|
||||||
<property name="top_attach">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="box_buttons">
|
<object class="GtkBox" id="box_buttons">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
<property name="spacing">50</property>
|
<property name="spacing">50</property>
|
||||||
<property name="homogeneous">True</property>
|
<property name="homogeneous">1</property>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
|
<layout>
|
||||||
|
<property name="column">1</property>
|
||||||
|
<property name="row">3</property>
|
||||||
|
</layout>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="left_attach">1</property>
|
|
||||||
<property name="top_attach">3</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
|
@ -151,89 +119,62 @@
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
</child>
|
</child>
|
||||||
|
<layout>
|
||||||
|
<property name="column">0</property>
|
||||||
|
<property name="row">1</property>
|
||||||
|
<property name="row-span">3</property>
|
||||||
|
</layout>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">1</property>
|
|
||||||
<property name="height">3</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="lbl_widget">
|
<object class="GtkLabel" id="lbl_widget">
|
||||||
<property name="visible">True</property>
|
<property name="vexpand">1</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="label" translatable="1">Widget</property>
|
||||||
<property name="label" translatable="yes">Widget</property>
|
|
||||||
<property name="yalign">0.25</property>
|
<property name="yalign">0.25</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="lbl_widget"/>
|
<class name="lbl_widget"/>
|
||||||
</style>
|
</style>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="expand">True</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="pack_type">end</property>
|
|
||||||
<property name="position">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
|
<layout>
|
||||||
|
<property name="column">0</property>
|
||||||
|
<property name="row">1</property>
|
||||||
|
<property name="row-span">2</property>
|
||||||
|
</layout>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">1</property>
|
|
||||||
<property name="height">2</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="box_top_panel">
|
<object class="GtkBox" id="box_top_panel">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkToolbar" id="toolbar">
|
<object class="GtkBox" id="toolbar">
|
||||||
<property name="visible">True</property>
|
<property name="css-classes">toolbar</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">0</property>
|
||||||
<property name="halign">end</property>
|
<property name="halign">end</property>
|
||||||
<property name="valign">start</property>
|
<property name="valign">start</property>
|
||||||
<property name="toolbar_style">icons</property>
|
|
||||||
<property name="icon_size">2</property>
|
|
||||||
<style>
|
<style>
|
||||||
<class name="toolbar"/>
|
<class name="toolbar"/>
|
||||||
</style>
|
</style>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="lbl_top">
|
<object class="GtkLabel" id="lbl_top">
|
||||||
<property name="visible">True</property>
|
<property name="vexpand">1</property>
|
||||||
<property name="can_focus">False</property>
|
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="expand">True</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<style>
|
<style>
|
||||||
<class name="box_top_panel"/>
|
<class name="box_top_panel"/>
|
||||||
</style>
|
</style>
|
||||||
|
<layout>
|
||||||
|
<property name="column">0</property>
|
||||||
|
<property name="row">0</property>
|
||||||
|
</layout>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
|
||||||
<property name="left_attach">0</property>
|
|
||||||
<property name="top_attach">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</property>
|
||||||
<style>
|
<style>
|
||||||
<class name="window_main"/>
|
<class name="window_main"/>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -25,6 +25,10 @@ import random
|
||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '4.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
from safeeyes import utility
|
from safeeyes import utility
|
||||||
|
|
||||||
|
|
||||||
|
@ -397,7 +401,8 @@ class TrayAction:
|
||||||
|
|
||||||
def get_icon(self):
|
def get_icon(self):
|
||||||
if self.system_icon:
|
if self.system_icon:
|
||||||
return self.__icon
|
image = Gtk.Image.new_from_icon_name(self.__icon)
|
||||||
|
return image
|
||||||
else:
|
else:
|
||||||
image = utility.load_and_scale_image(self.__icon, 16, 16)
|
image = utility.load_and_scale_image(self.__icon, 16, 16)
|
||||||
image.show()
|
image.show()
|
||||||
|
|
|
@ -74,5 +74,5 @@ def get_tray_action(break_obj):
|
||||||
if players:
|
if players:
|
||||||
return TrayAction.build("Pause media",
|
return TrayAction.build("Pause media",
|
||||||
tray_icon_path,
|
tray_icon_path,
|
||||||
Gtk.STOCK_MEDIA_PAUSE,
|
"media-playback-pause",
|
||||||
lambda: __pause_players(players))
|
lambda: __pause_players(players))
|
||||||
|
|
|
@ -131,5 +131,5 @@ def on_stop_break():
|
||||||
def get_tray_action(break_obj):
|
def get_tray_action(break_obj):
|
||||||
return TrayAction.build("Lock screen",
|
return TrayAction.build("Lock screen",
|
||||||
tray_icon_path,
|
tray_icon_path,
|
||||||
Gtk.STOCK_DIALOG_AUTHENTICATION,
|
"dialog-password",
|
||||||
__lock_screen)
|
__lock_screen)
|
||||||
|
|
|
@ -59,7 +59,9 @@ class BreakScreen:
|
||||||
# Initialize the theme
|
# Initialize the theme
|
||||||
css_provider = Gtk.CssProvider()
|
css_provider = Gtk.CssProvider()
|
||||||
css_provider.load_from_path(style_sheet_path)
|
css_provider.load_from_path(style_sheet_path)
|
||||||
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
|
||||||
|
display = Gdk.Display.get_default()
|
||||||
|
Gtk.StyleContext.add_provider_for_display(display, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||||
|
|
||||||
def initialize(self, config):
|
def initialize(self, config):
|
||||||
"""
|
"""
|
||||||
|
@ -152,22 +154,22 @@ class BreakScreen:
|
||||||
utility.start_thread(self.__lock_keyboard)
|
utility.start_thread(self.__lock_keyboard)
|
||||||
|
|
||||||
display = Gdk.Display.get_default()
|
display = Gdk.Display.get_default()
|
||||||
screen = display.get_default_screen()
|
monitors = display.get_monitors()
|
||||||
no_of_monitors = display.get_n_monitors()
|
logging.info("Show break screens in %d display(s)", len(monitors))
|
||||||
logging.info("Show break screens in %d display(s)", no_of_monitors)
|
|
||||||
|
|
||||||
for monitor_num in range(no_of_monitors):
|
i = 0
|
||||||
monitor = display.get_monitor(monitor_num)
|
|
||||||
|
for monitor in monitors:
|
||||||
monitor_gemoetry = monitor.get_geometry()
|
monitor_gemoetry = monitor.get_geometry()
|
||||||
x = monitor_gemoetry.x
|
x = monitor_gemoetry.x
|
||||||
y = monitor_gemoetry.y
|
y = monitor_gemoetry.y
|
||||||
|
|
||||||
builder = Gtk.Builder()
|
builder = Gtk.Builder()
|
||||||
builder.add_from_file(BREAK_SCREEN_GLADE)
|
builder.add_from_file(BREAK_SCREEN_GLADE)
|
||||||
builder.connect_signals(self)
|
|
||||||
|
|
||||||
window = builder.get_object("window_main")
|
window = builder.get_object("window_main")
|
||||||
window.set_title("SafeEyes-" + str(monitor_num))
|
window.connect("close-request", self.on_window_delete)
|
||||||
|
window.set_title("SafeEyes-" + str(i))
|
||||||
lbl_message = builder.get_object("lbl_message")
|
lbl_message = builder.get_object("lbl_message")
|
||||||
lbl_count = builder.get_object("lbl_count")
|
lbl_count = builder.get_object("lbl_count")
|
||||||
lbl_widget = builder.get_object("lbl_widget")
|
lbl_widget = builder.get_object("lbl_widget")
|
||||||
|
@ -176,15 +178,14 @@ class BreakScreen:
|
||||||
toolbar = builder.get_object("toolbar")
|
toolbar = builder.get_object("toolbar")
|
||||||
|
|
||||||
for tray_action in tray_actions:
|
for tray_action in tray_actions:
|
||||||
toolbar_button = None
|
# TODO: apparently, this would be better served with an icon theme + Gtk.button.new_from_icon_name
|
||||||
if tray_action.system_icon:
|
icon = tray_action.get_icon()
|
||||||
toolbar_button = Gtk.ToolButton.new_from_stock(tray_action.get_icon())
|
toolbar_button = Gtk.Button()
|
||||||
else:
|
toolbar_button.set_child(icon)
|
||||||
toolbar_button = Gtk.ToolButton.new(tray_action.get_icon(), tray_action.name)
|
|
||||||
tray_action.add_toolbar_button(toolbar_button)
|
tray_action.add_toolbar_button(toolbar_button)
|
||||||
toolbar_button.connect("clicked", lambda button, action: self.__tray_action(button, action), tray_action)
|
toolbar_button.connect("clicked", lambda button, action: self.__tray_action(button, action), tray_action)
|
||||||
toolbar_button.set_tooltip_text(_(tray_action.name))
|
toolbar_button.set_tooltip_text(_(tray_action.name))
|
||||||
toolbar.add(toolbar_button)
|
toolbar.append(toolbar_button)
|
||||||
toolbar_button.show()
|
toolbar_button.show()
|
||||||
|
|
||||||
# Add the buttons
|
# Add the buttons
|
||||||
|
@ -194,7 +195,7 @@ class BreakScreen:
|
||||||
btn_postpone.get_style_context().add_class('btn_postpone')
|
btn_postpone.get_style_context().add_class('btn_postpone')
|
||||||
btn_postpone.connect('clicked', self.on_postpone_clicked)
|
btn_postpone.connect('clicked', self.on_postpone_clicked)
|
||||||
btn_postpone.set_visible(True)
|
btn_postpone.set_visible(True)
|
||||||
box_buttons.pack_start(btn_postpone, True, True, 0)
|
box_buttons.append(btn_postpone)
|
||||||
|
|
||||||
if not self.strict_break:
|
if not self.strict_break:
|
||||||
# Add the skip button
|
# Add the skip button
|
||||||
|
@ -202,7 +203,7 @@ class BreakScreen:
|
||||||
btn_skip.get_style_context().add_class('btn_skip')
|
btn_skip.get_style_context().add_class('btn_skip')
|
||||||
btn_skip.connect('clicked', self.on_skip_clicked)
|
btn_skip.connect('clicked', self.on_skip_clicked)
|
||||||
btn_skip.set_visible(True)
|
btn_skip.set_visible(True)
|
||||||
box_buttons.pack_start(btn_skip, True, True, 0)
|
box_buttons.append(btn_skip)
|
||||||
|
|
||||||
# Set values
|
# Set values
|
||||||
if image_path:
|
if image_path:
|
||||||
|
@ -213,23 +214,14 @@ class BreakScreen:
|
||||||
self.windows.append(window)
|
self.windows.append(window)
|
||||||
self.count_labels.append(lbl_count)
|
self.count_labels.append(lbl_count)
|
||||||
|
|
||||||
# Set visual to apply css theme. It should be called before show method.
|
|
||||||
window.set_visual(window.get_screen().get_rgba_visual())
|
|
||||||
if self.context['desktop'] == 'kde':
|
if self.context['desktop'] == 'kde':
|
||||||
# Fix flickering screen in KDE by setting opacity to 1
|
# Fix flickering screen in KDE by setting opacity to 1
|
||||||
window.set_opacity(0.9)
|
window.set_opacity(0.9)
|
||||||
|
|
||||||
# In Unity, move the window before present
|
window.fullscreen_on_monitor(monitor)
|
||||||
window.move(x, y)
|
|
||||||
window.resize(monitor_gemoetry.width, monitor_gemoetry.height)
|
|
||||||
window.stick()
|
|
||||||
window.set_keep_above(True)
|
|
||||||
window.fullscreen_on_monitor(screen, monitor_num)
|
|
||||||
window.present()
|
window.present()
|
||||||
# In other desktop environments, move the window after present
|
|
||||||
window.move(x, y)
|
i = i + 1
|
||||||
window.resize(monitor_gemoetry.width, monitor_gemoetry.height)
|
|
||||||
logging.info("Moved break screen to Display[%d, %d]", x, y)
|
|
||||||
|
|
||||||
def __update_count_down(self, count):
|
def __update_count_down(self, count):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue