parent
397a096608
commit
04c22c513b
@ -1,183 +0,0 @@
|
||||
# Python imports
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Gtk and Gobject
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, Gio
|
||||
|
||||
# Internationalization support
|
||||
import gettext
|
||||
import locale
|
||||
|
||||
# Printing library import
|
||||
import smallprint
|
||||
|
||||
|
||||
if os.path.exists('locale/po') and os.path.exists('res'):
|
||||
# We're in the development tree
|
||||
DIR = "locale/po/"
|
||||
RESOURCES = "res/"
|
||||
|
||||
else:
|
||||
DIR = "po"
|
||||
RESOURCES = "res/"
|
||||
|
||||
# Internationalization code, we'll cross that bridge when we get there
|
||||
# APP = "smallprint"
|
||||
#
|
||||
#
|
||||
# locale.setlocale(locale.LC_ALL, '')
|
||||
#
|
||||
# gettext.bindtextdomain(APP, DIR)
|
||||
# locale.bindtextdomain(APP, DIR)
|
||||
#
|
||||
#
|
||||
# gettext.textdomain(APP)
|
||||
# _ = gettext.gettext
|
||||
#
|
||||
|
||||
|
||||
class MainWindowMethods(Gtk.Application):
|
||||
"""
|
||||
Main Application object with the main window signals
|
||||
"""
|
||||
def __init__(self):
|
||||
Gtk.Application.__init__(self, application_id="apps.gnome.smallprint",
|
||||
flags=Gio.ApplicationFlags.FLAGS_NONE)
|
||||
|
||||
self.connect("activate", self.on_app_start)
|
||||
|
||||
def on_app_start(self, data=None):
|
||||
"""
|
||||
Loads the MainWindow widgets, shows it up and starts the main loop
|
||||
"""
|
||||
self.builder = Gtk.Builder()
|
||||
# self.builder.set_translation_domain(APP)
|
||||
self.builder.add_from_file(os.path.join(RESOURCES, 'smallprint.gtkbuilder'))
|
||||
self.builder.connect_signals(self)
|
||||
|
||||
# We get the window and show it
|
||||
self.window = self.builder.get_object("MainWindow")
|
||||
self.add_window(self.window)
|
||||
self.window.show_all()
|
||||
|
||||
def onOpenMenuClicked(self, event):
|
||||
"""
|
||||
User has pressed Open in the menu
|
||||
"""
|
||||
# Create the FileChooser Dialog
|
||||
chooser = Gtk.FileChooserDialog(_("Open JSON text file"), self.window,
|
||||
Gtk.FileChooserAction.OPEN,
|
||||
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
||||
|
||||
# Launch it
|
||||
response = chooser.run()
|
||||
|
||||
# If we choose a file, we load it
|
||||
if response == Gtk.ResponseType.OK:
|
||||
filename = chooser.get_filename()
|
||||
label = self.builder.get_object("StatusLabel")
|
||||
|
||||
# We update the statusbar accordingly to what has happened
|
||||
if self.logicObj.loadjson(filename):
|
||||
|
||||
label.set_text(filename)
|
||||
treeStore = self.builder.get_object("treestore1")
|
||||
treeStore.clear()
|
||||
self.logicObj.loadTree(treeStore)
|
||||
|
||||
else:
|
||||
|
||||
label.set_text(_("No JSON loaded."))
|
||||
|
||||
# We finish the dialog
|
||||
chooser.destroy()
|
||||
|
||||
def onCopyJSONClicked(self, widget):
|
||||
"""
|
||||
User asked to paste a JSON code
|
||||
"""
|
||||
# Show up the TextWindow
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.show_all()
|
||||
|
||||
def onCopyJSONDelete(self, widget, event):
|
||||
"""
|
||||
We've been told to close the CopyJSON Window
|
||||
"""
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
|
||||
return True
|
||||
|
||||
def onCopyJSONDestroy(self, widget):
|
||||
"""
|
||||
We've been tasked with removing the CopyJSON window
|
||||
"""
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
|
||||
return True
|
||||
|
||||
def onCopyJSONAcceptClicked(self, widget):
|
||||
"""
|
||||
The input is finished and accepted.
|
||||
"""
|
||||
textView = self.builder.get_object("textview1")
|
||||
jsonBuffer = textView.get_buffer()
|
||||
jsonText = jsonBuffer.get_text(jsonBuffer.get_start_iter(),
|
||||
jsonBuffer.get_end_iter(), True)
|
||||
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
treestore = self.builder.get_object("treestore1")
|
||||
treestore.clear()
|
||||
|
||||
if self.logicObj.loadJSONText(jsonText):
|
||||
|
||||
status_label = self.builder.get_object("StatusLabel")
|
||||
status_label.set_text(_("Loaded from the clipboard."))
|
||||
self.logicObj.loadTree(treestore)
|
||||
|
||||
def onCopyJSONCancelClicked(self, widget):
|
||||
"""
|
||||
The user changed its mind and pressed cancel
|
||||
"""
|
||||
textWindow = self.builder.get_object("TextWindow")
|
||||
textWindow.hide()
|
||||
|
||||
def onExitMenuClicked(self, widget):
|
||||
"""
|
||||
Menu option Exit has been clicked
|
||||
"""
|
||||
self.quit()
|
||||
|
||||
def onAboutMenuActivate(self, widget):
|
||||
"""
|
||||
About option clicked
|
||||
"""
|
||||
about_dialog = self.builder.get_object("AboutDialog")
|
||||
about_dialog.run()
|
||||
about_dialog.hide()
|
||||
|
||||
def onMainWindowDelete(self, widget, event):
|
||||
"""
|
||||
Our MainWindow has been deleted or closed
|
||||
"""
|
||||
pass
|
||||
|
||||
def onAboutDialogClose(self, widget, event=None):
|
||||
pass
|
||||
|
||||
def onAboutDialogDeleteEvent(self, widget, event=None):
|
||||
pass
|
||||
|
||||
|
||||
# Main procedure
|
||||
if __name__ == "__main__":
|
||||
|
||||
mainWindow = MainWindowMethods()
|
||||
mainWindow.run(None)
|
@ -0,0 +1,57 @@
|
||||
import os
|
||||
import os.path
|
||||
import tempfile
|
||||
from icalendar import Calendar, Event
|
||||
from webdav3.client import Client as WDClient
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initializes a client
|
||||
"""
|
||||
options = {
|
||||
'webdav_hostname': config["WEBDAV_SERVER"],
|
||||
'webdav_login': config["WEBDAV_USER"],
|
||||
'webdav_password': config["WEBDAV_PASSWORD"],
|
||||
}
|
||||
self.calendar_path = config["CALENDAR_PATH"]
|
||||
self.client = WDClient(options)
|
||||
|
||||
def retrieve_calendars_list(self):
|
||||
"""
|
||||
Retrieves the calendar list
|
||||
"""
|
||||
return self.client.list(self.path)
|
||||
|
||||
def read_calendar(self, pathname):
|
||||
"""
|
||||
Given a filename, tries to read the calendar event
|
||||
"""
|
||||
f, temp_path = tempfile.mkstemp()
|
||||
rpath = os.path.join(self.calendar_path, pathname)
|
||||
self.client.download_sync(remote_path=rpath,
|
||||
local_path=temp_path)
|
||||
# Read the temporary data, close the file, remove it
|
||||
data = f.read()
|
||||
f.close()
|
||||
os.remove(temp_path)
|
||||
# Now with the data read, we can process it
|
||||
return self.parse_calendar(data)
|
||||
|
||||
def parse_calendar(self, data):
|
||||
"""
|
||||
Parses ICS calendar data received
|
||||
"""
|
||||
calendar = Calendar.from_ical(data)
|
||||
for component in calendar.walk():
|
||||
if component.name == 'VEVENT':
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def get_todays_events(self):
|
||||
"""
|
||||
Get todays events
|
||||
"""
|
||||
pass
|
Loading…
Reference in new issue