def get_table(self): table = self.tableWidget ret = [] for row in range(table.rowCount()): data = [table.item(row, 0).data(0), table.item(row, 1).data(0)] if not data[0]: break ret.append([float(d) for d in data]) if not ret: alert("Invalid completeness table") # sort by year (most recent to oldest) ret = sorted(ret, key=lambda row: -row[0]) # check that magnitude is increasing magnitude, years = zip(*ret) if (len(magnitude) > 1 and all(x < y for x, y in zip(magnitude, magnitude[1:]))): alert("""Your completeness table is not properly ordered. This might cause instability (E.g. in Weichert)""") return numpy.array(ret)
def FromFile(cls, filename, use_cache = False): Logger.info('From File with ' + str(filename)) if not use_cache: Logger.info(' From File without cache') from os.path import split from kivy.resources import resource_add_path import sys resource_add_path(split(filename)[0]) sys.path.append(split(filename)[0]) name, filename = find_template_path(filename) #Add filename dir to ressources folder to facilitate relativ import #Load & return all templates from a file as a list. Take an optionnal filter from kivy.lang import Builder # Remove any former trace of the file if use_cache and filename in templateList.templates: res = templateList[filename] res = [r.blank() for r in res] else: Builder.unload_file(filename) # Now create a widget try: Builder.load_file(filename) res = cls._process_file_build(filename) templateList[filename] = res except Exception, E: from utils import alert from utils import log import traceback alert(str(E)) Logger.error('[Error] While trying to import Template %s'%filename) log(E, traceback.print_exc()) res = list()
def realise(self,withValue = False, use_cache=False): Logger.info('Calling realisze on %s (with Value %s / use_cache %s'%(self,withValue,use_cache)) #Force the creation of an image from self.template, thourhg real display #Skipt of computed image exists if self.image: return from kivy.clock import Clock #Force the creaiotn of the tmpl miniture for display from template import BGTemplate if not self.template: return try: if not use_cache: Logger.info('[SGM]Realize StackPart calling from file') tmpl = BGTemplate.FromFile(self.template, use_cache)[-1] except IndexError: Logger.warn( 'Warning: template file %s contains no Template !!'%self.template) from utils import alert alert('Error while loading template %s '%self.template) return #App.get_running_app().root.ids['realizer'].add_widget(tmpl) #force draw of the beast if withValue: tmpl.apply_values(self.values) self.tmplWidget = tmpl def inner(*args): #Here is hould loop on the template to apply them on values from kivy.base import EventLoop EventLoop.idle() cim = tmpl.toImage() cim.texture.flip_vertical() self.ids['img'].texture = cim.texture #App.get_running_app().root.ids['realizer'].remove_widget(tmpl) Clock.schedule_once(inner, -1)
def create_game_folder(self): from conf import gamepath "Create Game Folder" # ~ 1.Get Current game name gameId=self.selected_game gameName=self.ids.details.title # ~ 2. Create folder for current game name import os.path path=os.path.join(gamepath,gameName) if os.path.isdir(path): alert('Already Existing folder for %s in %s. Aborting'%(gameName,gamepath)) else: os.mkdir(path) # ~ 3. create subfolders: rule, img, old , export os.mkdir(os.path.join(path, 'rules')) os.mkdir(os.path.join(path, 'img')) os.mkdir(os.path.join(path, 'download')) os.mkdir(os.path.join(path, 'export-%s'%gameName)) output = file(os.path.join(path, 'description.txt'),'wb') output.write('Game Description:\n') output.write(self.ids.details.ids.description.text) output.write('\n\nMore Information:') output.write(self.ids.details.ids.information.text.encode('cp1252')) from utils import start_file start_file(path)
def prepare_pdf(dst='test.pdf', stack= None, console_mode = True, mode = 'STANDARD'): if stack is None: from kivy.app import App stack = App.get_running_app().root.ids.deck.ids.stack #linearize stack to create list of element deck_front = list() deck_back = list() for item in stack.children: if not isinstance(item, Factory.get('StackPart')): continue #Create tuple with qt * (item) in front deck or back deck if item.verso == 'normal':#front deck_front += item.qt*[item] else: deck_back += item.qt*[item] if deck_back and len(deck_front)!= len(deck_back): print 'WARNING: Front/Back discrepencies: ',len(deck_front), len(deck_back) size = len(deck_back)+len(deck_front) # do that now, because they are going to be emptied book = PDFBook(dst, mode, deck_front, deck_back) book.calculate_size() if console_mode: # directly generate the stuff step_counter = range(size) while step_counter: print '-', step_counter.pop() book.generation_step(with_realize=True) book.save() book.show() from utils import alert alert('PDF Export completed') return False return (size , book)
def tie_del(self): index = self.table.selectedIndexes() if index: index = index[0] else: utils.alert("No Tie Selected", "Please Select a tie to delete", "warn") return backup = [] for i in range(self.model.columnCount()): value = self.model.data(self.model.index(index.row(), i)) backup.append(value) confirmation = utils.confirm( "Delete Team", f"Do you want to delete the Tie between the following teams?\n{backup[1]} - {backup[2]}", ) if confirmation == QtWidgets.QMessageBox.Yes: self.logger.info("Deleting Tie") self.logger.txn(f"[Deleted] Tie Data - {backup}") self.model.deleteRowFromTable(index.row()) self.model.select() else: self.logger.debug("Canceled team delete request")
def realise(self, use_cache=False, *args): if not self.name.endswith('.kv'): return #Force the creation of an image from self.template, thourhg real display from kivy.clock import Clock #Force the creaiotn of the tmpl miniture for display from template import BGTemplate try: Logger.info('[SGM] Realise FileItemView calling From File') tmpl = BGTemplate.FromFile(self.name, use_cache)[-1] except IndexError: Logger.warn('Warning: template file %s contains no Template !!' % self.name) from utils import alert alert('Error while loading %s template' % self.name) return #App.get_running_app().root.ids['realizer'].add_widget(tmpl) #force draw of the beast self.tmplWidget = tmpl def inner(*args): from kivy.base import EventLoop EventLoop.idle() cim = tmpl.toImage() cim.texture.flip_vertical() self.ids['img'].texture = cim.texture #App.get_running_app().root.ids['realizer'].remove_widget(tmpl) Clock.schedule_once(inner, -1)
def execute(self): if len(self.stack.children) < 8: alert('Stack contains less than 8 items !') return from PIL.Image import FLIP_TOP_BOTTOM from kivy.graphics.texture import Texture from img_xfos import img_modes pockets = self.stack.children[:8] imgs = [p.toPILImage() for p in reversed(pockets)] from template import BGTemplate tmpl = BGTemplate.FromFile('templates/pocketmode.kv')[0] from sgm import StackPart pm = StackPart() for i in range(1,9): name = 'page%d'%i imgfield = tmpl.ids[name] pilimage = imgs[i-1] flip = pilimage.transpose(FLIP_TOP_BOTTOM) flip = flip.convert('RGBA') ktext = Texture.create(size=flip.size) ktext.blit_buffer(flip.tobytes(), colorfmt=img_modes[flip.mode]) imgfield.texture = ktext def inner(*args): #Here is hould loop on the template to apply them on values from kivy.base import EventLoop EventLoop.idle() pim = tmpl.toPILImage(for_print = True).rotate(90) pm.setImage(pim) self.stack.add_widget(pm) if self.replace: for p in pockets: self.stack.remove_widget(p) from kivy.clock import Clock Clock.schedule_once(inner,-1)
def execute(self): if not self.stack.last_selected: alert('Selecta Stackpart First') return img = self.stack.last_selected.toPILImage() from img_xfos import grey self.stack.last_selected.setImage(grey(img))
def execute(self): if not self.stack.last_selected: alert('Select a StackPart First') return img = self.stack.last_selected.toPILImage() img = img.rotate(self.angle) self.stack.last_selected.setImage(img)
def realise(self,use_cache = False, *args): if not self.name.endswith('.kv'): return #Force the creation of an image from self.template, thourhg real display from kivy.clock import Clock #Force the creaiotn of the tmpl miniture for display from template import BGTemplate try: Logger.info('[SGM] Realise FileItemView calling From File') tmpl = BGTemplate.FromFile(self.name, use_cache)[-1] except IndexError: Logger.warn('Warning: template file %s contains no Template !!'%self.name) from utils import alert alert('Error while loading %s template'%self.name) return #App.get_running_app().root.ids['realizer'].add_widget(tmpl) #force draw of the beast self.tmplWidget = tmpl def inner(*args): from kivy.base import EventLoop EventLoop.idle() cim = tmpl.toImage() cim.texture.flip_vertical() self.ids['img'].texture = cim.texture #App.get_running_app().root.ids['realizer'].remove_widget(tmpl) Clock.schedule_once(inner, -1)
def team_delete(self): index = self.team_table.selectedIndexes() # Ensure there is a selection # Maybe disable in context menu if there is no selection? if index: index = index[0] else: utils.alert("No Team Selected", "Please Select a team to delete", "warn") return backup = [] for i in range(self.data_model.columnCount()): value = self.data_model.data(self.data_model.index(index.row(), i)) # Replace empty strings with none to better represent the database state if value == "": value = None backup.append(value) confirmation = utils.confirm( "Delete Team", f"Do you want to delete the following team?\n{backup[2]}") if confirmation == QtWidgets.QMessageBox.Yes: self.logger.info("Deleting Team") self.logger.txn(f"[Deleted] Team Data - {backup}") self.data_model.deleteRowFromTable(index.row()) self.data_model.select() else: self.logger.debug("Canceled team delete request")
def inner(*args): b = boxes.pop() b.realise(withValue=True, use_cache=True) if not boxes: Clock.unschedule(inner) from utils import alert alert(msg) return False
def _apply_algorithm(self, name): algorithm = self.current_tab().algorithm() try: config = self.current_tab().get_config() except ValueError as e: alert(str(e)) return return getattr(self.catalogue_model, name)(algorithm, config)
def load_osm(self, olplugin): # 4 is OpenStreetMap ol_gphyslayertype = olplugin.olLayerTypeRegistry.getById(4) olplugin.addLayer(ol_gphyslayertype) if not olplugin.layer.isValid(): utils.alert("Failed to load basemap") return olplugin.layer
def hexa_layout(): card_format.size = (hexagon_width, hexagon_height) layout.custom_layout(h_step, v_step, 0, "%s/2*(row%%2)" % h_step, "", clean_book_first=True) layout.export_phs() alert('Layout is done ! ')
def op_uninstall(self, is_right=False): """卸载""" serial = self.serial package = self.cbb_item.get_package() if not is_right: s = "是否卸载" + package utils.alert(s, self.uninstall, [package, False, serial]) else: self.msg("卸载一个应用,但保留此应用的数据...") s = "是否卸载" + package utils.alert(s, self.uninstall, [package, True, serial])
def check_clipper(_serial): package = 'ca.zgrs.clipper' device_apk = pm_path(_serial, package) if not device_apk: # utils.showinfo("此设备未安装 Clipper") params = [_serial] s = "此设备未安装 Clipper,是否进行安装?" utils.alert(s, install_clipper, params) return False else: return True
def __statServer(self, result): if __debug__: self.printCurrentView("__statServer") if self.testing: utils.alert(constants.TEST_SUCCESS, self.account.displayName) return self._actionCompleted() utils.NotifyUIAsync(constants.DOWNLOAD_CHECK_MESSAGES) d = self.proto.stat() d.addCallbacks(self.__serverHasMessages, self.catchErrors)
def execute(self): if not self.stack.last_selected: alert('Select a StackPart First') return img = self.stack.last_selected.toPILImage() if self.vertical: from img_xfos import v_flip img = v_flip(img) if self.horizontal: from img_xfos import h_flip img = h_flip(img) self.stack.last_selected.setImage(img)
def inner(*args): from utils import alert if not fg: Clock.unschedule(inner) from utils import alert alert('Book created') self.export_phs() from kivy.uix.widget import WidgetException try: self.set_page("Page %d" % (init_pi + 1)) except WidgetException, Err: print 'FATAL: Error in Setting page ???', Err return
def inner(*args): from utils import alert if not fg: Clock.unschedule(inner) from utils import alert alert('Book created') self.export_phs() from kivy.uix.widget import WidgetException try: self.set_page("Page %d"%(init_pi+1)) except WidgetException,Err: print 'FATAL: Error in Setting page ???',Err return
def register_file(self, filename): #Remove any former trace of the file Builder.unload_file(filename) #Now create a widget try: Builder.load_file(filename) res = [x for x in Builder.rules if x[1].ctx.filename == filename] except Exception, E: from utils import alert from utils import log import traceback alert(E) log(E,traceback.format_exc()) res= list()
def __selectInbox(self, result): if __debug__: self.printCurrentView("__selectInbox") if self.testing: utils.alert(constants.TEST_SUCCESS, self.account.displayName) self._actionCompleted() return utils.NotifyUIAsync(constants.DOWNLOAD_CHECK_MESSAGES) d = self.proto.select("INBOX") d.addCallbacks(self.__checkForNewMessages, self.catchErrors) return d
def inner(*args): progress.value += 1 b = boxes.pop() b.realise(withValue=True, use_cache=True) if self.cancel_action or not boxes: self.cancel_action = False Clock.unschedule(inner) self.ids['stop_action'].width = 0 self.ids['stop_action'].text = '' progress.value = 0 from utils import alert from os.path import split alert(msg) return False
def align_selection(self, *args): pos = args[1] if self.selections: unit = self.last_selected if pos == 'Max H': unit.width = unit.parent.width unit.x = unit.parent.x elif pos == 'Max V': unit.height = unit.parent.height unit.y = unit.parent.y elif pos == 'Copy': from utils import alert alert('Choose target to copy size from') self._do_copy = ('size', unit)
def align_selection(self, *args): pos = args[1] if self.selections: unit = self.last_selected if pos == 'Max H': unit.width = unit.parent.width unit.x = unit.parent.x elif pos == 'Max V': unit.height= unit.parent.height unit.y= unit.parent.y elif pos == 'Copy': from utils import alert alert('Choose target to copy size from') self._do_copy =('size', unit)
def execute(self): if self.row == 0: self.row = 1 if self.col == 0: self.col = 1 stack = self.stack try: current_part = stack.last_selected if not current_part: raise ValueError() except Exception, E: from utils import alert alert('Select a Stack Item first') return
def inner(*args): progress.value +=1 b= boxes.pop() b.realise(withValue=True) if self.cancel_action or not boxes: self.cancel_action = False Clock.unschedule(inner) self.ids['stop_action'].width = 0 self.ids['stop_action'].text = '' progress.value = 0 from utils import alert from os.path import split alert('Import %s over'%split(filepath)[-1]) return False
def tie_add(self, use_selections=False): # TODO: Add confirmation logic for scores that significantly differ if use_selections: indexes = self.team_table.selectionModel().selectedRows() else: indexes = [] if len(indexes) == 1: t_id = indexes[0].data(QtCore.Qt.EditRole) diag = dialogs.TieDialog(t_id) elif len(indexes) == 2: t1_id = indexes[0].data(QtCore.Qt.EditRole) t2_id = indexes[1].data(QtCore.Qt.EditRole) query = QtSql.QSqlQuery() query.exec_(f"SELECT Division from teams where id = {t1_id};") query.next() t1_div = query.value(0) query.exec_(f"SELECT Division from teams where id = {t2_id};") query.next() t2_div = query.value(0) query.clear() del query if t1_div != t2_div: utils.alert("Error", "Ties can only exist within a division ", "crit") return else: diag = dialogs.TieDialog(t1_id, t2_id) else: diag = dialogs.TieDialog() if diag.exec_(): t1_id = diag.team_1.currentData() t1_name = diag.team_1.currentText() t2_id = diag.team_2.currentData() t2_name = diag.team_2.currentText() e_name = diag.tie_event.currentText() w_id = diag.winner.currentData() w_name = diag.winner.currentText() query = QtSql.QSqlQuery() self.logger.txn( f"Add Tie between {t1_name} and {t2_name}, E: {e_name}, W: {w_name}" ) query.exec_( f"INSERT INTO ties (team_1_id, team_2_id, event, winner) VALUES ({t1_id}, {t2_id}, '{e_name}', {w_id});" ) query.clear() del query self.ties_window.model.select()
def update_news(): """[localhost] Atualiza zip das noticias locais do servidor """ if not env.platform == "windows": abort(alert("Esse comando soh executa no servidor (Windows)")) # TODO: implementar execucao do scripts/get_sintonia_zip.cmd notify("getting done")
def __init__(self): try: clientid = os.environ.get("clientid") self.RPC = Presence(clientid) #Put ur client id alert(Fore.RED + " Place ur magplant remote or a block to your 2 slot and select it") print(Style.RESET_ALL) self.RPC.connect() self.RPC.update(state="AutoFarm-Py", details="Starting!") self.getInformation() self.running = False self.infinity = False self.app = pywinauto.application.Application().connect(best_match='Growtopia') self.form = self.app.window(title_re='Growtopia') self.form.move_window(x=0, y=0, width=None, height=None, repaint=True) self.run() except: raise initError
def cb(instance): s = instance.ids.fpicker.selection val = instance.ids.tmpl_name.text if len(s) and isfile(s[0]): _name = val if val == '-': _name = '' tmplname = '%s@%s'%(_name, s[0]) from template import BGTemplate print '[Designer] Add Template within template' tmpl = BGTemplate.FromFile(tmplname).pop() node = self.insert_field(tmpl) self.selections = {tmpl: None} self.last_selected = tmpl else: from utils import alert alert('Wrong selection in template:' + s)
def inner(*args): step_counter.pop() progress.value += 1 #print 'remaninig index', len(book.index) book.generation_step() if (not step_counter) or self.cancel_action: self.cancel_action = False Clock.unschedule(inner) self.ids['stop_action'].width = 0 self.ids['stop_action'].text = '' progress.value = 0 book.save() book.show() from utils import alert alert('PDF Export completed') return False else: Clock.schedule_once(inner, 0.01)
def cb(instance): s = instance.ids.fpicker.selection val = instance.ids.tmpl_name.text if len(s) and isfile(s[0]): _name = val if val == '-': _name = '' tmplname = '%s@%s' % (_name, s[0]) from template import BGTemplate print '[Designer] Add Template within template' tmpl = BGTemplate.FromFile(tmplname).pop() node = self.insert_field(tmpl) self.selections = {tmpl: None} self.last_selected = tmpl else: from utils import alert alert('Wrong selection in template:' + s)
def main(): bad_good_fit = read_prob_bad_good_fit() over_under_est = read_prob_under_over_estimation() submit = pd.merge( left = bad_good_fit, right = over_under_est, on = 'parcelid', how = 'left') del bad_good_fit, over_under_est gc.collect() logerror_per_bin = read_logerror_per_bin() logerror_per_bin.set_index('bin',inplace=True) logerror_per_bin = logerror_per_bin.to_dict()['pred_logerror'] submit['logerror_0'] = logerror_per_bin[0] submit['logerror_1'] = logerror_per_bin[1] submit['logerror_2'] = logerror_per_bin[2] submit['pred'] = (submit['logerror_0'] * submit['p_bad_fit'] * submit['p_under_est'] + submit['logerror_1'] * submit['p_good_fit'] + submit['logerror_2'] * submit['p_bad_fit'] * submit['p_over_est'] ) submit['201610'] = submit['pred'] submit['201611'] = submit['pred'] submit['201612'] = submit['pred'] submit['201710'] = submit['pred'] submit['201711'] = submit['pred'] submit['201712'] = submit['pred'] submit = submit[['parcelid','201610','201611','201612','201710','201711','201712']] print('..writting submission file') submit.to_csv("submissions/submission"+datetime.now().strftime("%Y%m%d%H%M%S")+".csv",index=False) alert(2)
def normalize(self): tonormalize = [ os.path.join(root, name) for root, dirs, files in os.walk(os.getcwd() + "/" + self.outputdir) for name in files if name.endswith(tuple(convertable)) ] i = 0 for f in tonormalize: f = utils.cleanstr(f) tonormalize[i] = f i += 1 utils.action("Normalizing files.") try: if self.verbosity == False: os.system("mp3gain -k -r -d " + str(self.decibel) + " " + " ".join(tonormalize) + " >/dev/null 2>&1") else: os.system("mp3gain -k -r -d " + str(self.decibel) + " " + " ".join(tonormalize)) except: utils.alert("Error during normalizing files.")
def realise(self, withValue=False, use_cache=False): Logger.info('Calling realisze on %s (with Value %s / use_cache %s' % (self, withValue, use_cache)) #Force the creation of an image from self.template, thourhg real display #Skipt of computed image exists if self.image: return from kivy.clock import Clock #Force the creaiotn of the tmpl miniture for display from template import BGTemplate if not self.template: return try: if not use_cache: Logger.info('[SGM]Realize StackPart calling from file') tmpl = BGTemplate.FromFile(self.template, use_cache)[-1] except IndexError: Logger.warn('Warning: template file %s contains no Template !!' % self.template) from utils import alert alert('Error while loading template %s ' % self.template) return #App.get_running_app().root.ids['realizer'].add_widget(tmpl) #force draw of the beast if withValue: tmpl.apply_values(self.values) self.tmplWidget = tmpl def inner(*args): #Here is hould loop on the template to apply them on values from kivy.base import EventLoop EventLoop.idle() cim = tmpl.toImage() cim.texture.flip_vertical() self.ids['img'].texture = cim.texture #App.get_running_app().root.ids['realizer'].remove_widget(tmpl) Clock.schedule_once(inner, -1)
def main(): submit = read_classification_output() logerror_per_bin = read_logerror_per_bin() logerror_per_bin.set_index('bin',inplace=True) logerror_per_bin = logerror_per_bin.to_dict() submit['pred'] = submit.apply(lambda r : logerror_per_bin['pred_logerror'][0] * r['0'] + logerror_per_bin['pred_logerror'][1] * r['1'] + logerror_per_bin['pred_logerror'][2] * r['2'],axis=1) submit['201610'] = submit['pred'] submit['201611'] = submit['pred'] submit['201612'] = submit['pred'] submit['201710'] = submit['pred'] submit['201711'] = submit['pred'] submit['201712'] = submit['pred'] submit.drop(['0','1','2','pred'],axis=1,inplace=True) submit.to_csv("submissions/submission"+datetime.now().strftime("%Y%m%d%H%M%S")+".csv",index=False) alert(3)
def handleError(self, view, client, account, err): if __debug__: trace("handleError") if self.shuttingDown: return None if client is None: errText = unicode(err.__str__(), 'utf8', 'ignore') if account is None: alert(constants.MAIL_GENERIC_ERROR % {'errText': errText}) else: alertMailError(constants.MAIL_PROTOCOL_ERROR, account, \ {'hostName': account.host, 'errText': errText}) else: reactor.callFromThread(client.catchErrors, err) view.cancel() if account: self._resetWorker(account)
def prepare_pdf(dst='test.pdf', stack=None, console_mode=True, mode='STANDARD'): if stack is None: from kivy.app import App stack = App.get_running_app().root.ids.deck.ids.stack #linearize stack to create list of element deck_front = list() deck_back = list() for item in stack.children: if not isinstance(item, Factory.get('StackPart')): continue #Create tuple with qt * (item) in front deck or back deck if item.verso == 'normal': #front deck_front += item.qt * [item] else: deck_back += item.qt * [item] if deck_back and len(deck_front) != len(deck_back): print 'WARNING: Front/Back discrepencies: ', len(deck_front), len( deck_back) size = len(deck_back) + len( deck_front) # do that now, because they are going to be emptied book = PDFBook(dst, mode, deck_front, deck_back) book.calculate_size() if console_mode: # directly generate the stuff step_counter = range(size) while step_counter: print '-', step_counter.pop() book.generation_step(with_realize=True) book.save() book.show() from utils import alert alert('PDF Export completed') return False return (size, book)
def show_tip(self, point): rectangle = QgsRectangle() radius = self.canvas.extent().width() / 100 * 5 # 5% of the map width rectangle.setXMinimum(point.x() - radius) rectangle.setYMinimum(point.y() - radius) rectangle.setXMaximum(point.x() + radius) rectangle.setYMaximum(point.y() + radius) layer_rectangle = self.canvas.mapRenderer().mapToLayerCoordinates( self.catalogue_layer, rectangle) features = self.catalogue_layer.getFeatures( QgsFeatureRequest().setFilterRect(layer_rectangle)) # assume the first one is the closest try: feat = features.next() msg_lines = ["Event Found"] for k in self.catalogue_model.catalogue_keys(): msg_lines.append("%s=%s" % (k, feat[k])) except StopIteration: msg_lines = ["No Event found"] if self.raster_layer is not None: src = self.basemap_layer.crs() dst = QgsCoordinateReferenceSystem(4326) trans = QgsCoordinateTransform(src, dst) point = trans.transform(point) raster_data = self.raster_layer.dataProvider().identify( point, QgsRaster.IdentifyFormatValue) for k, v in raster_data.results().items(): msg_lines.append("Smoothed=%s" % str(v)) utils.alert('\n'.join(msg_lines))
def load_osm_plugin(self): """ Initialize the QGIS OpenLayer plugin and load the basemap layer """ canvas = self.canvas class IFace(object): def mapCanvas(self): return canvas iface = IFace() olplugin = OpenlayersPlugin(iface) # hacked from #OpenlayersPlugin#initGui if not olplugin._OpenlayersPlugin__setCoordRSGoogle(): utils.alert("Error in setting coordinate system") oltype = OpenlayersPluginLayerType( iface, olplugin.setReferenceLayer, olplugin._OpenlayersPlugin__coordRSGoogle, olplugin.olLayerTypeRegistry) QgsPluginLayerRegistry.instance().addPluginLayerType(oltype) return olplugin
def save(self, PATH=None, *args): from conf import CP from os.path import isfile, split, splitext if PATH is not None: self.current_template.template_name = splitext( split(PATH)[-1])[0].capitalize() self.tmplPath = PATH else: self.current_template.template_name = self.current_template.template_name.capitalize( ) if PATH is None: if self.tmplPath: PATH = self.tmplPath if "@" in PATH: PATH = PATH.split('@')[-1] overwrite = True else: PATH = 'templates/%s.kv' % self.current_template.template_name overwrite = CP.getboolean('Designer', 'OVERWRITE_SAVED_TMPL') alert('Template Saved in Library as %s.kv' % self.current_template.template_name) else: overwrite = CP.getboolean('Designer', 'OVERWRITE_SAVED_TMPL') exists = isfile(PATH) kv = self.export_kv(split(PATH)[0]) if overwrite or not exists: file(PATH, 'wb').write(kv) else: from utils import alert alert('Template %s already exists !' % PATH) return from utils import alert alert('Template %s saved' % self.current_template.template_name) #Force update on deck widget from kivy.app import App deck = App.get_running_app().root.ids.deck stack = deck.ids['stack'] from template import find_template_path, templateList templateList.register_file(PATH) for child in stack.children: if not hasattr(child, 'template'): continue _, tpath = find_template_path(getattr(child, 'template')) if tpath.endswith(PATH): child.realise(use_cache=True) print 'todo: how do I save pultiple template on a single KV file ? '
def save(self,PATH=None, *args): from conf import CP from os.path import isfile, split, splitext if PATH is not None: self.current_template.template_name = splitext(split(PATH)[-1])[0].capitalize() self.tmplPath = PATH else: self.current_template.template_name = self.current_template.template_name.capitalize() if PATH is None: if self.tmplPath: PATH = self.tmplPath if "@" in PATH: PATH = PATH.split('@')[-1] overwrite = True else: PATH = 'templates/%s.kv'%self.current_template.template_name overwrite = CP.getboolean('Designer','OVERWRITE_SAVED_TMPL') alert('Template Saved in Library as %s.kv'%self.current_template.template_name) else: overwrite = CP.getboolean('Designer', 'OVERWRITE_SAVED_TMPL') exists = isfile(PATH) kv = self.export_kv(split(PATH)[0]) if overwrite or not exists: file(PATH,'wb').write(kv) else: from utils import alert alert('Template %s already exists !'%PATH) return from utils import alert alert('Template %s saved'%self.current_template.template_name) #Force update on deck widget from kivy.app import App deck = App.get_running_app().root.ids.deck stack = deck.ids['stack'] from template import find_template_path, templateList templateList.register_file(PATH) for child in stack.children: if not hasattr(child, 'template'): continue _, tpath = find_template_path(getattr(child, 'template')) if tpath.endswith(PATH): child.realise(use_cache=True) print 'todo: how do I save pultiple template on a single KV file ? '
def export_file(self, filepath='myxlfile.xlsx'): from collections import OrderedDict from conf import gamepath from os.path import relpath, isfile, splitext, split self.record_last_file(filepath) FOLDER, FNAME = split(filepath) FNAME = splitext(FNAME)[0] od = OrderedDict() cards = list() HAS_LAYOUT = False HAS_TEMPLATE = False HAS_SOURCE = False for item in reversed(self.ids['stack'].children): if not isinstance(item, Factory.get('StackPart')): continue d = dict() d['qt'] = item.qt if item.source: HAS_SOURCE = True if isfile(item.source): #it is a full path. convert it _s = relpath(item.source, gamepath) if item.source.startswith(FOLDER): _s = relpath(item.source, FOLDER) else: _s = item.source if item.template and item.source == 'img/card_template.png': _s = "" d['source'] = _s else: d['source'] = "" if item.template: HAS_TEMPLATE = True d['template'] = item.template d['dual'] = not(item.verso == 'normal') d['values'] = item.values if item.layout: HAS_LAYOUT = True #d['layout'] = item.layout _x,_y,_w,_h,_a, _p = item.layout d['layout_w'] = _w d['layout_h'] = _h d['layout_y'] = _y d['layout_x'] = _x d['layout_page'] = _p d['layout_angle'] = _a cards.append(d) od['cards'] = cards from conf import CP mode = CP.get('Export','format') if mode =='csv': self.export_file_CSV(cards, filepath, HAS_LAYOUT) return elif mode == 'xlsx': #Now also XL export import openpyxl from openpyxl.utils import get_column_letter if cards: my_dict = {} #update the dict with all possible 'values' keys for c in cards: if c['values']: my_dict.update(**c['values']) wb= openpyxl.Workbook() ws = wb.active ws.title = FNAME fields_order = ['qt','dual'] if HAS_TEMPLATE: fields_order.append('template') if HAS_SOURCE: fields_order.append('source') if HAS_LAYOUT: fields_order.extend([ 'layout_x','layout_y','layout_w','layout_h', 'layout_angle','layout_page']) fields_order.extend(sorted(my_dict.keys())) for colindex, h in enumerate(fields_order): ws['%s%s'%(get_column_letter(colindex+1),1)] = h for rowindex,c in enumerate(cards): for k in my_dict: my_dict[k]=None my_dict.update(c) del my_dict['values'] my_dict.update(**c['values']) for colindex,h in enumerate(fields_order): _v = my_dict[h] ws['%s%s' % (get_column_letter(colindex+1),rowindex+2)] = _v wb.save(filepath) from utils import alert from os.path import split alert('Exporting %s over'%split(filepath)[-1])
def prepare_print(self, dst): """Launch PDF preparation. First determine the best method for placing images""" from conf import CP from utils import alert if CP.getboolean('Print', 'AUTOCSV'): alert('Auto saving XLS deck') self.export_file(dst.replace('.pdf','.xlsx')) #Save last pdf file name & path self.record_last_file(dst) from printer import prepare_pdf from conf import card_format FFORMAT = (card_format.width, card_format.height) #3 possibilites # If FORCE_FOMART, just use it with auto layout placement if self.ids['force_format'].active: mode = 'FORCED' else: #Loop on all stack & check their size. #IF ALL have layout, launch print with layout #ELSE USE_LAYOUT = True sizes = set() WARNING = False for cs in self.ids.stack.children: if cs.layout: WARNING = True else: USE_LAYOUT = False if WARNING: from utils import alert alert('Can not have both with and without layout (%s was without)!'%cs) return if cs.template: if cs.tmplWidget: sizes.add(tuple(cs.tmplWidget.size)) else: from template import BGTemplate sizes.add(tuple(BGTemplate.FromFile(cs.template, use_cache=True)[-1].size)) elif cs.image: sizes.add(cs.image.size) else: sizes.add(FFORMAT) if USE_LAYOUT: mode = 'LAYOUT' else: if len(sizes) == 1: mode = sizes.pop() else: mode = 'BINCAN' #Now add the advancement gauge progress = self.ids['load_progress'] progress.value = 0 #ensure the stop button is reachable self.ids['stop_action'].width = 80 self.ids['stop_action'].text = 'Stop' self.cancel_action = False size, book = prepare_pdf(stack=self.ids['stack'], dst=dst, console_mode= False, mode = mode) progress.max = size from kivy.clock import Clock step_counter = range(size) #Now ensure that ALL stackpart from front & back are realized, while re-creating cache from template import templateList templateList.templates = dict() SS = book.stack[0] + book.stack[1] def inner(*args): step_counter.pop() progress.value += 1 #print 'remaninig index', len(book.index) book.generation_step() if (not step_counter) or self.cancel_action: self.cancel_action = False Clock.unschedule(inner) self.ids['stop_action'].width = 0 self.ids['stop_action'].text = '' progress.value = 0 book.save() book.show() from utils import alert alert('PDF Export completed') return False else: Clock.schedule_once(inner, 0.01) def realize_inner(*args): s = SS.pop() s.realise(withValue=True, use_cache=True) if SS: Clock.schedule_once(realize_inner, 0.01) else: Clock.schedule_once(inner,.1) if step_counter: Clock.schedule_once(inner, .1) return True
def triangle_layout(h,v): layout.custom_layout(h,v,180,clean_book_first=True) layout.export_phs() alert('Layout done')
def __init__(self, config, opts): utils.fix_output_encoding() self.config = config self.opts = opts self.port = self.config['general']['port'] self.webroot = self.config['general']['webroot'] self.comicArchiveList = [] #if len(self.config['general']['folder_list']) == 0: # logging.error("No folders on either command-line or config file. Quitting.") # sys.exit(-1) self.dm = DataManager() self.library = Library(self.dm.Session) if opts.reset or opts.reset_and_run: logging.info( "Deleting any existing database!") self.dm.delete() # quit on a standard reset if opts.reset: sys.exit(0) try: self.dm.create() except SchemaVersionException as e: msg = "Couldn't open database. Probably the schema has changed." logging.error(msg) utils.alert("Schema change", msg) sys.exit(-1) try: self.listen(self.port, no_keep_alive = True) except Exception as e: logging.error(e) msg = "Couldn't open socket on port {0}. (Maybe ComicStreamer is already running?) Quitting.".format(self.port) logging.error(msg) utils.alert("Port not available", msg) sys.exit(-1) logging.info( "Stream server running on port {0}...".format(self.port)) #http_server = tornado.httpserver.HTTPServer(self, no_keep_alive = True, ssl_options={ # "certfile": "server.crt", # "keyfile": "server.key", #}) #http_server.listen(port+1) self.version = csversion.version handlers = [ # Web Pages (self.webroot + r"/", MainHandler), (self.webroot + r"/(.*)\.html", GenericPageHandler), (self.webroot + r"/about", AboutPageHandler), (self.webroot + r"/control", ControlPageHandler), (self.webroot + r"/configure", ConfigPageHandler), (self.webroot + r"/log", LogPageHandler), (self.webroot + r"/comiclist/browse", ComicListBrowserHandler), (self.webroot + r"/folders/browse(/.*)*", FoldersBrowserHandler), (self.webroot + r"/entities/browse(/.*)*", EntitiesBrowserHandler), (self.webroot + r"/comic/([0-9]+)/reader", ReaderHandler), (self.webroot + r"/login", LoginHandler), # Data (self.webroot + r"/dbinfo", DBInfoAPIHandler), (self.webroot + r"/version", VersionAPIHandler), (self.webroot + r"/deleted", DeletedAPIHandler), (self.webroot + r"/comic/([0-9]+)", ComicAPIHandler), (self.webroot + r"/comiclist", ComicListAPIHandler), (self.webroot + r"/comic/([0-9]+)/page/([0-9]+|clear)/bookmark", ComicBookmarkAPIHandler ), (self.webroot + r"/comic/([0-9]+)/page/([0-9]+)", ComicPageAPIHandler ), (self.webroot + r"/comic/([0-9]+)/thumbnail", ThumbnailAPIHandler), (self.webroot + r"/comic/([0-9]+)/file", FileAPIHandler), (self.webroot + r"/entities(/.*)*", EntityAPIHandler), (self.webroot + r"/folders(/.*)*", FolderAPIHandler), (self.webroot + r"/command", CommandAPIHandler), (self.webroot + r"/scanstatus", ScanStatusAPIHandler), #(r'/favicon.ico', tornado.web.StaticFileHandler, {'path': os.path.join(AppFolders.appBase(), "static","images")}), (self.webroot + r'/.*', UnknownHandler), ] settings = dict( template_path=os.path.join(AppFolders.appBase(), "templates"), static_path=os.path.join(AppFolders.appBase(), "static"), static_url_prefix=self.webroot + "/static/", debug=True, #autoreload=False, login_url=self.webroot + "/login", cookie_secret=self.config['security']['cookie_secret'], xsrf_cookies=True, ) tornado.web.Application.__init__(self, handlers, **settings) if not opts.no_monitor: logging.debug("Going to scan the following folders:") for l in self.config['general']['folder_list']: logging.debug(u" {0}".format(repr(l))) self.monitor = Monitor(self.dm, self.config['general']['folder_list']) self.monitor.start() self.monitor.scan() self.bookmarker = Bookmarker(self.dm) self.bookmarker.start() if opts.launch_browser and self.config['general']['launch_browser']: if ((platform.system() == "Linux" and os.environ.has_key('DISPLAY')) or (platform.system() == "Darwin" and not os.environ.has_key('SSH_TTY')) or platform.system() == "Windows"): webbrowser.open("http://localhost:{0}".format(self.port), new=0)
def magic_fill(self): #alas, I have to linezarise in order to save layout for each widget from kivy.app import App from kivy.base import EventLoop from kivy.uix.label import Label from utils import alert print 'linearize deck', alert('Linearizing Deck') EventLoop.idle() App.get_running_app().root.ids.deck.linearize( progressbar=self.ids.progress) print 'done' init_pi = self.page_index from conf import page_format SIZE = page_format.width - page_format.left - page_format.right, page_format.height - page_format.top - page_format.bottom print 'calculating stack size' alert('Calculating Size') EventLoop.idle() #first create tuple of fg/bg fg, bg, dual_dict = self.get_duals() #fill current page with what you can def skey(item): w, h = item[0].stack.getSize() return w * h, -item[1] self.ids.progress.max = len(fg) self.ids.progress.value = 1 from kivy.clock import Clock alert('Sorting Layouts by size') EventLoop.idle() print 'sorting layout' fg = sorted(fg, key=skey, reverse=True) def inner(*args): from utils import alert if not fg: Clock.unschedule(inner) from utils import alert alert('Book created') self.export_phs() from kivy.uix.widget import WidgetException try: self.set_page("Page %d" % (init_pi + 1)) except WidgetException, Err: print 'FATAL: Error in Setting page ???', Err return alert('Organizing Layout on Page %d' % (len(self.pages))) EventLoop.idle() print 'Organizing Layout on Page %d' % (len(self.pages)) sorted_phs = fg[:] added_ones = list() PAGE_LAYOUT = BinCanNode(0, 0, SIZE[0], SIZE[1]) for f, i in sorted_phs: layout = PAGE_LAYOUT.find(f, *f.stack.getSize()) if not layout: continue del fg[fg.index((f, i))] added_ones.append(f) self.ids.progress.value += 1 ph = self.add_ph() self.set_ph_img(ph, f, use_img_size=True) X, Y = layout.x, layout.y #Rebase properly ph.x = X + page_format.left ph.top = page_format.height - page_format.top - Y ph.angle = layout.retry.get(ph, 0) * 90 ph.layout = [ ph.x, ph.y, ph.width, ph.height, ph.angle, self.page_index ] if not added_ones: #We could NOT feet any of the pictures: raise error: print 'Error: not pictures could be fit inside one page' from utils import alert alert('No more pictures can fit on page') Clock.unschedule(inner) return if dual_dict: #First page is done, create dual mp = self.add_mirror_page() for ph, b in zip(reversed(mp.children), [dual_dict[f] for f in added_ones]): #print 'settings back for', ph, b, b.stack.source self.set_ph_img( ph, b, use_img_size=False ) # Is it interesting: this will force that front & back have exact same size, depending on front size #Add a new page, only if necessay: if fg: self.add_page() #now loop on remaining fg/bg Clock.schedule_once(inner, .1)