Changeset 4992:80c9f8d2e548 in orange


Ignore:
Timestamp:
07/18/08 17:36:23 (6 years ago)
Author:
gregor <gregor@…>
Branch:
default
Convert:
0d1576a82c373d29feb8f8cd3b7a2a0a6e5290ed
Message:
  • tree view is now even more beautiful.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeCanvas/orngTabs.py

    r4991 r4992  
    465465        iconSize = self.canvasDlg.iconSizeDict[self.canvasDlg.settings["iconSize"]] 
    466466        self.treeWidget.setIconSize(QSize(iconSize,iconSize)) 
     467        self.treeWidget.setRootIsDecorated(0)  
    467468                 
    468469 
     
    470471        item = QTreeWidgetItem(self.treeWidget) 
    471472        item.setText(0, name) 
    472         #item.setBackground(0, QBrush(QColor(200,200,200))) 
    473473        item.widgets = [] 
    474474        self.tabDict[name] = item 
    475475          
    476         if show: 
    477             self.treeWidget.insertTopLevelItem(self.treeWidget.topLevelItemCount(), item) 
     476        push = WidgetTreeButton(item, name, self.treeWidget) 
     477        self.treeWidget.setItemWidget(item, 0, push) 
     478         
     479        if not show: 
     480            item.setHidden(1) 
     481        if self.treeWidget.topLevelItemCount() == 1: 
     482            item.setExpanded(1) 
    478483        self.tabs.append((name, 2*int(show), item)) 
    479484 
    480485        return item 
    481486 
    482  
     487# button that contains the name of the widget category.  
     488# when clicked it shows or hides the widgets in the category 
     489class WidgetTreeButton(QPushButton): 
     490    def __init__(self, treeItem, name, parent): 
     491        QPushButton.__init__(self, name, parent) 
     492        self.treeItem = treeItem 
     493         
     494    def mousePressEvent(self, e): 
     495        self.treeItem.setExpanded(not self.treeItem.isExpanded()) 
    483496 
    484497class WidgetToolBox(WidgetListBase, QDockWidget): 
     
    533546        self.setMouseTracking(1) 
    534547        self.setHeaderHidden(1) 
     548        self.mousePressed = 0 
     549        self.mouseRightClick = 0 
     550        self.connect(self, SIGNAL("itemClicked (QTreeWidgetItem *,int)"), self.itemClicked) 
    535551 
    536552         
    537553    def mouseMoveEvent(self, e): 
    538         QTreeWidget.mouseMoveEvent(self, e) 
     554        if not self.mousePressed:   # this is needed, otherwise another widget in the tree might get selected while we drag the icon to the canvas 
     555            QTreeWidget.mouseMoveEvent(self, e) 
    539556        ### Semaphore "busy" is needed for some widgets whose loading takes more time, e.g. Select Data 
    540557        ### Since the active window cannot change during dragging, we wouldn't have to remember the window; but let's leave the code in, it can't hurt 
     
    576593        delattr(self, "busy") 
    577594         
     595    def mousePressEvent(self, e): 
     596        QTreeWidget.mousePressEvent(self, e) 
     597        self.mousePressed = 1 
     598        self.mouseRightClick = e.button() == Qt.RightButton 
     599         
    578600    def mouseReleaseEvent(self, e): 
    579601        QTreeWidget.mouseReleaseEvent(self, e) 
    580602        dinwin, widget = getattr(self, "widgetDragging", (None, None)) 
    581         self.shiftPressed = e.modifiers() & Qt.ShiftModifier 
     603        self.shiftPressed = bool(e.modifiers() & Qt.ShiftModifier) 
    582604        if widget: 
    583605            if widget.invalidPosition: 
     
    587609                dinwin.addLine(dinwin.widgets[-2], dinwin.widgets[-1]) 
    588610            delattr(self, "widgetDragging") 
    589         else: 
    590             win = self.canvasDlg.workspace.activeSubWindow() 
    591             if (win and isinstance(win, orngDoc.SchemaDoc)): 
    592                 if self.selectedItems() and isinstance(self.selectedItems()[0], WidgetTreeItem): 
    593                     win.addWidget(self.selectedItems()[0]) 
    594 #                    if (rightClick or self.shiftPressed) and len(win.widgets) > 1: 
    595 #                        win.addLine(win.widgets[-2], win.widgets[-1]) 
    596             elif (isinstance(win, orngOutput.OutputWindow)): 
    597                 QMessageBox.information(self,'Orange Canvas','Unable to add widget instance to Output window. Please select a document window first.',QMessageBox.Ok) 
    598             else: 
    599                 QMessageBox.information(self,'Orange Canvas','Unable to add widget instance. Please open a document window first.',QMessageBox.Ok) 
    600              
     611            
     612        self.mousePressed = 0 
     613         
     614    def itemClicked(self, item, column): 
     615        win = self.canvasDlg.workspace.activeSubWindow() 
     616        if (win and isinstance(win, orngDoc.SchemaDoc)): 
     617            win.addWidget(item) 
     618            if (self.mouseRightClick or self.shiftPressed) and len(win.widgets) > 1: 
     619                win.addLine(win.widgets[-2], win.widgets[-1]) 
     620        elif (isinstance(win, orngOutput.OutputWindow)): 
     621            QMessageBox.information(self,'Orange Canvas','Unable to add widget instance to Output window. Please select a document window first.',QMessageBox.Ok) 
     622        else: 
     623            QMessageBox.information(self,'Orange Canvas','Unable to add widget instance. Please open a document window first.',QMessageBox.Ok) 
     624     
Note: See TracChangeset for help on using the changeset viewer.