Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 131 lines (101 sloc) 4.73 KB
#! /usr/bin/python3
# -*- coding: utf-8 -*-
# grimm
#
# grimm 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, version 3.
#
# grimm 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 grimm; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Copyright © 2013 Pietro Battiston <me@pietrobattiston.it>
import os
from gi.repository import Gtk
from grimm_lib.ui import Ui
from grimm_lib.config import STUFF_DIR
from grimm_lib.actions import GrimmAction
from grimm_lib.python_shell import GrimmPythonShell
from grimm_lib.scripts_editor import GrimmScriptsEditor
SINGLE, WINDOWED = range( 2 )
WINDOW_MODE = SINGLE
class Grimm(object):
df = None
def __init__(self):
self.ui = Ui( 'grimm', os.path.join( STUFF_DIR, 'main.glade' ) )
self.ui.connect_signals( self )
self.context = { "df" : None }
self.ui_manager = Gtk.UIManager()
self.action_group = Gtk.ActionGroup( "actions" )
self.ui_manager.insert_action_group( self.action_group )
self.add_base_actions()
menu_xml_path = os.path.join( STUFF_DIR, 'base_actions.xml' )
self.ui_manager.add_ui_from_file( menu_xml_path )
menubar = self.ui_manager.get_widget( "/MenuBar" )
menubar.show()
self.ui.main_box.pack_start( menubar, False, True, 0 )
icon_path = os.path.join( STUFF_DIR, 'grimm.svg' )
self.ui.main_win.set_default_icon_from_file( icon_path )
self.load_actions()
self.ui.main_win.add_accel_group( self.ui_manager.get_accel_group() )
self.python_shell = GrimmPythonShell( self )
self.scripts_editor = GrimmScriptsEditor( self )
if WINDOW_MODE == WINDOWED:
self.python_shell_window = Gtk.Window()
self.python_shell_window.set_default_size( 800, 300 )
self.python_shell_window.add( self.python_shell )
self.python_shell_window.show_all()
self.scripts_editor_window = Gtk.Window()
self.scripts_editor_window.set_default_size( 800, 300 )
self.scripts_editor_window.add( self.scripts_editor )
self.scripts_editor_window.show_all()
else:
self.ui.scripts_frame.add( self.scripts_editor )
self.ui.console_frame.add( self.python_shell )
self.ui.vicetop_pane.set_position( 300 )
self.ui.top_pane.set_position( 700 )
self.ui.main_win.show_all()
self.ui.main_win.maximize()
Gtk.main()
def add_base_actions(self):
self.action_group.add_action( Gtk.Action("FileMenu", "File", None, None) )
self.action_group.add_action( Gtk.Action("HelpMenu", "Help", None, None) )
self.action_group.add_action( Gtk.Action("ModelsMenu", "Models", None, None) )
self.action_group.add_action( Gtk.Action("GraphsMenu", "Graphs", None, None) )
self.action_group.add_action( Gtk.Action("OpenData", "Open data", None, None) )
self.action_group.add_action( Gtk.Action("ScriptsMenu", "Scripts", None, None) )
def load_actions(self):
actions = GrimmAction.register()
for action in actions:
action.class_init( self )
self.action_group.add_action_with_accel( action.gtk_action,
action.accel )
action.merge_id = self.ui_manager.new_merge_id()
self.ui_manager.add_ui( action.merge_id,
action.path,
action.name,
action.name,
Gtk.UIManagerItemType.AUTO,
False )
# TODO: refactor a bit names:
if hasattr( action, "run_inner" ):
self.context[action.grimm_command] = action.context()
def refresh_series(self, df):
# TODO: Remove old series from context
self.df = df
self.ui.series.clear()
self.context["df"] = df
for col in self.df.columns:
self.ui.series.append( [col] )
self.context[col] = df[[col]]
def quit(self, *args):
print("quit")
Gtk.main_quit()
if __name__ == '__main__':
g = Grimm()