Created
June 19, 2012 15:11
-
-
Save powerswitch/2954700 to your computer and use it in GitHub Desktop.
Document Chooser Patch for Cournal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -pruN cournal/cournal/documentchooserdialog.py cournal-simon-workspace/cournal/documentchooserdialog.py | |
--- cournal/cournal/documentchooserdialog.py 1970-01-01 01:00:00.000000000 +0100 | |
+++ cournal-simon-workspace/cournal/documentchooserdialog.py 2012-06-19 16:28:52.351488468 +0200 | |
@@ -0,0 +1,86 @@ | |
+#!/usr/bin/env python3 | |
+# -*- coding: utf-8 -*- | |
+ | |
+# This file is part of Cournal. | |
+# Copyright (C) 2012 Simon Vetter | |
+# | |
+# Cournal is free software: you can redistribute it and/or modify | |
+# it under the terms of the GNU General Public License as published by | |
+# the Free Software Foundation, either version 3 of the License, or | |
+# (at your option) any later version. | |
+# | |
+# Cournal is distributed in the hope that it will be useful, | |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
+# GNU General Public License for more details. | |
+# | |
+# You should have received a copy of the GNU General Public License | |
+# along with Cournal. If not, see <http://www.gnu.org/licenses/>. | |
+ | |
+from gi.repository import Gtk, Gdk | |
+from . import network | |
+ | |
+class DocumentChooserDialog(Gtk.Dialog): | |
+ def __init__(self, parent, **args): | |
+ Gtk.Dialog.__init__(self, **args) | |
+ | |
+ self.parent = parent | |
+ | |
+ self.selected = None | |
+ | |
+ builder = Gtk.Builder() | |
+ builder.add_from_file("document_chooser_dialog.glade") | |
+ | |
+ self.doc_tree = builder.get_object("doc_tree") | |
+ self.doc_tree_selection = builder.get_object("doc_tree_selection") | |
+ self.doc_name = builder.get_object("doc_name") | |
+ self.doc_tree_store = builder.get_object("doc_tree_store") | |
+ self.doc_tree_column = builder.get_object("doc_tree_column") | |
+ | |
+ #help(self.doc_tree_view_column) | |
+ | |
+ self.doc_tree_selection.connect("changed", self.on_tree_select) | |
+ | |
+ self.get_content_area().add(builder.get_object("main_grid")) | |
+ | |
+ self.set_modal(False) | |
+ self.set_has_resize_grip(False) | |
+ self.set_resizable(True) | |
+ self.set_title("Choose server document") | |
+ self.set_transient_for(parent) | |
+ self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL) | |
+ self.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT) | |
+ self.set_default_response(Gtk.ResponseType.ACCEPT) | |
+ | |
+ self.cell = Gtk.CellRendererText() | |
+ self.doc_tree_column.pack_start(self.cell, True) | |
+ self.doc_tree_column.add_attribute(self.cell, "text", 0) | |
+ | |
+ d = network.get_document_list() | |
+ d.addCallback(self.got_document_list) | |
+ | |
+ self.show_all() | |
+ | |
+ def got_document_list(self, documents): | |
+ for i in documents: | |
+ self.doc_tree_store.append(None, [i]) | |
+ | |
+ def on_tree_select(self, item): | |
+ store, iter = item.get_selected() | |
+ if iter: | |
+ self.selected = store.get(iter,0)[0] | |
+ self.doc_name.set_text(self.selected) | |
+ | |
+ def run_nonblocking(self): | |
+ self.connect('response', self.response) | |
+ self.show() | |
+ | |
+ def response(self, widget, response_id): | |
+ if response_id == Gtk.ResponseType.ACCEPT: | |
+ network.connect_document(self.doc_name.get_text()) | |
+ self.destroy() | |
+ | |
+# For testing purposes: | |
+if __name__ == "__main__": | |
+ dialog = DocumentChooserDialog(None) | |
+ dialog.run() | |
diff -pruN cournal/cournal/__init__.py cournal-simon-workspace/cournal/__init__.py | |
--- cournal/cournal/__init__.py 2012-06-11 10:50:55.290744267 +0200 | |
+++ cournal-simon-workspace/cournal/__init__.py 2012-06-11 14:13:16.736837099 +0200 | |
@@ -1,6 +1,7 @@ | |
from .network import network | |
from .connectiondialog import ConnectionDialog | |
from .aboutdialog import AboutDialog | |
+from .documentchooserdialog import DocumentChooserDialog | |
from .mainwindow import MainWindow | |
-__all__ = ["MainWindow", "network", "ConnectionDialog", "AboutDialog"] | |
+__all__ = ["MainWindow", "network", "ConnectionDialog", "AboutDialog", "DocumentChooserDialog"] | |
diff -pruN cournal/cournal/mainwindow.py cournal-simon-workspace/cournal/mainwindow.py | |
--- cournal/cournal/mainwindow.py 2012-06-19 17:01:09.588659443 +0200 | |
+++ cournal-simon-workspace/cournal/mainwindow.py 2012-06-19 16:43:02.089914087 +0200 | |
@@ -24,7 +24,7 @@ from .viewer import Layout | |
from .viewer.tools import pen | |
from .document import Document, xojparser | |
from . import network | |
-from . import ConnectionDialog, AboutDialog | |
+from . import ConnectionDialog, AboutDialog, DocumentChooserDialog | |
pdf_filter = Gtk.FileFilter() | |
pdf_filter.add_mime_type("application/pdf") | |
@@ -77,6 +77,7 @@ class MainWindow(Gtk.Window): | |
self.menu_open_xoj = builder.get_object("imagemenuitem_open_xoj") | |
self.menu_open_pdf = builder.get_object("imagemenuitem_open_pdf") | |
self.menu_connect = builder.get_object("imagemenuitem_connect") | |
+ self.menu_choose_document = builder.get_object("imagemenuitem_choose_document") | |
self.menu_save = builder.get_object("imagemenuitem_save") | |
self.menu_save_as = builder.get_object("imagemenuitem_save_as") | |
self.menu_export_pdf = builder.get_object("imagemenuitem_export_pdf") | |
@@ -100,6 +101,7 @@ class MainWindow(Gtk.Window): | |
self.menu_save_as.set_sensitive(False) | |
self.menu_export_pdf.set_sensitive(False) | |
self.menu_import_xoj.set_sensitive(False) | |
+ self.menu_choose_document.set_sensitive(False) | |
self.tool_save.set_sensitive(False) | |
self.tool_connect.set_sensitive(False) | |
self.tool_zoom_in.set_sensitive(False) | |
@@ -113,6 +115,7 @@ class MainWindow(Gtk.Window): | |
self.menu_open_xoj.connect("activate", self.run_open_xoj_dialog) | |
self.menu_open_pdf.connect("activate", self.run_open_pdf_dialog) | |
self.menu_connect.connect("activate", self.run_connection_dialog) | |
+ self.menu_choose_document.connect("activate", self.run_choose_document_dialog) | |
self.menu_save.connect("activate", self.save) | |
self.menu_save_as.connect("activate", self.run_save_as_dialog) | |
self.menu_export_pdf.connect("activate", self.run_export_pdf_dialog) | |
@@ -163,6 +166,7 @@ class MainWindow(Gtk.Window): | |
self.menu_save_as.set_sensitive(True) | |
self.menu_export_pdf.set_sensitive(True) | |
self.menu_import_xoj.set_sensitive(True) | |
+ self.menu_choose_document.set_sensitive(True) | |
self.tool_save.set_sensitive(True) | |
self.tool_connect.set_sensitive(True) | |
self.tool_zoom_in.set_sensitive(True) | |
@@ -204,6 +208,15 @@ class MainWindow(Gtk.Window): | |
self._connection_dialog = ConnectionDialog(self) | |
self._connection_dialog.connect("destroy", destroyed) | |
self._connection_dialog.run_nonblocking() | |
+ | |
+ def run_choose_document_dialog(self, menuitem): | |
+ def destroyed(widget): | |
+ self._choose_document_dialog = None | |
+ self._choose_document_dialog = DocumentChooserDialog(self) | |
+ self._choose_document_dialog.connect("destroy", destroyed) | |
+ self._choose_document_dialog.run_nonblocking() | |
+ | |
+ | |
def run_import_xoj_dialog(self, menuitem): | |
""" | |
diff -pruN cournal/cournal/network.py cournal-simon-workspace/cournal/network.py | |
--- cournal/cournal/network.py 2012-06-19 17:01:09.588659443 +0200 | |
+++ cournal-simon-workspace/cournal/network.py 2012-06-19 16:51:59.779173195 +0200 | |
@@ -47,6 +47,7 @@ class _Network(pb.Referenceable): | |
self.document = None | |
self.window = None | |
self.is_connected = False | |
+ self.documentlist = None | |
def set_document(self, document): | |
""" | |
@@ -83,7 +84,13 @@ class _Network(pb.Referenceable): | |
client=self) | |
d.addCallbacks(self.connected, self.connection_failed) | |
return d | |
- | |
+ | |
+ def connect_document(self, document): | |
+ if self.document: | |
+ self.document.clear_pages() | |
+ d = self.perspective.callRemote("join_document", document) | |
+ d.addCallbacks(self.got_server_document, callbackArgs=[document]) | |
+ | |
def connected(self, perspective): | |
""" | |
Called, when the connection succeeded. Join a document now | |
@@ -99,10 +106,7 @@ class _Network(pb.Referenceable): | |
self.perspective = perspective | |
self.perspective.notifyOnDisconnect(self.disconnect_event) | |
self.ping() | |
- d = perspective.callRemote("join_document", "document1") | |
- d.addCallbacks(self.got_server_document, callbackArgs=["document1"]) | |
- | |
- return d | |
+ self.window.run_choose_document_dialog(None) | |
def connection_failed(self, reason): | |
""" | |
@@ -129,6 +133,10 @@ class _Network(pb.Referenceable): | |
if self.window: | |
self.window.disconnect_event() | |
+ def get_document_list(self): | |
+ doclist = self.perspective.callRemote("list_documents") | |
+ return doclist | |
+ | |
def got_server_document(self, server_document, name): | |
""" | |
Called, when the server sent a reference to the remote document we requested | |
@@ -138,6 +146,8 @@ class _Network(pb.Referenceable): | |
name -- Name of the document | |
""" | |
debug(2, "Started editing", name) | |
+ #if self.document: | |
+ # self.document.clear_pages() | |
self.server_document = server_document | |
def remote_new_stroke(self, pagenum, stroke): | |
diff -pruN cournal/cournal-server.py cournal-simon-workspace/cournal-server.py | |
--- cournal/cournal-server.py 2012-06-19 17:01:09.585326052 +0200 | |
+++ cournal-simon-workspace/cournal-server.py 2012-06-19 16:30:26.899855915 +0200 | |
@@ -201,6 +201,11 @@ class User(pb.Avatar): | |
for document in self.documents: | |
document.remove_user(self) | |
+ def perspective_list_documents(self): | |
+ debug(2, "User", self.name, "requested document list") | |
+ | |
+ return list(self.server.documents.keys()) | |
+ | |
def perspective_join_document(self, documentname): | |
""" | |
Called by the user to join a document session. | |
@@ -281,7 +286,7 @@ class Document(pb.Viewable): | |
for user in self.users: | |
if user != except_user: | |
user.call_remote(method, *args) | |
- | |
+ | |
def view_new_stroke(self, from_user, pagenum, stroke): | |
""" | |
Broadcast the stroke received from one to all other clients. | |
diff -pruN cournal/document_chooser_dialog.glade cournal-simon-workspace/document_chooser_dialog.glade | |
--- cournal/document_chooser_dialog.glade 1970-01-01 01:00:00.000000000 +0100 | |
+++ cournal-simon-workspace/document_chooser_dialog.glade 2012-06-11 11:11:40.167736577 +0200 | |
@@ -0,0 +1,72 @@ | |
+<?xml version="1.0" encoding="UTF-8"?> | |
+<interface> | |
+ <!-- interface-requires gtk+ 3.0 --> | |
+ <object class="GtkTreeStore" id="doc_tree_store"> | |
+ <columns> | |
+ <!-- column-name gchararray1 --> | |
+ <column type="gchararray"/> | |
+ </columns> | |
+ </object> | |
+ <object class="GtkBox" id="main_grid"> | |
+ <property name="visible">True</property> | |
+ <property name="can_focus">False</property> | |
+ <property name="border_width">5</property> | |
+ <property name="orientation">vertical</property> | |
+ <child> | |
+ <object class="GtkTreeView" id="doc_tree"> | |
+ <property name="width_request">220</property> | |
+ <property name="height_request">150</property> | |
+ <property name="visible">True</property> | |
+ <property name="can_focus">True</property> | |
+ <property name="hexpand">True</property> | |
+ <property name="vexpand">True</property> | |
+ <property name="border_width">3</property> | |
+ <property name="model">doc_tree_store</property> | |
+ <child internal-child="selection"> | |
+ <object class="GtkTreeSelection" id="doc_tree_selection"/> | |
+ </child> | |
+ <child> | |
+ <object class="GtkTreeViewColumn" id="doc_tree_column"> | |
+ <property name="fixed_width">30</property> | |
+ <property name="title" translatable="yes">Documents</property> | |
+ <property name="sort_column_id">0</property> | |
+ </object> | |
+ </child> | |
+ </object> | |
+ <packing> | |
+ <property name="expand">False</property> | |
+ <property name="fill">True</property> | |
+ <property name="position">0</property> | |
+ </packing> | |
+ </child> | |
+ <child> | |
+ <object class="GtkEntry" id="doc_name"> | |
+ <property name="visible">True</property> | |
+ <property name="can_focus">True</property> | |
+ <property name="invisible_char">â</property> | |
+ </object> | |
+ <packing> | |
+ <property name="expand">False</property> | |
+ <property name="fill">True</property> | |
+ <property name="position">1</property> | |
+ </packing> | |
+ </child> | |
+ <child> | |
+ <object class="GtkGrid" id="button_grid"> | |
+ <property name="visible">True</property> | |
+ <property name="can_focus">False</property> | |
+ <child> | |
+ <placeholder/> | |
+ </child> | |
+ <child> | |
+ <placeholder/> | |
+ </child> | |
+ </object> | |
+ <packing> | |
+ <property name="expand">False</property> | |
+ <property name="fill">True</property> | |
+ <property name="position">2</property> | |
+ </packing> | |
+ </child> | |
+ </object> | |
+</interface> | |
diff -pruN cournal/mainwindow.glade cournal-simon-workspace/mainwindow.glade | |
--- cournal/mainwindow.glade 2012-06-19 17:01:09.588659443 +0200 | |
+++ cournal-simon-workspace/mainwindow.glade 2012-06-19 16:30:26.883188950 +0200 | |
@@ -20,6 +20,11 @@ | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
</object> | |
+ <object class="GtkImage" id="image5"> | |
+ <property name="visible">True</property> | |
+ <property name="can_focus">False</property> | |
+ <property name="stock">gtk-dnd-multiple</property> | |
+ </object> | |
<object class="GtkBox" id="outer_box"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
@@ -68,6 +73,17 @@ | |
<property name="use_stock">False</property> | |
</object> | |
</child> | |
+ <child> | |
+ <object class="GtkImageMenuItem" id="imagemenuitem_choose_document"> | |
+ <property name="label" translatable="yes">Choose _document</property> | |
+ <property name="use_action_appearance">False</property> | |
+ <property name="visible">True</property> | |
+ <property name="can_focus">False</property> | |
+ <property name="use_underline">True</property> | |
+ <property name="image">image5</property> | |
+ <property name="use_stock">False</property> | |
+ </object> | |
+ </child> | |
<child> | |
<object class="GtkImageMenuItem" id="imagemenuitem_save"> | |
<property name="label">gtk-save</property> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment