Switch some calls to gtk.util helper methods
This commit is contained in:
parent
6b5d559d7a
commit
c109db6eeb
|
@ -56,6 +56,7 @@ from gajim.common.exceptions import GajimGeneralException
|
||||||
from gajim.gtk.dialogs import *
|
from gajim.gtk.dialogs import *
|
||||||
from gajim.gtk.add_contact import AddNewContactWindow
|
from gajim.gtk.add_contact import AddNewContactWindow
|
||||||
from gajim.gtk.util import get_icon_name
|
from gajim.gtk.util import get_icon_name
|
||||||
|
from gajim.gtk.util import resize_window
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('gajim.dialogs')
|
log = logging.getLogger('gajim.dialogs')
|
||||||
|
@ -1559,7 +1560,7 @@ class DataFormWindow(Dialog):
|
||||||
Gtk.ResponseType.CANCEL), (Gtk.STOCK_OK, Gtk.ResponseType.OK)],
|
Gtk.ResponseType.CANCEL), (Gtk.STOCK_OK, Gtk.ResponseType.OK)],
|
||||||
on_response_ok=self.on_ok)
|
on_response_ok=self.on_ok)
|
||||||
self.set_resizable(True)
|
self.set_resizable(True)
|
||||||
gtkgui_helpers.resize_window(self, 600, 400)
|
resize_window(self, 600, 400)
|
||||||
self.dataform_widget = dataforms_widget.DataFormWidget()
|
self.dataform_widget = dataforms_widget.DataFormWidget()
|
||||||
self.dataform = dataforms.extend_form(node=form)
|
self.dataform = dataforms.extend_form(node=form)
|
||||||
self.dataform_widget.set_sensitive(True)
|
self.dataform_widget.set_sensitive(True)
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
from enum import IntEnum, unique
|
from enum import IntEnum
|
||||||
|
from enum import unique
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository import Gdk
|
from gi.repository import Gdk
|
||||||
|
@ -33,12 +34,19 @@ from gajim.common import app
|
||||||
from gajim.common import helpers
|
from gajim.common import helpers
|
||||||
from gajim.common import exceptions
|
from gajim.common import exceptions
|
||||||
from gajim.common.i18n import _
|
from gajim.common.i18n import _
|
||||||
from gajim.common.const import ShowConstant, KindConstant
|
from gajim.common.const import ShowConstant
|
||||||
|
from gajim.common.const import KindConstant
|
||||||
|
|
||||||
from gajim import conversation_textview
|
from gajim import conversation_textview
|
||||||
|
|
||||||
from gajim.gtk import util
|
from gajim.gtk.util import python_month
|
||||||
from gajim.gtk.util import python_month, gtk_month
|
from gajim.gtk.util import gtk_month
|
||||||
|
from gajim.gtk.util import resize_window
|
||||||
|
from gajim.gtk.util import move_window
|
||||||
|
from gajim.gtk.util import get_icon_name
|
||||||
|
from gajim.gtk.util import get_completion_liststore
|
||||||
|
from gajim.gtk.util import get_builder
|
||||||
|
|
||||||
from gajim.gtk.dialogs import ErrorDialog
|
from gajim.gtk.dialogs import ErrorDialog
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
|
@ -66,7 +74,7 @@ class HistoryWindow:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, jid=None, account=None):
|
def __init__(self, jid=None, account=None):
|
||||||
xml = util.get_builder('history_window.ui')
|
xml = get_builder('history_window.ui')
|
||||||
self.window = xml.get_object('history_window')
|
self.window = xml.get_object('history_window')
|
||||||
self.window.set_application(app.app)
|
self.window.set_application(app.app)
|
||||||
self.calendar = xml.get_object('calendar')
|
self.calendar = xml.get_object('calendar')
|
||||||
|
@ -137,10 +145,10 @@ class HistoryWindow:
|
||||||
else:
|
else:
|
||||||
self._load_history(None)
|
self._load_history(None)
|
||||||
|
|
||||||
util.resize_window(self.window,
|
resize_window(self.window,
|
||||||
app.config.get('history_window_width'),
|
app.config.get('history_window_width'),
|
||||||
app.config.get('history_window_height'))
|
app.config.get('history_window_height'))
|
||||||
util.move_window(self.window,
|
move_window(self.window,
|
||||||
app.config.get('history_window_x-position'),
|
app.config.get('history_window_x-position'),
|
||||||
app.config.get('history_window_y-position'))
|
app.config.get('history_window_y-position'))
|
||||||
|
|
||||||
|
@ -163,7 +171,7 @@ class HistoryWindow:
|
||||||
{key : (jid, account, nick_name, full_completion_name}
|
{key : (jid, account, nick_name, full_completion_name}
|
||||||
This is a generator and does pseudo-threading via idle_add().
|
This is a generator and does pseudo-threading via idle_add().
|
||||||
"""
|
"""
|
||||||
liststore = util.get_completion_liststore(
|
liststore = get_completion_liststore(
|
||||||
self.jid_entry.get_child())
|
self.jid_entry.get_child())
|
||||||
liststore.set_sort_column_id(1, Gtk.SortType.ASCENDING)
|
liststore.set_sort_column_id(1, Gtk.SortType.ASCENDING)
|
||||||
self.jid_entry.get_child().get_completion().connect(
|
self.jid_entry.get_child().get_completion().connect(
|
||||||
|
@ -183,8 +191,8 @@ class HistoryWindow:
|
||||||
completion_dict.update(
|
completion_dict.update(
|
||||||
helpers.get_contact_dict_for_account(account))
|
helpers.get_contact_dict_for_account(account))
|
||||||
|
|
||||||
muc_active_icon = util.get_icon_name('muc-active')
|
muc_active_icon = get_icon_name('muc-active')
|
||||||
online_icon = util.get_icon_name('online')
|
online_icon = get_icon_name('online')
|
||||||
|
|
||||||
keys = list(completion_dict.keys())
|
keys = list(completion_dict.keys())
|
||||||
# Move the actual jid at first so we load history faster
|
# Move the actual jid at first so we load history faster
|
||||||
|
|
|
@ -24,12 +24,14 @@ import os
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
from gajim import dialogs
|
from gajim import dialogs
|
||||||
from gajim import gtkgui_helpers
|
|
||||||
from gajim.common import app
|
from gajim.common import app
|
||||||
from gajim.common import helpers
|
from gajim.common import helpers
|
||||||
from gajim.common.i18n import _
|
from gajim.common.i18n import _
|
||||||
|
|
||||||
from gajim.gtk.util import get_builder
|
from gajim.gtk.util import get_builder
|
||||||
from gajim.gtk.util import get_icon_name
|
from gajim.gtk.util import get_icon_name
|
||||||
|
from gajim.gtk.util import move_window
|
||||||
from gajim.gtk.single_message import SingleMessageWindow
|
from gajim.gtk.single_message import SingleMessageWindow
|
||||||
from gajim.gtk.tooltips import NotificationAreaTooltip
|
from gajim.gtk.tooltips import NotificationAreaTooltip
|
||||||
|
|
||||||
|
@ -382,7 +384,7 @@ class StatusIcon:
|
||||||
if not win.get_property('visible'):
|
if not win.get_property('visible'):
|
||||||
win.show_all()
|
win.show_all()
|
||||||
if app.config.get('save-roster-position'):
|
if app.config.get('save-roster-position'):
|
||||||
gtkgui_helpers.move_window(win,
|
move_window(win,
|
||||||
app.config.get('roster_x-position'),
|
app.config.get('roster_x-position'),
|
||||||
app.config.get('roster_y-position'))
|
app.config.get('roster_y-position'))
|
||||||
if not app.config.get('roster_window_skip_taskbar'):
|
if not app.config.get('roster_window_skip_taskbar'):
|
||||||
|
@ -398,7 +400,7 @@ class StatusIcon:
|
||||||
win = app.interface.roster.window
|
win = app.interface.roster.window
|
||||||
if not win.get_property('visible') and app.config.get(
|
if not win.get_property('visible') and app.config.get(
|
||||||
'save-roster-position'):
|
'save-roster-position'):
|
||||||
gtkgui_helpers.move_window(win,
|
move_window(win,
|
||||||
app.config.get('roster_x-position'),
|
app.config.get('roster_x-position'),
|
||||||
app.config.get('roster_y-position'))
|
app.config.get('roster_y-position'))
|
||||||
app.interface.handle_event(account, jid, event.type_)
|
app.interface.handle_event(account, jid, event.type_)
|
||||||
|
|
|
@ -262,3 +262,12 @@ def convert_rgb_to_hex(rgb_string: str) -> str:
|
||||||
green = int(rgb.green * 255)
|
green = int(rgb.green * 255)
|
||||||
blue = int(rgb.blue * 255)
|
blue = int(rgb.blue * 255)
|
||||||
return '#%02x%02x%02x' % (red, green, blue)
|
return '#%02x%02x%02x' % (red, green, blue)
|
||||||
|
|
||||||
|
|
||||||
|
def get_monitor_scale_factor() -> int:
|
||||||
|
display = Gdk.Display.get_default()
|
||||||
|
monitor = display.get_primary_monitor()
|
||||||
|
if monitor is None:
|
||||||
|
log.warning('Could not determine scale factor')
|
||||||
|
return 1
|
||||||
|
return monitor.get_scale_factor()
|
||||||
|
|
|
@ -97,13 +97,6 @@ if os.name == 'nt':
|
||||||
|
|
||||||
from gajim.common import helpers
|
from gajim.common import helpers
|
||||||
|
|
||||||
def get_total_screen_geometry():
|
|
||||||
screen = Gdk.Screen.get_default()
|
|
||||||
window = Gdk.Screen.get_root_window(screen)
|
|
||||||
w, h = window.get_width(), window.get_height()
|
|
||||||
log.debug('Get screen geometry: %s %s', w, h)
|
|
||||||
return w, h
|
|
||||||
|
|
||||||
def add_image_to_button(button, icon_name):
|
def add_image_to_button(button, icon_name):
|
||||||
img = Gtk.Image()
|
img = Gtk.Image()
|
||||||
path_img = get_icon_path(icon_name)
|
path_img = get_icon_path(icon_name)
|
||||||
|
@ -153,55 +146,6 @@ def get_gtk_builder(file_name, widget=None):
|
||||||
builder.add_from_file(file_path)
|
builder.add_from_file(file_path)
|
||||||
return builder
|
return builder
|
||||||
|
|
||||||
def get_completion_liststore(entry):
|
|
||||||
"""
|
|
||||||
Create a completion model for entry widget completion list consists of
|
|
||||||
(Pixbuf, Text) rows
|
|
||||||
"""
|
|
||||||
completion = Gtk.EntryCompletion()
|
|
||||||
liststore = Gtk.ListStore(str, str)
|
|
||||||
|
|
||||||
render_pixbuf = Gtk.CellRendererPixbuf()
|
|
||||||
completion.pack_start(render_pixbuf, False)
|
|
||||||
completion.add_attribute(render_pixbuf, 'icon_name', 0)
|
|
||||||
|
|
||||||
render_text = Gtk.CellRendererText()
|
|
||||||
completion.pack_start(render_text, True)
|
|
||||||
completion.add_attribute(render_text, 'text', 1)
|
|
||||||
completion.set_property('text_column', 1)
|
|
||||||
completion.set_model(liststore)
|
|
||||||
entry.set_completion(completion)
|
|
||||||
return liststore
|
|
||||||
|
|
||||||
def move_window(window, x, y):
|
|
||||||
"""
|
|
||||||
Move the window, but also check if out of screen
|
|
||||||
"""
|
|
||||||
screen_w, screen_h = get_total_screen_geometry()
|
|
||||||
if x < 0:
|
|
||||||
x = 0
|
|
||||||
if y < 0:
|
|
||||||
y = 0
|
|
||||||
w, h = window.get_size()
|
|
||||||
if x + w > screen_w:
|
|
||||||
x = screen_w - w
|
|
||||||
if y + h > screen_h:
|
|
||||||
y = screen_h - h
|
|
||||||
window.move(x, y)
|
|
||||||
|
|
||||||
def resize_window(window, w, h):
|
|
||||||
"""
|
|
||||||
Resize window, but also checks if huge window or negative values
|
|
||||||
"""
|
|
||||||
screen_w, screen_h = get_total_screen_geometry()
|
|
||||||
if not w or not h:
|
|
||||||
return
|
|
||||||
if w > screen_w:
|
|
||||||
w = screen_w
|
|
||||||
if h > screen_h:
|
|
||||||
h = screen_h
|
|
||||||
window.resize(abs(w), abs(h))
|
|
||||||
|
|
||||||
def at_the_end(widget):
|
def at_the_end(widget):
|
||||||
"""Determines if a Scrollbar in a GtkScrolledWindow is at the end.
|
"""Determines if a Scrollbar in a GtkScrolledWindow is at the end.
|
||||||
|
|
||||||
|
@ -373,18 +317,6 @@ def get_fade_color(treeview, selected, focused):
|
||||||
return Gdk.RGBA(bg.red*p + fg.red*q, bg.green*p + fg.green*q,
|
return Gdk.RGBA(bg.red*p + fg.red*q, bg.green*p + fg.green*q,
|
||||||
bg.blue*p + fg.blue*q)
|
bg.blue*p + fg.blue*q)
|
||||||
|
|
||||||
def make_gtk_month_python_month(month):
|
|
||||||
"""
|
|
||||||
GTK starts counting months from 0, so January is 0 but Python's time start
|
|
||||||
from 1, so align to Python
|
|
||||||
|
|
||||||
NOTE: Month MUST be an integer.
|
|
||||||
"""
|
|
||||||
return month + 1
|
|
||||||
|
|
||||||
def make_python_month_gtk_month(month):
|
|
||||||
return month - 1
|
|
||||||
|
|
||||||
def make_pixbuf_grayscale(pixbuf):
|
def make_pixbuf_grayscale(pixbuf):
|
||||||
pixbuf2 = pixbuf.copy()
|
pixbuf2 = pixbuf.copy()
|
||||||
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
|
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
|
||||||
|
@ -805,11 +737,3 @@ def pango_to_css_weight(number):
|
||||||
if number > 900:
|
if number > 900:
|
||||||
return 900
|
return 900
|
||||||
return int(math.ceil(number / 100.0)) * 100
|
return int(math.ceil(number / 100.0)) * 100
|
||||||
|
|
||||||
def get_monitor_scale_factor():
|
|
||||||
display = Gdk.Display.get_default()
|
|
||||||
monitor = display.get_primary_monitor()
|
|
||||||
if monitor is None:
|
|
||||||
log.warning('Could not determine scale factor')
|
|
||||||
return 1
|
|
||||||
return monitor.get_scale_factor()
|
|
||||||
|
|
|
@ -42,6 +42,8 @@ from gajim.chat_control import ChatControl
|
||||||
|
|
||||||
from gajim.gtk.dialogs import YesNoDialog
|
from gajim.gtk.dialogs import YesNoDialog
|
||||||
from gajim.gtk.util import get_icon_name
|
from gajim.gtk.util import get_icon_name
|
||||||
|
from gajim.gtk.util import resize_window
|
||||||
|
from gajim.gtk.util import move_window
|
||||||
|
|
||||||
####################
|
####################
|
||||||
|
|
||||||
|
@ -185,7 +187,7 @@ class MessageWindow:
|
||||||
return sum(len(d) for d in self._controls.values())
|
return sum(len(d) for d in self._controls.values())
|
||||||
|
|
||||||
def resize(self, width, height):
|
def resize(self, width, height):
|
||||||
gtkgui_helpers.resize_window(self.window, width, height)
|
resize_window(self.window, width, height)
|
||||||
|
|
||||||
def _on_window_focus(self, widget, event):
|
def _on_window_focus(self, widget, event):
|
||||||
# on destroy() the window that was last focused gets the focus
|
# on destroy() the window that was last focused gets the focus
|
||||||
|
@ -1047,7 +1049,7 @@ class MessageWindowMgr(GObject.GObject):
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
gtkgui_helpers.move_window(win.window, pos[0], pos[1])
|
move_window(win.window, pos[0], pos[1])
|
||||||
|
|
||||||
def _mode_to_key(self, contact, acct, type_, resource=None):
|
def _mode_to_key(self, contact, acct, type_, resource=None):
|
||||||
if self.mode == self.ONE_MSG_WINDOW_NEVER:
|
if self.mode == self.ONE_MSG_WINDOW_NEVER:
|
||||||
|
@ -1284,7 +1286,7 @@ class MessageWindowMgr(GObject.GObject):
|
||||||
child = w.parent_paned.get_child2()
|
child = w.parent_paned.get_child2()
|
||||||
w.parent_paned.remove(child)
|
w.parent_paned.remove(child)
|
||||||
self.parent_win.lookup_action('show-roster').set_enabled(False)
|
self.parent_win.lookup_action('show-roster').set_enabled(False)
|
||||||
gtkgui_helpers.resize_window(w.window,
|
resize_window(w.window,
|
||||||
app.config.get('roster_width'),
|
app.config.get('roster_width'),
|
||||||
app.config.get('roster_height'))
|
app.config.get('roster_height'))
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ from gajim.common import ged
|
||||||
from gajim.common.i18n import _
|
from gajim.common.i18n import _
|
||||||
|
|
||||||
from gajim.gtk.util import get_icon_name
|
from gajim.gtk.util import get_icon_name
|
||||||
|
from gajim.gtk.util import get_monitor_scale_factor
|
||||||
|
from gajim.gtk.util import get_total_screen_geometry
|
||||||
|
|
||||||
log = logging.getLogger('gajim.notify')
|
log = logging.getLogger('gajim.notify')
|
||||||
|
|
||||||
|
@ -172,7 +174,7 @@ class Notification:
|
||||||
app.interface.roster.popup_notification_windows.append(instance)
|
app.interface.roster.popup_notification_windows.append(instance)
|
||||||
return
|
return
|
||||||
|
|
||||||
scale = gtkgui_helpers.get_monitor_scale_factor()
|
scale = get_monitor_scale_factor()
|
||||||
icon_pixbuf = gtkgui_helpers.gtk_icon_theme.load_icon_for_scale(
|
icon_pixbuf = gtkgui_helpers.gtk_icon_theme.load_icon_for_scale(
|
||||||
icon_name, 48, scale, 0)
|
icon_name, 48, scale, 0)
|
||||||
|
|
||||||
|
@ -300,7 +302,7 @@ class PopupNotificationWindow:
|
||||||
window_width, self.window_height = self.window.get_size()
|
window_width, self.window_height = self.window.get_size()
|
||||||
app.interface.roster.popups_notification_height += self.window_height
|
app.interface.roster.popups_notification_height += self.window_height
|
||||||
pos_x = app.config.get('notification_position_x')
|
pos_x = app.config.get('notification_position_x')
|
||||||
screen_w, screen_h = gtkgui_helpers.get_total_screen_geometry()
|
screen_w, screen_h = get_total_screen_geometry()
|
||||||
if pos_x < 0:
|
if pos_x < 0:
|
||||||
pos_x = screen_w - window_width + pos_x + 1
|
pos_x = screen_w - window_width + pos_x + 1
|
||||||
pos_y = app.config.get('notification_position_y')
|
pos_y = app.config.get('notification_position_y')
|
||||||
|
@ -337,7 +339,7 @@ class PopupNotificationWindow:
|
||||||
current_index += 1
|
current_index += 1
|
||||||
window_width, window_height = window_instance.window.get_size()
|
window_width, window_height = window_instance.window.get_size()
|
||||||
app.interface.roster.popups_notification_height += window_height
|
app.interface.roster.popups_notification_height += window_height
|
||||||
screen_w, screen_h = gtkgui_helpers.get_total_screen_geometry()
|
screen_w, screen_h = get_total_screen_geometry()
|
||||||
window_instance.window.move(screen_w - window_width,
|
window_instance.window.move(screen_w - window_width,
|
||||||
screen_h - \
|
screen_h - \
|
||||||
app.interface.roster.popups_notification_height)
|
app.interface.roster.popups_notification_height)
|
||||||
|
|
|
@ -83,6 +83,8 @@ from gajim.gtk.history import HistoryWindow
|
||||||
from gajim.gtk.accounts import AccountsWindow
|
from gajim.gtk.accounts import AccountsWindow
|
||||||
from gajim.gtk.tooltips import RosterTooltip
|
from gajim.gtk.tooltips import RosterTooltip
|
||||||
from gajim.gtk.util import get_icon_name
|
from gajim.gtk.util import get_icon_name
|
||||||
|
from gajim.gtk.util import resize_window
|
||||||
|
from gajim.gtk.util import move_window
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger('gajim.roster')
|
log = logging.getLogger('gajim.roster')
|
||||||
|
@ -2373,7 +2375,7 @@ class RosterWindow:
|
||||||
def on_message_window_delete(self, win_mgr, msg_win):
|
def on_message_window_delete(self, win_mgr, msg_win):
|
||||||
if app.config.get('one_message_window') == 'always_with_roster':
|
if app.config.get('one_message_window') == 'always_with_roster':
|
||||||
self.show_roster_vbox(True)
|
self.show_roster_vbox(True)
|
||||||
gtkgui_helpers.resize_window(self.window,
|
resize_window(self.window,
|
||||||
app.config.get('roster_width'),
|
app.config.get('roster_width'),
|
||||||
app.config.get('roster_height'))
|
app.config.get('roster_height'))
|
||||||
|
|
||||||
|
@ -5704,11 +5706,11 @@ class RosterWindow:
|
||||||
if len(app.connections) < 2:
|
if len(app.connections) < 2:
|
||||||
# Do not merge accounts if only one exists
|
# Do not merge accounts if only one exists
|
||||||
self.regroup = False
|
self.regroup = False
|
||||||
gtkgui_helpers.resize_window(self.window,
|
resize_window(self.window,
|
||||||
app.config.get('roster_width'),
|
app.config.get('roster_width'),
|
||||||
app.config.get('roster_height'))
|
app.config.get('roster_height'))
|
||||||
if app.config.get('save-roster-position'):
|
if app.config.get('save-roster-position'):
|
||||||
gtkgui_helpers.move_window(self.window,
|
move_window(self.window,
|
||||||
app.config.get('roster_x-position'),
|
app.config.get('roster_x-position'),
|
||||||
app.config.get('roster_y-position'))
|
app.config.get('roster_y-position'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue