Added basic copy/paste functionality for individual records.

pull/65/head
Christian Jacobs 2018-02-04 23:15:57 +00:00
rodzic 7a162b2a2d
commit 946f03d95f
4 zmienionych plików z 74 dodań i 2 usunięć

Wyświetl plik

@ -20,7 +20,7 @@
from gi import require_version
require_version('Gtk', '3.0')
require_version('PangoCairo', '1.0')
from gi.repository import Gtk, GdkPixbuf
from gi.repository import Gtk, Gdk, GdkPixbuf
import argparse
try:
import configparser
@ -94,11 +94,15 @@ class PyQSO:
self.logbook = Logbook(self)
self.toolbox = Toolbox(self)
# Set up menu and toolbar. These classes depend on the Logbook and Toolbox class.
# Set up the menu and toolbar. These classes depend on the Logbook and Toolbox class.
self.menu = Menu(self)
self.popup = Popup(self)
self.toolbar = Toolbar(self)
# Clipboard for copy/paste operations.
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
# Show the main window.
self.window.show_all()
if(have_config):

Wyświetl plik

@ -20,6 +20,7 @@
from gi.repository import Gtk
import logging
import sqlite3 as sqlite
import json
from os.path import expanduser
try:
import configparser
@ -1068,6 +1069,49 @@ class Logbook:
return
def copy_callback(self, widget=None, path=None):
""" A callback function used to copy selected logs. """
try:
log_index = self.get_log_index()
row_index = self.get_record_index()
if(log_index is None or row_index is None):
raise ValueError("Could not determine the log and/or record index.")
r = self.logs[log_index].get_record_by_index(row_index)
except ValueError as e:
logging.error(e)
return
d = {}
for key in r.keys():
d[key.upper()] = r[key]
j = json.dumps(d)
self.application.clipboard.set_text(j, len(j))
return
def clipboard_text_received(self, clipboard, text, log):
r = json.loads(text)
log.add_record(r)
return
def paste_callback(self, widget=None, path=None):
""" A callback function used to paste selected logs. """
try:
log_index = self.get_log_index()
if(log_index is None):
raise ValueError("Could not determine the log index.")
l = self.logs[log_index]
except ValueError as e:
logging.error(e)
return
self.application.clipboard.request_text(self.clipboard_text_received, l)
return
@property
def log_count(self):
""" Return the total number of logs in the logbook.

Wyświetl plik

@ -37,4 +37,10 @@ class Popup:
self.items["PINPOINT"] = self.builder.get_object("mitem_pinpoint")
self.items["PINPOINT"].connect("activate", self.application.logbook.pinpoint_callback)
self.items["COPY"] = self.builder.get_object("mitem_copy")
self.items["COPY"].connect("activate", self.application.logbook.copy_callback)
self.items["PASTE"] = self.builder.get_object("mitem_paste")
self.items["PASTE"].connect("activate", self.application.logbook.paste_callback)
return

Wyświetl plik

@ -4558,6 +4558,24 @@ Base64-encoded plain text in the configuration file.</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="mitem_copy">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="mitem_paste">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
</object>
<object class="GtkBox" id="summary_page">
<property name="visible">True</property>