grc: Add 'Create Duplicate' feature

This commit is contained in:
Kartik Patel 2017-01-25 16:03:25 +05:30
parent 54d962f207
commit 0ae76e24ca
5 changed files with 30 additions and 11 deletions

View File

@ -30,7 +30,6 @@ from .FileDialogs import (OpenFlowGraphFileDialog, SaveFlowGraphFileDialog,
from .MainWindow import MainWindow
from .ParserErrorsDialog import ParserErrorsDialog
from .PropsDialog import PropsDialog
from ..core import ParseXML, Messages
gobject.threads_init()
@ -130,7 +129,7 @@ class ActionHandler:
action.set_sensitive(False) # set all actions disabled
for action in (
Actions.APPLICATION_QUIT, Actions.FLOW_GRAPH_NEW,
Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS,
Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS, Actions.FLOW_GRAPH_DUPLICATE,
Actions.FLOW_GRAPH_CLOSE, Actions.ABOUT_WINDOW_DISPLAY,
Actions.FLOW_GRAPH_SCREEN_CAPTURE, Actions.HELP_WINDOW_DISPLAY,
Actions.TYPES_WINDOW_DISPLAY, Actions.TOGGLE_BLOCKS_WINDOW,
@ -561,6 +560,9 @@ class ActionHandler:
Preferences.add_recent_file(file_path)
main.tool_bar.refresh_submenus()
main.menu_bar.refresh_submenus()
elif action == Actions.FLOW_GRAPH_DUPLICATE:
curr_flow_graph = main.get_flow_graph()
main.new_page(flow_graph = curr_flow_graph)
elif action == Actions.FLOW_GRAPH_SCREEN_CAPTURE:
file_path, background_transparent = SaveScreenShotDialog(page.get_file_path()).run()
if file_path is not None:

View File

@ -203,6 +203,12 @@ FLOW_GRAPH_SAVE_AS = Action(
stock_id=gtk.STOCK_SAVE_AS,
keypresses=(gtk.keysyms.s, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
)
FLOW_GRAPH_DUPLICATE = Action(
label='_Duplicate',
tooltip='Create a duplicate of current flowgraph',
stock_id=gtk.STOCK_COPY,
keypresses=(gtk.keysyms.d, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK),
)
FLOW_GRAPH_CLOSE = Action(
label='_Close',
tooltip='Close the current flow graph',

View File

@ -69,6 +69,7 @@ MENU_BAR_LIST = (
None,
Actions.FLOW_GRAPH_SAVE,
Actions.FLOW_GRAPH_SAVE_AS,
Actions.FLOW_GRAPH_DUPLICATE,
None,
Actions.FLOW_GRAPH_SCREEN_CAPTURE,
None,

View File

@ -247,7 +247,7 @@ class MainWindow(gtk.Window):
# Pages: create and close
############################################################
def new_page(self, file_path='', show=False):
def new_page(self, file_path='', flow_graph = None, show=False):
"""
Create a new notebook page.
Set the tab to be selected.
@ -263,13 +263,17 @@ class MainWindow(gtk.Window):
return
try: #try to load from file
if file_path: Messages.send_start_load(file_path)
flow_graph = self._platform.get_new_flow_graph()
is_blank = False
if not flow_graph:
flow_graph = self._platform.get_new_flow_graph()
is_blank = True
flow_graph.grc_file_path = file_path
#print flow_graph
page = NotebookPage(
self,
flow_graph=flow_graph,
file_path=file_path,
is_blank = is_blank
)
if file_path: Messages.send_end_load()
except Exception, e: #return on failure

View File

@ -25,12 +25,12 @@ from StateCache import StateCache
from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT
from DrawingArea import DrawingArea
import os
from FlowGraph import FlowGraph
class NotebookPage(gtk.HBox):
"""A page in the notebook."""
def __init__(self, main_window, flow_graph, file_path=''):
def __init__(self, main_window, flow_graph, file_path='', is_blank = True):
"""
Page constructor.
@ -38,16 +38,22 @@ class NotebookPage(gtk.HBox):
main_window: main window
file_path: path to a flow graph file
"""
self._flow_graph = flow_graph
self._flow_graph = FlowGraph(platform=flow_graph.platform)
self.process = None
#import the file
self.main_window = main_window
self.file_path = file_path
initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
self.state_cache = StateCache(initial_state)
self.saved = True
#import the data to the flow graph
self.get_flow_graph().import_data(initial_state)
if is_blank:
initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
self.state_cache = StateCache(initial_state)
self.get_flow_graph().import_data(initial_state)
self.saved = True
else:
initial_state = flow_graph.export_data()
self.state_cache = StateCache(initial_state)
self.get_flow_graph().import_data(initial_state)
self.saved = False
#initialize page gui
gtk.HBox.__init__(self, False, 0)
self.show()