- Text Popup Style. Fixes #23
This commit is contained in:
parent
6b2c257086
commit
e3004b817d
3 changed files with 70 additions and 29 deletions
|
|
@ -4,6 +4,7 @@ import time
|
|||
import json
|
||||
import requests
|
||||
import logging
|
||||
import calendar
|
||||
|
||||
|
||||
class DiscordConnector:
|
||||
|
|
@ -84,6 +85,10 @@ class DiscordConnector:
|
|||
self.in_room.remove(userid)
|
||||
|
||||
def add_text(self, message):
|
||||
utc_time = time.strptime(
|
||||
message["timestamp"], "%Y-%m-%dT%H:%M:%S.%f%z")
|
||||
t = time.time()
|
||||
epoch_time = calendar.timegm(utc_time)
|
||||
un = message["author"]["username"]
|
||||
if "nick" in message and message['nick'] and len(message["nick"]) > 1:
|
||||
un = message["nick"]
|
||||
|
|
@ -95,6 +100,7 @@ class DiscordConnector:
|
|||
'content': self.get_message_from_message(message),
|
||||
'nick': un,
|
||||
'nick_col': ac,
|
||||
'time': epoch_time,
|
||||
})
|
||||
self.text_altered = True
|
||||
|
||||
|
|
@ -105,7 +111,8 @@ class DiscordConnector:
|
|||
new_message = {'id': message['id'],
|
||||
'content': self.get_message_from_message(message_in),
|
||||
'nick': message['nick'],
|
||||
'nick_col': message['nick_col']}
|
||||
'nick_col': message['nick_col'],
|
||||
'time': message['time']}
|
||||
self.text[idx] = new_message
|
||||
self.text_altered = True
|
||||
return
|
||||
|
|
@ -372,6 +379,8 @@ class DiscordConnector:
|
|||
self.voice_overlay.set_connection(self.last_connection)
|
||||
list_altered = False
|
||||
# Update text list
|
||||
if self.text_overlay.popup_style:
|
||||
self.text_altered = True
|
||||
if self.text_altered:
|
||||
self.text_overlay.set_text_list(self.text, self.text_altered)
|
||||
self.text_altered = False
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from gi.repository.GdkPixbuf import Pixbuf
|
|||
from gi.repository import Gtk, GLib, Gio, GdkPixbuf, Gdk, Pango, PangoCairo
|
||||
import cairo
|
||||
import logging
|
||||
import time
|
||||
|
||||
|
||||
class TextOverlayWindow(OverlayWindow):
|
||||
|
|
@ -40,32 +41,37 @@ class TextOverlayWindow(OverlayWindow):
|
|||
self.bg_col = bg_col
|
||||
self.redraw()
|
||||
|
||||
def set_popup_style(self, b):
|
||||
self.popup_style = b
|
||||
|
||||
def do_draw(self, context):
|
||||
self.context = context
|
||||
context.set_antialias(self.compositing)
|
||||
(w, h) = self.get_size()
|
||||
|
||||
# Make background transparent
|
||||
context.set_source_rgba(0.0, 0.0, 0.0, 0.4)
|
||||
# Don't layer drawing over each other, always replace
|
||||
self.col(self.bg_col)
|
||||
context.set_source_rgba(0.0, 0.0, 0.0, 0.0)
|
||||
context.paint()
|
||||
context.set_operator(cairo.OPERATOR_OVER)
|
||||
self.col(self.fg_col)
|
||||
|
||||
if not self.connected:
|
||||
return
|
||||
|
||||
long_string = ""
|
||||
sep = ""
|
||||
tnow = time.time()
|
||||
for line in self.content:
|
||||
col = "#fff"
|
||||
if 'nick_col' in line and line['nick_col']:
|
||||
col = line['nick_col']
|
||||
long_string = "%s\n<span foreground='%s'>%s</span>: %s" % (
|
||||
long_string,
|
||||
self.santize_string(col),
|
||||
self.santize_string(line["nick"]),
|
||||
self.santize_string(line["content"]))
|
||||
if not self.popup_style or tnow - line['time'] < 30:
|
||||
col = "#fff"
|
||||
if 'nick_col' in line and line['nick_col']:
|
||||
col = line['nick_col']
|
||||
long_string = "%s%s<span foreground='%s'>%s</span>: %s" % (
|
||||
long_string,
|
||||
sep,
|
||||
self.santize_string(col),
|
||||
self.santize_string(line["nick"]),
|
||||
self.santize_string(line["content"]))
|
||||
sep = '\n'
|
||||
if len(long_string) == 0:
|
||||
return
|
||||
layout = self.create_pango_layout(long_string)
|
||||
layout.set_markup(long_string, -1)
|
||||
attr = Pango.AttrList()
|
||||
|
|
@ -77,6 +83,14 @@ class TextOverlayWindow(OverlayWindow):
|
|||
"%s %s" % (self.text_font, self.text_size))
|
||||
layout.set_font_description(font)
|
||||
tw, th = layout.get_pixel_size()
|
||||
|
||||
# Don't layer drawing over each other, always replace
|
||||
self.col(self.bg_col)
|
||||
context.rectangle(0, -th + h, w, th)
|
||||
context.fill()
|
||||
context.set_operator(cairo.OPERATOR_OVER)
|
||||
self.col(self.fg_col)
|
||||
|
||||
context.move_to(0, -th + h)
|
||||
PangoCairo.show_layout(context, layout)
|
||||
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ class TextSettingsWindow(SettingsWindow):
|
|||
"text", "bg_col", fallback="[0.0,0.0,0.0,0.5]"))
|
||||
self.fg_col = json.loads(config.get(
|
||||
"text", "fg_col", fallback="[1.0,1.0,1.0,1.0]"))
|
||||
self.popup_style = config.getboolean(
|
||||
"text", "popup_style", fallback=False)
|
||||
|
||||
logging.info(
|
||||
"Loading saved channel %s" % (self.channel))
|
||||
|
|
@ -111,6 +113,7 @@ class TextSettingsWindow(SettingsWindow):
|
|||
self.floating, self.floating_x, self.floating_y, self.floating_w, self.floating_h)
|
||||
self.overlay.set_bg(self.bg_col)
|
||||
self.overlay.set_fg(self.fg_col)
|
||||
self.overlay.set_popup_style(self.popup_style)
|
||||
|
||||
def save_config(self):
|
||||
config = ConfigParser(interpolation=None)
|
||||
|
|
@ -130,6 +133,7 @@ class TextSettingsWindow(SettingsWindow):
|
|||
config.set("text", "channel", self.channel)
|
||||
config.set("text", "bg_col", json.dumps(self.bg_col))
|
||||
config.set("text", "fg_col", json.dumps(self.fg_col))
|
||||
config.set("text", "popup_style", "%s" % (int(self.popup_style)))
|
||||
|
||||
if self.font:
|
||||
config.set("text", "font", self.font)
|
||||
|
|
@ -146,6 +150,12 @@ class TextSettingsWindow(SettingsWindow):
|
|||
enabled.set_active(self.enabled)
|
||||
enabled.connect("toggled", self.change_enabled)
|
||||
|
||||
# Popup Style
|
||||
popup_style_label = Gtk.Label.new("Popup Style")
|
||||
popup_style = Gtk.CheckButton.new()
|
||||
popup_style.set_active(self.popup_style)
|
||||
popup_style.connect("toggled", self.change_popup_style)
|
||||
|
||||
# Font chooser
|
||||
font_label = Gtk.Label.new("Font")
|
||||
font = Gtk.FontButton()
|
||||
|
|
@ -235,21 +245,23 @@ class TextSettingsWindow(SettingsWindow):
|
|||
|
||||
box.attach(enabled_label, 0, 0, 1, 1)
|
||||
box.attach(enabled, 1, 0, 1, 1)
|
||||
box.attach(channel_label, 0, 1, 1, 1)
|
||||
box.attach(channel, 1, 1, 1, 1)
|
||||
box.attach(popup_style_label, 0, 1, 1, 1)
|
||||
box.attach(popup_style, 1, 1, 1, 1)
|
||||
box.attach(channel_label, 0, 2, 1, 1)
|
||||
box.attach(channel, 1, 2, 1, 1)
|
||||
|
||||
box.attach(font_label, 0, 2, 1, 1)
|
||||
box.attach(font, 1, 2, 1, 1)
|
||||
box.attach(fg_col_label, 0, 3, 1, 1)
|
||||
box.attach(fg_col, 1, 3, 1, 1)
|
||||
box.attach(bg_col_label, 0, 4, 1, 1)
|
||||
box.attach(bg_col, 1, 4, 1, 1)
|
||||
box.attach(align_label, 0, 5, 1, 5)
|
||||
box.attach(align_type_box, 1, 5, 1, 1)
|
||||
box.attach(monitor, 1, 6, 1, 1)
|
||||
box.attach(align_x, 1, 7, 1, 1)
|
||||
box.attach(align_y, 1, 8, 1, 1)
|
||||
box.attach(align_placement_button, 1, 9, 1, 1)
|
||||
box.attach(font_label, 0, 3, 1, 1)
|
||||
box.attach(font, 1, 3, 1, 1)
|
||||
box.attach(fg_col_label, 0, 4, 1, 1)
|
||||
box.attach(fg_col, 1, 4, 1, 1)
|
||||
box.attach(bg_col_label, 0, 5, 1, 1)
|
||||
box.attach(bg_col, 1, 5, 1, 1)
|
||||
box.attach(align_label, 0, 6, 1, 5)
|
||||
box.attach(align_type_box, 1, 6, 1, 1)
|
||||
box.attach(monitor, 1, 7, 1, 1)
|
||||
box.attach(align_x, 1, 8, 1, 1)
|
||||
box.attach(align_y, 1, 9, 1, 1)
|
||||
box.attach(align_placement_button, 1, 10, 1, 1)
|
||||
|
||||
self.add(box)
|
||||
|
||||
|
|
@ -342,6 +354,12 @@ class TextSettingsWindow(SettingsWindow):
|
|||
self.enabled = button.get_active()
|
||||
self.save_config()
|
||||
|
||||
def change_popup_style(self, button):
|
||||
self.overlay.set_popup_style(button.get_active())
|
||||
|
||||
self.popup_style = button.get_active()
|
||||
self.save_config()
|
||||
|
||||
def get_channel(self):
|
||||
return self.channel
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue