Skip to content

Commit

Permalink
tabs to menu, safe for python 2.6, rename ComponentsControl, add script
Browse files Browse the repository at this point in the history
  • Loading branch information
gamaanderson committed Aug 2, 2015
1 parent 0381223 commit d533b9f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 44 deletions.
13 changes: 8 additions & 5 deletions artview/__main__.py
Expand Up @@ -9,10 +9,13 @@

import artview

def main(argv):
script, DirIn, filename, field = artview.parser.parse(argv)

script, DirIn, filename, field = artview.parser.parse(sys.argv)
if script:
artview.scripts.scripts[script](DirIn, filename, field)
else:
artview.run(DirIn, filename, field)

if script:
artview.scripts.scripts[script](DirIn, filename, field)
else:
artview.run(DirIn, filename, field)
if __name__ == "__main__":
main(sys.argv)
36 changes: 18 additions & 18 deletions artview/components/component_control.py
Expand Up @@ -109,8 +109,8 @@ def _setRadioButtons(self):
# Radio Buttons
self.radioLayout = QtGui.QGridLayout()
self.layout.addLayout(self.radioLayout, 2, 0)
self.radioLayout.addWidget(QtGui.QLabel("Conect"), 0, 1)
self.radioLayout.addWidget(QtGui.QLabel("Disconect"), 0, 2)
self.radioLayout.addWidget(QtGui.QLabel("Link"), 0, 1)
self.radioLayout.addWidget(QtGui.QLabel("Unlink"), 0, 2)

self.radioBoxes = []
for idx, var in enumerate(self.variables):
Expand All @@ -121,26 +121,26 @@ def _addRadioButton(self, var, idx):
radioBox = QtGui.QButtonGroup()
self.radioBoxes.append(radioBox) # avoid garbage collector

conect = QtGui.QRadioButton()
disconect = QtGui.QRadioButton()
QtCore.QObject.connect(conect, QtCore.SIGNAL("clicked()"),
partial(self.conectVar, var))
QtCore.QObject.connect(disconect, QtCore.SIGNAL("clicked()"),
partial(self.disconectVar, var))
radioBox.addButton(conect)
radioBox.addButton(disconect)
link = QtGui.QRadioButton()
unlink = QtGui.QRadioButton()
QtCore.QObject.connect(link, QtCore.SIGNAL("clicked()"),
partial(self.connectVar, var))
QtCore.QObject.connect(unlink, QtCore.SIGNAL("clicked()"),
partial(self.disconnectVar, var))
radioBox.addButton(link)
radioBox.addButton(unlink)

if getattr(self.comp0, var) is getattr(self.comp1, var):
conect.setChecked(True)
link.setChecked(True)
else:
disconect.setChecked(True)
unlink.setChecked(True)

if self.comp0 is self.comp1:
disconect.setDisabled(True)
unlink.setDisabled(True)

self.radioLayout.addWidget(QtGui.QLabel(var), idx+1, 0)
self.radioLayout.addWidget(conect, idx+1, 1)
self.radioLayout.addWidget(disconect, idx+1, 2)
self.radioLayout.addWidget(QtGui.QLabel(var[1::]), idx+1, 0)
self.radioLayout.addWidget(link, idx+1, 1)
self.radioLayout.addWidget(unlink, idx+1, 2)

def _comp0Action(self, idx):
'''Update Component 0'''
Expand All @@ -158,7 +158,7 @@ def _comp1Action(self, idx):
self.layout.removeItem(self.radioLayout)
self._setRadioButtons()

def conectVar(self, var):
def connectVar(self, var):
'''Assign variable in component 0 to component 1'''
# Disconect old Variable
self.comp1.disconnectSharedVariable(var)
Expand All @@ -171,7 +171,7 @@ def conectVar(self, var):
print "connect var %s of %s from %s" % (
var, self.comp1.name, self.comp0.name)

def disconectVar(self, var):
def disconnectVar(self, var):
'''Turn variable in component 1 independente of component 0'''
# Disconect old Variable
self.comp1.disconnectSharedVariable(var)
Expand Down
41 changes: 25 additions & 16 deletions artview/components/menu.py
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import pyart

import os
import os, sys
from PyQt4 import QtGui, QtCore

from ..core import Variable, Component, common
Expand Down Expand Up @@ -100,16 +100,23 @@ def LaunchApp(self):
'''Launches a GUI interface.'''
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

# Create layout
self.central_widget = QtGui.QWidget()
self.setCentralWidget(self.central_widget)
self.centralLayout = QtGui.QVBoxLayout(self.central_widget)
self.centralLayout.setSpacing(8)
self.frames = {}

# Create the menus
self.CreateMenu()

# Create layout
if sys.version_info<(2,7,0):
self.central_widget = QtGui.QWidget()
self.setCentralWidget(self.central_widget)
self.centralLayout = QtGui.QVBoxLayout(self.central_widget)
self.centralLayout.setSpacing(8)
self.frames = {}
self.addLayoutMenu()
else:
self.mdiArea = QtGui.QMdiArea()
self.setCentralWidget(self.mdiArea)
self.mdiArea.setViewMode(1)
self.mdiArea.setTabsClosable(True)

def showFileDialog(self):
'''Open a dialog box to choose file.'''

Expand All @@ -127,13 +134,16 @@ def addLayoutWidget(self, widget):
Add a widget to central layout.
This function is to be called both internal and external
'''
frame = QtGui.QFrame()
frame.setFrameShape(QtGui.QFrame.Box)
layout = QtGui.QVBoxLayout(frame)
layout.addWidget(widget)
self.frames[widget.__repr__()] = frame
self.centralLayout.addWidget(frame)
self.addLayoutMenuItem(widget)
if sys.version_info<(2,7,0):
frame = QtGui.QFrame()
frame.setFrameShape(QtGui.QFrame.Box)
layout = QtGui.QVBoxLayout(frame)
layout.addWidget(widget)
self.frames[widget.__repr__()] = widget
self.centralLayout.addWidget(widget)
self.addLayoutMenuItem(widget)
else:
self.mdiArea.addSubWindow(widget)

def removeLayoutWidget(self, widget):
'''Remove widget from central layout.'''
Expand Down Expand Up @@ -163,7 +173,6 @@ def CreateMenu(self):
self.addFileMenu()
self.addAboutMenu()
self.addFileAdvanceMenu()
self.addLayoutMenu()
self.addComponentMenu()

def addFileMenu(self):
Expand Down
6 changes: 5 additions & 1 deletion artview/core/core.py
Expand Up @@ -9,6 +9,7 @@

# Load the needed packages
from PyQt4 import QtGui, QtCore
import sys

# keet track of all components, this is not fundamental, but may be usefull
# for some control utilities
Expand Down Expand Up @@ -166,7 +167,10 @@ def __init__(self, name="Component", parent=None, flags=QtCore.Qt.Widget):
Parent instance to associate to Component. If None, then Qt owns,
otherwise associated with parent PyQt instance.
'''
super(Component, self).__init__(parent=parent, flags=flags)
if sys.version_info<(2,7,0):
super(Component, self).__init__()
else:
super(Component, self).__init__(parent=parent, flags=flags)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.name = name
self.parent = parent
Expand Down
5 changes: 2 additions & 3 deletions artview/scripts/standard.py
Expand Up @@ -71,9 +71,8 @@ def run(DirIn=os.getcwd(), filename=None, field=None):
height = desktop_rect.height()
width = desktop_rect.width()

menu_width = max(
MainMenu.menubar.sizeHint().width(), MainMenu.sizeHint().width())
menu_height = MainMenu.sizeHint().height()
menu_width = 300
menu_height = 180

MainMenu.setGeometry(0, 0, menu_width, menu_height)

Expand Down
5 changes: 5 additions & 0 deletions scripts/artview
@@ -0,0 +1,5 @@
#! /usr/bin/env python

import sys
import artview.__main__
artview.__main__.main(sys.argv)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -54,7 +54,7 @@
MICRO = 0
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
SCRIPTS = glob.glob('scripts/*')
SCRIPTS = glob.glob('scripts/*') + ['scripts/artview']


# Return the git revision as a string
Expand Down

0 comments on commit d533b9f

Please sign in to comment.