예제 #1
0
def play(url, title, player=None):
    '''Play'''
    if player is None:
        player = get_default_player()
    
    print "Playing %s" % title
    option = ""
    try:
        if os.name == "nt": 
            os.filestart(url)
            
        elif os.name == "posix":
            if "http://" not in url: #if it's not an url
                if not os.path.exists(url): #if it's not a file
                    print "Not a valid URL or file"
                    raise KeyboardInterrupt
                else:
                    url = url.replace('"', '\"')

            if not player:
                print "Player not found!"
                raise KeyboardInterrupt
            
            if player == "totem": option = "--enqueue"
            
            Popen((player, option, url))
    except KeyboardInterrupt:
        print '\r'
        sys.exit()
예제 #2
0
 def verTutorial(self):
     filename = os.path.join(os.path.dirname(__file__),"tutorial.pdf")
     #print("---"+filename+"---")
     if os.name == "posix":
         os.system("/usr/bin/xdg-open " + filename) 
     else :
         os.filestart(filename)
예제 #3
0
 def openFileByDefaultApplication(self, file):
     if os.name == "nt":
         os.filestart(file)
     elif os.name == "posix":
         if os.uname()[0] == "Linux":
             os.system("/usr/bin/xdg-open " + self.convertFilename(file))
         elif os.uname()[0] == "Darwin":
             os.system("open "+file)
     print os.uname()[0]
예제 #4
0
def saveFileAndOpenInDefaultApp(filename, contents):
    if not contents:
        return
    
    f = open(filename, "w")
    f.write(contents)
    f.close()
    if os.name == 'nt':
        os.filestart(filename)
    elif os.name == 'posix':
        os.system('/usr/bin/xdg-open ' + filename)  
예제 #5
0
def saveFileAndOpenInDefaultApp(filename, contents):
    if not contents:
        return

    f = open(filename, "w")
    f.write(contents)
    f.close()
    if os.name == 'nt':
        os.filestart(filename)
    elif os.name == 'posix':
        os.system('/usr/bin/xdg-open ' + filename)
예제 #6
0
    def on_button_print_clicked(self, widget):
        '''
        Print the book list we are viewing to pdf then open the default pdf viewer.
        TODO: Auto width columns
        This will likely be system specific
        '''
        try:
            from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT
            from reportlab.lib.pagesizes import A4
            from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle,KeepTogether
            from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
            from reportlab.lib.units import mm

        except ImportError as e:
            messages.pop_info(e)
            return
        filename = "booklist.pdf"
        doc = SimpleDocTemplate(filename,pagesize=A4,
                                rightMargin=10,leftMargin=20,
                                topMargin=40,bottomMargin=18)
        Story=[]
        data = []
        styles=getSampleStyleSheet()
        text = Paragraph("long line",styles['Normal'])
        styles.add(ParagraphStyle(name='Justify', alignment = TA_LEFT))
        model = self.booklist
        myiter = model.get_iter_first()
        if myiter is not None:
            while str(myiter) != 'None':
                row = []
                if myiter is not None:
                    row.append(Paragraph(model.get_value(myiter, 9), styles["Normal"]))
                    row.append(Paragraph(model.get_value(myiter, 1), styles["Normal"]))
                    row.append(Paragraph(model.get_value(myiter, 2), styles["Normal"]))
                    myiter = model.iter_next(myiter)
                data.append(row)
            t = Table(data,[100, 180, 200]) # Values are cell widths
            t.hAlign='LEFT' # Move WHOLE TABLE to the left, defaults to CENTRE
            t.setStyle(TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')])) # Apples to CELLS
            Story.append(t)
            doc.build(Story)

        # Open a reader for viewing and printing
        if os.name == "nt": # Windoze.  Not tested, I don't have Windoze :)
            os.filestart(filename)
        elif os.name == "posix": # Linux
            os.system("/usr/bin/xdg-open " + filename)
예제 #7
0
def showFile(pdf):
    if os.name == 'nt':
        os.filestart(pdf)
    elif os.name == 'posix':
        os.system('/usr/bin/xdg-open ' + pdf)
예제 #8
0
def showFile(html):
    if os.name == 'nt':
        os.filestart(html)
    elif os.name == 'posix':
        os.system('/usr/bin/xdg-open ' + html)  
예제 #9
0
class borrowers():
    def __init__(self, bid=0):
        builder = gtk.Builder()
        self.gladefile = os.path.join(os.path.dirname(__file__),
                                      "ui/borrower_dialog.glade")
        builder.add_from_file(self.gladefile)
        self.window = builder.get_object("dialog1")
        self.name = builder.get_object("entry1")
        self.contact = builder.get_object("entry2")
        self.notes = builder.get_object("entry3")
        self.status = builder.get_object("status_label")
        self.button_cancel = builder.get_object("button_cancel")
        builder.connect_signals(self)
        self.bid = bid
        logging.info(bid)
        self.populate()

    def run(self):
        self.window.run()
        self.window.destroy()

    def populate(self):
        '''If we are passed a bid > 0 populate the dialog.

    '''
        db_query = sql()
        logging.info(self.bid)
        if self.bid > 0:
            result = db_query.get_one_borrower(self.bid)
            logging.info(result)
            self.name.set_text(result["name"])
            self.contact.set_text(result["contact"])
            self.notes.set_text(str(result["notes"]))

    def on_button_add_clicked(self, widget):
        ''' Add a borrower to the database.

    '''
        db_query = sql()
        logging.info("Added a borrower")
        logging.info(self.name.get_text())
        if len(self.name.get_text()) > 0:
            if self.bid == 0:
                db_query.add_new_borrower(self.name.get_text(),
                                          self.contact.get_text(),
                                          self.notes.get_text())
            else:
                db_query.update_borrower(self.name.get_text(),
                                         self.contact.get_text(),
                                         self.notes.get_text(), self.bid)
            self.status.set_text("Added a borrower.")
        else:
            logging.info("Nothing to add.")
            self.status.set_text("Nothing to add.")
        self.button_cancel.set_label(_("CLOSE"))

    def on_button_print_clicked(self, widget):
        ''' Create a pdf of the current users.  Optionally open the default
    reader for viewing and printing of the document.

    '''
        db_query = sql()
        try:
            import time, os
            from reportlab.lib.enums import TA_LEFT
            from reportlab.lib.pagesizes import A4
            from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image
            from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
            from reportlab.lib.units import mm
        except ImportError, e:
            print e
            messages.pop_info(e)
            return

        filename = "borrowers.pdf"
        doc = SimpleDocTemplate(filename,
                                pagesize=A4,
                                rightMargin=72,
                                leftMargin=72,
                                topMargin=72,
                                bottomMargin=18)
        Story = []
        styles = getSampleStyleSheet()
        styles.add(ParagraphStyle(name='Justify', alignment=TA_LEFT))
        Story.append(
            Paragraph("Book Borrowers and their Books", styles["Normal"]))
        Story.append(Spacer(1, 12))

        ptext = ''
        Story.append(Paragraph(ptext, styles["Justify"]))
        Story.append(Spacer(1, 12))
        # Get the data
        db_query.get_borrowers_borrowed_books()
        for row in result:
            ptext = row[2] + " -- " + row[1] + " -- " + row[
                0] + " -- Borrowed: " + row[3].strftime('%Y %b %d')
            Story.append(Paragraph(ptext, styles["Normal"]))

        doc.build(Story)

        # Open a reader
        if os.name == "nt":  # Windoze
            os.filestart(filename)
        elif os.name == "posix":  # Linux
            os.system("/usr/bin/xdg-open " + filename)
예제 #10
0
    os.system('git log -1 >> %s' % header)
    os.system(r'echo \\end{verbatim} >> %s' % header)

    os.system(r'echo \\hrule >> %s' % header)

    os.system(r'echo \\begin{verbatim} >> %s' % header)
    os.system('echo To: %s >> %s' % (commit2, header))
    shutil.copytree(basedir, dir2)
    os.chdir(dir2)
    os.system('git checkout %s' % commit2)
    os.system('git log -1 >> %s' % header)
    os.system(r'echo \\end{verbatim} >> %s' % header)

    (hdl, header_name) = split(header)
    os.system('latexdiff --flatten %s %s > %s' % (join(dir1, texin), join(dir2, texin), texout))
    #os.system(r"sed -i 's/$/\/\/\//g' %s " % header)
    shutil.copy(header, join(dir2, '%s.tex' % header_name))
    os.system(r"sed -i 's/begin{document}/begin{document}\\include{%s}/g' %s " % (header_name, texout))
    os.system('pdflatex %s' % texout)
    shutil.copy(texout, basedir)
    shutil.copy(pdf, basedir)
    os.chdir(basedir)
    shutil.rmtree(options.tmp_path, ignore_errors = True)
    os.remove(header)
    if os.name == 'nt':
        os.filestart(pdf)
    elif os.name == 'posix':
        os.system('/usr/bin/xdg-open %s' % pdf)
    else:
        os.system('open %s' % pdf)
예제 #11
0
class Librarian:
    '''
  A simple book tracking program that uses a webcam to scan the barcodes
  to add books.  It also tracks borrowers and can include your e-books
  in the listings.  It doesn't track the "borrowing" of e-books. :)
  '''
    def __init__(self):
        print(_("Version: "), version.__version__)
        builder = gtk.Builder()
        self.gladefile = os.path.join(os.path.dirname(__file__),
                                      "ui/librarian.glade")
        builder.add_from_file(self.gladefile)
        builder.connect_signals(self)

        self.treeview = builder.get_object('treeview1')
        self.booklist = builder.get_object("liststore1")
        self.status1 = builder.get_object("status1")

        column = gtk.TreeViewColumn(_('Medium'),
                                    gtk.CellRendererText(),
                                    text=9)
        column.set_clickable(True)
        column.set_resizable(True)
        column.set_sort_column_id(9)
        column.sizing = gtk.TREE_VIEW_COLUMN_AUTOSIZE
        self.treeview.append_column(column)

        column = gtk.TreeViewColumn(_('Author'),
                                    gtk.CellRendererText(),
                                    text=1)
        column.set_clickable(True)
        column.set_sort_indicator(True)
        column.set_resizable(True)
        column.set_visible(True)
        column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
        column.set_sort_column_id(1)
        self.treeview.append_column(column)

        column = gtk.TreeViewColumn(_('Title'), gtk.CellRendererText(), text=2)
        column.set_clickable(True)
        column.set_resizable(True)
        column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
        column.set_sort_column_id(2)
        self.treeview.append_column(column)

        column = gtk.TreeViewColumn(_('Rating'),
                                    gtk.CellRendererText(),
                                    text=3)
        column.set_clickable(True)
        column.set_resizable(True)
        column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
        column.set_sort_column_id(3)
        self.treeview.append_column(column)
        self.status1.set_text("Version:" + version.__version__)

        self.search_string = builder.get_object("entry_search")
        self.booklist.set_sort_column_id(1, gtk.SORT_ASCENDING)

        self.get_book_list(1)
        window = builder.get_object("window1")
        window.show_all()

    def export_csv(self):
        '''
    Export the entire database to CSV when called from the command line.
    '''
        db_query = sql()
        result, numrows = db_query.get_all_books()
        with open('books.csv', 'wb') as csvfile:
            csvwriter = csv.writer(
                csvfile, delimiter=',',
                quotechar='"')  #, quoting=csv.QUOTE_MINIMAL)
            for row in result:
                csvwriter.writerow([row['mtype'], row['author'], row['title']])
        return

    def on_button_print_clicked(self, widget):
        '''
    Print the book list we are viewing to pdf then open the default pdf viewer.
    TODO: Auto width columns
    This will likely be system specific
    '''
        try:
            from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT
            from reportlab.lib.pagesizes import A4
            from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Image, Table, TableStyle, KeepTogether
            from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
            from reportlab.lib.units import mm

        except ImportError, e:
            messages.pop_info(e)
            return
        filename = "booklist.pdf"
        doc = SimpleDocTemplate(filename,
                                pagesize=A4,
                                rightMargin=10,
                                leftMargin=20,
                                topMargin=40,
                                bottomMargin=18)
        Story = []
        data = []
        styles = getSampleStyleSheet()
        text = Paragraph("long line", styles['Normal'])
        styles.add(ParagraphStyle(name='Justify', alignment=TA_LEFT))
        model = self.booklist
        myiter = model.get_iter_first()
        if myiter is not None:
            while str(myiter) != 'None':
                row = []
                if myiter is not None:
                    row.append(
                        Paragraph(model.get_value(myiter, 9),
                                  styles["Normal"]))
                    row.append(
                        Paragraph(model.get_value(myiter, 1),
                                  styles["Normal"]))
                    row.append(
                        Paragraph(model.get_value(myiter, 2),
                                  styles["Normal"]))
                    myiter = model.iter_next(myiter)
                data.append(row)
            t = Table(data, [100, 180, 200])  # Values are cell widths
            t.hAlign = 'LEFT'  # Move WHOLE TABLE to the left, defaults to CENTRE
            t.setStyle(TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')
                                   ]))  # Apples to CELLS
            Story.append(t)
            doc.build(Story)

        # Open a reader for viewing and printing
        if os.name == "nt":  # Windoze.  Not tested, I don't have Windoze :)
            os.filestart(filename)
        elif os.name == "posix":  # Linux
            os.system("/usr/bin/xdg-open " + filename)
예제 #12
0
 def openManual(self):
     if os.name == "nt":
         os.filestart(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "manual.pdf"))
     elif os.name == "posix":
         os.system("xdg-open " + os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "manual.pdf"))
예제 #13
0
def showFile(pdf):
    if os.name == "nt":
        os.filestart(pdf)
    elif os.name == "posix":
        os.system("/usr/bin/xdg-open " + pdf)