Changeset 115 in main for trunk/plugins
- Timestamp:
- 07/21/10 13:50:49 (12 years ago)
- Location:
- trunk/plugins/freecad/OpenPLM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/freecad/OpenPLM/InitGui.py
r114 r115 155 155 156 156 MenuText = "OpenPLM" 157 ToolTip = "The OpenPLM module is used for basic 2D CAD OpenPLMing"157 ToolTip = "The OpenPLM module" 158 158 159 159 def Initialize(self): … … 163 163 self.cmdList = ["OpenPLM_Login"] 164 164 self.appendMenu("OpenPLM", self.cmdList) 165 self.cmdList2 = ["OpenPLM_CheckOut"] 165 self.cmdList2 = ["OpenPLM_CheckOut", "OpenPLM_Download", "OpenPLM_Forget", 166 "OpenPLM_CheckIn", "OpenPLM_Revise", 167 "OpenPLM_AttachToPart", "OpenPLM_Create", 168 "OpenPLM_Configure"] 166 169 self.appendMenu("OpenPLM", self.cmdList2) 167 170 FreeCAD.activeOpenPLMCommand = None # a global place to look for active draft Command -
trunk/plugins/freecad/OpenPLM/openplm.py
r114 r115 21 21 connect = QtCore.QObject.connect 22 22 23 def close(gdoc, desktop): 24 enum = desktop.getComponents().createEnumeration() 25 cpt = 0 26 while enum.hasMoreElements(): 27 cpt += 1 28 enum.nextElement() 29 gdoc.setModified(False) 30 if cpt == 1: 31 name = "_default" 32 type = doc_to_type(gdoc) 33 desktop.loadComponentFromURL("private:factory/" + type, name, 34 CREATE | ALL, ()) 35 try: 36 gdoc.close(True) 37 except CloseVetoException: 38 pass 23 def main_window(): 24 app = qt.qApp 25 for x in app.topLevelWidgets(): 26 if type(x) == qt.QMainWindow: 27 return x 28 29 def close(gdoc): 30 FreeCAD.closeDocument(gdoc.Label) 39 31 40 32 class OpenPLMPluginInstance(object): … … 55 47 urllib2.HTTPCookieProcessor()) 56 48 self.username = "" 57 self.desktop = None58 49 self.documents = {} 59 50 self.disable_menuitems() … … 68 59 pass 69 60 70 def set_desktop(self, desktop): 71 self.desktop = desktop 72 self.window = desktop.getCurrentFrame().ContainerWindow 61 self.window = main_window() 73 62 74 63 def disable_menuitems(self): … … 112 101 # directory already exists, just ignores the exception 113 102 pass 114 gdoc = self.desktop.getCurrentComponent()103 gdoc = FreeCAD.ActiveDocument 115 104 path = os.path.join(rep, filename) 116 gdoc.storeAsURL("file://" + path, ()) 105 gdoc.FileName = path 106 FreeCADGui.runCommand("Std_Save") 117 107 doc_file = self.upload_file(doc, path) 118 108 self.add_managed_file(doc, doc_file, path) … … 207 197 208 198 def set_server(self, url): 199 if not url.endswith("/"): 200 url += "/" 209 201 data = self.get_conf_data() 210 202 data["server"] = url … … 225 217 226 218 def forget(self, gdoc=None, delete=True, close_doc=False): 227 gdoc = gdoc or self.desktop.getCurrentComponent()219 gdoc = gdoc or FreeCAD.ActiveDocument 228 220 if gdoc and gdoc in self.documents: 229 221 doc = self.documents[gdoc]["openplm_doc"] … … 239 231 os.remove(path) 240 232 if close_doc: 241 close(gdoc , self.desktop)233 close(gdoc) 242 234 243 235 def load_managed_files(self): … … 245 237 self.load_file(doc, doc_file_id, path) 246 238 247 def load_file(self, doc, doc_file_id, path): 248 document = FreeCAD.openDocument(path) 249 if not document: 239 def load_file(self, doc, doc_file_id, path, gdoc=None): 240 try: 241 document = gdoc or FreeCAD.openDocument(path) 242 except IOError: 250 243 show_error("Can not load %s" % path, self.window) 251 244 return … … 273 266 self.forget(gdoc) 274 267 if save: 275 gdoc.store()268 FreeCADGui.runCommand("Std_Save") 276 269 func() 277 270 else: … … 288 281 {"revision" : revision}) 289 282 new_doc = res["doc"] 290 name = os.path.basename(gdoc )283 name = os.path.basename(gdoc.FileName) 291 284 doc_file = None 292 285 for f in res["files"]: … … 302 295 # directory already exists, just ignores the exception 303 296 pass 304 305 gdoc.store()306 new_path = os.path.join(rep, name)307 shutil.move(path, new_path)308 self.forget(gdoc, delete=False)309 gd = self.load_file(new_doc, doc_file["id"], new_path)310 self.add_managed_file(new_doc, doc_file, new_path)297 298 self.forget(gdoc, close_doc=False) 299 path = os.path.join(rep, name) 300 gdoc.FileName = path 301 FreeCADGui.runCommand("Std_Save") 302 gd = self.load_file(new_doc, doc_file["id"], path, gdoc) 303 self.add_managed_file(new_doc, doc_file, path) 311 304 self.check_in(gd, unlock, False) 312 self.get_data("api/object/%s/unlock/%s/" % (doc["id"], doc_file_id)) 313 return gd 305 self.get_data("api/object/%s/unlock/%s/" % (doc["id"], doc_file_id)) 314 306 else: 315 307 show_error("Can not revise : file not in openPLM", self.window) … … 445 437 HEIGHT = 105 446 438 447 def run(self): 448 label = self.addWidget('url', 'FixedText', 5, 10, 60, 14, 449 Label="OpenPLM server's location:") 450 self.url_entry = self.addWidget('UrlEntry', 'Edit', 90, 10, 100, 14) 451 self.url_entry.Text = PLUGIN.SERVER 452 453 button = self.addWidget('configure', 'Button', 55, 85, 50, 14, 454 Label='Configure') 455 self.container = smgr.createInstanceWithContext( 456 'com.sun.star.awt.UnoControlDialog', ) 457 self.container.setModel(self.dialog) 458 self.container.getControl('configure').addActionListener(self) 459 toolkit = smgr.createInstanceWithContext( 460 'com.sun.star.awt.ExtToolkit', ) 461 self.container.setVisible(False) 462 self.container.createPeer(toolkit, None) 463 self.container.execute() 464 465 def actionPerformed(self, actionEvent): 466 try: 467 url = self.url_entry.Text 468 PLUGIN.set_server(url) 469 self.accept() 470 except: 471 traceback.print_exc() 439 def update_ui(self): 440 441 table = qt.QGridLayout() 442 label = qt.QLabel() 443 label.setText("OpenPLM server's location:") 444 self.url_entry = qt.QLineEdit() 445 self.url_entry.setText(PLUGIN.SERVER) 446 table.addWidget(label, 0, 0) 447 table.addWidget(self.url_entry, 0, 1) 448 449 self.vbox.addLayout(table) 450 buttons = qt.QDialogButtonBox.Ok | qt.QDialogButtonBox.Cancel 451 buttons_box = qt.QDialogButtonBox(buttons, parent=self) 452 connect(buttons_box, QtCore.SIGNAL("accepted()"), self.action_cb) 453 connect(buttons_box, QtCore.SIGNAL("rejected()"), self.reject) 454 self.vbox.addWidget(buttons_box) 455 456 def action_cb(self): 457 self.accept() 458 url = self.get_value(self.url_entry, None) 459 PLUGIN.set_server(url) 472 460 473 461 class SearchDialog(Dialog): … … 585 573 text = "%(reference)s|%(type)s|%(revision)s : %(name)s" % res 586 574 node = qt.QTreeWidgetItem([text]) 587 child = qt.QTreeWidgetItem(["..."]) 588 node.addChild(child) 575 if self.EXPAND_FILES: 576 child = qt.QTreeWidgetItem(["..."]) 577 node.addChild(child) 589 578 node.setExpanded(False) 590 579 self.tree.insertTopLevelItem(i, node) … … 631 620 HEIGHT = 100 632 621 633 def __init__(self, ctx, doc, name): 634 Dialog.__init__(self, ctx) 622 def __init__(self, doc, name): 635 623 self.doc = doc 636 624 self.name = name 637 638 def run(self): 639 625 Dialog.__init__(self) 626 627 def update_ui(self): 640 628 text = "%s|%s|%s" % (self.doc["reference"], self.doc["revision"], 641 629 self.doc["type"]) 642 630 643 label = self.addWidget('label', 'FixedText', 5, 10, 60, 14, 644 Label = text) 645 self.unlock_button = self.addWidget('unlock_button', 'CheckBox', 646 5, 30, 100, 14, Label='Unlock ?') 647 648 button = self.addWidget('action', 'Button', 55, 85, 50, 14, 649 Label=self.ACTION_NAME) 650 self.container = smgr.createInstanceWithContext( 651 'com.sun.star.awt.UnoControlDialog', ) 652 self.container.setModel(self.dialog) 653 self.container.getControl('action').addActionListener(self) 654 toolkit = smgr.createInstanceWithContext( 655 'com.sun.star.awt.ExtToolkit', ) 656 self.container.setVisible(False) 657 self.container.createPeer(toolkit, None) 658 self.container.execute() 659 660 def actionPerformed(self, actionEvent): 661 try: 662 doc = desktop.getCurrentComponent() 663 unlock = self.get_value(self.unlock_button, None) 664 PLUGIN.check_in(doc, unlock) 665 self.accept() 666 except: 667 traceback.print_exc() 631 label = qt.QLabel(text) 632 self.vbox.addWidget(label) 633 self.unlock_button = qt.QCheckBox('Unlock ?') 634 self.vbox.addWidget(self.unlock_button) 635 636 button = qt.QPushButton(self.ACTION_NAME) 637 connect(button, QtCore.SIGNAL("clicked()"), self.action_cb) 638 self.vbox.addWidget(button) 639 640 def action_cb(self): 641 doc = FreeCAD.ActiveDocument 642 unlock = self.get_value(self.unlock_button, None) 643 PLUGIN.check_in(doc, unlock) 644 self.accept() 668 645 669 646 class ReviseDialog(Dialog): … … 674 651 HEIGHT = 100 675 652 676 def __init__(self, ctx, doc, name, revision): 677 Dialog.__init__(self, ctx) 653 def __init__(self, doc, name, revision): 678 654 self.doc = doc 679 655 self.name = name 680 656 self.revision = revision 681 657 self.gdoc = None 682 683 def run(self): 684 658 Dialog.__init__(self) 659 660 def update_ui(self): 661 hbox = qt.QHBoxLayout() 685 662 text = "%s|" % self.doc["reference"] 686 label = self.addWidget('ref', 'FixedText', 5, 10, 60, 14, 687 Label = text) 688 self.revision_entry = self.addWidget("rev_button", "Edit", 70, 10, 60, 14, 689 Text=self.revision) 663 label = qt.QLabel(text) 664 hbox.addWidget(label) 665 self.revision_entry = qt.QLineEdit() 666 self.revision_entry.setText(self.revision) 667 hbox.addWidget(self.revision_entry) 690 668 text = "|%s" % self.doc["type"] 691 label = self.addWidget('type', 'FixedText', 135, 10, 60, 14, 692 Label=text) 693 self.unlock_button = self.addWidget('unlock_button', 'CheckBox', 694 5, 30, 100, 14, Label='Unlock ?') 695 696 button = self.addWidget('action', 'Button', 55, 85, 50, 14, 697 Label=self.ACTION_NAME) 698 text = "Warning, old revision file will be automatically unlocked!" 699 label = self.addWidget('warning', 'FixedText', 5, 45, 150, 14, 700 Label=text) 701 self.container = smgr.createInstanceWithContext( 702 'com.sun.star.awt.UnoControlDialog', ) 703 self.container.setModel(self.dialog) 704 self.container.getControl('action').addActionListener(self) 705 toolkit = smgr.createInstanceWithContext( 706 'com.sun.star.awt.ExtToolkit', ) 707 self.container.setVisible(False) 708 self.container.createPeer(toolkit, None) 709 self.container.execute() 710 711 def actionPerformed(self, actionEvent): 712 try: 713 self.accept() 714 self.gdoc = PLUGIN.revise(desktop.getCurrentComponent(), 669 label = qt.QLabel(text) 670 hbox.addWidget(label) 671 self.vbox.addLayout(hbox) 672 self.unlock_button = qt.QCheckBox('Unlock ?') 673 self.vbox.addWidget(self.unlock_button) 674 675 button = qt.QPushButton(self.ACTION_NAME) 676 connect(button, QtCore.SIGNAL("clicked()"), self.action_cb) 677 self.vbox.addWidget(button) 678 679 def action_cb(self): 680 doc = FreeCAD.ActiveDocument 681 self.gdoc = PLUGIN.revise(doc, 715 682 self.get_value(self.revision_entry, None), 716 683 self.get_value(self.unlock_button, None)) 717 except: 718 traceback.print_exc() 719 684 self.accept() 685 720 686 class AttachToPartDialog(SearchDialog): 721 687 TITLE = "Attach to part" … … 725 691 EXPAND_FILES = False 726 692 727 def __init__(self, ctx,doc):728 SearchDialog.__init__(self , ctx)693 def __init__(self, doc): 694 SearchDialog.__init__(self) 729 695 self.doc = doc 730 696 … … 732 698 PLUGIN.attach_to_part(self.doc, part["id"]) 733 699 self.accept() 734 735 def actionPerformed(self, actionEvent): 736 try: 737 if actionEvent.Source == self.container.getControl('search_button'): 738 self.search() 739 elif actionEvent.Source == self.container.getControl('action_button'): 740 node = self.container.getControl('tree').getSelection() 741 doc = self.nodes[node.getDisplayValue()] 742 self.do_action(doc) 743 except: 744 traceback.print_exc() 700 701 def action_cb(self): 702 node = self.tree.currentItem() 703 if not node: 704 return 705 doc = self.nodes[node] 706 self.do_action(doc) 745 707 746 708 class CreateDialog(SearchDialog): … … 886 848 def Activated(self): 887 849 dialog = ConfigureDialog() 888 dialog. run()850 dialog.exec_() 889 851 890 852 def GetResources(self): … … 909 871 def Activated(self): 910 872 dialog = DownloadDialog() 911 dialog. run()873 dialog.exec_() 912 874 913 875 def GetResources(self): … … 930 892 931 893 def Activated(self): 932 gdoc = self.desktop.getCurrentComponent()894 gdoc = FreeCAD.ActiveDocument 933 895 if gdoc and gdoc in PLUGIN.documents: 934 896 doc = PLUGIN.documents[gdoc]["openplm_doc"] … … 939 901 name = os.path.basename(path) 940 902 dialog = CheckInDialog(doc, name) 941 dialog. run()903 dialog.exec_() 942 904 if gdoc not in PLUGIN.documents: 943 close(gdoc , self.desktop)944 945 win = gdoc.CurrentController.Frame.ContainerWindow946 905 close(gdoc) 906 else: 907 win = main_window() 908 show_error("Document not stored in OpenPLM", win) 947 909 948 910 def GetResources(self): 949 911 return {'Pixmap' : 'plop.png', 'MenuText': 'Check-in', 'ToolTip': 'Check-in'} 950 912 951 FreeCADGui.addCommand('OpenPLM CheckIn', OpenPLMCheckIn())913 FreeCADGui.addCommand('OpenPLM_CheckIn', OpenPLMCheckIn()) 952 914 953 915 class OpenPLMRevise: 954 916 955 917 def Activated(self): 956 gdoc = self.desktop.getCurrentComponent()918 gdoc = FreeCAD.ActiveDocument 957 919 if gdoc and gdoc in PLUGIN.documents: 958 920 doc = PLUGIN.documents[gdoc]["openplm_doc"] … … 963 925 revisable = PLUGIN.get_data("api/object/%s/isrevisable/" % doc["id"])["revisable"] 964 926 if not revisable: 965 win = gdoc.CurrentController.Frame.ContainerWindow927 win = main_window() 966 928 show_error("Document can not be revised", win) 967 929 return … … 970 932 name = os.path.basename(path) 971 933 dialog = ReviseDialog(doc, name, revision) 972 dialog. run()934 dialog.exec_() 973 935 if gdoc not in PLUGIN.documents: 974 close(gdoc, self.desktop) 975 if dialog.gdoc and dialog.gdoc not in PLUGIN.documents: 976 close(dialog.gdoc, self.desktop) 977 else: 978 win = gdoc.CurrentController.Frame.ContainerWindow 979 show_error("Document not stored in OpenPLM", win) 936 close(gdoc) 937 else: 938 win = main_window() 939 show_error("Document not stored in OpenPLM", win) 980 940 981 941 def GetResources(self): … … 987 947 988 948 def Activated(self): 989 gdoc = self.desktop.getCurrentComponent()949 gdoc = FreeCAD.ActiveDocument 990 950 if gdoc and gdoc in PLUGIN.documents: 991 951 doc = PLUGIN.documents[gdoc]["openplm_doc"] 992 952 dialog = AttachToPartDialog(doc) 993 dialog. run()953 dialog.exec_() 994 954 else: 995 win = gdoc.CurrentController.Frame.ContainerWindow955 win = main_window() 996 956 show_error("Document not stored in OpenPLM", win) 997 957 … … 1000 960 'ToolTip': 'Attach to a part'} 1001 961 1002 FreeCADGui.addCommand('OpenPLM_Attach ', OpenPLMAttach())962 FreeCADGui.addCommand('OpenPLM_AttachToPart', OpenPLMAttach()) 1003 963 1004 964 class OpenPLMCreate: 1005 965 1006 966 def Activated(self): 1007 gdoc = self.desktop.getCurrentComponent()1008 win = gdoc.CurrentController.Frame.ContainerWindow967 gdoc = FreeCAD.ActiveDocument 968 win = main_window() 1009 969 if not gdoc: 1010 970 show_error("Need an opened file to create a document", win) … … 1014 974 return 1015 975 dialog = CreateDialog() 1016 resp = dialog. run()976 resp = dialog.exec_() 1017 977 if dialog.doc_created and gdoc not in PLUGIN.documents: 1018 close(gdoc , self.desktop)978 close(gdoc) 1019 979 1020 980 def GetResources(self): … … 1023 983 1024 984 FreeCADGui.addCommand('OpenPLM_Create', OpenPLMCreate()) 1025 1026 def main_window():1027 app = qt.qApp1028 for x in app.topLevelWidgets():1029 if type(x) == qt.QMainWindow:1030 return x1031 985 1032 986 def build_menu():
Note: See TracChangeset
for help on using the changeset viewer.