Package qubx :: Module model_link
[hide private]
[frames] | no frames]

Source Code for Module qubx.model_link

  1  """"Modeling Tools" menu: "Link to this model online" 
  2   
  3  Copyright 2015 Research Foundation State University of New York  
  4  This file is part of QUB Express.                                           
  5   
  6  QUB Express is free software; you can redistribute it and/or modify           
  7  it under the terms of the GNU General Public License as published by  
  8  the Free Software Foundation, either version 3 of the License, or     
  9  (at your option) any later version.                                   
 10   
 11  QUB Express is distributed in the hope that it will be useful,                
 12  but WITHOUT ANY WARRANTY; without even the implied warranty of        
 13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
 14  GNU General Public License for more details.                          
 15   
 16  You should have received a copy of the GNU General Public License,    
 17  named LICENSE.txt, in the QUB Express program directory.  If not, see         
 18  <http://www.gnu.org/licenses/>.                                       
 19   
 20  """ 
 21   
 22  import gobject 
 23  import gtk 
 24  import qubx.global_namespace 
 25  import qubx.modelGTK 
 26  import qubx.pyenv 
 27   
 28  from qubx.GTK import NumEntry, pack_item, pack_label 
 29  from qubx.pyenv import call_async_wait 
 30  from qubx.pyenvGTK import show_message 
 31  from qubx.sock import postJson 
 32  from qubx.task import Robot 
 33  from qubx.util_types import * 
 34   
 35  MODELDB_URL = 'https://qub.mandelics.com/online/models/createLink' 
 36  MODELDB_SIGNIN = '5aa66b9a-b862-48cd-8f5b-4bad171bdb30' 
 37  MODELLINK_FMT = 'https://qub.mandelics.com/online/#link=%(linkId)s&k=%(linkKey)s' 
 38   
 50   
51 -def ThreadMain(robot, name, about, qmj):
52 receiver = [None] 53 def main(): 54 url = "" 55 try: 56 url = createModelLink(name, about, qmj) 57 except: 58 pass 59 receiver[0](url)
60 def sched(recv): 61 receiver[0] = recv 62 robot.do(main) 63 return sched 64
65 -def Prompt(name, about, model):
66 nm = name or (model and model.path) or "" 67 ab = about or "" 68 dlg = gtk.Dialog("Link to this model online...", qubx.global_namespace.QubX.Models.parent_window, gtk.DIALOG_MODAL, 69 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OK,gtk.RESPONSE_OK)) 70 h = pack_item(gtk.HBox(True), dlg.vbox) 71 pack_label("Title:", h) 72 title = pack_item(NumEntry(nm), h) 73 h = pack_item(gtk.HBox(), dlg.vbox) 74 pack_label("About:", h) 75 about = pack_item(gtk.TextView(), dlg.vbox, expand=True) 76 buf = about.get_buffer() 77 buf.set_text(ab) 78 yes = (dlg.run() == gtk.RESPONSE_OK) 79 nm, ab = title.value, buf.get_text(buf.get_start_iter(), buf.get_end_iter()) 80 dlg.destroy() 81 if yes: 82 return nm, ab 83 else: 84 return None, None
85
86 -def LinkToModel(item=None, name=None, about=None, model=None, alert=True):
87 if None in [name, about, model]: 88 nm, ab = Prompt(name, about, model) 89 if nm is None: 90 return 91 else: 92 nm, ab = name, about 93 print nm, ab 94 qubx.pyenv.env.OnScriptable('qubx.model_link.LinkToModel(name=nm, about=ab)') 95 mdl = qubx.global_namespace.QubX.Models.file if (model is None) else model 96 robot = Robot("model_link") 97 url = call_async_wait(ThreadMain(robot, nm, ab, mdl.as_json()))[0] 98 robot.stop() 99 if alert: 100 if url: 101 show_message(url) 102 else: 103 show_message("Connection failed.") 104 return url
105 106 qubx.modelGTK.Tools.register('other', 'Link to this model online...', LinkToModel) 107