def main(self): self.mainContainer = gui.Widget( width='100%', height='100%', layout_orientation=gui.Widget.LAYOUT_VERTICAL) self.mainContainer.style['background-color'] = 'white' self.mainContainer.style['border'] = 'none' menubar = gui.MenuBar(height='4%') menu = gui.Menu(width='100%', height='100%') menu.style['z-index'] = '1' m1 = gui.MenuItem('File', width=150, height='100%') m10 = gui.MenuItem('New', width=150, height=30) m11 = gui.MenuItem('Open', width=150, height=30) m12 = gui.MenuItem('Save Your App', width=150, height=30) #m12.style['visibility'] = 'hidden' m121 = gui.MenuItem('Save', width=100, height=30) m122 = gui.MenuItem('Save as', width=100, height=30) m1.append([m10, m11, m12]) m12.append([m121, m122]) m2 = gui.MenuItem('Edit', width=100, height='100%') m21 = gui.MenuItem('Cut', width=100, height=30) m22 = gui.MenuItem('Paste', width=100, height=30) m2.append([m21, m22]) m3 = gui.MenuItem('Project Config', width=200, height='100%') menu.append([m1, m2, m3]) menubar.append(menu) self.toolbar = editor_widgets.ToolBar(width='100%', height='30px', margin='0px 0px') self.toolbar.style['border-bottom'] = '1px solid rgba(0,0,0,.12)' self.toolbar.add_command('/editor_resources:delete.png', self.toolbar_delete_clicked, 'Delete Widget') self.toolbar.add_command('/editor_resources:cut.png', self.menu_cut_selection_clicked, 'Cut Widget') self.toolbar.add_command('/editor_resources:paste.png', self.menu_paste_selection_clicked, 'Paste Widget') lbl = gui.Label("Snap grid", width=100) spin_grid_size = gui.SpinBox('1', '1', '100', width=50) spin_grid_size.set_on_change_listener(self.on_snap_grid_size_change) grid_size = gui.HBox(children=[lbl, spin_grid_size], style={ 'outline': '1px solid gray', 'margin': '2px', 'margin-left': '10px' }) self.toolbar.append(grid_size) self.fileOpenDialog = editor_widgets.EditorFileSelectionDialog( 'Open Project', 'Select the project file.<br>It have to be a python program created with this editor.', False, '.', True, False, self) self.fileOpenDialog.confirm_value.connect(self.on_open_dialog_confirm) self.fileSaveAsDialog = editor_widgets.EditorFileSaveDialog( 'Project Save', 'Select the project folder and type a filename', False, '.', False, True, self) self.fileSaveAsDialog.add_fileinput_field('untitled.py') self.fileSaveAsDialog.confirm_value.connect( self.on_saveas_dialog_confirm) m10.onclick.connect(self.menu_new_clicked) m11.onclick.connect(self.fileOpenDialog.show) m121.onclick.connect(self.menu_save_clicked) m122.onclick.connect(self.fileSaveAsDialog.show) m21.onclick.connect(self.menu_cut_selection_clicked) m22.onclick.connect(self.menu_paste_selection_clicked) m3.onclick.connect(self.menu_project_config_clicked) self.subContainer = gui.HBox( width='100%', height='96%', layout_orientation=gui.Widget.LAYOUT_HORIZONTAL) self.subContainer.style.update({ 'position': 'relative', 'overflow': 'auto', 'align-items': 'stretch' }) #here are contained the widgets self.widgetsCollection = editor_widgets.WidgetCollection(self, width='100%', height='50%') self.project = Project(width='100%', height='100%') self.project.style['min-height'] = '400px' self.project.attributes['ondragover'] = "event.preventDefault();" self.EVENT_ONDROPPPED = "on_dropped" self.project.attributes['ondrop'] = """event.preventDefault(); var data = JSON.parse(event.dataTransfer.getData('application/json')); var params={}; if( data[0] == 'add'){ params['left']=event.clientX-event.currentTarget.getBoundingClientRect().left; params['top']=event.clientY-event.currentTarget.getBoundingClientRect().top; } sendCallbackParam(data[1],'%(evt)s',params); return false;""" % { 'evt': self.EVENT_ONDROPPPED } self.project.attributes['editor_varname'] = 'App' self.project.onkeydown.connect(self.onkeydown) self.projectConfiguration = editor_widgets.ProjectConfigurationDialog( 'Project Configuration', 'Write here the configuration for your project.') self.attributeEditor = editor_widgets.EditorAttributes(self, width='100%') self.attributeEditor.style['overflow'] = 'hide' self.signalConnectionManager = editor_widgets.SignalConnectionManager( width='100%', height='50%') self.mainContainer.append([menubar, self.subContainer]) self.subContainerLeft = gui.Widget(width='20%', height='100%') self.subContainerLeft.style['position'] = 'relative' self.subContainerLeft.style['left'] = '0px' self.subContainerLeft.append( [self.widgetsCollection, self.signalConnectionManager]) self.subContainerLeft.add_class('RaisedFrame') self.centralContainer = gui.VBox(width='56%', height='100%') self.centralContainer.append([self.toolbar, self.project]) self.subContainerRight = gui.Widget(width='24%', height='100%') self.subContainerRight.style.update({ 'position': 'absolute', 'right': '0px', 'overflow': 'scroll' }) self.subContainerRight.add_class('RaisedFrame') self.instancesWidget = editor_widgets.InstancesWidget(width='100%') self.instancesWidget.treeView.on_tree_item_selected.connect( self.on_instances_widget_selection) self.subContainerRight.append( [self.instancesWidget, self.attributeEditor]) self.subContainer.append([ self.subContainerLeft, self.centralContainer, self.subContainerRight ]) self.project.style['position'] = 'relative' self.drag_helpers = [ ResizeHelper(self.project, width=16, height=16), DragHelper(self.project, width=15, height=15), SvgDraggablePoint(self.project, 'cx', 'cy', [gui.SvgCircle]), SvgDraggableCircleResizeRadius(self.project, [gui.SvgCircle]), SvgDraggablePoint(self.project, 'x1', 'y1', [gui.SvgLine]), SvgDraggablePoint(self.project, 'x2', 'y2', [gui.SvgLine]), SvgDraggablePoint(self.project, 'x', 'y', [gui.SvgRectangle, gui.SvgText]), SvgDraggableRectangleResizePoint(self.project, [gui.SvgRectangle]) ] for drag_helper in self.drag_helpers: drag_helper.stop_drag.connect(self.on_drag_resize_end) self.menu_new_clicked(None) self.projectPathFilename = '' self.editCuttedWidget = None #cut operation, contains the cutted tag # returning the root widget return self.mainContainer
def main(self): self.mainContainer = gui.Container( width='100%', height='100%', layout_orientation=gui.Container.LAYOUT_VERTICAL, style={ 'background-color': 'white', 'border': 'none', 'overflow': 'hidden' }) menubar = gui.MenuBar(height='4%') menu = gui.Menu(width='100%', height='100%') menu.style['z-index'] = '1' m1 = gui.MenuItem('File', width=150, height='100%') m10 = gui.MenuItem('New', width=150, height=30) m11 = gui.MenuItem('Open', width=150, height=30) m12 = gui.MenuItem('Save Your App', width=150, height=30) #m12.style['visibility'] = 'hidden' m121 = gui.MenuItem('Save', width=100, height=30) m122 = gui.MenuItem('Save as', width=100, height=30) m123 = gui.MenuItem('Export widget as', width=200, height=30) m1.append([m10, m11, m12]) m12.append([m121, m122, m123]) m2 = gui.MenuItem('Edit', width=100, height='100%') m21 = gui.MenuItem('Cut', width=100, height=30) m22 = gui.MenuItem('Paste', width=100, height=30) m2.append([m21, m22]) m3 = gui.MenuItem('Project Config', width=200, height='100%') m4 = gui.MenuItem('Became a Patron', width=200, height='100%', style={'font-weight': 'bold'}) menu.append([m1, m2, m3, m4]) menubar.append(menu) self.toolbar = editor_widgets.ToolBar(width='100%', height='30px', margin='0px 0px') self.toolbar.style['border-bottom'] = '1px solid rgba(0,0,0,.12)' self.toolbar.add_command('/editor_resources:delete.png', self.toolbar_delete_clicked, 'Delete Widget') self.toolbar.add_command('/editor_resources:cut.png', self.menu_cut_selection_clicked, 'Cut Widget') self.toolbar.add_command('/editor_resources:paste.png', self.menu_paste_selection_clicked, 'Paste Widget') lbl = gui.Label("Snap grid", width=100) spin_grid_size = gui.SpinBox('15', '1', '100', width=50) spin_grid_size.set_on_change_listener(self.on_snap_grid_size_change) grid_size = gui.HBox(children=[lbl, spin_grid_size], style={ 'outline': '1px solid gray', 'margin': '2px', 'margin-left': '10px' }) self.toolbar.append(grid_size) self.fileOpenDialog = editor_widgets.EditorFileSelectionDialog( 'Open Project', 'Select the project file.<br>It have to be a python program created with this editor.', False, '.', True, False, self) self.fileOpenDialog.confirm_value.do(self.on_open_dialog_confirm) self.fileSaveAsDialog = editor_widgets.EditorFileSaveDialog( 'Project Save', 'Select the project folder and type a filename', False, '.', False, True, self) self.fileSaveAsDialog.add_fileinput_field('untitled.py') self.fileSaveAsDialog.confirm_value.do(self.menu_save_clicked) m10.onclick.do(self.menu_new_clicked) m11.onclick.do(self.fileOpenDialog.show) m121.onclick.do(self.menu_save_clicked) m122.onclick.do(self.fileSaveAsDialog.show) m123.onclick.do(self.menu_save_widget_clicked) m21.onclick.do(self.menu_cut_selection_clicked) m22.onclick.do(self.menu_paste_selection_clicked) m3.onclick.do(self.menu_project_config_clicked) m4.onclick.do(self.menu_became_a_patron) self.subContainer = gui.HBox( width='100%', height='96%', layout_orientation=gui.Container.LAYOUT_HORIZONTAL) self.subContainer.style.update({ 'position': 'relative', 'overflow': 'hidden', 'align-items': 'stretch' }) # here are contained the widgets self.widgetsCollection = editor_widgets.WidgetCollection(self, width='100%', height='50%') self.projectConfiguration = editor_widgets.ProjectConfigurationDialog( 'Project Configuration', 'Write here the configuration for your project.') self.attributeEditor = editor_widgets.EditorAttributes(self, width='100%') self.attributeEditor.style['overflow'] = 'hide' self.signalConnectionManager = editor_widgets.SignalConnectionManager( width='100%', height='50%', style={'order': '1'}) self.mainContainer.append([menubar, self.subContainer]) self.subContainerLeft = gui.VBox(width='20%', height='100%') self.subContainerLeft.style['position'] = 'relative' self.subContainerLeft.style['left'] = '0px' self.widgetsCollection.style['order'] = '0' self.subContainerLeft.append({ 'widgets_collection': self.widgetsCollection, 'signal_manager': self.signalConnectionManager }) self.subContainerLeft.add_class('RaisedFrame') self.centralContainer = gui.VBox(width='56%', height='100%') self.centralContainer.append(self.toolbar) self.subContainerRight = gui.Container(width='24%', height='100%') self.subContainerRight.style.update({ 'position': 'absolute', 'right': '0px', 'overflow-y': 'auto', 'overflow-x': 'hidden' }) self.subContainerRight.add_class('RaisedFrame') self.instancesWidget = editor_widgets.InstancesWidget(width='100%') self.instancesWidget.treeView.on_tree_item_selected.do( self.on_instances_widget_selection) self.subContainerRight.append({ 'instances_widget': self.instancesWidget, 'attributes_editor': self.attributeEditor }) self.subContainer.append([ self.subContainerLeft, self.centralContainer, self.subContainerRight ]) self.drag_helpers = [ ResizeHelper(self, width=16, height=16), DragHelper(self, width=15, height=15), SvgDraggablePoint(self, 'cx', 'cy', [gui.SvgCircle]), SvgDraggableCircleResizeRadius(self, [gui.SvgCircle]), SvgDraggablePoint(self, 'x1', 'y1', [gui.SvgLine]), SvgDraggablePoint(self, 'x2', 'y2', [gui.SvgLine]), SvgDraggablePoint(self, 'x', 'y', [gui.SvgRectangle, gui.SvgText]), SvgDraggableRectangleResizePoint(self, [gui.SvgRectangle]) ] for drag_helper in self.drag_helpers: drag_helper.stop_drag.do(self.on_drag_resize_end) self.menu_new_clicked(None) self.on_snap_grid_size_change(spin_grid_size, spin_grid_size.get_value()) self.projectPathFilename = '' self.editCuttedWidget = None # cut operation, contains the cutted tag # returning the root widget return self.mainContainer
def main(self): self.mainContainer = gui.Widget( width='100%', height='100%', layout_orientation=gui.Widget.LAYOUT_VERTICAL) self.mainContainer.style['background-color'] = 'white' self.mainContainer.style['border'] = 'none' menubar = gui.MenuBar(height='4%') menu = gui.Menu(width='100%', height='100%') menu.style['z-index'] = '1' m1 = gui.MenuItem('File', width=150, height='100%') m10 = gui.MenuItem('New', width=150, height=30) m11 = gui.MenuItem('Open', width=150, height=30) m12 = gui.MenuItem('Save Your App', width=150, height=30) #m12.style['visibility'] = 'hidden' m121 = gui.MenuItem('Save', width=100, height=30) m122 = gui.MenuItem('Save as', width=100, height=30) m1.append(m10) m1.append(m11) m1.append(m12) m12.append(m121) m12.append(m122) m2 = gui.MenuItem('Edit', width=100, height='100%') m21 = gui.MenuItem('Cut', width=100, height=30) m22 = gui.MenuItem('Paste', width=100, height=30) m2.append(m21) m2.append(m22) m3 = gui.MenuItem('Project Config', width=200, height='100%') menu.append(m1) menu.append(m2) menu.append(m3) menubar.append(menu) self.toolbar = editor_widgets.ToolBar(width='100%', height='30px', margin='0px 0px') self.toolbar.style['border-bottom'] = '1px solid rgba(0,0,0,.12)' self.toolbar.add_command('/res/delete.png', self.toolbar_delete_clicked, 'Delete Widget') self.toolbar.add_command('/res/cut.png', self.menu_cut_selection_clicked, 'Cut Widget') self.toolbar.add_command('/res/paste.png', self.menu_paste_selection_clicked, 'Paste Widget') self.fileOpenDialog = editor_widgets.EditorFileSelectionDialog( 'Open Project', 'Select the project file.<br>It have to be a python program created with this editor.', False, '.', True, False, self) self.fileOpenDialog.set_on_confirm_value_listener( self.on_open_dialog_confirm) self.fileSaveAsDialog = editor_widgets.EditorFileSaveDialog( 'Project Save', 'Select the project folder and type a filename', False, '.', False, True, self) self.fileSaveAsDialog.add_fileinput_field('untitled.py') self.fileSaveAsDialog.set_on_confirm_value_listener( self.on_saveas_dialog_confirm) m10.set_on_click_listener(self.menu_new_clicked) m11.set_on_click_listener(self.fileOpenDialog.show) m121.set_on_click_listener(self.menu_save_clicked) m122.set_on_click_listener(self.fileSaveAsDialog.show) m21.set_on_click_listener(self.menu_cut_selection_clicked) m22.set_on_click_listener(self.menu_paste_selection_clicked) m3.set_on_click_listener(self.menu_project_config_clicked) self.subContainer = gui.HBox( width='100%', height='96%', layout_orientation=gui.Widget.LAYOUT_HORIZONTAL) self.subContainer.style['position'] = 'relative' self.subContainer.style['overflow'] = 'auto' self.subContainer.style['align-items'] = 'stretch' #here are contained the widgets self.widgetsCollection = editor_widgets.WidgetCollection(self, width='100%', height='50%') self.project = Project(width='100%', height='100%') self.project.style['min-height'] = '400px' self.project.attributes['ondragover'] = "event.preventDefault();" self.EVENT_ONDROPPPED = "on_dropped" self.project.attributes['ondrop'] = """event.preventDefault(); var data = JSON.parse(event.dataTransfer.getData('application/json')); var params={}; if( data[0] == 'resize'){ document.getElementById(data[1]).style.left = parseInt(document.getElementById(data[1]).style.left) + event.clientX - data[2] + 'px'; document.getElementById(data[1]).style.top = parseInt(document.getElementById(data[1]).style.top) + event.clientY - data[3] + 'px'; params['left']=document.getElementById(data[1]).style.left; params['top']=document.getElementById(data[1]).style.top; } if( data[0] == 'add'){ params['left']=event.clientX-event.currentTarget.getBoundingClientRect().left; params['top']=event.clientY-event.currentTarget.getBoundingClientRect().top; } if( data[0] == 'move'){ document.getElementById(data[1]).style.left = parseInt(document.getElementById(data[1]).style.left) + event.clientX - data[2] + 'px'; document.getElementById(data[1]).style.top = parseInt(document.getElementById(data[1]).style.top) + event.clientY - data[3] + 'px'; params['left']=document.getElementById(data[1]).style.left; params['top']=document.getElementById(data[1]).style.top; } sendCallbackParam(data[1],'%(evt)s',params); return false;""" % { 'evt': self.EVENT_ONDROPPPED } self.project.attributes['editor_varname'] = 'App' self.project.attributes[self.project.EVENT_ONKEYDOWN] = """ var params={}; params['keypressed']=event.keyCode; sendCallbackParam('%(id)s','%(evt)s',params); if(event.keyCode==46){ return false; } """ % { 'id': str(id(self)), 'evt': self.project.EVENT_ONKEYDOWN } self.projectConfiguration = editor_widgets.ProjectConfigurationDialog( 'Project Configuration', 'Write here the configuration for your project.') self.attributeEditor = editor_widgets.EditorAttributes(self, width='100%') self.attributeEditor.style['overflow'] = 'hide' self.signalConnectionManager = editor_widgets.SignalConnectionManager( width='100%', height='50%') self.mainContainer.append(menubar) self.mainContainer.append(self.subContainer) self.subContainerLeft = gui.Widget(width='20%', height='100%') self.subContainerLeft.style['position'] = 'relative' self.subContainerLeft.style['left'] = '0px' self.subContainerLeft.append(self.widgetsCollection) self.subContainerLeft.append(self.signalConnectionManager) self.subContainerLeft.add_class('RaisedFrame') self.centralContainer = gui.VBox(width='56%', height='100%') self.centralContainer.append(self.toolbar) self.centralContainer.append(self.project) self.subContainerRight = gui.Widget(width='24%', height='100%') self.subContainerRight.style['position'] = 'absolute' self.subContainerRight.style['right'] = '0px' self.subContainerRight.style['overflow'] = 'scroll' self.subContainerRight.add_class('RaisedFrame') self.instancesWidget = editor_widgets.InstancesWidget(width='100%') self.instancesWidget.dropDown.set_on_change_listener( self.on_instances_widget_selection) self.subContainerRight.append(self.instancesWidget) self.subContainerRight.append(self.attributeEditor) self.subContainer.append(self.subContainerLeft) self.subContainer.append(self.centralContainer) self.subContainer.append(self.subContainerRight) self.project.style['position'] = 'relative' self.resizeHelper = ResizeHelper(width=16, height=16) self.dragHelper = DragHelper(width=15, height=15) self.menu_new_clicked(None) self.projectPathFilename = '' self.editCuttedWidget = None #cut operation, contains the cutted tag # returning the root widget return self.mainContainer