Skip to content

Commit

Permalink
Open files from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael1193 committed Dec 21, 2014
1 parent 4d71a13 commit 06e8c23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions spicegui/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from __future__ import print_function

import sys
import argparse

from gi.repository import Gio, Gtk
from gi.repository import Gio, Gtk, GObject
import gui
import preferences_gui

Expand Down Expand Up @@ -69,10 +70,13 @@ class App(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self,
application_id="org.rafael1193.spicegui",
flags=Gio.ApplicationFlags.FLAGS_NONE)
flags=Gio.ApplicationFlags.HANDLES_OPEN)

self.connect("activate", self.on_activate)
self.connect("startup", self.on_startup)
self.connect("open", self.on_open)

self.file_args = []

def on_startup(self, app):
#Gtk.Application.do_startup(self)
Expand Down Expand Up @@ -107,6 +111,12 @@ def on_activate(self, app):
window = gui.MainWindow()
app.add_window(window)
window.show_all()

def on_open(self, app, files, hint, user_data):
for f in files:
window = gui.MainWindow(f.get_path())
app.add_window(window)
window.show_all()

def on_new_action(self, action, parameter):
self.activate()
Expand Down
5 changes: 4 additions & 1 deletion spicegui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class MainWindow(Gtk.ApplicationWindow):
</interface>
"""

def __init__(self):
def __init__(self, file_path=None):
Gtk.Window.__init__(self)
self.set_default_size(900, 600)

Expand Down Expand Up @@ -191,6 +191,9 @@ def __init__(self):

self.overview_view()
self.connect_after('destroy', self._on_destroy)

if file_path is not None:
self.load_file(file_path)

def _open_state(self, state="opened"):
"""
Expand Down

0 comments on commit 06e8c23

Please sign in to comment.