Commit e9054592 authored by Aurélien Lubert's avatar Aurélien Lubert

pyDV 0.2 - Allow to launch pyDV without monitor

* By default, pyDV open the presentation window on the same monitor as main
* interface
* The presentation window is hide when move on the same monitor as main
* interface
* A new argument has been added to list available monitors with --list-monitors
* The document argument presence was now removed to allow to open main
* interface without document
* Remove monitor argument in README example
parent 97cd1ddf
......@@ -24,7 +24,7 @@ The following commands need to be launch in pydv root folder (where this file
can be found)
```
python3 -m pydv --monitor DP-3 test.pdf
python3 -m pydv test.pdf
```
Arguments list can be obtain with --help
......@@ -52,6 +52,5 @@ Todo
Fix
---
- Change presentation view monitor to main monitor show a tiny window
- Document tab is not correctly update when focus on a script tab
- "Show output" switch in tab can be used in freezed mode
......@@ -59,6 +59,7 @@ def main():
parser.add_argument("document",
type=str,
nargs='?',
action="store",
metavar="FILE",
help="the document to show on specified monitor")
......@@ -89,7 +90,7 @@ def main():
type=str,
action="store",
metavar="NAME",
required=True,
default=None,
help="set the presentation viewer monitor")
parser_interface.add_argument("-M", "--main-monitor",
......@@ -99,6 +100,10 @@ def main():
default=None,
help="set the default monitor for main interface")
parser_interface.add_argument("-l", "--list-monitors",
action="store_true",
help="list available monitors")
parser_interface.add_argument("-t", "--timer",
type=str,
action="store",
......
......@@ -77,7 +77,7 @@ class Application(object):
# ----------------------------------------
# Document metadata
self.path = expanduser(abspath(args.document))
self.path = args.document
self.page = int(args.page) - 1
# Logger
......@@ -86,46 +86,67 @@ class Application(object):
# Monitors
self.displays = list()
self.display_id = args.display
self.monitor_id = args.monitor
self.main_monitor_id = args.main_monitor
# ----------------------------------------
# Check timer
# Initialization
# ----------------------------------------
self.timer = None
# Found main monitors
self.__init_monitors()
if len(args.timer) > 0 and match(r'^\d{1,2}:\d{1,2}$', args.timer):
hours, minutes = args.timer.split(':')
# Show available monitors
if args.list_monitors:
# Parse timer constant as integer
self.timer = (int(hours), int(minutes))
for display in self.displays:
self.logger.info("Found %d monitor(s) on display %s" % (
len(display.get_monitors()), display.get_name()))
# Hours
if self.timer[0] < 0:
self.timer[0] = 0
elif self.timer[0] > 7:
self.timer[0] = 7
for monitor in display.get_monitors():
self.logger.info("\t- %s" % str(monitor))
# Minutes
if self.timer[1] < 0:
self.timer[1] = 0
elif self.timer[1] > 59:
self.timer[1] = 59
# Launch application
else:
# A PDF document has been set
if self.path is not None:
self.path = expanduser(abspath(self.path))
# ----------------------------------------
# Initialization
# ----------------------------------------
# Main display
self.display_id = args.display
# Manage default monitors
self.monitor_id = args.monitor
self.main_monitor_id = args.main_monitor
# Found main monitors
self.__init_monitors()
if args.monitor is None:
self.monitor_id = args.main_monitor
# Initialize configurations
self.__init_configurations()
# ----------------------------------------
# Check timer
# ----------------------------------------
# Start application
self.__start_application()
self.timer = None
if len(args.timer) > 0 and match(r'^\d{1,2}:\d{1,2}$', args.timer):
hours, minutes = args.timer.split(':')
# Parse timer constant as integer
self.timer = (int(hours), int(minutes))
# Hours
if self.timer[0] < 0:
self.timer[0] = 0
elif self.timer[0] > 7:
self.timer[0] = 7
# Minutes
if self.timer[1] < 0:
self.timer[1] = 0
elif self.timer[1] > 59:
self.timer[1] = 59
# Initialize configurations
self.__init_configurations()
# Start application
self.__start_application()
def __init_monitors(self):
......@@ -183,7 +204,11 @@ class Application(object):
main_monitor = display.get_default_monitor()
# Get monitor object for presentation
second_monitor = display.get_monitor(self.monitor_id)
if self.monitor_id is not None:
second_monitor = display.get_monitor(self.monitor_id)
else:
second_monitor = main_monitor
self.logger.debug(
"Use %s as main monitor" % main_monitor.get_name())
......
......@@ -936,6 +936,13 @@ class MainInterface(Gtk.Window):
self.toolbar_mouse.set_sensitive(False)
self.toolbar_remove.set_sensitive(False)
self.toolbar_page_next.set_sensitive(False)
self.toolbar_page_previous.set_sensitive(False)
self.toolbar_freeze.set_sensitive(False)
self.toolbar_remove.set_sensitive(False)
self.toolbar_highlight.set_sensitive(False)
# Draw the result on screen
self.show_all()
self.box_popover_menu.show_all()
......@@ -944,6 +951,9 @@ class MainInterface(Gtk.Window):
self.box_notebook_actions.show_all()
self.listbox_application.show_all()
self.scroll_sidebar.hide()
self.statubar_progress_page.hide()
# Move window on monitor center
x, y = self.main_monitor.get_position()
width, height = self.main_monitor.get_size()
......@@ -1061,6 +1071,8 @@ class MainInterface(Gtk.Window):
for annotation in self.__annotations_cache:
self.view_document.remove_annotation(annotation)
self.toolbar_remove.set_sensitive(False)
self.view_document.reload()
self.presentation.view_presentation.reload()
......@@ -1081,13 +1093,6 @@ class MainInterface(Gtk.Window):
When the spcified path not exist
"""
if type(self.__current_path) is not str:
raise ValueError("Wrong type for path, need str but get %s" % type(
self.__current_path))
if not exists(expanduser(self.__current_path)):
raise IOError(2, "Cannot found %s" % str(self.__current_path))
self.__files_cache = dict()
self.__annotation_status = False
......@@ -1101,61 +1106,70 @@ class MainInterface(Gtk.Window):
for filename, widget in self.__files_cache.items():
self.on_close_tab(None, widget)
# ----------------------------------------
# Generate document instance
# ----------------------------------------
if self.__current_path is not None:
if not exists(expanduser(self.__current_path)):
raise IOError(2, "Cannot found %s" % str(self.__current_path))
self.thumbnails_view.unselect_all()
self.thumbnails_list.clear()
self.toolbar_freeze.set_sensitive(True)
self.toolbar_highlight.set_sensitive(True)
self.logger.info("Retrieve document %s" % basename(self.__current_path))
# ----------------------------------------
# Generate document instance
# ----------------------------------------
self.__current_page = page
self.thumbnails_view.unselect_all()
self.thumbnails_list.clear()
self.logger.debug("Start on page %d" % (self.__current_page + 1))
self.logger.info(
"Retrieve document %s" % basename(self.__current_path))
# Generate a document from filepath
self.document = EvinceDocument.Document.factory_get_document(
"file://%s" % abspath(self.__current_path))
self.__current_page = page
# Generate presentation instance
self.presentation.init_document(self.document, self.__current_page)
self.logger.debug("Start on page %d" % (self.__current_page + 1))
# ----------------------------------------
# Generate document model
# ----------------------------------------
# Generate a document from filepath
self.document = EvinceDocument.Document.factory_get_document(
"file://%s" % abspath(self.__current_path))
self.logger.debug("Generate a new model for this document")
self.model_document.set_document(self.document)
# Generate presentation instance
self.presentation.init_document(self.document, self.__current_page)
self.logger.debug("Set this model to evince viewer")
self.view_document.set_model(self.model_document)
# ----------------------------------------
# Generate document model
# ----------------------------------------
# ----------------------------------------
# Thumbnails
# ----------------------------------------
self.logger.debug("Generate a new model for this document")
self.model_document.set_document(self.document)
# Stop thumbnails generator thread
if self.__thread_thumbnails is not None:
self.logger.info("Closing remaining thread")
source_remove(self.__thread_thumbnails)
self.logger.debug("Set this model to evince viewer")
self.view_document.set_model(self.model_document)
# Render document page thumbnails
loader = self.__on_render_thumbnails()
self.__thread_thumbnails = idle_add(loader.__next__)
# ----------------------------------------
# Thumbnails
# ----------------------------------------
# ----------------------------------------
# Load widgets
# ----------------------------------------
# Stop thumbnails generator thread
if self.__thread_thumbnails is not None:
self.logger.info("Closing remaining thread")
source_remove(self.__thread_thumbnails)
if self.__current_page <= 0:
self.toolbar_page_previous.set_sensitive(False)
# Render document page thumbnails
loader = self.__on_render_thumbnails()
self.__thread_thumbnails = idle_add(loader.__next__)
# Show the document URI in statusbar
self.statusbar.push(0, basename(self.document.get_uri()))
# ----------------------------------------
# Load widgets
# ----------------------------------------
# Render first document page
self.on_change_page()
if self.__current_page <= 0:
self.toolbar_page_previous.set_sensitive(False)
# Show the document URI in statusbar
self.statusbar.push(0, basename(self.document.get_uri()))
# Render first document page
self.on_change_page()
def __on_render_thumbnails(self):
......@@ -1169,6 +1183,7 @@ class MainInterface(Gtk.Window):
size = self.config.getint("interface", "thumbnails-size", fallback=400)
self.logger.debug("Starting thumbnails renderer thread")
self.scroll_sidebar.show_all()
# Restore statusbar visibility
self.statubar_progress_page.show()
......
......@@ -370,10 +370,10 @@ class PresentationInterface(Gtk.Window):
self.fullscreen_on_monitor(
self.monitor.get_screen(), self.monitor.get_index())
# Draw the result on screen
self.show_all()
self.scroll_editor.hide()
self.scroll_output.hide()
# Draw the result on screen
self.show_all()
self.scroll_editor.hide()
self.scroll_output.hide()
def switch_view(self, output):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment