44import time
55import sys
66import os
7+
78try :
89 import pythoncom
910except ImportError :
2021__version__ = '0.2.2'
2122__author__ = 'kingname'
2223
24+ from config import read_config
2325
24- class MarkrdownPicPicker (object ):
2526
27+ class MarkrdownPicPicker (object ):
2628 CONFIG_PATH = 'config.ini'
2729
2830 def __init__ (self , link_only = False ):
@@ -45,8 +47,17 @@ def __init__(self, link_only=False):
4547 elif self .method == 'global_listen' :
4648 self .keyboard_listen ()
4749
50+ def _to_string (self ):
51+ """
52+ To test if the config reading is ok
53+ :return: None
54+ """
55+ print ("folder" , self .picture_folder )
56+ print ("suffix" , self .picture_suffix )
57+ print ("picture_bed" , self .picture_bed )
58+
4859 def init_environment (self ):
49- self .read_config ()
60+ self .__dict__ . update ( read_config () )
5061 if not self .method \
5162 or not self .picture_folder \
5263 or not self .picture_suffix \
@@ -55,28 +66,8 @@ def init_environment(self):
5566 exit ()
5667 if not os .path .exists (self .picture_folder ):
5768 os .makedirs (self .picture_folder )
58-
59- def read_config (self ):
60- if getattr (sys , 'frozen' , None ):
61- config_path = os .path .join (os .path .dirname (sys .executable ), self .CONFIG_PATH )
62- else :
63- config_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), self .CONFIG_PATH )
64- configs = ConfigParser ()
65- if not os .path .exists (config_path ):
66- print ('can not find the config.ini, exit' )
67- exit ()
68- configs .read (config_path )
69- self .method = configs ['basic' ].get ('run_method' , '' )
70- self .picture_folder = configs ['basic' ].get ('picture_folder' , '' )
71- self .picture_suffix = configs ['basic' ].get ('picture_suffix' , '' )
72- self .picture_bed = configs ['basic' ].get ('picture_bed' , '' )
73-
7469 if self .picture_bed :
75- self .uploader = QiniuUploader (configs ['qiniu' ])
76-
77- if self .method == 'global_listen' :
78- self .short_key_one = configs ['global_listen' ]['short_key_one' ]
79- self .short_key_two = configs ['global_listen' ]['short_key_two' ]
70+ self .uploader = QiniuUploader (self .uploader_info )
8071
8172 def keyboard_listen (self ):
8273 if not pythoncom or not pyHook :
@@ -125,6 +116,7 @@ def save_picture(self):
125116 print ('get picture from clipboard error because: {}' .format (e ))
126117 return '' , ''
127118
119+
128120if __name__ == '__main__' :
129121 arg = sys .argv [- 1 ]
130122 if arg == '-linkonly' :
0 commit comments