Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
gtklib: Add Open argument to native save dialog class
Seemed less bad than copying the entire dialog for a two line difference. I don't care much for the capitalized options, but it's too late to fix them all now.
## miscellaneous PyGTK classes and functions for TortoiseHg## Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>#importosimportsysimportgtkimportgobjectimportpangofromthgutil.i18nimport_fromthgutilimportpaths,hglibfromhggtkimporthgtkdefset_tortoise_icon(window,thgicon):ico=paths.get_tortoise_icon(thgicon)ifico:window.set_icon_from_file(ico)defget_thg_modifier():ifsys.platform=='darwin':return'<Mod1>'else:return'<Control>'defset_tortoise_keys(window):'Set default TortoiseHg keyboard accelerators'ifsys.platform=='darwin':mask=gtk.accelerator_get_default_mod_mask()mask|=gtk.gdk.MOD1_MASK;gtk.accelerator_set_default_mod_mask(mask)mod=get_thg_modifier()accelgroup=gtk.AccelGroup()window.add_accel_group(accelgroup)key,modifier=gtk.accelerator_parse(mod+'w')window.add_accelerator('thg-close',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)key,modifier=gtk.accelerator_parse(mod+'q')window.add_accelerator('thg-exit',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)key,modifier=gtk.accelerator_parse('F5')window.add_accelerator('thg-refresh',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)key,modifier=gtk.accelerator_parse(mod+'Return')window.add_accelerator('thg-accept',accelgroup,key,modifier,gtk.ACCEL_VISIBLE)# connect ctrl-w and ctrl-q to every windowwindow.connect('thg-close',thgclose)window.connect('thg-exit',thgexit)defthgexit(window):ifthgclose(window):gobject.idle_add(hgtk.thgexit,window)defthgclose(window):ifhasattr(window,'should_live'):ifwindow.should_live():returnFalsewindow.destroy()returnTrueclassStatusBar(gtk.HBox):def__init__(self,extra=None):gtk.HBox.__init__(self)self.pbar=gtk.ProgressBar()self.sttext=gtk.Label("")self.sttext.set_ellipsize(pango.ELLIPSIZE_END)self.sttext.set_alignment(0,0.5)self.pbox=gtk.HBox()self.pbox.pack_start(gtk.VSeparator(),False,False)self.pbox.pack_start(self.pbar,False,False)self.pack_start(self.sttext,padding=1)ifextra:self.pack_end(extra,False,False)self.pack_end(self.pbox,False,False,padding=1)self.pbox.set_child_visible(False)self.show_all()def_pulse_timer(self,now=False):self.pbar.pulse()returnTruedefbegin(self,msg=_('Running'),timeout=100):self.pbox.set_child_visible(True)self.pbox.map()self.set_status_text(msg)self._timeout_event=gobject.timeout_add(timeout,self._pulse_timer)defend(self,msg=_('Done'),unmap=True):gobject.source_remove(self._timeout_event)self.set_status_text(msg)ifunmap:self.pbox.unmap()else:self.pbar.set_fraction(1.0)defset_status_text(self,msg):self.sttext.set_text(str(msg))defset_pulse_step(self,val):self.pbar.set_pulse_step(val)classMessageDialog(gtk.Dialog):button_map={gtk.BUTTONS_NONE:None,gtk.BUTTONS_OK:(gtk.STOCK_OK,gtk.RESPONSE_OK),gtk.BUTTONS_CLOSE:(gtk.STOCK_CLOSE,gtk.RESPONSE_CLOSE),gtk.BUTTONS_CANCEL:(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL),gtk.BUTTONS_YES_NO:(gtk.STOCK_YES,gtk.RESPONSE_YES,gtk.STOCK_NO,gtk.RESPONSE_NO),gtk.BUTTONS_OK_CANCEL:(gtk.STOCK_OK,gtk.RESPONSE_OK,gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL),}image_map={gtk.MESSAGE_INFO:gtk.STOCK_DIALOG_INFO,gtk.MESSAGE_WARNING:gtk.STOCK_DIALOG_WARNING,gtk.MESSAGE_QUESTION:gtk.STOCK_DIALOG_QUESTION,gtk.MESSAGE_ERROR:gtk.STOCK_DIALOG_ERROR,}def__init__(self,parent=None,flags=0,type=gtk.MESSAGE_INFO,buttons=gtk.BUTTONS_NONE,message_format=None):gtk.Dialog.__init__(self,parent=parent,flags=flags|gtk.DIALOG_NO_SEPARATOR,buttons=MessageDialog.button_map[buttons])self.set_resizable(False)hbox=gtk.HBox()self._image_frame=gtk.Frame()self._image_frame.set_shadow_type(gtk.SHADOW_NONE)self._image=gtk.Image()self._image.set_from_stock(MessageDialog.image_map[type],gtk.ICON_SIZE_DIALOG)self._image_frame.add(self._image)hbox.pack_start(self._image_frame,padding=5)lblbox=gtk.VBox(spacing=10)self._primary=gtk.Label("")self._primary.set_alignment(0.0,0.5)self._primary.set_line_wrap(True)lblbox.pack_start(self._primary)self._secondary=gtk.Label()lblbox.pack_end(self._secondary)self._secondary.set_line_wrap(True)hbox.pack_start(lblbox,padding=5)self.vbox.pack_start(hbox,False,False,10)self.show_all()defset_markup(self,s):self._primary.set_markup(s)defformat_secondary_markup(self,message_format):self._secondary.set_markup(message_format)defformat_secondary_text(self,message_format):self._secondary.set_text(message_format)defset_image(self,image):self._image_frame.remove(self._image)self._image=imageself._image_frame.add(self._image)self._image.show()classNativeSaveFileDialogWrapper: """Wrap the windows file dialog, or display default gtk dialog if
that isn't available"""
def __init__(self, InitialDir = None, Title = _('Save File'),
- Filter = (_("All files"), "*.*"), FilterIndex = 1, FileName = ''):
+ Filter = (_("All files"), "*.*"), FilterIndex = 1,
+ FileName = '', Open=False):
if InitialDir == None:
InitialDir = os.path.expanduser("~")
self.InitialDir = InitialDir
self.FileName=FileName self.Title = Title
self.Filter = Filter
self.FilterIndex = FilterIndex
+ self.Open = Open def run(self):
"""run the file dialog, either return a file name, or False if
the user aborted the dialog"""try:importwin32gui,win32con,pywintypesreturnself.runWindows()exceptImportError:returnself.runCompatible()defrunWindows(self):importwin32gui,win32con,pywintypes cwd = os.getcwd()
fname = None
try:
- fname, customfilter, flags=win32gui.GetSaveFileNameW(- InitialDir=self.InitialDir,
- Flags=win32con.OFN_EXPLORER,
- File=self.FileName,
- DefExt=None,
- Title=hglib.fromutf(self.Title),
- Filter= hglib.fromutf('\0'.join(self.Filter)+'\0'),
- CustomFilter=None,
- FilterIndex=self.FilterIndex)
+ if self.Open:+ fname, customfilter, flags=win32gui.GetOpenFileNameW(+ InitialDir=self.InitialDir,
+Flags=win32con.OFN_EXPLORER,
+File=self.FileName,
+DefExt=None,
+Title=hglib.fromutf(self.Title),
+ Filter= hglib.fromutf('\0'.join(self.Filter)+'\0'),
+CustomFilter=None,
+FilterIndex=self.FilterIndex)
+ else:+ fname, customfilter, flags=win32gui.GetSaveFileNameW(+ InitialDir=self.InitialDir,+ Flags=win32con.OFN_EXPLORER,+ File=self.FileName,+ DefExt=None,+ Title=hglib.fromutf(self.Title),+ Filter= hglib.fromutf('\0'.join(self.Filter)+'\0'),+ CustomFilter=None,+ FilterIndex=self.FilterIndex) if fname:
fname = os.path.abspath(fname)
except pywintypes.error:
passos.chdir(cwd) return fname
def runCompatible(self):
- file_save = gtk.FileChooserDialog(self.Title, None,
- gtk.FILE_CHOOSER_ACTION_SAVE,
+ if self.Open:+ action = gtk.FILE_CHOOSER_ACTION_OPEN+ else:+ action = gtk.FILE_CHOOSER_ACTION_SAVE+ file_save = gtk.FileChooserDialog(self.Title, None, action,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
file_save.set_do_overwrite_confirmation(True)
file_save.set_default_response(gtk.RESPONSE_OK)file_save.set_current_folder(self.InitialDir)file_save.set_current_name(self.FileName)forname,patternindict(self.Filter).iteritems():fi=gtk.FileFilter()fi.set_name(name)fi.add_pattern(pattern)file_save.add_filter(fi)iffile_save.run()==gtk.RESPONSE_OK:result=file_save.get_filename();else:result=Falsefile_save.destroy()returnresultclassNativeFolderSelectDialog:"""Wrap the windows folder dialog, or display default gtk dialog if that isn't available"""def__init__(self,initial=None,title=_('Select Folder')):self.initial=initialoros.getcwd()self.title=titledefrun(self):"""run the file dialog, either return a file name, or False if the user aborted the dialog"""try:importwin32com,win32gui,pywintypesreturnself.runWindows()exceptImportError,e:returnself.runCompatible()defrunWindows(self):fromwin32com.shellimportshell,shellconimportwin32gui,pywintypesdefBrowseCallbackProc(hwnd,msg,lp,data):ifmsg==shellcon.BFFM_INITIALIZED:win32gui.SendMessage(hwnd,shellcon.BFFM_SETSELECTION,1,data)elifmsg==shellcon.BFFM_SELCHANGED:# Set the status text of the# For this message, 'lp' is the address of the PIDL.pidl=shell.AddressAsPIDL(lp)try:path=shell.SHGetPathFromIDList(pidl)win32gui.SendMessage(hwnd,shellcon.BFFM_SETSTATUSTEXT,0,path)exceptshell.error:# No path for this PIDLpassfname=Nonetry:flags=shellcon.BIF_EDITBOX|0x40#shellcon.BIF_NEWDIALOGSTYLEpidl,_,_=shell.SHBrowseForFolder(0,None,hglib.fromutf(self.title),flags,BrowseCallbackProc,# callback functionself.initial)# 'data' param for the callbackifpidl:fname=hglib.toutf(shell.SHGetPathFromIDList(pidl))except(pywintypes.error,pywintypes.com_error):passreturnfnamedefrunCompatible(self):dialog=gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))dialog.set_default_response(gtk.RESPONSE_OK)response=dialog.run()fname=dialog.get_filename()dialog.destroy()ifresponse==gtk.RESPONSE_OK:returnfnamereturnNone
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.